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

Side by Side Diff: src/core/SkRecorder.cpp

Issue 727363003: wip for drawables (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: works, but I took a few short-cuts Created 6 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h"
8 #include "SkRecorder.h" 9 #include "SkRecorder.h"
9 #include "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
10 #include "SkPicture.h" 11 #include "SkPicture.h"
11 12
12 // SkCanvas will fail in mysterious ways if it doesn't know the real width and h eight. 13 // SkCanvas will fail in mysterious ways if it doesn't know the real width and h eight.
13 SkRecorder::SkRecorder(SkRecord* record, int width, int height) 14 SkRecorder::SkRecorder(SkRecord* record, int width, int height)
14 : SkCanvas(width, height, SkCanvas::kConservativeRasterClip_InitFlag) 15 : SkCanvas(width, height, SkCanvas::kConservativeRasterClip_InitFlag)
15 , fRecord(record) 16 , fRecord(record)
16 , fSaveLayerCount(0) {} 17 , fSaveLayerCount(0) {}
17 18
19 SkRecorder::~SkRecorder() {
20 fDrawableList.unrefAll();
21 }
22
18 void SkRecorder::forgetRecord() { 23 void SkRecorder::forgetRecord() {
24 fDrawableList.unrefAll();
25 fDrawableList.reset();
19 fRecord = NULL; 26 fRecord = NULL;
20 } 27 }
21 28
29 SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFl ags) {
30 const int count = fDrawableList.count();
31 if (0 == count) {
32 return NULL;
33 }
34 SkData* data = SkData::NewUninitialized(count * sizeof(SkPicture*));
35 SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data());
36 for (int i = 0; i < count; ++i) {
37 pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags);
38 }
39 return data;
40 }
41
22 // To make appending to fRecord a little less verbose. 42 // To make appending to fRecord a little less verbose.
23 #define APPEND(T, ...) \ 43 #define APPEND(T, ...) \
24 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__)) 44 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__))
25 45
26 // For methods which must call back into SkCanvas. 46 // For methods which must call back into SkCanvas.
27 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) 47 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__)
28 48
29 // The structs we're creating all copy their constructor arguments. Given the w ay the SkRecords 49 // The structs we're creating all copy their constructor arguments. Given the w ay the SkRecords
30 // framework works, sometimes they happen to technically be copied twice, which is fine and elided 50 // framework works, sometimes they happen to technically be copied twice, which is fine and elided
31 // into a single copy unless the class has a non-trivial copy constructor. For classes with 51 // into a single copy unless the class has a non-trivial copy constructor. For classes with
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 135 }
116 136
117 void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 137 void SkRecorder::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
118 APPEND(DrawRRect, delay_copy(paint), rrect); 138 APPEND(DrawRRect, delay_copy(paint), rrect);
119 } 139 }
120 140
121 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { 141 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
122 APPEND(DrawDRRect, delay_copy(paint), outer, inner); 142 APPEND(DrawDRRect, delay_copy(paint), outer, inner);
123 } 143 }
124 144
145 void SkRecorder::onDrawDrawable(SkCanvasDrawable* drawable) {
146 *fDrawableList.append() = SkRef(drawable);
147 APPEND(DrawDrawable, drawable->getBounds(), fDrawableList.count() - 1);
148 }
149
125 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) { 150 void SkRecorder::drawPath(const SkPath& path, const SkPaint& paint) {
126 APPEND(DrawPath, delay_copy(paint), delay_copy(path)); 151 APPEND(DrawPath, delay_copy(paint), delay_copy(path));
127 } 152 }
128 153
129 void SkRecorder::drawBitmap(const SkBitmap& bitmap, 154 void SkRecorder::drawBitmap(const SkBitmap& bitmap,
130 SkScalar left, 155 SkScalar left,
131 SkScalar top, 156 SkScalar top,
132 const SkPaint* paint) { 157 const SkPaint* paint) {
133 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top); 158 APPEND(DrawBitmap, this->copy(paint), delay_copy(bitmap), left, top);
134 } 159 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 APPEND(EndCommentGroup); 342 APPEND(EndCommentGroup);
318 } 343 }
319 344
320 bool SkRecorder::isDrawingToLayer() const { 345 bool SkRecorder::isDrawingToLayer() const {
321 return fSaveLayerCount > 0; 346 return fSaveLayerCount > 0;
322 } 347 }
323 348
324 void SkRecorder::drawData(const void* data, size_t length) { 349 void SkRecorder::drawData(const void* data, size_t length) {
325 APPEND(DrawData, copy((const char*)data), length); 350 APPEND(DrawData, copy((const char*)data), length);
326 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698