| OLD | NEW |
| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 int flags, |
| 95 HANDLE shared_section) { | 95 HANDLE shared_section) { |
| 96 |
| 96 SkBitmap bitmap; | 97 SkBitmap bitmap; |
| 97 | 98 |
| 98 // 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 |
| 99 // just create a minimal bitmap | 100 // just create a minimal bitmap |
| 100 if ((width == 0) || (height == 0)) { | 101 if ((width == 0) || (height == 0)) { |
| 101 width = 1; | 102 width = 1; |
| 102 height = 1; | 103 height = 1; |
| 103 } | 104 } |
| 104 | 105 |
| 105 BITMAPINFOHEADER hdr = {0}; | 106 BITMAPINFOHEADER hdr = {0}; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 HBITMAP hbitmap = CreateDIBSection(screen_dc, | 120 HBITMAP hbitmap = CreateDIBSection(screen_dc, |
| 120 reinterpret_cast<BITMAPINFO*>(&hdr), 0, | 121 reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
| 121 &data, | 122 &data, |
| 122 shared_section, 0); | 123 shared_section, 0); |
| 123 if (!hbitmap) { | 124 if (!hbitmap) { |
| 124 return NULL; | 125 return NULL; |
| 125 } | 126 } |
| 126 | 127 |
| 127 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 128 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 128 bitmap.setPixels(data); | 129 bitmap.setPixels(data); |
| 129 bitmap.setIsOpaque(is_opaque); | 130 bitmap.setIsOpaque(flags & FLAGS_OPAQUE); |
| 130 | 131 |
| 131 // If we were given data, then don't clobber it! | 132 // If we were given data, then don't clobber it! |
| 132 if (!shared_section) { | 133 if (!shared_section) { |
| 133 if (is_opaque) { | 134 if (flags & FLAGS_OPAQUE) { |
| 134 #ifndef NDEBUG | 135 #ifndef NDEBUG |
| 135 // 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 |
| 136 // 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 |
| 137 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green | 138 bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green |
| 138 #endif | 139 #endif |
| 139 } else { | 140 } else { |
| 140 bitmap.eraseARGB(0, 0, 0, 0); | 141 if (flags & FLAGS_INITIALIZED) |
| 142 bitmap.eraseARGB(0, 0, 0, 0); |
| 141 } | 143 } |
| 142 } | 144 } |
| 143 | 145 |
| 144 // 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 |
| 145 // 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. |
| 146 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), | 148 return new BitmapPlatformDevice(new BitmapPlatformDeviceData(hbitmap), |
| 147 bitmap); | 149 bitmap); |
| 148 } | 150 } |
| 149 | 151 |
| 150 // static | 152 // static |
| 151 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, | 153 BitmapPlatformDevice* BitmapPlatformDevice::create(int width, |
| 152 int height, | 154 int height, |
| 153 bool is_opaque, | 155 int flags, |
| 154 HANDLE shared_section) { | 156 HANDLE shared_section) { |
| 155 HDC screen_dc = GetDC(NULL); | 157 HDC screen_dc = GetDC(NULL); |
| 156 BitmapPlatformDevice* device = BitmapPlatformDevice::create( | 158 BitmapPlatformDevice* device = BitmapPlatformDevice::create( |
| 157 screen_dc, width, height, is_opaque, shared_section); | 159 screen_dc, width, height, flags, shared_section); |
| 158 ReleaseDC(NULL, screen_dc); | 160 ReleaseDC(NULL, screen_dc); |
| 159 return device; | 161 return device; |
| 160 } | 162 } |
| 161 | 163 |
| 162 // The device will own the HBITMAP, which corresponds to also owning the pixel | 164 // 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. | 165 // data. Therefore, we do not transfer ownership to the SkDevice's bitmap. |
| 164 BitmapPlatformDevice::BitmapPlatformDevice( | 166 BitmapPlatformDevice::BitmapPlatformDevice( |
| 165 BitmapPlatformDeviceData* data, | 167 BitmapPlatformDeviceData* data, |
| 166 const SkBitmap& bitmap) | 168 const SkBitmap& bitmap) |
| 167 : SkDevice(bitmap), | 169 : SkDevice(bitmap), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 // operation has occurred on our DC. | 254 // operation has occurred on our DC. |
| 253 if (data_->IsBitmapDCCreated()) | 255 if (data_->IsBitmapDCCreated()) |
| 254 GdiFlush(); | 256 GdiFlush(); |
| 255 return *bitmap; | 257 return *bitmap; |
| 256 } | 258 } |
| 257 | 259 |
| 258 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( | 260 SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice( |
| 259 SkBitmap::Config config, int width, int height, bool isOpaque, | 261 SkBitmap::Config config, int width, int height, bool isOpaque, |
| 260 Usage /*usage*/) { | 262 Usage /*usage*/) { |
| 261 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 263 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 262 return BitmapPlatformDevice::create(width, height, isOpaque, NULL); | 264 return BitmapPlatformDevice::create(width, height, |
| 265 GetDefaultFlags(isOpaque), |
| 266 NULL); |
| 263 } | 267 } |
| 264 | 268 |
| 265 } // namespace skia | 269 } // namespace skia |
| OLD | NEW |