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

Side by Side Diff: skia/ext/vector_platform_device_skia.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, 4 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
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 "skia/ext/vector_platform_device_skia.h" 5 #include "skia/ext/vector_platform_device_skia.h"
6 6
7 #include "skia/ext/bitmap_platform_device.h" 7 #include "skia/ext/bitmap_platform_device.h"
8 #include "skia/ext/platform_canvas.h"
8 #include "third_party/skia/include/core/SkClipStack.h" 9 #include "third_party/skia/include/core/SkClipStack.h"
9 #include "third_party/skia/include/core/SkDraw.h" 10 #include "third_party/skia/include/core/SkDraw.h"
10 #include "third_party/skia/include/core/SkRect.h" 11 #include "third_party/skia/include/core/SkRect.h"
11 #include "third_party/skia/include/core/SkRegion.h" 12 #include "third_party/skia/include/core/SkRegion.h"
12 #include "third_party/skia/include/core/SkScalar.h" 13 #include "third_party/skia/include/core/SkScalar.h"
13 14
14 namespace skia { 15 namespace skia {
15 16
16 static inline SkBitmap makeABitmap(int width, int height) { 17 static inline SkBitmap makeABitmap(int width, int height) {
17 SkBitmap bitmap; 18 SkBitmap bitmap;
18 bitmap.setConfig(SkBitmap::kNo_Config, width, height); 19 bitmap.setConfig(SkBitmap::kNo_Config, width, height);
19 return bitmap; 20 return bitmap;
20 } 21 }
21 22
22 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(SkPDFDevice* pdf_device) 23 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
23 : PlatformDevice(makeABitmap(pdf_device->width(), pdf_device->height())), 24 const SkISize& pageSize,
24 pdf_device_(pdf_device) { 25 const SkISize& contentSize,
26 const SkMatrix& initialTransform)
27 : SkPDFDevice(pageSize, contentSize, initialTransform) {
28 SetPlatformDevice(this, this);
25 } 29 }
26 30
27 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { 31 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
28 } 32 }
29 33
30 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() { 34 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
31 return false; 35 return false;
32 } 36 }
33 37
34 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() { 38 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
35 // Even when drawing a vector representation of the page, we have to 39 // Even when drawing a vector representation of the page, we have to
36 // provide a raster surface for plugins to render into - they don't have 40 // provide a raster surface for plugins to render into - they don't have
37 // a vector interface. Therefore we create a BitmapPlatformDevice here 41 // a vector interface. Therefore we create a BitmapPlatformDevice here
38 // and return the context from it, then layer on the raster data as an 42 // and return the context from it, then layer on the raster data as an
39 // image in EndPlatformPaint. 43 // image in EndPlatformPaint.
40 DCHECK(raster_surface_ == NULL); 44 DCHECK(raster_surface_ == NULL);
41 #if defined(OS_WIN) 45 #if defined(OS_WIN)
42 raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(), 46 raster_surface_ = BitmapPlatformDevice::create(width(),
43 pdf_device_->height(), 47 height(),
44 false, /* not opaque */ 48 false, /* not opaque */
45 NULL); 49 NULL);
46 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 50 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
47 raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(), 51 raster_surface_ = BitmapPlatformDevice::Create(width(),
48 pdf_device_->height(), 52 height(),
49 false /* not opaque */); 53 false /* not opaque */);
50 #endif 54 #endif
51 raster_surface_->unref(); // SkRefPtr and create both took a reference. 55 raster_surface_->unref(); // SkRefPtr and create both took a reference.
52 56
53 SkCanvas canvas(raster_surface_.get()); 57 SkCanvas canvas(raster_surface_.get());
54 return raster_surface_->BeginPlatformPaint(); 58 return raster_surface_->BeginPlatformPaint();
55 } 59 }
56 60
57 void VectorPlatformDeviceSkia::EndPlatformPaint() { 61 void VectorPlatformDeviceSkia::EndPlatformPaint() {
58 DCHECK(raster_surface_ != NULL); 62 DCHECK(raster_surface_ != NULL);
59 SkPaint paint; 63 SkPaint paint;
60 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake 64 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake
61 // it out by setting a non-empty clip. 65 // it out by setting a non-empty clip.
62 SkDraw draw; 66 SkDraw draw;
63 SkRegion clip(SkIRect::MakeWH(pdf_device_->width(), pdf_device_->height())); 67 SkRegion clip(SkIRect::MakeWH(width(), height()));
64 draw.fClip=&clip; 68 draw.fClip=&clip;
65 pdf_device_->drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, 69 drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, paint);
66 paint);
67 // BitmapPlatformDevice matches begin and end calls. 70 // BitmapPlatformDevice matches begin and end calls.
68 raster_surface_->EndPlatformPaint(); 71 raster_surface_->EndPlatformPaint();
69 raster_surface_ = NULL; 72 raster_surface_ = NULL;
70 } 73 }
71 74
72 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() {
73 return SkDevice::getDeviceCapabilities() | kVector_Capability;
74 }
75
76 int VectorPlatformDeviceSkia::width() const {
77 return pdf_device_->width();
78 }
79
80 int VectorPlatformDeviceSkia::height() const {
81 return pdf_device_->height();
82 }
83
84 void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix,
85 const SkRegion& region,
86 const SkClipStack& stack) {
87 pdf_device_->setMatrixClip(matrix, region, stack);
88 }
89
90 bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect,
91 SkBitmap* bitmap) {
92 return false;
93 }
94
95 void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw,
96 const SkPaint& paint) {
97 pdf_device_->drawPaint(draw, paint);
98 }
99
100 void VectorPlatformDeviceSkia::drawPoints(const SkDraw& draw,
101 SkCanvas::PointMode mode,
102 size_t count, const SkPoint pts[],
103 const SkPaint& paint) {
104 pdf_device_->drawPoints(draw, mode, count, pts, paint);
105 }
106
107 void VectorPlatformDeviceSkia::drawRect(const SkDraw& draw,
108 const SkRect& rect,
109 const SkPaint& paint) {
110 pdf_device_->drawRect(draw, rect, paint);
111 }
112
113 void VectorPlatformDeviceSkia::drawPath(const SkDraw& draw,
114 const SkPath& path,
115 const SkPaint& paint,
116 const SkMatrix* prePathMatrix,
117 bool pathIsMutable) {
118 pdf_device_->drawPath(draw, path, paint, prePathMatrix, pathIsMutable);
119 }
120
121 void VectorPlatformDeviceSkia::drawBitmap(const SkDraw& draw,
122 const SkBitmap& bitmap,
123 const SkIRect* srcRectOrNull,
124 const SkMatrix& matrix,
125 const SkPaint& paint) {
126 pdf_device_->drawBitmap(draw, bitmap, srcRectOrNull, matrix, paint);
127 }
128
129 void VectorPlatformDeviceSkia::drawSprite(const SkDraw& draw,
130 const SkBitmap& bitmap,
131 int x, int y,
132 const SkPaint& paint) {
133 pdf_device_->drawSprite(draw, bitmap, x, y, paint);
134 }
135
136 void VectorPlatformDeviceSkia::drawText(const SkDraw& draw,
137 const void* text,
138 size_t byteLength,
139 SkScalar x,
140 SkScalar y,
141 const SkPaint& paint) {
142 pdf_device_->drawText(draw, text, byteLength, x, y, paint);
143 }
144
145 void VectorPlatformDeviceSkia::drawPosText(const SkDraw& draw,
146 const void* text,
147 size_t len,
148 const SkScalar pos[],
149 SkScalar constY,
150 int scalarsPerPos,
151 const SkPaint& paint) {
152 pdf_device_->drawPosText(draw, text, len, pos, constY, scalarsPerPos, paint);
153 }
154
155 void VectorPlatformDeviceSkia::drawTextOnPath(const SkDraw& draw,
156 const void* text,
157 size_t len,
158 const SkPath& path,
159 const SkMatrix* matrix,
160 const SkPaint& paint) {
161 pdf_device_->drawTextOnPath(draw, text, len, path, matrix, paint);
162 }
163
164 void VectorPlatformDeviceSkia::drawVertices(const SkDraw& draw,
165 SkCanvas::VertexMode vmode,
166 int vertexCount,
167 const SkPoint vertices[],
168 const SkPoint texs[],
169 const SkColor colors[],
170 SkXfermode* xmode,
171 const uint16_t indices[],
172 int indexCount,
173 const SkPaint& paint) {
174 pdf_device_->drawVertices(draw, vmode, vertexCount, vertices, texs, colors,
175 xmode, indices, indexCount, paint);
176 }
177
178 void VectorPlatformDeviceSkia::drawDevice(const SkDraw& draw,
179 SkDevice* device,
180 int x,
181 int y,
182 const SkPaint& paint) {
183 SkDevice* real_device = device;
184 if ((device->getDeviceCapabilities() & kVector_Capability)) {
185 // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need
186 // to unwrap the embedded SkPDFDevice.
187 VectorPlatformDeviceSkia* vector_device =
188 static_cast<VectorPlatformDeviceSkia*>(device);
189 real_device = vector_device->pdf_device_.get();
190 }
191 pdf_device_->drawDevice(draw, real_device, x, y, paint);
192 }
193
194 #if defined(OS_WIN) 75 #if defined(OS_WIN)
195 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc, 76 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc,
196 int x, 77 int x,
197 int y, 78 int y,
198 const RECT* src_rect) { 79 const RECT* src_rect) {
199 SkASSERT(false); 80 SkASSERT(false);
200 } 81 }
201 #elif defined(OS_MACOSX) 82 #elif defined(OS_MACOSX)
202 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x, 83 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x,
203 int y, const CGRect* src_rect) { 84 int y, const CGRect* src_rect) {
204 SkASSERT(false); 85 SkASSERT(false);
205 } 86 }
206 87
207 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { 88 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() {
208 SkASSERT(false); 89 SkASSERT(false);
209 return NULL; 90 return NULL;
210 } 91 }
211
212 #endif 92 #endif
213 93
214 SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice(
215 SkBitmap::Config config, int width, int height, bool isOpaque,
216 Usage /*usage*/) {
217 SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width,
218 height,
219 isOpaque));
220 return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get()));
221 }
222
223 } // namespace skia 94 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698