OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 PlatformCanvasMac_h | |
6 #define PlatformCanvasMac_h | |
7 | |
8 #include "PlatformDeviceMac.h" | |
9 | |
10 #include "SkCanvas.h" | |
11 | |
12 namespace gfx { | |
13 | |
14 // This class is a specialization of the regular SkCanvas that is designed to | |
15 // work with a gfx::PlatformDevice to manage platform-specific drawing. It | |
16 // allows using both Skia operations and platform-specific operations. | |
17 class PlatformCanvasMac : public SkCanvas { | |
18 public: | |
19 // Set is_opaque if you are going to erase the bitmap and not use | |
20 // tranparency: this will enable some optimizations. The shared_section | |
21 // parameter is passed to gfx::PlatformDevice::create. See it for details. | |
22 // | |
23 // If you use the version with no arguments, you MUST call initialize() | |
24 PlatformCanvasMac(); | |
25 PlatformCanvasMac(int width, int height, bool is_opaque); | |
26 PlatformCanvasMac(int width, int height, bool is_opaque, CGContextRef context)
; | |
27 virtual ~PlatformCanvasMac(); | |
28 | |
29 // For two-part init, call if you use the no-argument constructor above | |
30 bool initialize(int width, int height, bool is_opaque); | |
31 | |
32 // These calls should surround calls to platform drawing routines. The CG | |
33 // context returned by beginPlatformPaint is the one that can be used to | |
34 // draw into. | |
35 // Call endPlatformPaint when you are done and want to use Skia operations | |
36 // again; this will synchronize the bitmap. | |
37 virtual CGContextRef beginPlatformPaint(); | |
38 virtual void endPlatformPaint(); | |
39 | |
40 // Returns the platform device pointer of the topmost rect with a non-empty | |
41 // clip. In practice, this is usually either the top layer or nothing, since | |
42 // we usually set the clip to new layers when we make them. | |
43 // | |
44 // If there is no layer that is not all clipped out, this will return a | |
45 // dummy device so callers do not have to check. If you are concerned about | |
46 // performance, check the clip before doing any painting. | |
47 // | |
48 // This is different than SkCanvas' getDevice, because that returns the | |
49 // bottommost device. | |
50 // | |
51 // Danger: the resulting device should not be saved. It will be invalidated | |
52 // by the next call to save() or restore(). | |
53 PlatformDeviceMac& getTopPlatformDevice() const; | |
54 | |
55 // Allow callers to see the non-virtual function even though we have an | |
56 // override of a virtual one. | |
57 using SkCanvas::clipRect; | |
58 | |
59 protected: | |
60 // Creates a device store for use by the canvas. We override this so that | |
61 // the device is always our own so we know that we can use GDI operations | |
62 // on it. Simply calls into createPlatformDevice(). | |
63 virtual SkDevice* createDevice(SkBitmap::Config, int width, int height, | |
64 bool is_opaque, bool isForLayer); | |
65 | |
66 // Creates a device store for use by the canvas. By default, it creates a | |
67 // BitmapPlatformDevice object. Can be overridden to change the object type. | |
68 virtual SkDevice* createPlatformDevice(int width, int height, bool is_opaque, | |
69 CGContextRef context); | |
70 | |
71 private: | |
72 // Unimplemented. This is to try to prevent people from calling this function | |
73 // on SkCanvas. SkCanvas' version is not virtual, so we can't prevent this | |
74 // 100%, but hopefully this will make people notice and not use the function. | |
75 // Calling SkCanvas' version will create a new device which is not compatible | |
76 // with us and we will crash if somebody tries to draw into it with | |
77 // CoreGraphics. | |
78 SkDevice* setBitmapDevice(const SkBitmap& bitmap); | |
79 | |
80 // Disallow copy and assign. | |
81 PlatformCanvasMac(const PlatformCanvasMac&); | |
82 PlatformCanvasMac& operator=(const PlatformCanvasMac&); | |
83 }; | |
84 | |
85 } // namespace gfx | |
86 | |
87 #endif // PlatformCanvasMac_h | |
88 | |
OLD | NEW |