OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 skia { | 10 namespace skia { |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { | 24 bool PlatformCanvas::initializeWithDevice(SkDevice* device) { |
25 if (!device) | 25 if (!device) |
26 return false; | 26 return false; |
27 | 27 |
28 setDevice(device); | 28 setDevice(device); |
29 device->unref(); // Was created with refcount 1, and setDevice also refs. | 29 device->unref(); // Was created with refcount 1, and setDevice also refs. |
30 return true; | 30 return true; |
31 } | 31 } |
32 | 32 |
33 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { | 33 SkCanvas* CreateBitmapCanvas(int width, int height, bool is_opaque) { |
34 return new PlatformCanvas(width, height, is_opaque); | 34 return CreateBitmapCanvas(width, height, |
| 35 PlatformDevice::GetDefaultFlags(is_opaque)); |
| 36 } |
| 37 |
| 38 SkCanvas* CreateBitmapCanvas(int width, int height, int flags) { |
| 39 return new PlatformCanvas(width, height, flags); |
35 } | 40 } |
36 | 41 |
37 SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque) { | 42 SkCanvas* TryCreateBitmapCanvas(int width, int height, bool is_opaque) { |
| 43 return TryCreateBitmapCanvas(width, height, |
| 44 PlatformDevice::GetDefaultFlags(is_opaque)); |
| 45 } |
| 46 |
| 47 SkCanvas* TryCreateBitmapCanvas(int width, int height, int flags) { |
38 PlatformCanvas* canvas = new PlatformCanvas(); | 48 PlatformCanvas* canvas = new PlatformCanvas(); |
39 if (!canvas->initialize(width, height, is_opaque)) { | 49 if (!canvas->initialize(width, height, flags)) { |
40 delete canvas; | 50 delete canvas; |
41 canvas = NULL; | 51 canvas = NULL; |
42 } | 52 } |
43 return canvas; | 53 return canvas; |
44 } | 54 } |
45 | 55 |
46 SkDevice* GetTopDevice(const SkCanvas& canvas) { | 56 SkDevice* GetTopDevice(const SkCanvas& canvas) { |
47 SkCanvas::LayerIter iter(const_cast<SkCanvas*>(&canvas), false); | 57 SkCanvas::LayerIter iter(const_cast<SkCanvas*>(&canvas), false); |
48 return iter.device(); | 58 return iter.device(); |
49 } | 59 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 SkIntToScalar(width), SkIntToScalar(height)); | 99 SkIntToScalar(width), SkIntToScalar(height)); |
90 SkPaint paint; | 100 SkPaint paint; |
91 // so we don't draw anything on a device that ignores xfermodes | 101 // so we don't draw anything on a device that ignores xfermodes |
92 paint.setColor(0); | 102 paint.setColor(0); |
93 // install our custom mode | 103 // install our custom mode |
94 paint.setXfermode(new SkProcXfermode(MakeOpaqueXfermodeProc))->unref(); | 104 paint.setXfermode(new SkProcXfermode(MakeOpaqueXfermodeProc))->unref(); |
95 canvas->drawRect(rect, paint); | 105 canvas->drawRect(rect, paint); |
96 } | 106 } |
97 | 107 |
98 } // namespace skia | 108 } // namespace skia |
OLD | NEW |