1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
6 #define CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
8 #include "base/basictypes.h"
9 #include "cc/base/cc_export.h"
10 #include "skia/ext/refptr.h"
11 // TODO(robertphillips): change this to "class SkBaseDevice;"
12 #include "third_party/skia/include/core/SkDevice.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
15 #include "ui/gfx/vector2d.h"
22 class SoftwareFrameData
;
24 // This is a "tear-off" class providing software drawing support to
25 // OutputSurface, such as to a platform-provided window framebuffer.
26 class CC_EXPORT SoftwareOutputDevice
{
28 SoftwareOutputDevice();
29 virtual ~SoftwareOutputDevice();
31 // Discards any pre-existing backing buffers and allocates memory for a
32 // software device of |size|. This must be called before the
33 // |SoftwareOutputDevice| can be used in other ways.
34 virtual void Resize(gfx::Size size
);
36 // Called on BeginDrawingFrame. The compositor will draw into the returned
37 // SkCanvas. The |SoftwareOutputDevice| implementation needs to provide a
38 // valid SkCanvas of at least size |damage_rect|. This class retains ownership
40 virtual SkCanvas
* BeginPaint(gfx::Rect damage_rect
);
42 // Called on FinishDrawingFrame. The compositor will no longer mutate the the
43 // SkCanvas instance returned by |BeginPaint| and should discard any reference
44 // that it holds to it.
45 virtual void EndPaint(SoftwareFrameData
* frame_data
);
47 // Copies pixels inside |rect| from the current software framebuffer to
48 // |output|. Fails if there is no current softwareframebuffer.
49 virtual void CopyToBitmap(gfx::Rect rect
, SkBitmap
* output
);
51 // Blit the pixel content of the SoftwareOutputDevice by |delta| with the
52 // write clipped to |clip_rect|.
53 virtual void Scroll(gfx::Vector2d delta
,
56 // Discard the backing buffer in the surface provided by this instance.
57 virtual void DiscardBackbuffer() {}
59 // Ensures that there is a backing buffer available on this instance.
60 virtual void EnsureBackbuffer() {}
62 // TODO(skaslev) Remove this after UberCompositor lands.
63 // Called in response to receiving a SwapBuffersAck. At this point, software
64 // frame identified by id can be reused or discarded as it is no longer being
66 virtual void ReclaimSoftwareFrame(unsigned id
);
69 gfx::Size viewport_size_
;
70 gfx::Rect damage_rect_
;
71 skia::RefPtr
<SkBaseDevice
> device_
;
72 skia::RefPtr
<SkCanvas
> canvas_
;
75 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDevice
);
80 #endif // CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_