| Index: skia/ext/skia_utils_win.cc
|
| diff --git a/skia/ext/skia_utils_win.cc b/skia/ext/skia_utils_win.cc
|
| index 37bd21e3c898ac1cd0432d89f0c6d999983773c9..e234da6756613d3e8f92f9a4a7661cf8de7a1aa4 100644
|
| --- a/skia/ext/skia_utils_win.cc
|
| +++ b/skia/ext/skia_utils_win.cc
|
| @@ -7,9 +7,9 @@
|
| #include <stddef.h>
|
| #include <windows.h>
|
|
|
| +#include "base/debug/gdi_debug_util_win.h"
|
| #include "third_party/skia/include/core/SkRect.h"
|
| #include "third_party/skia/include/core/SkTypes.h"
|
| -#include "third_party/skia/include/effects/SkGradientShader.h"
|
|
|
| namespace {
|
|
|
| @@ -23,6 +23,24 @@ static_assert(sizeof(RECT().right) == sizeof(SkIRect().fRight), "o7");
|
| static_assert(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), "o8");
|
| static_assert(sizeof(RECT) == sizeof(SkIRect), "o9");
|
|
|
| +void CreateBitmapHeaderWithColorDepth(LONG width,
|
| + LONG height,
|
| + WORD color_depth,
|
| + BITMAPINFOHEADER* hdr) {
|
| + // These values are shared with gfx::PlatformDevice.
|
| + hdr->biSize = sizeof(BITMAPINFOHEADER);
|
| + hdr->biWidth = width;
|
| + hdr->biHeight = -height; // Minus means top-down bitmap.
|
| + hdr->biPlanes = 1;
|
| + hdr->biBitCount = color_depth;
|
| + hdr->biCompression = BI_RGB; // No compression.
|
| + hdr->biSizeImage = 0;
|
| + hdr->biXPelsPerMeter = 1;
|
| + hdr->biYPelsPerMeter = 1;
|
| + hdr->biClrUsed = 0;
|
| + hdr->biClrImportant = 0;
|
| +}
|
| +
|
| } // namespace
|
|
|
| namespace skia {
|
| @@ -73,7 +91,7 @@ void InitializeDC(HDC context) {
|
| SkASSERT(res != 0);
|
| // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called
|
| // right after.
|
| - res = SetBrushOrgEx(context, 0, 0, NULL);
|
| + res = SetBrushOrgEx(context, 0, 0, nullptr);
|
| SkASSERT(res != 0);
|
|
|
| // Sets up default orientation.
|
| @@ -148,5 +166,32 @@ void CopyHDC(HDC source, HDC destination, int x, int y, bool is_opaque,
|
| LoadTransformToDC(source, transform);
|
| }
|
|
|
| +void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) {
|
| + CreateBitmapHeaderWithColorDepth(width, height, 32, hdr);
|
| +}
|
| +
|
| +HBITMAP CreateHBitmap(int width, int height, HANDLE shared_section, void** data) {
|
| + // CreateDIBSection fails to allocate anything if we try to create an empty
|
| + // bitmap, so just create a minimal bitmap.
|
| + if ((width == 0) || (height == 0)) {
|
| + width = 1;
|
| + height = 1;
|
| + }
|
| +
|
| + BITMAPINFOHEADER hdr = {0};
|
| + CreateBitmapHeaderWithColorDepth(width, height, 32, &hdr);
|
| +
|
| + HBITMAP hbitmap = CreateDIBSection(nullptr,
|
| + reinterpret_cast<BITMAPINFO*>(&hdr),
|
| + 0, data, shared_section, 0);
|
| +
|
| + // If CreateDIBSection() failed, try to get some useful information out
|
| + // before we crash for post-mortem analysis.
|
| + if (!hbitmap)
|
| + base::debug::GDIBitmapAllocFailure(&hdr, shared_section);
|
| +
|
| + return hbitmap;
|
| +}
|
| +
|
| } // namespace skia
|
|
|
|
|