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 "third_party/skia/include/core/SkRect.h" | 11 #include "third_party/skia/include/core/SkRect.h" |
11 #include "third_party/skia/include/core/SkTypes.h" | 12 #include "third_party/skia/include/core/SkTypes.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 static_assert(offsetof(RECT, left) == offsetof(SkIRect, fLeft), "o1"); | 16 static_assert(offsetof(RECT, left) == offsetof(SkIRect, fLeft), "o1"); |
17 static_assert(offsetof(RECT, top) == offsetof(SkIRect, fTop), "o2"); | 17 static_assert(offsetof(RECT, top) == offsetof(SkIRect, fTop), "o2"); |
18 static_assert(offsetof(RECT, right) == offsetof(SkIRect, fRight), "o3"); | 18 static_assert(offsetof(RECT, right) == offsetof(SkIRect, fRight), "o3"); |
19 static_assert(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), "o4"); | 19 static_assert(offsetof(RECT, bottom) == offsetof(SkIRect, fBottom), "o4"); |
20 static_assert(sizeof(RECT().left) == sizeof(SkIRect().fLeft), "o5"); | 20 static_assert(sizeof(RECT().left) == sizeof(SkIRect().fLeft), "o5"); |
21 static_assert(sizeof(RECT().top) == sizeof(SkIRect().fTop), "o6"); | 21 static_assert(sizeof(RECT().top) == sizeof(SkIRect().fTop), "o6"); |
22 static_assert(sizeof(RECT().right) == sizeof(SkIRect().fRight), "o7"); | 22 static_assert(sizeof(RECT().right) == sizeof(SkIRect().fRight), "o7"); |
23 static_assert(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), "o8"); | 23 static_assert(sizeof(RECT().bottom) == sizeof(SkIRect().fBottom), "o8"); |
24 static_assert(sizeof(RECT) == sizeof(SkIRect), "o9"); | 24 static_assert(sizeof(RECT) == sizeof(SkIRect), "o9"); |
25 | 25 |
| 26 void CreateBitmapHeaderWithColorDepth(LONG width, |
| 27 LONG height, |
| 28 WORD color_depth, |
| 29 BITMAPINFOHEADER* hdr) { |
| 30 // These values are shared with gfx::PlatformDevice. |
| 31 hdr->biSize = sizeof(BITMAPINFOHEADER); |
| 32 hdr->biWidth = width; |
| 33 hdr->biHeight = -height; // Minus means top-down bitmap. |
| 34 hdr->biPlanes = 1; |
| 35 hdr->biBitCount = color_depth; |
| 36 hdr->biCompression = BI_RGB; // No compression. |
| 37 hdr->biSizeImage = 0; |
| 38 hdr->biXPelsPerMeter = 1; |
| 39 hdr->biYPelsPerMeter = 1; |
| 40 hdr->biClrUsed = 0; |
| 41 hdr->biClrImportant = 0; |
| 42 } |
| 43 |
26 } // namespace | 44 } // namespace |
27 | 45 |
28 namespace skia { | 46 namespace skia { |
29 | 47 |
30 POINT SkPointToPOINT(const SkPoint& point) { | 48 POINT SkPointToPOINT(const SkPoint& point) { |
31 POINT win_point = { | 49 POINT win_point = { |
32 SkScalarRoundToInt(point.fX), SkScalarRoundToInt(point.fY) | 50 SkScalarRoundToInt(point.fX), SkScalarRoundToInt(point.fY) |
33 }; | 51 }; |
34 return win_point; | 52 return win_point; |
35 } | 53 } |
(...skipping 30 matching lines...) Expand all Loading... |
66 // and arcs themselves fully respect the device context's world-to-device | 84 // and arcs themselves fully respect the device context's world-to-device |
67 // transformation. | 85 // transformation. |
68 BOOL res = SetGraphicsMode(context, GM_ADVANCED); | 86 BOOL res = SetGraphicsMode(context, GM_ADVANCED); |
69 SkASSERT(res != 0); | 87 SkASSERT(res != 0); |
70 | 88 |
71 // Enables dithering. | 89 // Enables dithering. |
72 res = SetStretchBltMode(context, HALFTONE); | 90 res = SetStretchBltMode(context, HALFTONE); |
73 SkASSERT(res != 0); | 91 SkASSERT(res != 0); |
74 // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called | 92 // As per SetStretchBltMode() documentation, SetBrushOrgEx() must be called |
75 // right after. | 93 // right after. |
76 res = SetBrushOrgEx(context, 0, 0, NULL); | 94 res = SetBrushOrgEx(context, 0, 0, nullptr); |
77 SkASSERT(res != 0); | 95 SkASSERT(res != 0); |
78 | 96 |
79 // Sets up default orientation. | 97 // Sets up default orientation. |
80 res = SetArcDirection(context, AD_CLOCKWISE); | 98 res = SetArcDirection(context, AD_CLOCKWISE); |
81 SkASSERT(res != 0); | 99 SkASSERT(res != 0); |
82 | 100 |
83 // Sets up default colors. | 101 // Sets up default colors. |
84 res = SetBkColor(context, RGB(255, 255, 255)); | 102 res = SetBkColor(context, RGB(255, 255, 255)); |
85 SkASSERT(res != CLR_INVALID); | 103 SkASSERT(res != CLR_INVALID); |
86 res = SetTextColor(context, RGB(0, 0, 0)); | 104 res = SetTextColor(context, RGB(0, 0, 0)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 source, | 159 source, |
142 src_rect.left, | 160 src_rect.left, |
143 src_rect.top, | 161 src_rect.top, |
144 copy_width, | 162 copy_width, |
145 copy_height, | 163 copy_height, |
146 blend_function); | 164 blend_function); |
147 } | 165 } |
148 LoadTransformToDC(source, transform); | 166 LoadTransformToDC(source, transform); |
149 } | 167 } |
150 | 168 |
| 169 void CreateBitmapHeader(int width, int height, BITMAPINFOHEADER* hdr) { |
| 170 CreateBitmapHeaderWithColorDepth(width, height, 32, hdr); |
| 171 } |
| 172 |
| 173 HBITMAP CreateHBitmap(int width, int height, HANDLE shared_section, void** data)
{ |
| 174 // CreateDIBSection fails to allocate anything if we try to create an empty |
| 175 // bitmap, so just create a minimal bitmap. |
| 176 if ((width == 0) || (height == 0)) { |
| 177 width = 1; |
| 178 height = 1; |
| 179 } |
| 180 |
| 181 BITMAPINFOHEADER hdr = {0}; |
| 182 CreateBitmapHeaderWithColorDepth(width, height, 32, &hdr); |
| 183 |
| 184 HBITMAP hbitmap = CreateDIBSection(nullptr, |
| 185 reinterpret_cast<BITMAPINFO*>(&hdr), |
| 186 0, data, shared_section, 0); |
| 187 |
| 188 // If CreateDIBSection() failed, try to get some useful information out |
| 189 // before we crash for post-mortem analysis. |
| 190 if (!hbitmap) |
| 191 base::debug::GDIBitmapAllocFailure(&hdr, shared_section); |
| 192 |
| 193 return hbitmap; |
| 194 } |
| 195 |
151 } // namespace skia | 196 } // namespace skia |
152 | 197 |
OLD | NEW |