OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 SkDevice* VectorPlatformDeviceSkiaFactory::newDevice(SkCanvas* noUsed, | 16 SkDevice* VectorPlatformDeviceSkiaFactory::newDevice(SkCanvas* noUsed, |
17 SkBitmap::Config config, | 17 SkBitmap::Config config, |
18 int width, int height, | 18 int width, int height, |
19 bool isOpaque, | 19 bool isOpaque, |
20 bool isForLayer) { | 20 bool isForLayer) { |
21 SkASSERT(config == SkBitmap::kARGB_8888_Config); | 21 SkASSERT(config == SkBitmap::kARGB_8888_Config); |
22 SkPDFDevice::OriginTransform flip = SkPDFDevice::kFlip_OriginTransform; | 22 SkMatrix initialTransform; |
23 if (isForLayer) | 23 initialTransform.reset(); |
24 flip = SkPDFDevice::kNoFlip_OriginTransform; | 24 if (isForLayer) { |
25 return new VectorPlatformDeviceSkia(width, height, flip); | 25 initialTransform.setTranslate(0, height); |
| 26 initialTransform.preScale(1, -1); |
| 27 } |
| 28 return new VectorPlatformDeviceSkia(width, height, initialTransform); |
26 } | 29 } |
27 | 30 |
28 static inline SkBitmap makeABitmap(int width, int height) { | 31 static inline SkBitmap makeABitmap(int width, int height) { |
29 SkBitmap bitmap; | 32 SkBitmap bitmap; |
30 bitmap.setConfig(SkBitmap::kNo_Config, width, height); | 33 bitmap.setConfig(SkBitmap::kNo_Config, width, height); |
31 return bitmap; | 34 return bitmap; |
32 } | 35 } |
33 | 36 |
34 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia( | 37 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia( |
35 int width, int height, SkPDFDevice::OriginTransform flip) | 38 int width, int height, const SkMatrix& initialTransform) |
36 : PlatformDevice(makeABitmap(width, height)), | 39 : PlatformDevice(makeABitmap(width, height)), |
37 pdf_device_(new SkPDFDevice(width, height, flip)) { | 40 pdf_device_(new SkPDFDevice(width, height, initialTransform)) { |
38 pdf_device_->unref(); // SkRefPtr and new both took a reference. | 41 pdf_device_->unref(); // SkRefPtr and new both took a reference. |
39 base_transform_.reset(); | |
40 } | 42 } |
41 | 43 |
42 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { | 44 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { |
43 } | 45 } |
44 | 46 |
45 bool VectorPlatformDeviceSkia::IsVectorial() { | 47 bool VectorPlatformDeviceSkia::IsVectorial() { |
46 return true; | 48 return true; |
47 } | 49 } |
48 | 50 |
49 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() { | 51 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() { |
(...skipping 22 matching lines...) Expand all Loading... |
72 SkCanvas canvas(raster_surface_.get()); | 74 SkCanvas canvas(raster_surface_.get()); |
73 SkPaint black; | 75 SkPaint black; |
74 black.setColor(SK_ColorBLACK); | 76 black.setColor(SK_ColorBLACK); |
75 canvas.drawPaint(black); | 77 canvas.drawPaint(black); |
76 return raster_surface_->BeginPlatformPaint(); | 78 return raster_surface_->BeginPlatformPaint(); |
77 } | 79 } |
78 | 80 |
79 void VectorPlatformDeviceSkia::EndPlatformPaint() { | 81 void VectorPlatformDeviceSkia::EndPlatformPaint() { |
80 DCHECK(raster_surface_ != NULL); | 82 DCHECK(raster_surface_ != NULL); |
81 SkPaint paint; | 83 SkPaint paint; |
82 pdf_device_->drawSprite(SkDraw(), | 84 pdf_device_->drawSprite(SkDraw(), raster_surface_->accessBitmap(false), |
83 raster_surface_->accessBitmap(false), | 85 0, 0, paint); |
84 base_transform_.getTranslateX(), | |
85 base_transform_.getTranslateY(), | |
86 paint); | |
87 raster_surface_ = NULL; | 86 raster_surface_ = NULL; |
88 } | 87 } |
89 | 88 |
90 SkDeviceFactory* VectorPlatformDeviceSkia::getDeviceFactory() { | 89 SkDeviceFactory* VectorPlatformDeviceSkia::getDeviceFactory() { |
91 return SkNEW(VectorPlatformDeviceSkiaFactory); | 90 return SkNEW(VectorPlatformDeviceSkiaFactory); |
92 } | 91 } |
93 | 92 |
94 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() { | 93 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() { |
95 return kVector_Capability; | 94 return kVector_Capability; |
96 } | 95 } |
97 | 96 |
98 int VectorPlatformDeviceSkia::width() const { | 97 int VectorPlatformDeviceSkia::width() const { |
99 return pdf_device_->width(); | 98 return pdf_device_->width(); |
100 } | 99 } |
101 | 100 |
102 int VectorPlatformDeviceSkia::height() const { | 101 int VectorPlatformDeviceSkia::height() const { |
103 return pdf_device_->height(); | 102 return pdf_device_->height(); |
104 } | 103 } |
105 | 104 |
106 void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix, | 105 void VectorPlatformDeviceSkia::setMatrixClip(const SkMatrix& matrix, |
107 const SkRegion& region, | 106 const SkRegion& region, |
108 const SkClipStack& stack) { | 107 const SkClipStack& stack) { |
109 SkMatrix transform = base_transform_; | 108 pdf_device_->setMatrixClip(matrix, region, stack); |
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 } | 109 } |
120 | 110 |
121 bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect, | 111 bool VectorPlatformDeviceSkia::readPixels(const SkIRect& srcRect, |
122 SkBitmap* bitmap) { | 112 SkBitmap* bitmap) { |
123 return false; | 113 return false; |
124 } | 114 } |
125 | 115 |
126 void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw, | 116 void VectorPlatformDeviceSkia::drawPaint(const SkDraw& draw, |
127 const SkPaint& paint) { | 117 const SkPaint& paint) { |
128 pdf_device_->drawPaint(draw, paint); | 118 pdf_device_->drawPaint(draw, paint); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 214 |
225 #if defined(OS_WIN) | 215 #if defined(OS_WIN) |
226 void VectorPlatformDeviceSkia::drawToHDC(HDC dc, | 216 void VectorPlatformDeviceSkia::drawToHDC(HDC dc, |
227 int x, | 217 int x, |
228 int y, | 218 int y, |
229 const RECT* src_rect) { | 219 const RECT* src_rect) { |
230 SkASSERT(false); | 220 SkASSERT(false); |
231 } | 221 } |
232 #endif | 222 #endif |
233 | 223 |
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 | 224 } // namespace skia |
OLD | NEW |