OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "skia/ext/platform_canvas.h" | |
6 | |
7 #include "base/debug/trace_event.h" | |
8 #include "skia/ext/bitmap_platform_device.h" | |
9 | |
10 // TODO(reveman): a lot of unnecessary duplication of code from | |
11 // platform_canvas_[win|linux|mac].cc in here. Need to refactor | |
12 // PlatformCanvas to avoid this: | |
13 // http://code.google.com/p/chromium/issues/detail?id=119555 | |
14 | |
15 namespace skia { | |
16 | |
17 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { | |
18 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", | |
19 "width", width, "height", height); | |
20 if (!initialize(width, height, is_opaque)) | |
21 SK_CRASH(); | |
22 } | |
23 | |
24 #if defined(WIN32) | |
25 PlatformCanvas::PlatformCanvas(int width, | |
26 int height, | |
27 bool is_opaque, | |
28 HANDLE shared_section) { | |
29 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", | |
30 "width", width, "height", height); | |
31 if (!initialize(width, height, is_opaque, shared_section)) | |
32 SK_CRASH(); | |
33 } | |
34 #elif defined(__APPLE__) | |
35 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, | |
36 uint8_t* data) { | |
37 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", | |
38 "width", width, "height", height); | |
39 if (!initialize(width, height, is_opaque, data)) | |
40 SK_CRASH(); | |
41 } | |
42 PlatformCanvas::PlatformCanvas(int width, | |
43 int height, | |
44 bool is_opaque, | |
45 CGContextRef context) { | |
46 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", | |
47 "width", width, "height", height); | |
48 if (!initialize(context, width, height, is_opaque)) | |
49 SK_CRASH(); | |
50 } | |
51 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
52 defined(__sun) || defined(ANDROID) | |
53 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque, | |
54 uint8_t* data) { | |
55 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", | |
56 "width", width, "height", height); | |
57 if (!initialize(width, height, is_opaque, data)) | |
58 SK_CRASH(); | |
59 } | |
60 #endif | |
61 | |
62 PlatformCanvas::~PlatformCanvas() { | |
63 } | |
64 | |
65 #if defined(WIN32) | |
66 bool PlatformCanvas::initialize(int width, | |
67 int height, | |
68 bool is_opaque, | |
69 HANDLE shared_section) { | |
70 // Use platform specific device for shared_section. | |
71 if (shared_section) | |
72 return initializeWithDevice(BitmapPlatformDevice::Create( | |
73 width, height, is_opaque, shared_section)); | |
74 | |
75 return initializeWithDevice(new SkDevice( | |
76 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); | |
77 } | |
78 #elif defined(__APPLE__) | |
79 bool PlatformCanvas::initialize(int width, | |
80 int height, | |
81 bool is_opaque, | |
82 uint8_t* data) { | |
83 // Use platform specific device for data. | |
84 if (data) | |
85 return initializeWithDevice(BitmapPlatformDevice::CreateWithData( | |
86 data, width, height, is_opaque)); | |
87 | |
88 return initializeWithDevice(new SkDevice( | |
89 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); | |
90 } | |
91 | |
92 bool PlatformCanvas::initialize(CGContextRef context, | |
93 int width, | |
94 int height, | |
95 bool is_opaque) { | |
96 return initializeWithDevice(BitmapPlatformDevice::Create( | |
97 context, width, height, is_opaque)); | |
98 } | |
99 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ | |
100 defined(__sun) || defined(ANDROID) | |
101 bool PlatformCanvas::initialize(int width, int height, bool is_opaque, | |
102 uint8_t* data) { | |
103 // Use platform specific device for data. | |
104 if (data) | |
105 return initializeWithDevice(BitmapPlatformDevice::Create( | |
106 width, height, is_opaque, data)); | |
107 | |
108 return initializeWithDevice(new SkDevice( | |
109 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); | |
110 } | |
111 #endif | |
112 | |
113 } // namespace skia | |
OLD | NEW |