| 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 <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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 // Transform. | 82 // Transform. |
| 83 LoadTransformToDC(hdc_, transform_); | 83 LoadTransformToDC(hdc_, transform_); |
| 84 LoadClippingRegionToDC(hdc_, clip_region_, transform_); | 84 LoadClippingRegionToDC(hdc_, clip_region_, transform_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // We use this static factory function instead of the regular constructor so | 87 // We use this static factory function instead of the regular constructor so |
| 88 // that we can create the pixel data before calling the constructor. This is | 88 // that we can create the pixel data before calling the constructor. This is |
| 89 // required so that we can call the base class' constructor with the pixel | 89 // required so that we can call the base class' constructor with the pixel |
| 90 // data. | 90 // data. |
| 91 BitmapPlatformDevice* BitmapPlatformDevice::create( | 91 SkDevice* BitmapPlatformDevice::create( |
| 92 HDC screen_dc, | 92 HDC screen_dc, |
| 93 int width, | 93 int width, |
| 94 int height, | 94 int height, |
| 95 bool is_opaque, | 95 bool is_opaque, |
| 96 HANDLE shared_section) { | 96 HANDLE shared_section) { |
| 97 SkBitmap bitmap; | 97 SkBitmap bitmap; |
| 98 | 98 |
| 99 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so | 99 // CreateDIBSection appears to get unhappy if we create an empty bitmap, so |
| 100 // just create a minimal bitmap | 100 // just create a minimal bitmap |
| 101 if ((width == 0) || (height == 0)) { | 101 if ((width == 0) || (height == 0)) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 #ifndef NDEBUG | 135 #ifndef NDEBUG |
| 136 // To aid in finding bugs, we set the background color to something | 136 // To aid in finding bugs, we set the background color to something |
| 137 // obviously wrong so it will be noticable when it is not cleared | 137 // obviously wrong so it will be noticable when it is not cleared |
| 138 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 138 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| 139 #endif | 139 #endif |
| 140 } else { | 140 } else { |
| 141 bitmap.eraseARGB(0, 0, 0, 0); | 141 bitmap.eraseARGB(0, 0, 0, 0); |
| 142 } | 142 } |
| 143 } | 143 } |
| 144 | 144 |
| 145 SkDevice* new_device = new SkDevice(bitmap); |
| 145 // The device object will take ownership of the HBITMAP. The initial refcount | 146 // The device object will take ownership of the HBITMAP. The initial refcount |
| 146 // of the data object will be 1, which is what the constructor expects. | 147 // of the data object will be 1, which is what the constructor expects. |
| 147 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), | 148 BitmapPlatformDevice* bitmap_platform_device = |
| 148 bitmap); | 149 new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), |
| 150 new_device); |
| 151 return new_device; |
| 149 } | 152 } |
| 150 | 153 |
| 151 // static | 154 // static |
| 152 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, | 155 SkDevice* BitmapPlatformDevice::create(int width, |
| 153 int height, | 156 int height, |
| 154 bool is_opaque, | 157 bool is_opaque, |
| 155 HANDLE shared_section) { | 158 HANDLE shared_section) { |
| 156 HDC screen_dc = GetDC(NULL); | 159 HDC screen_dc = GetDC(NULL); |
| 160 #if 0 |
| 157 BitmapPlatformDevice* device = BitmapPlatformDevice::create( | 161 BitmapPlatformDevice* device = BitmapPlatformDevice::create( |
| 158 screen_dc, width, height, is_opaque, shared_section); | 162 screen_dc, width, height, is_opaque, shared_section); |
| 163 #endif |
| 164 SkDevice* device = BitmapPlatformDevice::create(screen_dc, width, height, |
| 165 is_opaque, shared_section); |
| 159 ReleaseDC(NULL, screen_dc); | 166 ReleaseDC(NULL, screen_dc); |
| 160 return device; | 167 return device; |
| 161 } | 168 } |
| 162 | 169 |
| 163 // The device will own the HBITMAP, which corresponds to also owning the pixel | 170 // The device will own the HBITMAP, which corresponds to also owning the pixel |
| 164 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. | 171 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
| 165 BitmapPlatformDevice::BitmapPlatformDevice( | 172 BitmapPlatformDevice::BitmapPlatformDevice( |
| 166 BitmapPlatformDeviceData* data, | 173 BitmapPlatformDeviceData* data, |
| 167 const SkBitmap& bitmap) | 174 SkDevice* device |
| 168 : PlatformDevice(bitmap), | 175 /*const SkBitmap& bitmap*/) |
| 176 : /*PlatformDevice(bitmap),*/ |
| 177 PlatformDevice(device), |
| 169 data_(data) { | 178 data_(data) { |
| 170 // The data object is already ref'ed for us by create(). | 179 // The data object is already ref'ed for us by create(). |
| 171 SkDEBUGCODE(begin_paint_count_ = 0); | 180 SkDEBUGCODE(begin_paint_count_ = 0); |
| 181 |
| 182 GetOwningDevice()->setMatrixClipObserver(this); |
| 172 } | 183 } |
| 173 | 184 |
| 174 BitmapPlatformDevice::~BitmapPlatformDevice() { | 185 BitmapPlatformDevice::~BitmapPlatformDevice() { |
| 175 SkASSERT(begin_paint_count_ == 0); | 186 SkASSERT(begin_paint_count_ == 0); |
| 176 data_->unref(); | 187 data_->unref(); |
| 177 } | 188 } |
| 178 | 189 |
| 179 HDC BitmapPlatformDevice::BeginPlatformPaint() { | 190 HDC BitmapPlatformDevice::BeginPlatformPaint() { |
| 180 SkDEBUGCODE(begin_paint_count_++); | 191 SkDEBUGCODE(begin_paint_count_++); |
| 181 return data_->GetBitmapDC(); | 192 return data_->GetBitmapDC(); |
| 182 } | 193 } |
| 183 | 194 |
| 184 void BitmapPlatformDevice::EndPlatformPaint() { | 195 void BitmapPlatformDevice::EndPlatformPaint() { |
| 185 SkASSERT(begin_paint_count_--); | 196 SkASSERT(begin_paint_count_--); |
| 197 if (data_->IsBitmapDCCreated()) |
| 198 GdiFlush(); |
| 186 PlatformDevice::EndPlatformPaint(); | 199 PlatformDevice::EndPlatformPaint(); |
| 187 } | 200 } |
| 188 | 201 |
| 202 void BitmapPlatformDevice::matrixClipChanged(const SkMatrix& transform, |
| 203 const SkRegion& region, |
| 204 const SkClipStack&) { |
| 205 data_->SetMatrixClip(transform, region); |
| 206 } |
| 207 |
| 208 #if 0 |
| 189 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, | 209 void BitmapPlatformDevice::setMatrixClip(const SkMatrix& transform, |
| 190 const SkRegion& region, | 210 const SkRegion& region, |
| 191 const SkClipStack&) { | 211 const SkClipStack&) { |
| 192 data_->SetMatrixClip(transform, region); | 212 data_->SetMatrixClip(transform, region); |
| 193 } | 213 } |
| 214 #endif |
| 194 | 215 |
| 195 void BitmapPlatformDevice::DrawToNativeContext(HDC dc, int x, int y, | 216 void BitmapPlatformDevice::DrawToNativeContext(HDC dc, int x, int y, |
| 196 const RECT* src_rect) { | 217 const RECT* src_rect) { |
| 197 bool created_dc = !data_->IsBitmapDCCreated(); | 218 bool created_dc = !data_->IsBitmapDCCreated(); |
| 198 HDC source_dc = BeginPlatformPaint(); | 219 HDC source_dc = BeginPlatformPaint(); |
| 199 | 220 |
| 200 RECT temp_rect; | 221 RECT temp_rect; |
| 201 if (!src_rect) { | 222 if (!src_rect) { |
| 202 temp_rect.left = 0; | 223 temp_rect.left = 0; |
| 203 temp_rect.right = width(); | 224 temp_rect.right = GetOwningDevice()->width(); |
| 204 temp_rect.top = 0; | 225 temp_rect.top = 0; |
| 205 temp_rect.bottom = height(); | 226 temp_rect.bottom = GetOwningDevice()->height(); |
| 206 src_rect = &temp_rect; | 227 src_rect = &temp_rect; |
| 207 } | 228 } |
| 208 | 229 |
| 209 int copy_width = src_rect->right - src_rect->left; | 230 int copy_width = src_rect->right - src_rect->left; |
| 210 int copy_height = src_rect->bottom - src_rect->top; | 231 int copy_height = src_rect->bottom - src_rect->top; |
| 211 | 232 |
| 212 // We need to reset the translation for our bitmap or (0,0) won't be in the | 233 // We need to reset the translation for our bitmap or (0,0) won't be in the |
| 213 // upper left anymore | 234 // upper left anymore |
| 214 SkMatrix identity; | 235 SkMatrix identity; |
| 215 identity.reset(); | 236 identity.reset(); |
| 216 | 237 |
| 217 LoadTransformToDC(source_dc, identity); | 238 LoadTransformToDC(source_dc, identity); |
| 218 if (isOpaque()) { | 239 if (GetOwningDevice()->isOpaque()) { |
| 219 BitBlt(dc, | 240 BitBlt(dc, |
| 220 x, | 241 x, |
| 221 y, | 242 y, |
| 222 copy_width, | 243 copy_width, |
| 223 copy_height, | 244 copy_height, |
| 224 source_dc, | 245 source_dc, |
| 225 src_rect->left, | 246 src_rect->left, |
| 226 src_rect->top, | 247 src_rect->top, |
| 227 SRCCOPY); | 248 SRCCOPY); |
| 228 } else { | 249 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 copy_height, | 261 copy_height, |
| 241 blend_function); | 262 blend_function); |
| 242 } | 263 } |
| 243 LoadTransformToDC(source_dc, data_->transform()); | 264 LoadTransformToDC(source_dc, data_->transform()); |
| 244 | 265 |
| 245 EndPlatformPaint(); | 266 EndPlatformPaint(); |
| 246 if (created_dc) | 267 if (created_dc) |
| 247 data_->ReleaseBitmapDC(); | 268 data_->ReleaseBitmapDC(); |
| 248 } | 269 } |
| 249 | 270 |
| 271 #if 0 |
| 250 void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { | 272 void BitmapPlatformDevice::onAccessBitmap(SkBitmap* bitmap) { |
| 251 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI | 273 // FIXME(brettw) OPTIMIZATION: We should only flush if we know a GDI |
| 252 // operation has occurred on our DC. | 274 // operation has occurred on our DC. |
| 253 if (data_->IsBitmapDCCreated()) | 275 if (data_->IsBitmapDCCreated()) |
| 254 GdiFlush(); | 276 GdiFlush(); |
| 255 } | 277 } |
| 278 #endif |
| 256 | 279 |
| 280 #if 0 |
| 257 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 281 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 258 SkBitmap::Config config, int width, int height, bool isOpaque, | 282 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 259 Usage /*usage*/) { | 283 Usage /*usage*/) { |
| 260 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 284 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 261 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); | 285 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); |
| 262 } | 286 } |
| 287 #endif |
| 263 | 288 |
| 264 } // namespace skia | 289 } // namespace skia |
| 265 | 290 |
| OLD | NEW |