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

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, 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_skia.h ('k') | skia/skia.gyp » ('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 "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 "third_party/skia/include/core/SkClipStack.h" 8 #include "third_party/skia/include/core/SkClipStack.h"
9 #include "third_party/skia/include/core/SkDraw.h" 9 #include "third_party/skia/include/core/SkDraw.h"
10 #include "third_party/skia/include/core/SkRect.h" 10 #include "third_party/skia/include/core/SkRect.h"
11 #include "third_party/skia/include/core/SkRegion.h" 11 #include "third_party/skia/include/core/SkRegion.h"
12 #include "third_party/skia/include/core/SkScalar.h" 12 #include "third_party/skia/include/core/SkScalar.h"
13 13
14 namespace skia { 14 namespace skia {
15 15
16 static inline SkBitmap makeABitmap(int width, int height) { 16 static inline SkBitmap makeABitmap(int width, int height) {
17 SkBitmap bitmap; 17 SkBitmap bitmap;
18 bitmap.setConfig(SkBitmap::kNo_Config, width, height); 18 bitmap.setConfig(SkBitmap::kNo_Config, width, height);
19 return bitmap; 19 return bitmap;
20 } 20 }
21 21
22 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(SkPDFDevice* pdf_device) 22 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
23 : PlatformDevice(makeABitmap(pdf_device->width(), pdf_device->height())), 23 const SkISize& pageSize,
24 pdf_device_(pdf_device) { 24 const SkISize& contentSize,
25 const SkMatrix& initialTransform)
26 : SkPDFDevice(pageSize, contentSize, initialTransform) {
27 SetPlatformDevice(this, this);
25 } 28 }
26 29
27 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { 30 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
28 } 31 }
29 32
30 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() { 33 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
31 return false; 34 return false;
32 } 35 }
33 36
34 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() { 37 PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
35 // Even when drawing a vector representation of the page, we have to 38 // 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 39 // provide a raster surface for plugins to render into - they don't have
37 // a vector interface. Therefore we create a BitmapPlatformDevice here 40 // a vector interface. Therefore we create a BitmapPlatformDevice here
38 // and return the context from it, then layer on the raster data as an 41 // and return the context from it, then layer on the raster data as an
39 // image in EndPlatformPaint. 42 // image in EndPlatformPaint.
40 DCHECK(raster_surface_ == NULL); 43 DCHECK(raster_surface_ == NULL);
41 #if defined(OS_WIN) 44 #if defined(OS_WIN)
42 raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(), 45 raster_surface_ = BitmapPlatformDevice::create(width(),
43 pdf_device_->height(), 46 height(),
44 false, /* not opaque */ 47 false, /* not opaque */
45 NULL); 48 NULL);
46 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 49 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
47 raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(), 50 raster_surface_ = BitmapPlatformDevice::Create(width(),
48 pdf_device_->height(), 51 height(),
49 false /* not opaque */); 52 false /* not opaque */);
50 #endif 53 #endif
51 raster_surface_->unref(); // SkRefPtr and create both took a reference. 54 raster_surface_->unref(); // SkRefPtr and create both took a reference.
52 55
53 SkCanvas canvas(raster_surface_.get()); 56 SkCanvas canvas(raster_surface_.get());
54 return raster_surface_->BeginPlatformPaint(); 57 return raster_surface_->BeginPlatformPaint();
55 } 58 }
56 59
57 void VectorPlatformDeviceSkia::EndPlatformPaint() { 60 void VectorPlatformDeviceSkia::EndPlatformPaint() {
58 DCHECK(raster_surface_ != NULL); 61 DCHECK(raster_surface_ != NULL);
59 SkPaint paint; 62 SkPaint paint;
60 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake 63 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake
61 // it out by setting a non-empty clip. 64 // it out by setting a non-empty clip.
62 SkDraw draw; 65 SkDraw draw;
63 SkRegion clip(SkIRect::MakeWH(pdf_device_->width(), pdf_device_->height())); 66 SkRegion clip(SkIRect::MakeWH(width(), height()));
64 draw.fClip=&clip; 67 draw.fClip=&clip;
65 pdf_device_->drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, 68 drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, paint);
66 paint);
67 // BitmapPlatformDevice matches begin and end calls. 69 // BitmapPlatformDevice matches begin and end calls.
68 raster_surface_->EndPlatformPaint(); 70 raster_surface_->EndPlatformPaint();
69 raster_surface_ = NULL; 71 raster_surface_ = NULL;
70 } 72 }
71 73
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 vector_device->pdf_device_->setOrigin(vector_device->getOrigin().fX,
190 vector_device->getOrigin().fY);
191 real_device = vector_device->pdf_device_.get();
192 }
193 pdf_device_->drawDevice(draw, real_device, x, y, paint);
194 }
195
196 void VectorPlatformDeviceSkia::setDrawingArea(SkPDFDevice::DrawingArea area) {
197 pdf_device_->setDrawingArea(area);
198 }
199
200 #if defined(OS_WIN) 74 #if defined(OS_WIN)
201 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc, 75 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc,
202 int x, 76 int x,
203 int y, 77 int y,
204 const RECT* src_rect) { 78 const RECT* src_rect) {
205 SkASSERT(false); 79 SkASSERT(false);
206 } 80 }
207 #elif defined(OS_MACOSX) 81 #elif defined(OS_MACOSX)
208 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x, 82 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x,
209 int y, const CGRect* src_rect) { 83 int y, const CGRect* src_rect) {
210 SkASSERT(false); 84 SkASSERT(false);
211 } 85 }
212 86
213 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { 87 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() {
214 SkASSERT(false); 88 SkASSERT(false);
215 return NULL; 89 return NULL;
216 } 90 }
217 91 #elif defined(OS_LINUX)
92 void VectorPlatformDeviceSkia::DrawToNativeContext(
93 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
94 // Should never be called on Linux.
95 SkASSERT(false);
96 }
218 #endif 97 #endif
219 98
220 SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice(
221 SkBitmap::Config config, int width, int height, bool isOpaque,
222 Usage /*usage*/) {
223 SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width,
224 height,
225 isOpaque));
226 return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get()));
227 }
228
229 } // namespace skia 99 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/vector_platform_device_skia.h ('k') | skia/skia.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698