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

Side by Side Diff: skia/ext/vector_canvas.cc

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

Powered by Google App Engine
This is Rietveld 408576698