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 <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
8 | 8 |
9 #include "skia/ext/platform_device_linux.h" | 9 #include "skia/ext/platform_device_linux.h" |
10 #include "skia/ext/bitmap_platform_device_linux.h" | 10 #include "skia/ext/bitmap_platform_device_linux.h" |
11 #include "third_party/skia/include/core/SkTypes.h" | 11 #include "third_party/skia/include/core/SkTypes.h" |
12 | 12 |
13 namespace skia { | 13 namespace skia { |
14 | 14 |
15 PlatformCanvas::PlatformCanvas() : SkCanvas() { | |
16 } | |
17 | |
18 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) | 15 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) |
19 : SkCanvas() { | 16 : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) { |
20 if (!initialize(width, height, is_opaque)) | 17 if (!initialize(width, height, is_opaque)) |
21 SK_CRASH(); | 18 SK_CRASH(); |
22 } | 19 } |
23 | 20 |
24 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, | 21 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, |
25 uint8_t* data) | 22 uint8_t* data) |
26 : SkCanvas() { | 23 : SkCanvas(SkNEW(SkBitmapPlatformDeviceFactory)) { |
27 if (!initialize(width, height, is_opaque, data)) | 24 if (!initialize(width, height, is_opaque, data)) |
28 SK_CRASH(); | 25 SK_CRASH(); |
29 } | 26 } |
30 | 27 |
31 PlatformCanvas::~PlatformCanvas() { | 28 PlatformCanvas::~PlatformCanvas() { |
32 } | 29 } |
33 bool PlatformCanvas::initialize(int width, int height, bool is_opaque, | 30 bool PlatformCanvas::initialize(int width, int height, bool is_opaque, |
34 uint8_t* data) { | 31 uint8_t* data) { |
35 SkDevice* device = | 32 SkDevice* device = |
36 BitmapPlatformDevice::Create(width, height, is_opaque, data); | 33 BitmapPlatformDevice::Create(width, height, is_opaque, data); |
37 if (!device) | 34 if (!device) |
38 return false; | 35 return false; |
39 | 36 |
40 setDevice(device); | 37 setDevice(device); |
41 device->unref(); // was created with refcount 1, and setDevice also refs | 38 device->unref(); // was created with refcount 1, and setDevice also refs |
42 return true; | 39 return true; |
43 } | 40 } |
44 | 41 |
45 cairo_t* PlatformCanvas::beginPlatformPaint() { | 42 cairo_t* PlatformCanvas::beginPlatformPaint() { |
46 return getTopPlatformDevice().beginPlatformPaint(); | 43 return getTopPlatformDevice().beginPlatformPaint(); |
47 } | 44 } |
48 | 45 |
49 void PlatformCanvas::endPlatformPaint() { | 46 void PlatformCanvas::endPlatformPaint() { |
50 // We don't need to do anything on Linux here. | 47 // We don't need to do anything on Linux here. |
51 } | 48 } |
52 | 49 |
53 SkDevice* PlatformCanvas::createDevice(SkBitmap::Config config, | |
54 int width, | |
55 int height, | |
56 bool is_opaque, | |
57 bool isForLayer) { | |
58 SkASSERT(config == SkBitmap::kARGB_8888_Config); | |
59 return BitmapPlatformDevice::Create(width, height, is_opaque); | |
60 } | |
61 | |
62 } // namespace skia | 50 } // namespace skia |
OLD | NEW |