OLD | NEW |
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 "SkRecorder.h" | 8 #include "SkRecorder.h" |
9 #include "SkPatchUtils.h" | 9 #include "SkPatchUtils.h" |
10 #include "SkPicture.h" | 10 #include "SkPicture.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 void SkCanvasDrawableList::append(SkCanvasDrawable* drawable) { | 28 void SkCanvasDrawableList::append(SkCanvasDrawable* drawable) { |
29 *fArray.append() = SkRef(drawable); | 29 *fArray.append() = SkRef(drawable); |
30 } | 30 } |
31 | 31 |
32 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 32 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
33 | 33 |
34 SkRecorder::SkRecorder(SkRecord* record, int width, int height) | 34 SkRecorder::SkRecorder(SkRecord* record, int width, int height) |
35 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) | 35 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) |
36 , fRecord(record) | 36 , fRecord(record) {} |
37 , fSaveLayerCount(0) {} | |
38 | 37 |
39 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) | 38 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) |
40 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) | 39 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) |
41 , fRecord(record) | 40 , fRecord(record) {} |
42 , fSaveLayerCount(0) {} | |
43 | 41 |
44 void SkRecorder::forgetRecord() { | 42 void SkRecorder::forgetRecord() { |
45 fDrawableList.reset(NULL); | 43 fDrawableList.reset(NULL); |
46 fRecord = NULL; | 44 fRecord = NULL; |
47 } | 45 } |
48 | 46 |
49 // To make appending to fRecord a little less verbose. | 47 // To make appending to fRecord a little less verbose. |
50 #define APPEND(T, ...) \ | 48 #define APPEND(T, ...) \ |
51 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) | 49 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) |
52 | 50 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], | 264 void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
267 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { | 265 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { |
268 APPEND(DrawPatch, delay_copy(paint), | 266 APPEND(DrawPatch, delay_copy(paint), |
269 cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : NULL, | 267 cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : NULL, |
270 colors ? this->copy(colors, SkPatchUtils::kNumCorners) : NULL, | 268 colors ? this->copy(colors, SkPatchUtils::kNumCorners) : NULL, |
271 texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : NULL, | 269 texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : NULL, |
272 xmode); | 270 xmode); |
273 } | 271 } |
274 | 272 |
275 void SkRecorder::willSave() { | 273 void SkRecorder::willSave() { |
276 fSaveIsSaveLayer.push(false); | |
277 APPEND(Save); | 274 APPEND(Save); |
278 } | 275 } |
279 | 276 |
280 SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds, | 277 SkCanvas::SaveLayerStrategy SkRecorder::willSaveLayer(const SkRect* bounds, |
281 const SkPaint* paint, | 278 const SkPaint* paint, |
282 SkCanvas::SaveFlags flags)
{ | 279 SkCanvas::SaveFlags flags)
{ |
283 fSaveLayerCount++; | |
284 fSaveIsSaveLayer.push(true); | |
285 APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags); | 280 APPEND(SaveLayer, this->copy(bounds), this->copy(paint), flags); |
286 return SkCanvas::kNoLayer_SaveLayerStrategy; | 281 return SkCanvas::kNoLayer_SaveLayerStrategy; |
287 } | 282 } |
288 | 283 |
289 void SkRecorder::didRestore() { | 284 void SkRecorder::didRestore() { |
290 SkBool8 saveLayer; | |
291 fSaveIsSaveLayer.pop(&saveLayer); | |
292 if (saveLayer) { | |
293 fSaveLayerCount--; | |
294 } | |
295 APPEND(Restore, this->devBounds(), this->getTotalMatrix()); | 285 APPEND(Restore, this->devBounds(), this->getTotalMatrix()); |
296 } | 286 } |
297 | 287 |
298 void SkRecorder::didConcat(const SkMatrix& matrix) { | 288 void SkRecorder::didConcat(const SkMatrix& matrix) { |
299 this->didSetMatrix(this->getTotalMatrix()); | 289 this->didSetMatrix(this->getTotalMatrix()); |
300 } | 290 } |
301 | 291 |
302 void SkRecorder::didSetMatrix(const SkMatrix& matrix) { | 292 void SkRecorder::didSetMatrix(const SkMatrix& matrix) { |
303 SkDEVCODE(if (matrix != this->getTotalMatrix()) { | 293 SkDEVCODE(if (matrix != this->getTotalMatrix()) { |
304 matrix.dump(); | 294 matrix.dump(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 326 } |
337 | 327 |
338 void SkRecorder::addComment(const char* key, const char* value) { | 328 void SkRecorder::addComment(const char* key, const char* value) { |
339 APPEND(AddComment, this->copy(key), this->copy(value)); | 329 APPEND(AddComment, this->copy(key), this->copy(value)); |
340 } | 330 } |
341 | 331 |
342 void SkRecorder::endCommentGroup() { | 332 void SkRecorder::endCommentGroup() { |
343 APPEND(EndCommentGroup); | 333 APPEND(EndCommentGroup); |
344 } | 334 } |
345 | 335 |
346 bool SkRecorder::isDrawingToLayer() const { | |
347 return fSaveLayerCount > 0; | |
348 } | |
349 | |
350 void SkRecorder::drawData(const void* data, size_t length) { | 336 void SkRecorder::drawData(const void* data, size_t length) { |
351 APPEND(DrawData, copy((const char*)data), length); | 337 APPEND(DrawData, copy((const char*)data), length); |
352 } | 338 } |
OLD | NEW |