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

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

Issue 2340133002: Clean up unused SkPictureRecorder::optimizeFor() (Closed)
Patch Set: Created 4 years, 3 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 | « include/core/SkPictureRecorder.h ('k') | no next file » | 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 "SkBigPicture.h" 8 #include "SkBigPicture.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDrawable.h" 10 #include "SkDrawable.h"
11 #include "SkImage.h"
12 #include "SkPictureRecorder.h" 11 #include "SkPictureRecorder.h"
13 #include "SkPictureUtils.h" 12 #include "SkPictureUtils.h"
14 #include "SkRecord.h" 13 #include "SkRecord.h"
15 #include "SkRecordDraw.h" 14 #include "SkRecordDraw.h"
16 #include "SkRecordOpts.h" 15 #include "SkRecordOpts.h"
17 #include "SkRecordedDrawable.h" 16 #include "SkRecordedDrawable.h"
18 #include "SkRecorder.h" 17 #include "SkRecorder.h"
19 #include "SkTypes.h" 18 #include "SkTypes.h"
20 #include "SkTLogic.h"
21
22 namespace SkRecords {
23
24 struct OptimizeFor {
25 GrContext* fCtx;
26
27 // A few ops have a top-level SkImage:
28 void operator()(DrawAtlas* op) { this->make_texture(&op->atlas); }
29 void operator()(DrawImage* op) { this->make_texture(&op->image); }
30 void operator()(DrawImageNine* op) { this->make_texture(&op->image); }
31 void operator()(DrawImageRect* op) { this->make_texture(&op->image); }
32 void make_texture(sk_sp<const SkImage>* img) const {
33 *img = (*img)->makeTextureImage(fCtx);
34 }
35
36 // Some ops have a paint, some have an optional paint.
37 // Either way, get back a pointer.
38 static SkPaint* AsPtr(SkPaint& p) { return &p; }
39 static SkPaint* AsPtr(SkRecords::Optional<SkPaint>& p) { return p; }
40
41 // For all other types of ops, look for images inside the paint.
42 template <typename T>
43 SK_WHEN(T::kTags & kHasPaint_Tag, void) operator()(T* op) {
44 SkMatrix matrix;
45 SkShader::TileMode xy[2];
46
47 if (auto paint = AsPtr(op->paint))
48 if (auto shader = paint->getShader())
49 if (auto image = shader->isAImage(&matrix, xy)) {
50 paint->setShader(image->makeTextureImage(fCtx)->makeShader(xy[0] , xy[1], &matrix));
51 }
52
53 // TODO: re-build compose shaders
54 }
55
56 // Control ops, etc. Nothing to do for these.
57 template <typename T>
58 SK_WHEN(!(T::kTags & kHasPaint_Tag), void) operator()(T*) {}
59 };
60
61 } // namespace SkRecords
62
63 static void optimize_for(GrContext* ctx, SkRecord* record) {
64 for (int i = 0; ctx && i < record->count(); i++) {
65 record->mutate(i, SkRecords::OptimizeFor{ctx});
66 }
67 }
68 19
69 SkPictureRecorder::SkPictureRecorder() { 20 SkPictureRecorder::SkPictureRecorder() {
70 fActivelyRecording = false; 21 fActivelyRecording = false;
71 fRecorder.reset(new SkRecorder(nullptr, SkRect::MakeWH(0, 0), &fMiniRecorder )); 22 fRecorder.reset(new SkRecorder(nullptr, SkRect::MakeWH(0, 0), &fMiniRecorder ));
72 } 23 }
73 24
74 SkPictureRecorder::~SkPictureRecorder() {} 25 SkPictureRecorder::~SkPictureRecorder() {}
75 26
76 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, 27 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect,
77 SkBBHFactory* bbhFactory /* = nullpt r */, 28 SkBBHFactory* bbhFactory /* = nullpt r */,
(...skipping 27 matching lines...) Expand all
105 56
106 if (fRecord->count() == 0) { 57 if (fRecord->count() == 0) {
107 if (finishFlags & kReturnNullForEmpty_FinishFlag) { 58 if (finishFlags & kReturnNullForEmpty_FinishFlag) {
108 return nullptr; 59 return nullptr;
109 } 60 }
110 return fMiniRecorder.detachAsPicture(fCullRect); 61 return fMiniRecorder.detachAsPicture(fCullRect);
111 } 62 }
112 63
113 // TODO: delay as much of this work until just before first playback? 64 // TODO: delay as much of this work until just before first playback?
114 SkRecordOptimize(fRecord); 65 SkRecordOptimize(fRecord);
115 optimize_for(fGrContextToOptimizeFor, fRecord);
116 66
117 if (fRecord->count() == 0) { 67 if (fRecord->count() == 0) {
118 if (finishFlags & kReturnNullForEmpty_FinishFlag) { 68 if (finishFlags & kReturnNullForEmpty_FinishFlag) {
119 return nullptr; 69 return nullptr;
120 } 70 }
121 } 71 }
122 72
123 SkDrawableList* drawableList = fRecorder->getDrawableList(); 73 SkDrawableList* drawableList = fRecorder->getDrawableList();
124 SkBigPicture::SnapshotArray* pictList = 74 SkBigPicture::SnapshotArray* pictList =
125 drawableList ? drawableList->newDrawableSnapshot() : nullptr; 75 drawableList ? drawableList->newDrawableSnapshot() : nullptr;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 116 }
167 SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, nullptr/*b bh*/, nullptr/*callback*/); 117 SkRecordDraw(*fRecord, canvas, nullptr, drawables, drawableCount, nullptr/*b bh*/, nullptr/*callback*/);
168 } 118 }
169 119
170 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable(uint32_t finishFl ags) { 120 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable(uint32_t finishFl ags) {
171 fActivelyRecording = false; 121 fActivelyRecording = false;
172 fRecorder->flushMiniRecorder(); 122 fRecorder->flushMiniRecorder();
173 fRecorder->restoreToCount(1); // If we were missing any restores, add them now. 123 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
174 124
175 SkRecordOptimize(fRecord); 125 SkRecordOptimize(fRecord);
176 optimize_for(fGrContextToOptimizeFor, fRecord);
177 126
178 if (fRecord->count() == 0) { 127 if (fRecord->count() == 0) {
179 if (finishFlags & kReturnNullForEmpty_FinishFlag) { 128 if (finishFlags & kReturnNullForEmpty_FinishFlag) {
180 return nullptr; 129 return nullptr;
181 } 130 }
182 } 131 }
183 132
184 if (fBBH.get()) { 133 if (fBBH.get()) {
185 SkAutoTMalloc<SkRect> bounds(fRecord->count()); 134 SkAutoTMalloc<SkRect> bounds(fRecord->count());
186 SkRecordFillBounds(fCullRect, *fRecord, bounds); 135 SkRecordFillBounds(fCullRect, *fRecord, bounds);
187 fBBH->insert(bounds, fRecord->count()); 136 fBBH->insert(bounds, fRecord->count());
188 } 137 }
189 138
190 sk_sp<SkDrawable> drawable = 139 sk_sp<SkDrawable> drawable =
191 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawable List(), fCullRect); 140 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawable List(), fCullRect);
192 141
193 // release our refs now, so only the drawable will be the owner. 142 // release our refs now, so only the drawable will be the owner.
194 fRecord.reset(nullptr); 143 fRecord.reset(nullptr);
195 fBBH.reset(nullptr); 144 fBBH.reset(nullptr);
196 145
197 return drawable; 146 return drawable;
198 } 147 }
OLDNEW
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698