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

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

Issue 9416017: Optionally clear PlatformCanvas instances. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address comments & add BitmapPlatformDevice::CreateAndClear. Created 8 years, 9 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 <windows.h> 5 #include <windows.h>
6 #include <psapi.h> 6 #include <psapi.h>
7 7
8 #include "skia/ext/bitmap_platform_device_win.h" 8 #include "skia/ext/bitmap_platform_device_win.h"
9 9
10 #include "skia/ext/bitmap_platform_device_data.h" 10 #include "skia/ext/bitmap_platform_device_data.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 // Transform. 81 // Transform.
82 LoadTransformToDC(hdc_, transform_); 82 LoadTransformToDC(hdc_, transform_);
83 LoadClippingRegionToDC(hdc_, clip_region_, transform_); 83 LoadClippingRegionToDC(hdc_, clip_region_, transform_);
84 } 84 }
85 85
86 // We use this static factory function instead of the regular constructor so 86 // We use this static factory function instead of the regular constructor so
87 // that we can create the pixel data before calling the constructor. This is 87 // that we can create the pixel data before calling the constructor. This is
88 // required so that we can call the base class' constructor with the pixel 88 // required so that we can call the base class' constructor with the pixel
89 // data. 89 // data.
90 BitmapPlatformDevice* BitmapPlatformDevice::create( 90 BitmapPlatformDevice* BitmapPlatformDevice::Create(
91 HDC screen_dc, 91 HDC screen_dc,
92 int width, 92 int width,
93 int height, 93 int height,
94 bool is_opaque, 94 bool is_opaque,
95 HANDLE shared_section) { 95 HANDLE shared_section) {
96 SkBitmap bitmap; 96 SkBitmap bitmap;
97 97
98 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so 98 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so
99 // just create a minimal bitmap 99 // just create a minimal bitmap
100 if ((width == 0) || (height == 0)) { 100 if ((width == 0) || (height == 0)) {
(...skipping 21 matching lines...) Expand all
122 shared_section, 0); 122 shared_section, 0);
123 if (!hbitmap) { 123 if (!hbitmap) {
124 return NULL; 124 return NULL;
125 } 125 }
126 126
127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
128 bitmap.setPixels(data); 128 bitmap.setPixels(data);
129 bitmap.setIsOpaque(is_opaque); 129 bitmap.setIsOpaque(is_opaque);
130 130
131 // If we were given data, then don't clobber it! 131 // If we were given data, then don't clobber it!
132 if (!shared_section) { 132 if (!shared_section) {
msw 2012/03/16 07:13:22 nit: combine nested ifs, drop braces, put the whol
Jeff Timanus 2012/03/16 15:52:42 Done.
133 if (is_opaque) { 133 if (is_opaque) {
134 #ifndef NDEBUG 134 #ifndef NDEBUG
135 // To aid in finding bugs, we set the background color to something 135 // To aid in finding bugs, we set the background color to something
136 // obviously wrong so it will be noticable when it is not cleared 136 // obviously wrong so it will be noticable when it is not cleared
137 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green 137 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
138 #endif 138 #endif
139 } else {
140 bitmap.eraseARGB(0, 0, 0, 0);
141 } 139 }
142 } 140 }
143 141
144 // The device object will take ownership of the HBITMAP. The initial refcount 142 // The device object will take ownership of the HBITMAP. The initial refcount
145 // of the data object will be 1, which is what the constructor expects. 143 // of the data object will be 1, which is what the constructor expects.
146 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), 144 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap),
147 bitmap); 145 bitmap);
148 } 146 }
149 147
150 // static 148 // static
151 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, 149 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width,
152 int height, 150 int height,
153 bool is_opaque, 151 bool is_opaque,
154 HANDLE shared_section) { 152 HANDLE shared_section) {
155 HDC screen_dc = GetDC(NULL); 153 HDC screen_dc = GetDC(NULL);
156 BitmapPlatformDevice* device = BitmapPlatformDevice::create( 154 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(
157 screen_dc, width, height, is_opaque, shared_section); 155 screen_dc, width, height, is_opaque, shared_section);
158 ReleaseDC(NULL, screen_dc); 156 ReleaseDC(NULL, screen_dc);
159 return device; 157 return device;
160 } 158 }
161 159
160 // static
161 BitmapPlatformDevice* BitmapPlatformDevice::Create(int width, int height,
162 bool is_opaque) {
163 return Create(width, height, is_opaque, NULL);
164 }
165
166 // static
167 BitmapPlatformDevice* BitmapPlatformDevice::CreateAndClear(int width,
168 int height,
169 bool is_opaque) {
170 BitmapPlatformDevice* device = BitmapPlatformDevice::Create(width, height,
171 is_opaque);
172 if (!is_opaque)
173 device->accessBitmap(true).eraseARGB(0, 0, 0, 0);
174 return device;
175 }
176
162 // The device will own the HBITMAP, which corresponds to also owning the pixel 177 // The device will own the HBITMAP, which corresponds to also owning the pixel
163 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. 178 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
164 BitmapPlatformDevice::BitmapPlatformDevice( 179 BitmapPlatformDevice::BitmapPlatformDevice(
165 BitmapPlatformDeviceData* data, 180 BitmapPlatformDeviceData* data,
166 const SkBitmap& bitmap) 181 const SkBitmap& bitmap)
167 : SkDevice(bitmap), 182 : SkDevice(bitmap),
168 data_(data) { 183 data_(data) {
169 // The data object is already ref'ed for us by create(). 184 // The data object is already ref'ed for us by create().
170 SkDEBUGCODE(begin_paint_count_ = 0); 185 SkDEBUGCODE(begin_paint_count_ = 0);
171 SetPlatformDevice(this, this); 186 SetPlatformDevice(this, this);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // operation has occurred on our DC. 267 // operation has occurred on our DC.
253 if (data_->IsBitmapDCCreated()) 268 if (data_->IsBitmapDCCreated())
254 GdiFlush(); 269 GdiFlush();
255 return *bitmap; 270 return *bitmap;
256 } 271 }
257 272
258 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( 273 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
259 SkBitmap::Config config, int width, int height, bool isOpaque, 274 SkBitmap::Config config, int width, int height, bool isOpaque,
260 Usage /*usage*/) { 275 Usage /*usage*/) {
261 SkASSERT(config == SkBitmap::kARGB_8888_Config); 276 SkASSERT(config == SkBitmap::kARGB_8888_Config);
262 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); 277 SkDevice* bitmap_device = BitmapPlatformDevice::CreateAndClear(width, height,
278 isOpaque);
279 return bitmap_device;
263 } 280 }
264 281
265 } // namespace skia 282 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698