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

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: And one more.. 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 SkDevice* CreateRecordingPlatformDeviceSkia(
18 SkPicture* picture, int width, int height) {
19 SkBitmap bm;
20 bm.setConfig(SkBitmap::kNo_Config, width, height);
21 return new RecordingPlatformDeviceSkia(bm, picture);
22 }
23
24 RecordingPlatformDeviceSkia::RecordingPlatformDeviceSkia(
25 const SkBitmap& bitmap, SkPicture* picture)
26 : SkDevice(bitmap),
27 raster_canvas_(NULL),
28 picture_(picture) {
29 SetPlatformDevice(this, this);
30 }
31
32 RecordingPlatformDeviceSkia::~RecordingPlatformDeviceSkia() {
33 if (raster_canvas_)
34 raster_canvas_->unref();
35 }
36
37 PlatformDevice::PlatformPaint RecordingPlatformDeviceSkia::
38 PlatformPaintSupport() {
39 return PLATFORM_PAINT_INDIRECT;
40 }
41
42 PlatformSurface RecordingPlatformDeviceSkia::BeginPlatformPaint() {
43 // Even when recording drawing commands of the page, we have to
44 // provide a raster surface for plugins to render into. Therefore we
45 // create a BitmapPlatformDevice here and return the context from it,
46 // then layer on the raster data as an image in EndPlatformPaint.
47 SkASSERT(raster_canvas_ == NULL);
48 // TODO(reveman): Need to restrict size of bitmap to the current clip.
49 // See http://crbug.com/152011
50 raster_canvas_ = CreateBitmapCanvas(width(), height(), false);
51
52 // We make a copy so that our original picture_ can continue to record.
53 // Normally if you "draw" a picture, that forces its recording to stop.
54 SkPicture raster_picture(*picture_);
55 raster_canvas_->drawPicture(raster_picture);
56 // Save the effect of all currently recorded matrix operations.
57 raster_matrix_ = raster_canvas_->getTotalMatrix();
58
59 return skia::BeginPlatformPaint(raster_canvas_);
60 }
61
62 void RecordingPlatformDeviceSkia::EndPlatformPaint() {
63 SkASSERT(raster_canvas_ != NULL);
64 SkMatrix inverse;
65 // To add a drawing command that will render the raster surface at the
66 // correct origin we need to revert the effect of all currently
67 // recorded matrix operations.
68 if (raster_matrix_.invert(&inverse)) {
69 SkCanvas* canvas = picture_->getRecordingCanvas();
70 SkASSERT(canvas != NULL);
71 canvas->save();
72 canvas->concat(inverse);
73 SkPaint paint;
74 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
75 // TODO(reveman): Need to mark bitmap as being "immutable" before
76 // calling drawBitmap to avoid having the picture recording code do
77 // a deep-copy of it.
78 canvas->drawBitmap(
79 raster_canvas_->getDevice()->accessBitmap(false), 0, 0, &paint);
80 canvas->restore();
81 }
82 skia::EndPlatformPaint(raster_canvas_);
83 raster_canvas_->unref();
84 raster_canvas_ = NULL;
85 }
86
87 #if defined(OS_WIN)
88 void RecordingPlatformDeviceSkia::DrawToNativeContext(
89 HDC dc, int x, int y, const RECT* src_rect) {
90 SkASSERT(false);
91 }
92 #elif defined(OS_MACOSX)
93 void RecordingPlatformDeviceSkia::DrawToNativeContext(
94 CGContext* context, int x, int y, const CGRect* src_rect) {
95 SkASSERT(false);
96 }
97
98 CGContextRef RecordingPlatformDeviceSkia::GetBitmapContext() {
99 SkASSERT(false);
100 return NULL;
101 }
102 #elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_OPENBSD)
103 void RecordingPlatformDeviceSkia::DrawToNativeContext(
104 PlatformSurface surface, int x, int y, const PlatformRect* src_rect) {
105 // Should never be called on Linux.
106 SkASSERT(false);
107 }
108 #endif
109
110 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698