| 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" |
| 11 #include "skia/ext/platform_device.h" |
| 11 #include "third_party/skia/include/core/SkMatrix.h" | 12 #include "third_party/skia/include/core/SkMatrix.h" |
| 12 #include "third_party/skia/include/core/SkRefCnt.h" | 13 #include "third_party/skia/include/core/SkRefCnt.h" |
| 13 #include "third_party/skia/include/core/SkRegion.h" | 14 #include "third_party/skia/include/core/SkRegion.h" |
| 14 #include "third_party/skia/include/core/SkUtils.h" | 15 #include "third_party/skia/include/core/SkUtils.h" |
| 15 | 16 |
| 16 namespace skia { | 17 namespace skia { |
| 17 | 18 |
| 18 BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( | 19 BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( |
| 19 HBITMAP hbitmap) | 20 HBITMAP hbitmap) |
| 20 : bitmap_context_(hbitmap), | 21 : bitmap_context_(hbitmap), |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 // obviously wrong so it will be noticable when it is not cleared | 138 // obviously wrong so it will be noticable when it is not cleared |
| 138 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 139 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| 139 #endif | 140 #endif |
| 140 } else { | 141 } else { |
| 141 bitmap.eraseARGB(0, 0, 0, 0); | 142 bitmap.eraseARGB(0, 0, 0, 0); |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 | 145 |
| 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 bitmap); |
| 151 return bitmap_platform_device; |
| 149 } | 152 } |
| 150 | 153 |
| 151 // static | 154 // static |
| 152 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, | 155 BitmapPlatformDevice* 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); |
| 157 BitmapPlatformDevice* device = BitmapPlatformDevice::create( | 160 SkDevice* device = BitmapPlatformDevice::create(screen_dc, width, height, |
| 158 screen_dc, width, height, is_opaque, shared_section); | 161 is_opaque, shared_section); |
| 159 ReleaseDC(NULL, screen_dc); | 162 ReleaseDC(NULL, screen_dc); |
| 160 return device; | 163 return device; |
| 161 } | 164 } |
| 162 | 165 |
| 163 // The device will own the HBITMAP, which corresponds to also owning the pixel | 166 // 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. | 167 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
| 165 BitmapPlatformDevice::BitmapPlatformDevice( | 168 BitmapPlatformDevice::BitmapPlatformDevice( |
| 166 BitmapPlatformDeviceData* data, | 169 BitmapPlatformDeviceData* data, |
| 167 const SkBitmap& bitmap) | 170 const SkBitmap& bitmap) |
| 168 : PlatformDevice(bitmap), | 171 : PlatformDevice(this), |
| 172 SkDevice(bitmap), |
| 169 data_(data) { | 173 data_(data) { |
| 170 // The data object is already ref'ed for us by create(). | 174 // The data object is already ref'ed for us by create(). |
| 171 SkDEBUGCODE(begin_paint_count_ = 0); | 175 SkDEBUGCODE(begin_paint_count_ = 0); |
| 176 |
| 177 // Pass false, because BitmapPlatformDevice inherits both SkDevice, and |
| 178 // PlatformDevice, so there is no need to explicitly bind the lifetime of the |
| 179 // two classes. |
| 180 SetPlatformDevice(this, this, false); |
| 172 } | 181 } |
| 173 | 182 |
| 174 BitmapPlatformDevice::~BitmapPlatformDevice() { | 183 BitmapPlatformDevice::~BitmapPlatformDevice() { |
| 175 SkASSERT(begin_paint_count_ == 0); | 184 SkASSERT(begin_paint_count_ == 0); |
| 176 data_->unref(); | 185 data_->unref(); |
| 177 } | 186 } |
| 178 | 187 |
| 179 HDC BitmapPlatformDevice::BeginPlatformPaint() { | 188 HDC BitmapPlatformDevice::BeginPlatformPaint() { |
| 180 SkDEBUGCODE(begin_paint_count_++); | 189 SkDEBUGCODE(begin_paint_count_++); |
| 181 return data_->GetBitmapDC(); | 190 return data_->GetBitmapDC(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 } | 264 } |
| 256 | 265 |
| 257 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 266 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 258 SkBitmap::Config config, int width, int height, bool isOpaque, | 267 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 259 Usage /*usage*/) { | 268 Usage /*usage*/) { |
| 260 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 269 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 261 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); | 270 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); |
| 262 } | 271 } |
| 263 | 272 |
| 264 } // namespace skia | 273 } // namespace skia |
| 265 | |
| OLD | NEW |