Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / cc / output / software_output_device.h
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.
4
5 #ifndef CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
6 #define CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "cc/base/cc_export.h"
11 #include "skia/ext/refptr.h"
12 // TODO(robertphillips): change this to "class SkBaseDevice;"
13 #include "third_party/skia/include/core/SkDevice.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/size.h"
16 #include "ui/gfx/vector2d.h"
17
18 class SkBitmap;
19 class SkCanvas;
20
21 namespace gfx {
22 class VSyncProvider;
23 }
24
25 namespace cc {
26
27 class SoftwareFrameData;
28
29 // This is a "tear-off" class providing software drawing support to
30 // OutputSurface, such as to a platform-provided window framebuffer.
31 class CC_EXPORT SoftwareOutputDevice {
32  public:
33   SoftwareOutputDevice();
34   virtual ~SoftwareOutputDevice();
35
36   // Discards any pre-existing backing buffers and allocates memory for a
37   // software device of |size|. This must be called before the
38   // |SoftwareOutputDevice| can be used in other ways.
39   virtual void Resize(const gfx::Size& size);
40
41   // Called on BeginDrawingFrame. The compositor will draw into the returned
42   // SkCanvas. The |SoftwareOutputDevice| implementation needs to provide a
43   // valid SkCanvas of at least size |damage_rect|. This class retains ownership
44   // of the SkCanvas.
45   virtual SkCanvas* BeginPaint(const gfx::Rect& damage_rect);
46
47   // Called on FinishDrawingFrame. The compositor will no longer mutate the the
48   // SkCanvas instance returned by |BeginPaint| and should discard any reference
49   // that it holds to it.
50   virtual void EndPaint(SoftwareFrameData* frame_data);
51
52   // Copies pixels inside |rect| from the current software framebuffer to
53   // |output|. Fails if there is no current softwareframebuffer.
54   virtual void CopyToBitmap(const gfx::Rect& rect, SkBitmap* output);
55
56   // Blit the pixel content of the SoftwareOutputDevice by |delta| with the
57   // write clipped to |clip_rect|.
58   virtual void Scroll(const gfx::Vector2d& delta, const gfx::Rect& clip_rect);
59
60   // Discard the backing buffer in the surface provided by this instance.
61   virtual void DiscardBackbuffer() {}
62
63   // Ensures that there is a backing buffer available on this instance.
64   virtual void EnsureBackbuffer() {}
65
66   // TODO(skaslev) Remove this after UberCompositor lands.
67   // Called in response to receiving a SwapBuffersAck. At this point, software
68   // frame identified by id can be reused or discarded as it is no longer being
69   // displayed.
70   virtual void ReclaimSoftwareFrame(unsigned id);
71
72   // VSyncProvider used to update the timer used to schedule draws with the
73   // hardware vsync. Return NULL if a provider doesn't exist.
74   virtual gfx::VSyncProvider* GetVSyncProvider();
75
76  protected:
77   gfx::Size viewport_size_;
78   gfx::Rect damage_rect_;
79   skia::RefPtr<SkBaseDevice> device_;
80   skia::RefPtr<SkCanvas> canvas_;
81   scoped_ptr<gfx::VSyncProvider> vsync_provider_;
82
83  private:
84   DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDevice);
85 };
86
87 }  // namespace cc
88
89 #endif  // CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_