OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 static inline SkBitmap makeABitmap(int width, int height) { | |
17 SkBitmap bitmap; | |
18 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); | |
19 return bitmap; | |
20 } | |
21 | |
22 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia( | |
23 const SkISize& pageSize, | |
24 const SkISize& contentSize, | |
25 const SkMatrix& initialTransform) | |
26 : SkPDFDevice(pageSize, contentSize, initialTransform) { | |
27 SetPlatformDevice(this, this); | |
28 } | |
29 | |
30 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() { | |
31 } | |
32 | |
33 bool VectorPlatformDeviceSkia::SupportsPlatformPaint() { | |
34 return false; | |
35 } | |
36 | |
37 PlatformSurface VectorPlatformDeviceSkia::BeginPlatformPaint() { | |
38 // Even when drawing a vector representation of the page, we have to | |
39 // provide a raster surface for plugins to render into - they don't have | |
40 // a vector interface. Therefore we create a BitmapPlatformDevice here | |
41 // and return the context from it, then layer on the raster data as an | |
42 // image in EndPlatformPaint. | |
43 DCHECK(raster_surface_ == NULL); | |
44 raster_surface_ = skia::AdoptRef( | |
45 BitmapPlatformDevice::CreateAndClear(width(), height(), false)); | |
46 return raster_surface_->BeginPlatformPaint(); | |
47 } | |
48 | |
49 void VectorPlatformDeviceSkia::EndPlatformPaint() { | |
50 DCHECK(raster_surface_ != NULL); | |
51 SkPaint paint; | |
52 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake | |
53 // it out by setting a non-empty clip. | |
54 SkDraw draw; | |
55 SkRegion clip(SkIRect::MakeWH(width(), height())); | |
56 draw.fClip=&clip; | |
57 drawSprite(draw, raster_surface_->accessBitmap(false), 0, 0, paint); | |
58 // BitmapPlatformDevice matches begin and end calls. | |
59 raster_surface_->EndPlatformPaint(); | |
60 raster_surface_.clear(); | |
61 } | |
62 | |
63 #if defined(OS_WIN) | |
64 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc, | |
65 int x, | |
66 int y, | |
67 const RECT* src_rect) { | |
68 SkASSERT(false); | |
69 } | |
70 #elif defined(OS_MACOSX) | |
71 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext* context, int x, | |
72 int y, const CGRect* src_rect) { | |
73 SkASSERT(false); | |
74 } | |
75 | |
76 CGContextRef VectorPlatformDeviceSkia::GetBitmapContext() { | |
77 SkASSERT(false); | |
78 return NULL; | |
79 } | |
80 #elif defined(OS_POSIX) | |
81 void VectorPlatformDeviceSkia::DrawToNativeContext( | |
82 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) { | |
83 // Should never be called on Linux. | |
84 SkASSERT(false); | |
85 } | |
86 #endif | |
87 | |
88 } // namespace skia | |
OLD | NEW |