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

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

Issue 6499024: Connect Skia PDF backend to printing subsystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add zlib dep to gyp and remove MOZ_Z prefix per crrev.com/74975 Created 9 years, 8 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
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "skia/ext/vector_platform_device_skia.h"
6
7 #include "skia/ext/bitmap_platform_device.h"
8 #include "third_party/skia/include/core/SkClipStack.h"
9 #include "third_party/skia/include/core/SkDraw.h"
10 #include "third_party/skia/include/core/SkRect.h"
11 #include "third_party/skia/include/core/SkRegion.h"
12 #include "third_party/skia/include/core/SkScalar.h"
13
14 namespace skia {
15
16 SkDevice* VectorPlatformDeviceSkiaFactory::newDevice(SkCanvas* noUsed,
17 SkBitmap::Config config,
18 int width, int height,
19 bool isOpaque,
20 bool isForLayer) {
21 SkASSERT(config == SkBitmap::kARGB_8888_Config);
22 SkPDFDevice::OriginTransform flip = SkPDFDevice::kFlip_OriginTransform;
23 if (isForLayer)
24 flip = SkPDFDevice::kNoFlip_OriginTransform;
25 return new VectorPlatformDeviceSkia(width, height, flip);
26 }
27
28 static inline SkBitmap makeABitmap(int width, int height) {
29 SkBitmap bitmap;
30 bitmap.setConfig(SkBitmap::kNo_Config, width, height);
31 return bitmap;
32 }
33
34 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
35 int width, int height, SkPDFDevice::OriginTransform flip)
36 : PlatformDevice(makeABitmap(width, height)),
37 pdf_device_(new SkPDFDevice(width, height, flip)) {
38 pdf_device_->unref(); // SkRefPtr and new both took a reference.
39 base_transform_.reset();
40 }
41
42 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
43 }
44
45 bool VectorPlatformDeviceSkia::IsVectorial() {
46 return true;
47 }
48
49 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
50 return false;
51 }
52
53 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
54 // Even when drawing a vector representation of the page, we have to
55 // provide a raster surface for plugins to render into - they don't have
56 // a vector interface. Therefore we create a BitmapPlatformDevice here
57 // and return the context from it, then layer on the raster data as an
58 // image in EndPlatformPaint.
59 DCHECK(raster_surface_ == NULL);
60 #if defined(OS_WIN)
61 raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(),
62 pdf_device_->height(),
63 false, /* not opaque */
64 NULL);
65 #elif defined(OS_LINUX)
66 raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(),
67 pdf_device_->height(),
68 false /* not opaque */);
69 #endif
70 raster_surface_->unref(); // SkRefPtr and create both took a reference.
71
72 SkCanvas canvas(raster_surface_.get());
73 SkPaint black;
74 black.setColor(SK_ColorBLACK);
75 canvas.drawPaint(black);
76 return raster_surface_->BeginPlatformPaint();
77 }
78
79 void VectorPlatformDeviceSkia::EndPlatformPaint() {
80 DCHECK(raster_surface_ != NULL);
81 SkPaint paint;
82 pdf_device_->drawSprite(SkDraw(),
83 raster_surface_->accessBitmap(false),
84 base_transform_.getTranslateX(),
85 base_transform_.getTranslateY(),
86 paint);
87 raster_surface_ = NULL;
88 }
89
90 SkDeviceFactory* VectorPlatformDeviceSkia::getDeviceFactory() {
91 return SkNEW(VectorPlatformDeviceSkiaFactory);
92 }
93
94 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() {
95 return kVector_Capability;
96 }
97
98 int VectorPlatformDeviceSkia::width() const {
99 return pdf_device_->width();
100 }
101
102 int VectorPlatformDeviceSkia::height() const {
103 return pdf_device_->height();
104 }
105
106 void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix,
107 const SkRegion& region,
108 const SkClipStack& stack) {
109 SkMatrix transform = base_transform_;
110 transform.preConcat(matrix);
111
112 DCHECK(SkMatrix::kTranslate_Mask == base_transform_.getType() ||
113 SkMatrix::kIdentity_Mask == base_transform_.getType());
114 SkRegion clip = region;
115 clip.translate(base_transform_.getTranslateX(),
116 base_transform_.getTranslateY());
117
118 pdf_device_->setMatrixClip(transform, clip, stack);
119 }
120
121 bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect,
122 SkBitmap* bitmap) {
123 return false;
124 }
125
126 void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw,
127 const SkPaint& paint) {
128 pdf_device_->drawPaint(draw, paint);
129 }
130
131 void VectorPlatformDeviceSkia::drawPoints(const SkDraw& draw,
132 SkCanvas::PointMode mode,
133 size_t count, const SkPoint pts[],
134 const SkPaint& paint) {
135 pdf_device_->drawPoints(draw, mode, count, pts, paint);
136 }
137
138 void VectorPlatformDeviceSkia::drawRect(const SkDraw& draw,
139 const SkRect& rect,
140 const SkPaint& paint) {
141 pdf_device_->drawRect(draw, rect, paint);
142 }
143
144 void VectorPlatformDeviceSkia::drawPath(const SkDraw& draw,
145 const SkPath& path,
146 const SkPaint& paint,
147 const SkMatrix* prePathMatrix,
148 bool pathIsMutable) {
149 pdf_device_->drawPath(draw, path, paint, prePathMatrix, pathIsMutable);
150 }
151
152 void VectorPlatformDeviceSkia::drawBitmap(const SkDraw& draw,
153 const SkBitmap& bitmap,
154 const SkIRect* srcRectOrNull,
155 const SkMatrix& matrix,
156 const SkPaint& paint) {
157 pdf_device_->drawBitmap(draw, bitmap, srcRectOrNull, matrix, paint);
158 }
159
160 void VectorPlatformDeviceSkia::drawSprite(const SkDraw& draw,
161 const SkBitmap& bitmap,
162 int x, int y,
163 const SkPaint& paint) {
164 pdf_device_->drawSprite(draw, bitmap, x, y, paint);
165 }
166
167 void VectorPlatformDeviceSkia::drawText(const SkDraw& draw,
168 const void* text,
169 size_t byteLength,
170 SkScalar x,
171 SkScalar y,
172 const SkPaint& paint) {
173 pdf_device_->drawText(draw, text, byteLength, x, y, paint);
174 }
175
176 void VectorPlatformDeviceSkia::drawPosText(const SkDraw& draw,
177 const void* text,
178 size_t len,
179 const SkScalar pos[],
180 SkScalar constY,
181 int scalarsPerPos,
182 const SkPaint& paint) {
183 pdf_device_->drawPosText(draw, text, len, pos, constY, scalarsPerPos, paint);
184 }
185
186 void VectorPlatformDeviceSkia::drawTextOnPath(const SkDraw& draw,
187 const void* text,
188 size_t len,
189 const SkPath& path,
190 const SkMatrix* matrix,
191 const SkPaint& paint) {
192 pdf_device_->drawTextOnPath(draw, text, len, path, matrix, paint);
193 }
194
195 void VectorPlatformDeviceSkia::drawVertices(const SkDraw& draw,
196 SkCanvas::VertexMode vmode,
197 int vertexCount,
198 const SkPoint vertices[],
199 const SkPoint texs[],
200 const SkColor colors[],
201 SkXfermode* xmode,
202 const uint16_t indices[],
203 int indexCount,
204 const SkPaint& paint) {
205 pdf_device_->drawVertices(draw, vmode, vertexCount, vertices, texs, colors,
206 xmode, indices, indexCount, paint);
207 }
208
209 void VectorPlatformDeviceSkia::drawDevice(const SkDraw& draw,
210 SkDevice* device,
211 int x,
212 int y,
213 const SkPaint& paint) {
214 SkDevice* real_device = device;
215 if ((device->getDeviceCapabilities() & kVector_Capability)) {
216 // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need
217 // to unwrap the embedded SkPDFDevice.
218 VectorPlatformDeviceSkia* vector_device =
219 static_cast<VectorPlatformDeviceSkia*>(device);
220 real_device = vector_device->pdf_device_.get();
221 }
222 pdf_device_->drawDevice(draw, real_device, x, y, paint);
223 }
224
225 #if defined(OS_WIN)
226 void VectorPlatformDeviceSkia::drawToHDC(HDC dc,
227 int x,
228 int y,
229 const RECT* src_rect) {
230 SkASSERT(false);
231 }
232 #endif
233
234 void VectorPlatformDeviceSkia::setInitialTransform(int xOffset, int yOffset,
235 float scale_factor) {
236 // TODO(vandebo) Supporting a scale factor is some work because we have to
237 // transform both matrices and clips that come in, but Region only supports
238 // translation. Instead, we could change SkPDFDevice to include it in the
239 // initial transform. Delay that work until we would use it. Also checked
240 // in setMatrixClip.
241 DCHECK_EQ(1.0f, scale_factor);
242
243 base_transform_.setTranslate(xOffset, yOffset);
244 SkScalar scale = SkFloatToScalar(scale_factor);
245 base_transform_.postScale(scale, scale);
246
247 SkMatrix matrix;
248 matrix.reset();
249 SkRegion region;
250 SkClipStack stack;
251 setMatrixClip(matrix, region, stack);
252 }
253
254 } // 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