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

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: Fix use of drawSprite. 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(SkPDFDevice* pdf_device)
23 : PlatformDevice(makeABitmap(pdf_device->width(), pdf_device->height())), 24 : PlatformDevice(pdf_device) {//PlatformDevice(makeABitmap(pdf_device->width (), pdf_device->height())),
24 pdf_device_(pdf_device) { 25 //pdf_device_(pdf_device) {
25 } 26 }
26 27
27 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { 28 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
28 } 29 }
29 30
30 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() { 31 bool VectorPlatformDeviceSkia::IsNativeFontRenderingAllowed() {
31 return false; 32 return false;
32 } 33 }
33 34
34 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() { 35 PlatformDevice::PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() {
35 // Even when drawing a vector representation of the page, we have to 36 // 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 37 // provide a raster surface for plugins to render into - they don't have
37 // a vector interface. Therefore we create a BitmapPlatformDevice here 38 // a vector interface. Therefore we create a BitmapPlatformDevice here
38 // and return the context from it, then layer on the raster data as an 39 // and return the context from it, then layer on the raster data as an
39 // image in EndPlatformPaint. 40 // image in EndPlatformPaint.
40 DCHECK(raster_surface_ == NULL); 41 DCHECK(raster_surface_ == NULL);
41 #if defined(OS_WIN) 42 #if defined(OS_WIN)
42 raster_surface_ = BitmapPlatformDevice::create(pdf_device_->width(), 43 raster_surface_ = BitmapPlatformDevice::create(GetOwningDevice()->width(),
43 pdf_device_->height(), 44 GetOwningDevice()->height(),
44 false, /* not opaque */ 45 false, /* not opaque */
45 NULL); 46 NULL);
46 #elif defined(OS_POSIX) && !defined(OS_MACOSX) 47 #elif defined(OS_POSIX) && !defined(OS_MACOSX)
47 raster_surface_ = BitmapPlatformDevice::Create(pdf_device_->width(), 48 raster_surface_ = BitmapPlatformDevice::Create(GetOwningDevice()->width(),
48 pdf_device_->height(), 49 GetOwningDevice()->height(),
49 false /* not opaque */); 50 false /* not opaque */);
50 #endif 51 #endif
51 raster_surface_->unref(); // SkRefPtr and create both took a reference. 52 raster_surface_->unref(); // SkRefPtr and create both took a reference.
52 53
53 SkCanvas canvas(raster_surface_.get()); 54 //SkCanvas canvas(raster_surface_.get());
54 return raster_surface_->BeginPlatformPaint(); 55 raster_canvas_ = new SkCanvas(raster_surface_.get());
56 //return raster_surface_->BeginPlatformPaint();
57 return skia::BeginPlatformPaint(raster_canvas_.get());
55 } 58 }
56 59
57 void VectorPlatformDeviceSkia::EndPlatformPaint() { 60 void VectorPlatformDeviceSkia::EndPlatformPaint() {
58 DCHECK(raster_surface_ != NULL); 61 DCHECK(raster_surface_ != NULL);
62
63 // BitmapPlatformDevice matches begin and end calls.
64 skia::EndPlatformPaint(raster_canvas_.get());
Jeff Timanus 2011/08/12 23:59:22 This was an example of where BitmapPlatformDevice:
59 SkPaint paint; 65 SkPaint paint;
60 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake 66 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake
61 // it out by setting a non-empty clip. 67 // it out by setting a non-empty clip.
62 SkDraw draw; 68 SkDraw draw;
63 SkRegion clip(SkIRect::MakeWH(pdf_device_->width(), pdf_device_->height())); 69 SkRegion clip(SkIRect::MakeWH(GetOwningDevice()->width(),
70 GetOwningDevice()->height()));
64 draw.fClip=&clip; 71 draw.fClip=&clip;
65 pdf_device_->drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, 72
66 paint); 73 SkCanvas pdf_canvas(GetOwningDevice());
vandebo (ex-Chrome) 2011/08/15 19:52:10 Will using two different canvases (with different
Jeff Timanus 2011/08/15 20:06:25 A third option is to make drawSprite a public entr
vandebo (ex-Chrome) 2011/08/15 20:13:56 I don't think either of these are particularly cle
67 // BitmapPlatformDevice matches begin and end calls. 74 pdf_canvas.drawSprite(raster_surface_->accessBitmap(false), 0, 0, &paint);
68 raster_surface_->EndPlatformPaint(); 75 #if 0
76 GetOwningDevice()->drawSprite(
77 draw,
78 raster_surface_->accessBitmap(false), 0, 0, paint);
79 #endif
80 //raster_surface_->EndPlatformPaint();
81 raster_canvas_ = NULL;
69 raster_surface_ = NULL; 82 raster_surface_ = NULL;
70 } 83 }
71 84
85 #if 0
72 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() { 86 uint32_t VectorPlatformDeviceSkia::getDeviceCapabilities() {
73 return SkDevice::getDeviceCapabilities() | kVector_Capability; 87 return SkDevice::getDeviceCapabilities() | kVector_Capability;
74 } 88 }
75 89
76 int VectorPlatformDeviceSkia::width() const { 90 int VectorPlatformDeviceSkia::width() const {
77 return pdf_device_->width(); 91 return pdf_device_->width();
78 } 92 }
79 93
80 int VectorPlatformDeviceSkia::height() const { 94 int VectorPlatformDeviceSkia::height() const {
81 return pdf_device_->height(); 95 return pdf_device_->height();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 SkDevice* real_device = device; 197 SkDevice* real_device = device;
184 if ((device->getDeviceCapabilities() & kVector_Capability)) { 198 if ((device->getDeviceCapabilities() & kVector_Capability)) {
185 // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need 199 // Assume that a vectorial device means a VectorPlatformDeviceSkia, we need
186 // to unwrap the embedded SkPDFDevice. 200 // to unwrap the embedded SkPDFDevice.
187 VectorPlatformDeviceSkia* vector_device = 201 VectorPlatformDeviceSkia* vector_device =
188 static_cast<VectorPlatformDeviceSkia*>(device); 202 static_cast<VectorPlatformDeviceSkia*>(device);
189 real_device = vector_device->pdf_device_.get(); 203 real_device = vector_device->pdf_device_.get();
190 } 204 }
191 pdf_device_->drawDevice(draw, real_device, x, y, paint); 205 pdf_device_->drawDevice(draw, real_device, x, y, paint);
192 } 206 }
207 #endif
193 208
194 #if defined(OS_WIN) 209 #if defined(OS_WIN)
195 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc, 210 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc,
196 int x, 211 int x,
197 int y, 212 int y,
198 const RECT* src_rect) { 213 const RECT* src_rect) {
199 SkASSERT(false); 214 SkASSERT(false);
200 } 215 }
201 #elif defined(OS_MACOSX) 216 #elif defined(OS_MACOSX)
202 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x, 217 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x,
203 int y, const CGRect* src_rect) { 218 int y, const CGRect* src_rect) {
204 SkASSERT(false); 219 SkASSERT(false);
205 } 220 }
206 221
207 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { 222 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() {
208 SkASSERT(false); 223 SkASSERT(false);
209 return NULL; 224 return NULL;
210 } 225 }
211 226
212 #endif 227 #endif
213 228
229 #if 0
214 SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice( 230 SkDevice* VectorPlatformDeviceSkia::onCreateCompatibleDevice(
215 SkBitmap::Config config, int width, int height, bool isOpaque, 231 SkBitmap::Config config, int width, int height, bool isOpaque,
216 Usage /*usage*/) { 232 Usage /*usage*/) {
217 SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width, 233 SkAutoTUnref<SkDevice> dev(pdf_device_->createCompatibleDevice(config, width,
218 height, 234 height,
219 isOpaque)); 235 isOpaque));
220 return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get())); 236 return new VectorPlatformDeviceSkia(static_cast<SkPDFDevice*>(dev.get()));
221 } 237 }
238 #endif
222 239
223 } // namespace skia 240 } // namespace skia
OLDNEW
« skia/ext/vector_platform_device_emf_win.h ('K') | « skia/ext/vector_platform_device_skia.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698