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

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

Issue 324293004: Remove picture pre-allocation from SkPictureRecorder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix initializer list order Created 6 years, 6 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
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBBoxHierarchyRecord.h" 8 #include "SkBBoxHierarchyRecord.h"
9 #include "SkPicturePlayback.h" 9 #include "SkPicturePlayback.h"
10 #include "SkPictureRecord.h" 10 #include "SkPictureRecord.h"
11 #include "SkPictureRecorder.h" 11 #include "SkPictureRecorder.h"
12 #include "SkTypes.h" 12 #include "SkTypes.h"
13 13
14 SkPictureRecorder::~SkPictureRecorder() { 14 SkPictureRecorder::~SkPictureRecorder() {
15 SkSafeSetNull(fCanvas); 15 SkSafeSetNull(fCanvas);
16 } 16 }
17 17
18 SkCanvas* SkPictureRecorder::beginRecording(int width, int height, 18 SkCanvas* SkPictureRecorder::beginRecording(int width, int height,
19 SkBBHFactory* bbhFactory /* = NULL * /, 19 SkBBHFactory* bbhFactory /* = NULL * /,
20 uint32_t recordFlags /* = 0 */) { 20 uint32_t recordFlags /* = 0 */) {
21 SkSafeSetNull(fCanvas); 21 SkSafeSetNull(fCanvas); // terminate any prior recording(s)
22 fPicture.reset(SkNEW(SkPicture));
23 22
24 fPicture->fWidth = width; 23 fWidth = width;
25 fPicture->fHeight = height; 24 fHeight = height;
26 25
27 const SkISize size = SkISize::Make(width, height); 26 const SkISize size = SkISize::Make(width, height);
28 27
29 if (NULL != bbhFactory) { 28 if (NULL != bbhFactory) {
30 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); 29 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height));
31 SkASSERT(NULL != tree); 30 SkASSERT(NULL != tree);
32 fCanvas = SkNEW_ARGS(SkBBoxHierarchyRecord, (fPicture, size, recordFlags , tree.get())); 31 fCanvas = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get ()));
33 } else { 32 } else {
34 fCanvas = SkNEW_ARGS(SkPictureRecord, (fPicture, size, recordFlags)); 33 fCanvas = SkNEW_ARGS(SkPictureRecord, (size, recordFlags));
35 } 34 }
36 35
37 fCanvas->beginRecording(); 36 fCanvas->beginRecording();
38 37
39 return fCanvas; 38 return fCanvas;
40 } 39 }
41 40
42 SkCanvas* SkPictureRecorder::getRecordingCanvas() { 41 SkCanvas* SkPictureRecorder::getRecordingCanvas() {
43 return fCanvas; 42 return fCanvas;
44 } 43 }
45 44
46 SkPicture* SkPictureRecorder::endRecording() { 45 SkPicture* SkPictureRecorder::endRecording() {
47 if (NULL == fPicture.get()) { 46 if (NULL == fCanvas) {
48 return NULL; 47 return NULL;
49 } 48 }
50 49
51 SkASSERT(NULL == fPicture->fPlayback);
52 SkASSERT(NULL != fCanvas);
53
54 fCanvas->endRecording(); 50 fCanvas->endRecording();
55 51
56 SkPictInfo info;
57 fPicture->createHeader(&info);
58 const bool deepCopyOps = false; 52 const bool deepCopyOps = false;
59 fPicture->fPlayback = SkNEW_ARGS(SkPicturePlayback, (fPicture, *fCanvas, inf o, deepCopyOps)); 53 SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight,
60 54 *fCanvas, deepCopyOps )));
61 SkSafeSetNull(fCanvas); 55 SkSafeSetNull(fCanvas);
62 56
63 return fPicture.detach(); 57 return picture.detach();
64 } 58 }
65 59
66 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { 60 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) {
67 if (NULL != fCanvas) { 61 if (NULL != fCanvas) {
68 fCanvas->internalOnly_EnableOpts(enableOpts); 62 fCanvas->internalOnly_EnableOpts(enableOpts);
69 } 63 }
70 } 64 }
71 65
72 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { 66 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const {
73 if (NULL == fPicture.get() || NULL == canvas) { 67 if (NULL == fCanvas || NULL == canvas) {
74 // Not recording or nothing to replay into 68 // Not recording or nothing to replay into
75 return; 69 return;
76 } 70 }
77 71
78 SkASSERT(NULL != fCanvas); 72 const bool deepCopyOps = true;
79 73 SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight,
80 SkAutoTDelete<SkPicturePlayback> playback(SkPicture::FakeEndRecording(fPictu re.get(), 74 *fCanvas, deepCopyOps )));
81 *fCanv as)); 75 picture->draw(canvas);
82 playback->draw(*canvas, NULL);
83 } 76 }
OLDNEW
« no previous file with comments | « src/core/SkPictureRecord.cpp ('k') | tests/CanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698