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