Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4206)

Unified Diff: skia/ext/skia_utils_win.cc

Issue 2158473002: Consolidate Windows bitmap and DC code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review error Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/ext/skia_utils_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b0aff357adbbcfb1ae01bafc415d0bf987e15948 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 {
@@ -148,5 +148,40 @@ void CopyHDC(HDC source, HDC destination, int x, int y, bool is_opaque,
LoadTransformToDC(source, transform);
}
+HBITMAP CreateHBitmap(int width, int height, bool is_opaque,
+ HANDLE shared_section, void** data) {
+ // 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;
+
+ HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr),
+ 0, data, shared_section, 0);
+
+#if !defined(_WIN64)
+ // If this call fails, we're gonna crash hard. Try to get some useful
+ // information out before we crash for post-mortem analysis.
+ if (!hbitmap)
+ base::debug::GDIBitmapAllocFailure(&hdr, shared_section);
+#endif
+
+ return hbitmap;
+}
+
} // namespace skia
« no previous file with comments | « skia/ext/skia_utils_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698