Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: skia/ext/platform_canvas_skia.cc

Issue 10093006: Fix win32 error checking in platform_canvas_skia.cc by moving code into ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "skia/ext/bitmap_platform_device.h" 8 #include "skia/ext/bitmap_platform_device.h"
9 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 { 10 namespace skia {
16 11
17 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) { 12 PlatformCanvas::PlatformCanvas(int width, int height, bool is_opaque) {
18 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", 13 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
19 "width", width, "height", height); 14 "width", width, "height", height);
20 if (!initialize(width, height, is_opaque)) 15 if (!initialize(width, height, is_opaque))
21 SK_CRASH(); 16 SK_CRASH();
22 } 17 }
23 18
24 #if defined(WIN32)
25 PlatformCanvas::PlatformCanvas(int width, 19 PlatformCanvas::PlatformCanvas(int width,
26 int height, 20 int height,
27 bool is_opaque, 21 bool is_opaque,
28 HANDLE shared_section) { 22 PlatformData data) {
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", 23 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
38 "width", width, "height", height); 24 "width", width, "height", height);
39 if (!initialize(width, height, is_opaque, data)) 25 if (!initialize(width, height, is_opaque, data))
40 SK_CRASH(); 26 SK_CRASH();
41 } 27 }
28
29 #if defined(__APPLE__)
42 PlatformCanvas::PlatformCanvas(int width, 30 PlatformCanvas::PlatformCanvas(int width,
43 int height, 31 int height,
44 bool is_opaque, 32 bool is_opaque,
45 CGContextRef context) { 33 CGContextRef context) {
46 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas", 34 TRACE_EVENT2("skia", "PlatformCanvas::PlatformCanvas",
47 "width", width, "height", height); 35 "width", width, "height", height);
48 if (!initialize(context, width, height, is_opaque)) 36 if (!initialize(context, width, height, is_opaque))
49 SK_CRASH(); 37 SK_CRASH();
50 } 38 }
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 39 #endif
61 40
62 PlatformCanvas::~PlatformCanvas() { 41 PlatformCanvas::~PlatformCanvas() {
63 } 42 }
64 43
65 #if defined(WIN32)
66 bool PlatformCanvas::initialize(int width, 44 bool PlatformCanvas::initialize(int width,
67 int height, 45 int height,
68 bool is_opaque, 46 bool is_opaque,
69 HANDLE shared_section) { 47 PlatformData data) {
70 // Use platform specific device for shared_section. 48 // Use platform specific device for data.
71 if (shared_section) { 49 if (data) {
72 if (initializeWithDevice(BitmapPlatformDevice::Create(width, 50 if (initializeWithDevice(BitmapPlatformDevice::Create(width,
Alexei Svitkine (slow) 2012/04/16 20:18:43 Nit: Just return initializeWithDevice(...).
73 height, 51 height,
74 is_opaque, 52 is_opaque,
75 shared_section))) 53 data)))
76 return true; 54 return true;
77 55
78 // TODO(reveman): move the failure investigation from
79 // platform_canvas_win.cc to bitmap_platform_device_win.cc.
80 return false; 56 return false;
81 } 57 }
82 58
83 return initializeWithDevice(new SkDevice( 59 return initializeWithDevice(new SkDevice(
84 SkBitmap::kARGB_8888_Config, width, height, is_opaque)); 60 SkBitmap::kARGB_8888_Config, width, height, is_opaque));
85 } 61 }
86 #elif defined(__APPLE__)
87 bool PlatformCanvas::initialize(int width,
88 int height,
89 bool is_opaque,
90 uint8_t* data) {
91 // Use platform specific device for data.
92 if (data)
93 return initializeWithDevice(BitmapPlatformDevice::CreateWithData(
94 data, width, height, is_opaque));
95 62
96 return initializeWithDevice(new SkDevice( 63 #if defined(__APPLE__)
97 SkBitmap::kARGB_8888_Config, width, height, is_opaque));
98 }
99
100 bool PlatformCanvas::initialize(CGContextRef context, 64 bool PlatformCanvas::initialize(CGContextRef context,
101 int width, 65 int width,
102 int height, 66 int height,
103 bool is_opaque) { 67 bool is_opaque) {
104 return initializeWithDevice(BitmapPlatformDevice::Create( 68 return initializeWithDevice(BitmapPlatformDevice::Create(
105 context, width, height, is_opaque)); 69 context, width, height, is_opaque));
106 } 70 }
107 #elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
108 defined(__sun) || defined(ANDROID)
109 bool PlatformCanvas::initialize(int width, int height, bool is_opaque,
110 uint8_t* data) {
111 // Use platform specific device for data.
112 if (data)
113 return initializeWithDevice(BitmapPlatformDevice::Create(
114 width, height, is_opaque, data));
115
116 return initializeWithDevice(new SkDevice(
117 SkBitmap::kARGB_8888_Config, width, height, is_opaque));
118 }
119 #endif 71 #endif
120 72
121 } // namespace skia 73 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698