OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include "skia/ext/vector_platform_device_emf_win.h" | 7 #include "skia/ext/vector_platform_device_emf_win.h" |
8 | 8 |
9 #include "skia/ext/bitmap_platform_device.h" | 9 #include "skia/ext/bitmap_platform_device.h" |
10 #include "skia/ext/skia_utils_win.h" | 10 #include "skia/ext/skia_utils_win.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 SkSafeUnref(paint_no_effet.setPathEffect(NULL)); | 187 SkSafeUnref(paint_no_effet.setPathEffect(NULL)); |
188 | 188 |
189 // Draw the calculated path. | 189 // Draw the calculated path. |
190 drawPath(draw, path_modified, paint_no_effet); | 190 drawPath(draw, path_modified, paint_no_effet); |
191 return; | 191 return; |
192 } | 192 } |
193 | 193 |
194 if (!ApplyPaint(paint)) { | 194 if (!ApplyPaint(paint)) { |
195 return; | 195 return; |
196 } | 196 } |
197 HDC dc = getBitmapDC(); | 197 HDC dc = beginPlatformPaint(); |
198 if (!Rectangle(dc, SkScalarRound(rect.fLeft), | 198 if (!Rectangle(dc, SkScalarRound(rect.fLeft), |
199 SkScalarRound(rect.fTop), | 199 SkScalarRound(rect.fTop), |
200 SkScalarRound(rect.fRight), | 200 SkScalarRound(rect.fRight), |
201 SkScalarRound(rect.fBottom))) { | 201 SkScalarRound(rect.fBottom))) { |
202 SkASSERT(false); | 202 SkASSERT(false); |
203 } | 203 } |
| 204 endPlatformPaint(); |
204 Cleanup(); | 205 Cleanup(); |
205 } | 206 } |
206 | 207 |
207 void VectorPlatformDeviceEmf::drawPath(const SkDraw& draw, | 208 void VectorPlatformDeviceEmf::drawPath(const SkDraw& draw, |
208 const SkPath& path, | 209 const SkPath& path, |
209 const SkPaint& paint, | 210 const SkPaint& paint, |
210 const SkMatrix* prePathMatrix, | 211 const SkMatrix* prePathMatrix, |
211 bool pathIsMutable) { | 212 bool pathIsMutable) { |
212 if (paint.getPathEffect()) { | 213 if (paint.getPathEffect()) { |
213 // Apply the path effect forehand. | 214 // Apply the path effect forehand. |
214 SkPath path_modified; | 215 SkPath path_modified; |
215 paint.getFillPath(path, &path_modified); | 216 paint.getFillPath(path, &path_modified); |
216 | 217 |
217 // Removes the path effect from the temporary SkPaint object. | 218 // Removes the path effect from the temporary SkPaint object. |
218 SkPaint paint_no_effet(paint); | 219 SkPaint paint_no_effet(paint); |
219 SkSafeUnref(paint_no_effet.setPathEffect(NULL)); | 220 SkSafeUnref(paint_no_effet.setPathEffect(NULL)); |
220 | 221 |
221 // Draw the calculated path. | 222 // Draw the calculated path. |
222 drawPath(draw, path_modified, paint_no_effet); | 223 drawPath(draw, path_modified, paint_no_effet); |
223 return; | 224 return; |
224 } | 225 } |
225 | 226 |
226 if (!ApplyPaint(paint)) { | 227 if (!ApplyPaint(paint)) { |
227 return; | 228 return; |
228 } | 229 } |
229 HDC dc = getBitmapDC(); | 230 HDC dc = beginPlatformPaint(); |
230 PlatformDevice::LoadPathToDC(dc, path); | 231 PlatformDevice::LoadPathToDC(dc, path); |
231 switch (paint.getStyle()) { | 232 switch (paint.getStyle()) { |
232 case SkPaint::kFill_Style: { | 233 case SkPaint::kFill_Style: { |
233 BOOL res = StrokeAndFillPath(dc); | 234 BOOL res = StrokeAndFillPath(dc); |
234 SkASSERT(res != 0); | 235 SkASSERT(res != 0); |
235 break; | 236 break; |
236 } | 237 } |
237 case SkPaint::kStroke_Style: { | 238 case SkPaint::kStroke_Style: { |
238 BOOL res = StrokePath(dc); | 239 BOOL res = StrokePath(dc); |
239 SkASSERT(res != 0); | 240 SkASSERT(res != 0); |
240 break; | 241 break; |
241 } | 242 } |
242 case SkPaint::kStrokeAndFill_Style: { | 243 case SkPaint::kStrokeAndFill_Style: { |
243 BOOL res = StrokeAndFillPath(dc); | 244 BOOL res = StrokeAndFillPath(dc); |
244 SkASSERT(res != 0); | 245 SkASSERT(res != 0); |
245 break; | 246 break; |
246 } | 247 } |
247 default: | 248 default: |
248 SkASSERT(false); | 249 SkASSERT(false); |
249 break; | 250 break; |
250 } | 251 } |
| 252 endPlatformPaint(); |
251 Cleanup(); | 253 Cleanup(); |
252 } | 254 } |
253 | 255 |
254 void VectorPlatformDeviceEmf::drawBitmap(const SkDraw& draw, | 256 void VectorPlatformDeviceEmf::drawBitmap(const SkDraw& draw, |
255 const SkBitmap& bitmap, | 257 const SkBitmap& bitmap, |
256 const SkIRect* srcRectOrNull, | 258 const SkIRect* srcRectOrNull, |
257 const SkMatrix& matrix, | 259 const SkMatrix& matrix, |
258 const SkPaint& paint) { | 260 const SkPaint& paint) { |
259 // Load the temporary matrix. This is what will translate, rotate and resize | 261 // Load the temporary matrix. This is what will translate, rotate and resize |
260 // the bitmap. | 262 // the bitmap. |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 BITMAPV4HEADER bitmap_header; | 627 BITMAPV4HEADER bitmap_header; |
626 memset(&bitmap_header, 0, sizeof(BITMAPV4HEADER)); | 628 memset(&bitmap_header, 0, sizeof(BITMAPV4HEADER)); |
627 FillBitmapInfoHeader(src_size_x, src_size_y, | 629 FillBitmapInfoHeader(src_size_x, src_size_y, |
628 reinterpret_cast<BITMAPINFOHEADER*>(&bitmap_header)); | 630 reinterpret_cast<BITMAPINFOHEADER*>(&bitmap_header)); |
629 bitmap_header.bV4Size = sizeof(BITMAPV4HEADER); | 631 bitmap_header.bV4Size = sizeof(BITMAPV4HEADER); |
630 bitmap_header.bV4RedMask = 0x00ff0000; | 632 bitmap_header.bV4RedMask = 0x00ff0000; |
631 bitmap_header.bV4GreenMask = 0x0000ff00; | 633 bitmap_header.bV4GreenMask = 0x0000ff00; |
632 bitmap_header.bV4BlueMask = 0x000000ff; | 634 bitmap_header.bV4BlueMask = 0x000000ff; |
633 bitmap_header.bV4AlphaMask = 0xff000000; | 635 bitmap_header.bV4AlphaMask = 0xff000000; |
634 | 636 |
635 HDC dc = getBitmapDC(); | |
636 SkAutoLockPixels lock(bitmap); | 637 SkAutoLockPixels lock(bitmap); |
637 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 638 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
638 const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels()); | 639 const uint32_t* pixels = static_cast<const uint32_t*>(bitmap.getPixels()); |
639 if (pixels == NULL) { | 640 if (pixels == NULL) { |
640 SkASSERT(false); | 641 SkASSERT(false); |
641 return; | 642 return; |
642 } | 643 } |
643 | 644 |
644 if (!is_translucent) { | 645 if (!is_translucent) { |
645 int row_length = bitmap.rowBytesAsPixels(); | 646 int row_length = bitmap.rowBytesAsPixels(); |
646 // There is no quick way to determine if an image is opaque. | 647 // There is no quick way to determine if an image is opaque. |
647 for (int y2 = 0; y2 < src_size_y; ++y2) { | 648 for (int y2 = 0; y2 < src_size_y; ++y2) { |
648 for (int x2 = 0; x2 < src_size_x; ++x2) { | 649 for (int x2 = 0; x2 < src_size_x; ++x2) { |
649 if (SkColorGetA(pixels[(y2 * row_length) + x2]) != 255) { | 650 if (SkColorGetA(pixels[(y2 * row_length) + x2]) != 255) { |
650 is_translucent = true; | 651 is_translucent = true; |
651 y2 = src_size_y; | 652 y2 = src_size_y; |
652 break; | 653 break; |
653 } | 654 } |
654 } | 655 } |
655 } | 656 } |
656 } | 657 } |
657 | 658 |
| 659 HDC dc = beginPlatformPaint(); |
658 BITMAPINFOHEADER hdr; | 660 BITMAPINFOHEADER hdr; |
659 FillBitmapInfoHeader(src_size_x, src_size_y, &hdr); | 661 FillBitmapInfoHeader(src_size_x, src_size_y, &hdr); |
660 if (is_translucent) { | 662 if (is_translucent) { |
661 // The image must be loaded as a bitmap inside a device context. | 663 // The image must be loaded as a bitmap inside a device context. |
662 HDC bitmap_dc = ::CreateCompatibleDC(dc); | 664 HDC bitmap_dc = ::CreateCompatibleDC(dc); |
663 void* bits = NULL; | 665 void* bits = NULL; |
664 HBITMAP hbitmap = ::CreateDIBSection( | 666 HBITMAP hbitmap = ::CreateDIBSection( |
665 bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr), | 667 bitmap_dc, reinterpret_cast<const BITMAPINFO*>(&hdr), |
666 DIB_RGB_COLORS, &bits, NULL, 0); | 668 DIB_RGB_COLORS, &bits, NULL, 0); |
667 | 669 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 x, y, // Destination origin. | 715 x, y, // Destination origin. |
714 src_size_x, src_size_y, | 716 src_size_x, src_size_y, |
715 0, 0, // Source origin. | 717 0, 0, // Source origin. |
716 src_size_x, src_size_y, // Source size. | 718 src_size_x, src_size_y, // Source size. |
717 pixels, | 719 pixels, |
718 reinterpret_cast<const BITMAPINFO*>(&hdr), | 720 reinterpret_cast<const BITMAPINFO*>(&hdr), |
719 DIB_RGB_COLORS, | 721 DIB_RGB_COLORS, |
720 SRCCOPY); | 722 SRCCOPY); |
721 SkASSERT(result); | 723 SkASSERT(result); |
722 } | 724 } |
| 725 endPlatformPaint(); |
723 Cleanup(); | 726 Cleanup(); |
724 } | 727 } |
725 | 728 |
726 } // namespace skia | 729 } // namespace skia |
727 | 730 |
OLD | NEW |