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.
5 #include "skia/ext/vector_platform_device_skia.h"
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"
16 static inline SkBitmap
makeABitmap(int width
, int height
) {
18 bitmap
.setInfo(SkImageInfo::MakeUnknown(width
, height
));
22 VectorPlatformDeviceSkia::VectorPlatformDeviceSkia(
23 const SkISize
& pageSize
,
24 const SkISize
& contentSize
,
25 const SkMatrix
& initialTransform
)
26 : SkPDFDevice(pageSize
, contentSize
, initialTransform
) {
27 SetPlatformDevice(this, this);
30 VectorPlatformDeviceSkia::~VectorPlatformDeviceSkia() {
33 bool VectorPlatformDeviceSkia::SupportsPlatformPaint() {
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();
49 void VectorPlatformDeviceSkia::EndPlatformPaint() {
50 DCHECK(raster_surface_
!= NULL
);
52 // SkPDFDevice checks the passed SkDraw for an empty clip (only). Fake
53 // it out by setting a non-empty clip.
55 SkRegion
clip(SkIRect::MakeWH(width(), height()));
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();
64 void VectorPlatformDeviceSkia::DrawToNativeContext(HDC dc
,
67 const RECT
* src_rect
) {
70 #elif defined(OS_MACOSX)
71 void VectorPlatformDeviceSkia::DrawToNativeContext(CGContext
* context
, int x
,
72 int y
, const CGRect
* src_rect
) {
76 CGContextRef
VectorPlatformDeviceSkia::GetBitmapContext() {
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.