Chromium Code Reviews| Index: skia/ext/platform_canvas.cc |
| =================================================================== |
| --- skia/ext/platform_canvas.cc (revision 83722) |
| +++ skia/ext/platform_canvas.cc (working copy) |
| @@ -5,13 +5,21 @@ |
| #include "skia/ext/platform_canvas.h" |
| #include "skia/ext/bitmap_platform_device.h" |
| +#include "third_party/skia/include/core/SkMetaData.h" |
| #include "third_party/skia/include/core/SkTypes.h" |
| namespace { |
| +static const char* kPlatformDeviceIdentifier = "CrPlatformDevice"; |
|
Jeff Timanus
2011/05/04 21:22:47
Style guide nit/question. Does static have any me
|
| + |
| skia::PlatformDevice* GetTopPlatformDevice(const SkCanvas* canvas) { |
| - // All of our devices should be our special PlatformDevice. |
| SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false); |
| - return static_cast<skia::PlatformDevice*>(iter.device()); |
| + SkDevice* device = iter.device(); |
| + // Check if this device is our custom PlatformDevice. |
| + // The custom devices are tagged with meta-data named |
| + // kPlatformDeviceIdentifier. |
| + SkMetaData& meta_data = device->getMetaData(); |
| + return meta_data.findBool(kPlatformDeviceIdentifier) ? |
| + static_cast<skia::PlatformDevice*>(device) : NULL; |
| } |
| } |
| @@ -38,10 +46,15 @@ |
| return 4 * width; |
| } |
| -bool PlatformCanvas::initializeWithDevice(SkDevice* device) { |
| +bool PlatformCanvas::initializeWithDevice(PlatformDevice* device) { |
| if (!device) |
| return false; |
| + // Set meta-data on the device indicating that this device is our custom |
| + // platform device. |
| + SkMetaData& meta_data = device->getMetaData(); |
| + meta_data.setBool(kPlatformDeviceIdentifier, true); |
| + |
| setDevice(device); |
| device->unref(); // Was created with refcount 1, and setDevice also refs. |
| return true; |
| @@ -52,9 +65,8 @@ |
| } |
| bool SupportsPlatformPaint(const SkCanvas* canvas) { |
| - // TODO(alokp): Rename PlatformDevice::IsNativeFontRenderingAllowed after |
| - // removing these calls from WebKit. |
| - return GetTopPlatformDevice(canvas)->IsNativeFontRenderingAllowed(); |
| + skia::PlatformDevice* device = GetTopPlatformDevice(canvas); |
| + return device ? device->IsNativeFontRenderingAllowed() : false; |
| } |
| PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { |