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 #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/SkTypes.h" | 8 #include "third_party/skia/include/core/SkTypes.h" |
9 | 9 |
10 namespace { | |
11 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); | |
14 return static_cast<skia::PlatformDevice*>(iter.device()); | |
15 } | |
16 } | |
17 | |
18 namespace skia { | 10 namespace skia { |
19 | 11 |
20 PlatformCanvas::PlatformCanvas() { | 12 PlatformCanvas::PlatformCanvas() { |
21 setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); | 13 setDeviceFactory(SkNEW(BitmapPlatformDeviceFactory))->unref(); |
22 } | 14 } |
23 | 15 |
24 PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) { | 16 PlatformCanvas::PlatformCanvas(SkDeviceFactory* factory) : SkCanvas(factory) { |
25 } | 17 } |
26 | 18 |
27 SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) { | 19 SkDevice* PlatformCanvas::setBitmapDevice(const SkBitmap&) { |
28 SkASSERT(false); // Should not be called. | 20 SkASSERT(false); // Should not be called. |
29 return NULL; | 21 return NULL; |
30 } | 22 } |
31 | 23 |
32 PlatformDevice& PlatformCanvas::getTopPlatformDevice() const { | |
33 return *GetTopPlatformDevice(this); | |
34 } | |
35 | |
36 // static | 24 // static |
37 size_t PlatformCanvas::StrideForWidth(unsigned width) { | 25 size_t PlatformCanvas::StrideForWidth(unsigned width) { |
38 return 4 * width; | 26 return 4 * width; |
39 } | 27 } |
40 | 28 |
41 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { | 29 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { |
42 if (!device) | 30 if (!device) |
43 return false; | 31 return false; |
44 | 32 |
45 setDevice(device); | 33 setDevice(device); |
46 device->unref(); // Was created with refcount 1, and setDevice also refs. | 34 device->unref(); // Was created with refcount 1, and setDevice also refs. |
47 return true; | 35 return true; |
48 } | 36 } |
49 | 37 |
50 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { | 38 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { |
51 return new PlatformCanvas(width, height, is_opaque); | 39 return new PlatformCanvas(width, height, is_opaque); |
52 } | 40 } |
53 | 41 |
54 bool SupportsPlatformPaint(const SkCanvas* canvas) { | 42 SkDevice* GetTopDevice(const SkCanvas& canvas) { |
55 // TODO(alokp): Rename PlatformDevice::IsNativeFontRenderingAllowed after | 43 SkCanvas::LayerIter iter(const_cast<SkCanvas*>(&canvas), false); |
56 // removing these calls from WebKit. | 44 return iter.device(); |
57 return GetTopPlatformDevice(canvas)->IsNativeFontRenderingAllowed(); | |
58 } | 45 } |
59 | 46 |
60 PlatformDevice::PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { | 47 bool SupportsPlatformPaint(const SkCanvas* canvas) { |
61 return GetTopPlatformDevice(canvas)->BeginPlatformPaint(); | 48 // TODO(alokp): Rename IsNativeFontRenderingAllowed after removing these |
| 49 // calls from WebKit. |
| 50 return IsNativeFontRenderingAllowed(GetTopDevice(*canvas)); |
| 51 } |
| 52 |
| 53 PlatformSurface BeginPlatformPaint(SkCanvas* canvas) { |
| 54 return BeginPlatformPaint(GetTopDevice(*canvas)); |
62 } | 55 } |
63 | 56 |
64 void EndPlatformPaint(SkCanvas* canvas) { | 57 void EndPlatformPaint(SkCanvas* canvas) { |
65 GetTopPlatformDevice(canvas)->EndPlatformPaint(); | 58 EndPlatformPaint(GetTopDevice(*canvas)); |
| 59 } |
| 60 |
| 61 void DrawToNativeContext(SkCanvas* canvas, PlatformSurface context, int x, |
| 62 int y, const PlatformRect* src_rect) { |
| 63 DrawToNativeContext(GetTopDevice(*canvas), context, x, y, src_rect); |
| 64 } |
| 65 |
| 66 void MakeOpaque(SkCanvas* canvas, int x, int y, int width, int height) { |
| 67 MakeOpaque(GetTopDevice(*canvas), x, y, width, height); |
66 } | 68 } |
67 | 69 |
68 } // namespace skia | 70 } // namespace skia |
OLD | NEW |