summaryrefslogtreecommitdiffstats
path: root/skia/ext/bitmap_platform_device_win.cc
diff options
context:
space:
mode:
authorreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 19:57:15 +0000
committerreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 19:57:15 +0000
commit3b798343ad6244041f094ab1c7929cddef451945 (patch)
treef95ab6f60499c493016870931161e879a86e2e6f /skia/ext/bitmap_platform_device_win.cc
parentb27ccd4d945890566a5897d7dc903ebd67c76948 (diff)
downloadchromium_src-3b798343ad6244041f094ab1c7929cddef451945.zip
chromium_src-3b798343ad6244041f094ab1c7929cddef451945.tar.gz
chromium_src-3b798343ad6244041f094ab1c7929cddef451945.tar.bz2
Introduce PlatformBitmap, which is a minimal helper class that wraps an SkBitmap
and a PlatformSurface. This is used to replace the PlatformCanvas that was being passed to BackingStore to return pixels. The problem to solve is that PlatformCanvas is an extension of SkCanvas, and SkCanvas is losing the ability to have its backend specified after its constructor (for performance reasons). The BackingStore interface only needs to return a copy of its pixels, and offer a platform-specific way to draw into it (i.e. BitBlt). The PlatformSurface is sufficient for this, so the larger infrastructure of PlatformCanvas/PlatformDevice is not required. Review URL: https://codereview.chromium.org/11031055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'skia/ext/bitmap_platform_device_win.cc')
-rw-r--r--skia/ext/bitmap_platform_device_win.cc88
1 files changed, 58 insertions, 30 deletions
diff --git a/skia/ext/bitmap_platform_device_win.cc b/skia/ext/bitmap_platform_device_win.cc
index a52dd4e..12b9266 100644
--- a/skia/ext/bitmap_platform_device_win.cc
+++ b/skia/ext/bitmap_platform_device_win.cc
@@ -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, &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 @@ BitmapPlatformDevice* BitmapPlatformDevice::Create(
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,26 @@ SkDevice* BitmapPlatformDevice::onCreateCompatibleDevice(
return bitmap_device;
}
+// Port of PlatformBitmap to win
+
+PlatformBitmap::~PlatformBitmap() {
+ if (surface_)
+ DeleteDC(surface_);
+}
+
+bool PlatformBitmap::Allocate(int width, int height, bool is_opaque) {
+ HBITMAP hbitmap = CreateHBitmap(width, height, is_opaque, 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;
+}
+
} // namespace skia