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