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

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

Issue 7633040: CL removing inheritance of SkDevice from PlatformDevice. Flavours of PlatformDevice classes now ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « skia/ext/vector_platform_device_emf_win.h ('k') | skia/ext/vector_platform_device_skia.h » ('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) 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"
11 #include "third_party/skia/include/core/SkTemplates.h" 11 #include "third_party/skia/include/core/SkTemplates.h"
12 #include "third_party/skia/include/core/SkUtils.h" 12 #include "third_party/skia/include/core/SkUtils.h"
13 #include "third_party/skia/include/ports/SkTypeface_win.h" 13 #include "third_party/skia/include/ports/SkTypeface_win.h"
14 14
15 namespace skia { 15 namespace skia {
16 16
17 //static 17 //static
18 PlatformDevice* VectorPlatformDeviceEmf::CreateDevice(int width, int height, 18 SkDevice* VectorPlatformDeviceEmf::CreateDevice(
19 bool is_opaque, 19 int width, int height, bool is_opaque, HANDLE shared_section) {
20 HANDLE shared_section) {
21 if (!is_opaque) { 20 if (!is_opaque) {
22 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent 21 // TODO(maruel): http://crbug.com/18382 When restoring a semi-transparent
23 // layer, i.e. merging it, we need to rasterize it because GDI doesn't 22 // layer, i.e. merging it, we need to rasterize it because GDI doesn't
24 // support transparency except for AlphaBlend(). Right now, a 23 // support transparency except for AlphaBlend(). Right now, a
25 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers() 24 // BitmapPlatformDevice is created when VectorCanvas think a saveLayers()
26 // call is being done. The way to save a layer would be to create an 25 // call is being done. The way to save a layer would be to create an
27 // EMF-based VectorDevice and have this device registers the drawing. When 26 // EMF-based VectorDevice and have this device registers the drawing. When
28 // playing back the device into a bitmap, do it at the printer's dpi instead 27 // playing back the device into a bitmap, do it at the printer's dpi instead
29 // of the layout's dpi (which is much lower). 28 // of the layout's dpi (which is much lower).
30 return BitmapPlatformDevice::create(width, height, is_opaque, 29 return BitmapPlatformDevice::create(width, height, is_opaque,
31 shared_section); 30 shared_section);
32 } 31 }
33 32
34 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to 33 // TODO(maruel): http://crbug.com/18383 Look if it would be worth to
35 // increase the resolution by ~10x (any worthy factor) to increase the 34 // increase the resolution by ~10x (any worthy factor) to increase the
36 // rendering precision (think about printing) while using a relatively 35 // rendering precision (think about printing) while using a relatively
37 // low dpi. This happens because we receive float as input but the GDI 36 // low dpi. This happens because we receive float as input but the GDI
38 // functions works with integers. The idea is to premultiply the matrix 37 // functions works with integers. The idea is to premultiply the matrix
39 // with this factor and multiply each SkScalar that are passed to 38 // with this factor and multiply each SkScalar that are passed to
40 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already 39 // SkScalarRound(value) as SkScalarRound(value * 10). Safari is already
41 // doing the same for text rendering. 40 // doing the same for text rendering.
42 SkASSERT(shared_section); 41 SkASSERT(shared_section);
43 PlatformDevice* device = VectorPlatformDeviceEmf::create( 42 SkDevice* device = VectorPlatformDeviceEmf::create(
44 reinterpret_cast<HDC>(shared_section), width, height); 43 reinterpret_cast<HDC>(shared_section), width, height);
45 return device; 44 return device;
46 } 45 }
47 46
48 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) { 47 static void FillBitmapInfoHeader(int width, int height, BITMAPINFOHEADER* hdr) {
49 hdr->biSize = sizeof(BITMAPINFOHEADER); 48 hdr->biSize = sizeof(BITMAPINFOHEADER);
50 hdr->biWidth = width; 49 hdr->biWidth = width;
51 hdr->biHeight = -height; // Minus means top-down bitmap. 50 hdr->biHeight = -height; // Minus means top-down bitmap.
52 hdr->biPlanes = 1; 51 hdr->biPlanes = 1;
53 hdr->biBitCount = 32; 52 hdr->biBitCount = 32;
54 hdr->biCompression = BI_RGB; // no compression 53 hdr->biCompression = BI_RGB; // no compression
55 hdr->biSizeImage = 0; 54 hdr->biSizeImage = 0;
56 hdr->biXPelsPerMeter = 1; 55 hdr->biXPelsPerMeter = 1;
57 hdr->biYPelsPerMeter = 1; 56 hdr->biYPelsPerMeter = 1;
58 hdr->biClrUsed = 0; 57 hdr->biClrUsed = 0;
59 hdr->biClrImportant = 0; 58 hdr->biClrImportant = 0;
60 } 59 }
61 60
62 VectorPlatformDeviceEmf* VectorPlatformDeviceEmf::create(HDC dc, 61 SkDevice* VectorPlatformDeviceEmf::create(HDC dc, int width, int height) {
63 int width,
64 int height) {
65 InitializeDC(dc); 62 InitializeDC(dc);
66 63
67 // Link the SkBitmap to the current selected bitmap in the device context. 64 // Link the SkBitmap to the current selected bitmap in the device context.
68 SkBitmap bitmap; 65 SkBitmap bitmap;
69 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP); 66 HGDIOBJ selected_bitmap = GetCurrentObject(dc, OBJ_BITMAP);
70 bool succeeded = false; 67 bool succeeded = false;
71 if (selected_bitmap != NULL) { 68 if (selected_bitmap != NULL) {
72 BITMAP bitmap_data; 69 BITMAP bitmap_data;
73 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) == 70 if (GetObject(selected_bitmap, sizeof(BITMAP), &bitmap_data) ==
74 sizeof(BITMAP)) { 71 sizeof(BITMAP)) {
(...skipping 14 matching lines...) Expand all
89 } 86 }
90 } 87 }
91 88
92 if (!succeeded) 89 if (!succeeded)
93 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 90 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
94 91
95 return new VectorPlatformDeviceEmf(dc, bitmap); 92 return new VectorPlatformDeviceEmf(dc, bitmap);
96 } 93 }
97 94
98 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap) 95 VectorPlatformDeviceEmf::VectorPlatformDeviceEmf(HDC dc, const SkBitmap& bitmap)
99 : PlatformDevice(bitmap), 96 : SkDevice(bitmap),
100 hdc_(dc), 97 hdc_(dc),
101 previous_brush_(NULL), 98 previous_brush_(NULL),
102 previous_pen_(NULL), 99 previous_pen_(NULL),
103 alpha_blend_used_(false) { 100 alpha_blend_used_(false) {
104 transform_.reset(); 101 transform_.reset();
102 SetPlatformDevice(this, this);
105 } 103 }
106 104
107 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() { 105 VectorPlatformDeviceEmf::~VectorPlatformDeviceEmf() {
108 SkASSERT(previous_brush_ == NULL); 106 SkASSERT(previous_brush_ == NULL);
109 SkASSERT(previous_pen_ == NULL); 107 SkASSERT(previous_pen_ == NULL);
110 } 108 }
111 109
112 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() { 110 HDC VectorPlatformDeviceEmf::BeginPlatformPaint() {
113 return hdc_; 111 return hdc_;
114 } 112 }
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 pixels, 856 pixels,
859 reinterpret_cast<const BITMAPINFO*>(&hdr), 857 reinterpret_cast<const BITMAPINFO*>(&hdr),
860 DIB_RGB_COLORS, 858 DIB_RGB_COLORS,
861 SRCCOPY); 859 SRCCOPY);
862 } 860 }
863 EndPlatformPaint(); 861 EndPlatformPaint();
864 Cleanup(); 862 Cleanup();
865 } 863 }
866 864
867 } // namespace skia 865 } // namespace skia
868
OLDNEW
« no previous file with comments | « skia/ext/vector_platform_device_emf_win.h ('k') | skia/ext/vector_platform_device_skia.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698