| 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/vector_canvas.h" | 5 #include "skia/ext/vector_canvas.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "skia/ext/vector_device.h" | 7 #include "skia/ext/vector_device.h" |
| 9 | 8 |
| 10 namespace skia { | 9 namespace skia { |
| 11 | 10 |
| 12 VectorCanvas::VectorCanvas() { | 11 VectorCanvas::VectorCanvas() { |
| 13 } | 12 } |
| 14 | 13 |
| 15 VectorCanvas::VectorCanvas(HDC dc, int width, int height) { | 14 VectorCanvas::VectorCanvas(HDC dc, int width, int height) { |
| 16 bool initialized = initialize(dc, width, height); | 15 bool initialized = initialize(dc, width, height); |
| 17 CHECK(initialized); | 16 if (!initialized) |
| 17 __debugbreak(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 VectorCanvas::~VectorCanvas() { | 20 VectorCanvas::~VectorCanvas() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 bool VectorCanvas::initialize(HDC context, int width, int height) { | 23 bool VectorCanvas::initialize(HDC context, int width, int height) { |
| 24 SkDevice* device = createPlatformDevice(width, height, true, context); | 24 SkDevice* device = createPlatformDevice(width, height, true, context); |
| 25 if (!device) | 25 if (!device) |
| 26 return false; | 26 return false; |
| 27 | 27 |
| 28 setDevice(device); | 28 setDevice(device); |
| 29 device->unref(); // was created with refcount 1, and setDevice also refs | 29 device->unref(); // was created with refcount 1, and setDevice also refs |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 SkBounder* VectorCanvas::setBounder(SkBounder* bounder) { | 33 SkBounder* VectorCanvas::setBounder(SkBounder* bounder) { |
| 34 if (!IsTopDeviceVectorial()) | 34 if (!IsTopDeviceVectorial()) |
| 35 return PlatformCanvasWin::setBounder(bounder); | 35 return PlatformCanvasWin::setBounder(bounder); |
| 36 | 36 |
| 37 // This function isn't used in the code. Verify this assumption. | 37 // This function isn't used in the code. Verify this assumption. |
| 38 NOTREACHED(); | 38 SkASSERT(false); |
| 39 return NULL; | 39 return NULL; |
| 40 } | 40 } |
| 41 | 41 |
| 42 SkDevice* VectorCanvas::createDevice(SkBitmap::Config config, | 42 SkDevice* VectorCanvas::createDevice(SkBitmap::Config config, |
| 43 int width, int height, | 43 int width, int height, |
| 44 bool is_opaque, bool isForLayer) { | 44 bool is_opaque, bool isForLayer) { |
| 45 DCHECK(config == SkBitmap::kARGB_8888_Config); | 45 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
| 46 return createPlatformDevice(width, height, is_opaque, NULL); | 46 return createPlatformDevice(width, height, is_opaque, NULL); |
| 47 } | 47 } |
| 48 | 48 |
| 49 SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { | 49 SkDrawFilter* VectorCanvas::setDrawFilter(SkDrawFilter* filter) { |
| 50 // This function isn't used in the code. Verify this assumption. | 50 // This function isn't used in the code. Verify this assumption. |
| 51 NOTREACHED(); | 51 SkASSERT(false); |
| 52 return NULL; | 52 return NULL; |
| 53 } | 53 } |
| 54 | 54 |
| 55 SkDevice* VectorCanvas::createPlatformDevice(int width, | 55 SkDevice* VectorCanvas::createPlatformDevice(int width, |
| 56 int height, bool is_opaque, | 56 int height, bool is_opaque, |
| 57 HANDLE shared_section) { | 57 HANDLE shared_section) { |
| 58 if (!is_opaque) { | 58 if (!is_opaque) { |
| 59 // TODO(maruel): http://b/1184002 1184002 When restoring a semi-transparent | 59 // TODO(maruel): http://b/1184002 1184002 When restoring a semi-transparent |
| 60 // layer, i.e. merging it, we need to rasterize it because GDI doesn't | 60 // layer, i.e. merging it, we need to rasterize it because GDI doesn't |
| 61 // support transparency except for AlphaBlend(). Right now, a | 61 // support transparency except for AlphaBlend(). Right now, a |
| 62 // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers() | 62 // BitmapPlatformDeviceWin is created when VectorCanvas think a saveLayers() |
| 63 // call is being done. The way to save a layer would be to create an | 63 // call is being done. The way to save a layer would be to create an |
| 64 // EMF-based VectorDevice and have this device registers the drawing. When | 64 // EMF-based VectorDevice and have this device registers the drawing. When |
| 65 // playing back the device into a bitmap, do it at the printer's dpi instead | 65 // playing back the device into a bitmap, do it at the printer's dpi instead |
| 66 // of the layout's dpi (which is much lower). | 66 // of the layout's dpi (which is much lower). |
| 67 return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque, | 67 return PlatformCanvasWin::createPlatformDevice(width, height, is_opaque, |
| 68 shared_section); | 68 shared_section); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // TODO(maruel): http://b/1183870 Look if it would be worth to increase the | 71 // TODO(maruel): http://b/1183870 Look if it would be worth to increase the |
| 72 // resolution by ~10x (any worthy factor) to increase the rendering precision | 72 // resolution by ~10x (any worthy factor) to increase the rendering precision |
| 73 // (think about printing) while using a relatively low dpi. This happens | 73 // (think about printing) while using a relatively low dpi. This happens |
| 74 // because we receive float as input but the GDI functions works with | 74 // because we receive float as input but the GDI functions works with |
| 75 // integers. The idea is to premultiply the matrix with this factor and | 75 // integers. The idea is to premultiply the matrix with this factor and |
| 76 // multiply each SkScalar that are passed to SkScalarRound(value) as | 76 // multiply each SkScalar that are passed to SkScalarRound(value) as |
| 77 // SkScalarRound(value * 10). Safari is already doing the same for text | 77 // SkScalarRound(value * 10). Safari is already doing the same for text |
| 78 // rendering. | 78 // rendering. |
| 79 DCHECK(shared_section); | 79 SkASSERT(shared_section); |
| 80 PlatformDeviceWin* device = VectorDevice::create( | 80 PlatformDeviceWin* device = VectorDevice::create( |
| 81 reinterpret_cast<HDC>(shared_section), width, height); | 81 reinterpret_cast<HDC>(shared_section), width, height); |
| 82 return device; | 82 return device; |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool VectorCanvas::IsTopDeviceVectorial() const { | 85 bool VectorCanvas::IsTopDeviceVectorial() const { |
| 86 return getTopPlatformDevice().IsVectorial(); | 86 return getTopPlatformDevice().IsVectorial(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace skia | 89 } // namespace skia |
| 90 | 90 |
| OLD | NEW |