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

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

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