Chromium Code Reviews| Index: skia/ext/bitmap_platform_device_win.cc |
| =================================================================== |
| --- skia/ext/bitmap_platform_device_win.cc (revision 160846) |
| +++ skia/ext/bitmap_platform_device_win.cc (working copy) |
| @@ -6,13 +6,46 @@ |
| #include <psapi.h> |
| #include "skia/ext/bitmap_platform_device_win.h" |
| - |
| #include "skia/ext/bitmap_platform_device_data.h" |
| +#include "skia/ext/platform_canvas.h" |
| #include "third_party/skia/include/core/SkMatrix.h" |
| #include "third_party/skia/include/core/SkRefCnt.h" |
| #include "third_party/skia/include/core/SkRegion.h" |
| #include "third_party/skia/include/core/SkUtils.h" |
| +static HBITMAP CreateHBitmap(int width, int height, bool is_opaque, |
| + HANDLE shared_section, SkBitmap* output) { |
| + // CreateDIBSection appears to get unhappy if we create an empty bitmap, so |
| + // just create a minimal bitmap |
| + if ((width == 0) || (height == 0)) { |
| + width = 1; |
| + height = 1; |
| + } |
| + |
| + BITMAPINFOHEADER hdr = {0}; |
| + hdr.biSize = sizeof(BITMAPINFOHEADER); |
| + hdr.biWidth = width; |
| + hdr.biHeight = -height; // minus means top-down bitmap |
| + hdr.biPlanes = 1; |
| + hdr.biBitCount = 32; |
| + hdr.biCompression = BI_RGB; // no compression |
| + hdr.biSizeImage = 0; |
| + hdr.biXPelsPerMeter = 1; |
| + hdr.biYPelsPerMeter = 1; |
| + hdr.biClrUsed = 0; |
| + hdr.biClrImportant = 0; |
| + |
| + void* data = NULL; |
| + HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
|
brettw
2012/10/09 20:40:12
Line too long.
reed1
2012/10/09 21:06:43
Done.
|
| + &data, shared_section, 0); |
| + if (hbitmap) { |
| + output->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| + output->setPixels(data); |
| + output->setIsOpaque(is_opaque); |
| + } |
| + return hbitmap; |
| +} |
| + |
| namespace skia { |
| BitmapPlatformDevice::BitmapPlatformDeviceData::BitmapPlatformDeviceData( |
| @@ -94,38 +127,11 @@ |
| HANDLE shared_section) { |
| SkBitmap bitmap; |
| - // CreateDIBSection appears to get unhappy if we create an empty bitmap, so |
| - // just create a minimal bitmap |
| - if ((width == 0) || (height == 0)) { |
| - width = 1; |
| - height = 1; |
| - } |
| - |
| - BITMAPINFOHEADER hdr = {0}; |
| - hdr.biSize = sizeof(BITMAPINFOHEADER); |
| - hdr.biWidth = width; |
| - hdr.biHeight = -height; // minus means top-down bitmap |
| - hdr.biPlanes = 1; |
| - hdr.biBitCount = 32; |
| - hdr.biCompression = BI_RGB; // no compression |
| - hdr.biSizeImage = 0; |
| - hdr.biXPelsPerMeter = 1; |
| - hdr.biYPelsPerMeter = 1; |
| - hdr.biClrUsed = 0; |
| - hdr.biClrImportant = 0; |
| - |
| - void* data = NULL; |
| - HBITMAP hbitmap = CreateDIBSection(NULL, |
| - reinterpret_cast<BITMAPINFO*>(&hdr), 0, |
| - &data, |
| - shared_section, 0); |
| + HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, shared_section, |
| + &bitmap); |
| if (!hbitmap) |
| return NULL; |
| - bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| - bitmap.setPixels(data); |
| - bitmap.setIsOpaque(is_opaque); |
| - |
| #ifndef NDEBUG |
| // If we were given data, then don't clobber it! |
| if (!shared_section && is_opaque) |
| @@ -262,4 +268,34 @@ |
| return bitmap_device; |
| } |
| +// Port of PlatformBitmap to win |
| + |
| +PlatformBitmap::~PlatformBitmap() { |
| + if (surface_) |
| + DeleteDC(surface_); |
| +} |
| + |
| +bool PlatformBitmap::Allocate(int width, int height, bool isOpaque) { |
|
brettw
2012/10/09 20:40:12
is_opaque.
|
| + HBITMAP hbitmap = CreateHBitmap(width, height, isOpaque, 0, &bitmap_); |
| + if (!hbitmap) |
| + return false; |
| + |
| + surface_ = CreateCompatibleDC(NULL); |
| + InitializeDC(surface_); |
| + HGDIOBJ old_bitmap = SelectObject(surface_, hbitmap); |
| + // When the memory DC is created, its display surface is exactly one |
| + // monochrome pixel wide and one monochrome pixel high. Since we select our |
| + // own bitmap, we must delete the previous one. |
| + DeleteObject(old_bitmap); |
| + return true; |
| +} |
| + |
| +PlatformSurface PlatformBitmap::LockSurface() { |
| + return surface_; |
| +} |
| + |
| +void PlatformBitmap::UnlockSurface() { |
| + // nothing to do for our surface_. It will be released in our destructor |
|
brettw
2012/10/09 20:40:12
Style nit: should be a complete sentence with cap
|
| +} |
| + |
| } // namespace skia |