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(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(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(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(gfx::Vector2d delta, 59 gfx::Rect clip_rect); 60 61 // Discard the backing buffer in the surface provided by this instance. DiscardBackbuffer()62 virtual void DiscardBackbuffer() {} 63 64 // Ensures that there is a backing buffer available on this instance. EnsureBackbuffer()65 virtual void EnsureBackbuffer() {} 66 67 // TODO(skaslev) Remove this after UberCompositor lands. 68 // Called in response to receiving a SwapBuffersAck. At this point, software 69 // frame identified by id can be reused or discarded as it is no longer being 70 // displayed. 71 virtual void ReclaimSoftwareFrame(unsigned id); 72 73 // VSyncProvider used to update the timer used to schedule draws with the 74 // hardware vsync. Return NULL if a provider doesn't exist. 75 virtual gfx::VSyncProvider* GetVSyncProvider(); 76 77 protected: 78 gfx::Size viewport_size_; 79 gfx::Rect damage_rect_; 80 skia::RefPtr<SkBaseDevice> device_; 81 skia::RefPtr<SkCanvas> canvas_; 82 scoped_ptr<gfx::VSyncProvider> vsync_provider_; 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDevice); 86 }; 87 88 } // namespace cc 89 90 #endif // CC_OUTPUT_SOFTWARE_OUTPUT_DEVICE_H_ 91