Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: skia/ext/platform_canvas.cc

Issue 6914029: We assume that each SkDevice is our custom PlatformDevice. This assumption is not valid when usin... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « skia/ext/platform_canvas.h ('k') | ui/gfx/native_theme_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "skia/ext/platform_canvas.h" 5 #include "skia/ext/platform_canvas.h"
6 6
7 #include "skia/ext/bitmap_platform_device.h" 7 #include "skia/ext/bitmap_platform_device.h"
8 #include "third_party/skia/include/core/SkMetaData.h"
8 #include "third_party/skia/include/core/SkTypes.h" 9 #include "third_party/skia/include/core/SkTypes.h"
9 10
10 namespace { 11 namespace {
12 static const char* kPlatformDeviceIdentifier = "CrPlatformDevice";
Jeff Timanus 2011/05/04 21:22:47 Style guide nit/question. Does static have any me
13
11 skia::PlatformDevice* GetTopPlatformDevice(const SkCanvas* canvas) { 14 skia::PlatformDevice* GetTopPlatformDevice(const SkCanvas* canvas) {
12 // All of our devices should be our special PlatformDevice.
13 SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false); 15 SkCanvas::LayerIter iter(const_cast<SkCanvas*>(canvas), false);
14 return static_cast<skia::PlatformDevice*>(iter.device()); 16 SkDevice* device = iter.device();
17 // Check if this device is our custom PlatformDevice.
18 // The custom devices are tagged with meta-data named
19 // kPlatformDeviceIdentifier.
20 SkMetaData& meta_data = device->getMetaData();
21 return meta_data.findBool(kPlatformDeviceIdentifier) ?
22 static_cast<skia::PlatformDevice*>(device) : NULL;
15 } 23 }
16 } 24 }
17 25
18 namespace skia { 26 namespace skia {
19 27
20 PlatformCanvas::PlatformCanvas() { 28 PlatformCanvas::PlatformCanvas() {
21 setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); 29 setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref();
22 } 30 }
23 31
24 PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) { 32 PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) {
25 } 33 }
26 34
27 SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) { 35 SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) {
28 SkASSERT(false); // Should not be called. 36 SkASSERT(false); // Should not be called.
29 return NULL; 37 return NULL;
30 } 38 }
31 39
32 PlatformDevice& PlatformCanvas::getTopPlatformDevice() const { 40 PlatformDevice& PlatformCanvas::getTopPlatformDevice() const {
33 return *GetTopPlatformDevice(this); 41 return *GetTopPlatformDevice(this);
34 } 42 }
35 43
36 // static 44 // static
37 size_t PlatformCanvas::StrideForWidth(unsigned width) { 45 size_t PlatformCanvas::StrideForWidth(unsigned width) {
38 return 4 * width; 46 return 4 * width;
39 } 47 }
40 48
41 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { 49 bool PlatformCanvas::initializeWithDevice(PlatformDevice* device) {
42 if (!device) 50 if (!device)
43 return false; 51 return false;
44 52
53 // Set meta-data on the device indicating that this device is our custom
54 // platform device.
55 SkMetaData& meta_data = device->getMetaData();
56 meta_data.setBool(kPlatformDeviceIdentifier, true);
57
45 setDevice(device); 58 setDevice(device);
46 device->unref(); // Was created with refcount 1, and setDevice also refs. 59 device->unref(); // Was created with refcount 1, and setDevice also refs.
47 return true; 60 return true;
48 } 61 }
49 62
50 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { 63 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) {
51 return new PlatformCanvas(width, height, is_opaque); 64 return new PlatformCanvas(width, height, is_opaque);
52 } 65 }
53 66
54 bool SupportsPlatformPaint(const SkCanvas* canvas) { 67 bool SupportsPlatformPaint(const SkCanvas* canvas) {
55 // TODO(alokp): Rename PlatformDevice::IsNativeFontRenderingAllowed after 68 skia::PlatformDevice* device = GetTopPlatformDevice(canvas);
56 // removing these calls from WebKit. 69 return device ? device->IsNativeFontRenderingAllowed() : false;
57 return GetTopPlatformDevice(canvas)->IsNativeFontRenderingAllowed();
58 } 70 }
59 71
60 PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { 72 PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) {
61 return GetTopPlatformDevice(canvas)->BeginPlatformPaint(); 73 return GetTopPlatformDevice(canvas)->BeginPlatformPaint();
62 } 74 }
63 75
64 void EndPlatformPaint(SkCanvas* canvas) { 76 void EndPlatformPaint(SkCanvas* canvas) {
65 GetTopPlatformDevice(canvas)->EndPlatformPaint(); 77 GetTopPlatformDevice(canvas)->EndPlatformPaint();
66 } 78 }
67 79
68 } // namespace skia 80 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/platform_canvas.h ('k') | ui/gfx/native_theme_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698