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

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

Issue 10915065: Add PlatformPictureSkia and RecordingPlatformDeviceSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add IsPlatformPaintSupported(), update comment in WebPluginDelegateProxy::Paint and require direct … Created 8 years, 2 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
(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/recording_platform_device_skia.h"
6
7 #include "skia/ext/platform_canvas.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/SkPicture.h"
11 #include "third_party/skia/include/core/SkRect.h"
12 #include "third_party/skia/include/core/SkRegion.h"
13 #include "third_party/skia/include/core/SkScalar.h"
14
15 namespace skia {
16
17 RecordingPlatformDeviceSkia::RecordingPlatformDeviceSkia(
18 const SkBitmap& bitmap, SkPicture* picture)
19 : SkDevice(bitmap),
20 raster_canvas_(NULL),
21 picture_(picture) {
22 SetPlatformDevice(this, this);
23 }
24
25 RecordingPlatformDeviceSkia::~RecordingPlatformDeviceSkia() {
26 if (raster_canvas_)
27 raster_canvas_->unref();
28 }
29
30 RecordingPlatformDeviceSkia* RecordingPlatformDeviceSkia::Create(
31 SkPicture* picture, int width, int height) {
32 SkBitmap bm;
33 bm.setConfig(SkBitmap::kNo_Config, width, height);
34 return new RecordingPlatformDeviceSkia(bm, picture);
35 }
36
37 PlatformDevice::PlatformPaint RecordingPlatformDeviceSkia::
38 PlatformPaintSupport() {
39 return PLATFORM_PAINT_INDIRECT;
40 }
41
42 PlatformSurface RecordingPlatformDeviceSkia::BeginPlatformPaint() {
43 SkASSERT(raster_canvas_ == NULL);
44
45 SkCanvas* canvas = picture_->getRecordingCanvas();
46 SkASSERT(canvas != NULL);
47
48 SkIRect clip;
49 if (!canvas->getClipDeviceBounds(&clip)) {
50 raster_canvas_ = CreateBitmapCanvas(1, 1, false);
51 return skia::BeginPlatformPaint(raster_canvas_);
52 }
53
54 // Even when recording drawing commands of the page, we have to
55 // provide a raster surface for plugins to render into. Therefore we
56 // create a BitmapPlatformDevice here and return the context from it,
57 // then layer on the raster data as an image in EndPlatformPaint.
58 raster_canvas_ = CreateBitmapCanvas(clip.fRight - clip.fLeft,
59 clip.fBottom - clip.fTop,
60 false);
61 raster_canvas_->translate(-clip.fLeft, -clip.fTop);
62
63 // We make a copy so that our original picture_ can continue to record.
64 // Normally if you "draw" a picture, that forces its recording to stop.
65 SkPicture raster_picture(*picture_);
66 raster_canvas_->drawPicture(raster_picture);
67
68 return skia::BeginPlatformPaint(raster_canvas_);
69 }
70
71 void RecordingPlatformDeviceSkia::EndPlatformPaint() {
72 SkASSERT(raster_canvas_ != NULL);
73
74 SkCanvas* canvas = picture_->getRecordingCanvas();
75 SkASSERT(canvas != NULL);
76
77 SkMatrix matrix = canvas->getTotalMatrix();
78 SkMatrix inverse;
79 SkIRect clip;
80 // To add a drawing command that will render the raster surface at the
81 // correct origin we need to revert the effect of all currently
82 // recorded matrix operations.
83 if (canvas->getClipDeviceBounds(&clip) && matrix.invert(&inverse)) {
84 canvas->save();
85 canvas->concat(inverse);
86 canvas->translate(clip.fLeft, clip.fTop);
87 SkPaint paint;
88 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
89 // TODO(reveman): Need to mark bitmap as being "immutable" before
90 // calling drawBitmap to avoid having the picture recording code do
91 // a deep-copy of it.
92 canvas->drawBitmap(
93 raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint);
94 canvas->restore();
95 }
96
97 skia::EndPlatformPaint(raster_canvas_);
98 raster_canvas_->unref();
99 raster_canvas_ = NULL;
100 }
101
102 #if defined(OS_WIN)
103 void RecordingPlatformDeviceSkia::DrawToNativeContext(
104 HDC dc, int x, int y, const RECT* src_rect) {
105 SkASSERT(false);
106 }
107 #elif defined(OS_MACOSX)
108 void RecordingPlatformDeviceSkia::DrawToNativeContext(
109 CGContext* context, int x, int y, const CGRect* src_rect) {
110 SkASSERT(false);
111 }
112
113 CGContextRef RecordingPlatformDeviceSkia::GetBitmapContext() {
114 SkASSERT(false);
115 return NULL;
116 }
117 #elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD)
118 void RecordingPlatformDeviceSkia::DrawToNativeContext(
119 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
120 // Should never be called on Linux.
121 SkASSERT(false);
122 }
123 #endif
124
125 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698