| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "skia/ext/skia_utils_win.h" | 5 #include "skia/ext/skia_utils_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include "base/debug/gdi_debug_util_win.h" | 10 #include "base/debug/gdi_debug_util_win.h" |
| 11 #include "base/win/scoped_hdc.h" | |
| 12 #include "base/win/win_util.h" | |
| 13 #include "third_party/skia/include/core/SkRect.h" | 11 #include "third_party/skia/include/core/SkRect.h" |
| 14 #include "third_party/skia/include/core/SkSurface.h" | 12 #include "third_party/skia/include/core/SkSurface.h" |
| 15 #include "third_party/skia/include/core/SkTypes.h" | 13 #include "third_party/skia/include/core/SkTypes.h" |
| 16 | 14 |
| 17 namespace { | 15 namespace { |
| 18 | 16 |
| 19 static_assert(offsetof(RECT, left) == offsetof(SkIRect, fLeft), "o1"); | 17 static_assert(offsetof(RECT, left) == offsetof(SkIRect, fLeft), "o1"); |
| 20 static_assert(offsetof(RECT, top) == offsetof(SkIRect, fTop), "o2"); | 18 static_assert(offsetof(RECT, top) == offsetof(SkIRect, fTop), "o2"); |
| 21 static_assert(offsetof(RECT, right) == offsetof(SkIRect, fRight), "o3"); | 19 static_assert(offsetof(RECT, right) == offsetof(SkIRect, fRight), "o3"); |
| 22 static_assert(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), "o4"); | 20 static_assert(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), "o4"); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 186 |
| 189 SkBitmap MapPlatformBitmap(HDC context) { | 187 SkBitmap MapPlatformBitmap(HDC context) { |
| 190 BITMAP backing; | 188 BITMAP backing; |
| 191 const SkImageInfo size(PrepareAllocation(context, &backing)); | 189 const SkImageInfo size(PrepareAllocation(context, &backing)); |
| 192 SkBitmap bitmap; | 190 SkBitmap bitmap; |
| 193 if (!size.isEmpty()) | 191 if (!size.isEmpty()) |
| 194 bitmap.installPixels(size, backing.bmBits, size.minRowBytes()); | 192 bitmap.installPixels(size, backing.bmBits, size.minRowBytes()); |
| 195 return bitmap; | 193 return bitmap; |
| 196 } | 194 } |
| 197 | 195 |
| 198 HDC CreateOffscreenSurface(int width, int height) { | |
| 199 HBITMAP bitmap = nullptr; | |
| 200 | |
| 201 // If this process doesn't have access to GDI, we'll have to use a shared | |
| 202 // memory segment instead. | |
| 203 if (!base::win::IsUser32AndGdi32Available()) | |
| 204 return nullptr; | |
| 205 | |
| 206 bitmap = CreateHBitmap(width, height, false, nullptr, nullptr); | |
| 207 if (!bitmap) | |
| 208 return nullptr; | |
| 209 | |
| 210 base::win::ScopedCreateDC scoped_hdc(CreateCompatibleDC(nullptr)); | |
| 211 if (!scoped_hdc.IsValid()) | |
| 212 return nullptr; | |
| 213 InitializeDC(scoped_hdc.Get()); | |
| 214 HRGN clip = CreateRectRgn(0, 0, width, height); | |
| 215 if ((SelectClipRgn(scoped_hdc.Get(), clip) == ERROR) || | |
| 216 (!DeleteObject(clip))) | |
| 217 return nullptr; | |
| 218 | |
| 219 SelectObject(scoped_hdc.Get(), bitmap); | |
| 220 | |
| 221 // The caller must call DeleteDC(hdc) on this object once done with it. | |
| 222 return scoped_hdc.Take(); | |
| 223 } | |
| 224 | |
| 225 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { | 196 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
| 226 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); | 197 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); |
| 227 } | 198 } |
| 228 | 199 |
| 229 HBITMAP CreateHBitmap(int width, int height, bool is_opaque, | 200 HBITMAP CreateHBitmap(int width, int height, bool is_opaque, |
| 230 HANDLE shared_section, void** data) { | 201 HANDLE shared_section, void** data) { |
| 231 // CreateDIBSection fails to allocate anything if we try to create an empty | 202 // CreateDIBSection fails to allocate anything if we try to create an empty |
| 232 // bitmap, so just create a minimal bitmap. | 203 // bitmap, so just create a minimal bitmap. |
| 233 if ((width == 0) || (height == 0)) { | 204 if ((width == 0) || (height == 0)) { |
| 234 width = 1; | 205 width = 1; |
| 235 height = 1; | 206 height = 1; |
| 236 } | 207 } |
| 237 | 208 |
| 238 BITMAPINFOHEADER hdr = {0}; | 209 BITMAPINFOHEADER hdr = {0}; |
| 239 CreateBitmapHeader(width, height, &hdr); | 210 CreateBitmapHeader(width, height, &hdr); |
| 240 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), | 211 HBITMAP hbitmap = CreateDIBSection(NULL, reinterpret_cast<BITMAPINFO*>(&hdr), |
| 241 0, data, shared_section, 0); | 212 0, data, shared_section, 0); |
| 242 | 213 |
| 243 // If CreateDIBSection() failed, try to get some useful information out | 214 // If CreateDIBSection() failed, try to get some useful information out |
| 244 // before we crash for post-mortem analysis. | 215 // before we crash for post-mortem analysis. |
| 245 if (!hbitmap) | 216 if (!hbitmap) |
| 246 base::debug::GDIBitmapAllocFailure(&hdr, shared_section); | 217 base::debug::GDIBitmapAllocFailure(&hdr, shared_section); |
| 247 | 218 |
| 248 return hbitmap; | 219 return hbitmap; |
| 249 } | 220 } |
| 250 | 221 |
| 251 } // namespace skia | 222 } // namespace skia |
| 252 | 223 |
| OLD | NEW |