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

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

Issue 748853002: Add support for hoisting layers in pictures drawn with a matrix (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 6 years 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 | « no previous file | src/gpu/GrLayerHoister.h » ('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 // Need to include something before #if SK_SUPPORT_GPU so that the Android 8 // Need to include something before #if SK_SUPPORT_GPU so that the Android
9 // framework build, which gets its defines from SkTypes rather than a makefile, 9 // framework build, which gets its defines from SkTypes rather than a makefile,
10 // has the definition before checking it. 10 // has the definition before checking it.
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkCanvasPriv.h"
12 #include "SkMultiPictureDraw.h" 13 #include "SkMultiPictureDraw.h"
13 #include "SkPicture.h" 14 #include "SkPicture.h"
14 #include "SkTaskGroup.h" 15 #include "SkTaskGroup.h"
15 16
16 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
17 #include "GrLayerHoister.h" 18 #include "GrLayerHoister.h"
18 #include "GrRecordReplaceDraw.h" 19 #include "GrRecordReplaceDraw.h"
19 #include "GrRenderTarget.h" 20 #include "GrRenderTarget.h"
20 #endif 21 #endif
21 22
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Start by collecting all the layers that are going to be atlased and rende r 105 // Start by collecting all the layers that are going to be atlased and rende r
105 // them (if necessary). Hoisting the free floating layers is deferred until 106 // them (if necessary). Hoisting the free floating layers is deferred until
106 // drawing the canvas that requires them. 107 // drawing the canvas that requires them.
107 SkTDArray<GrHoistedLayer> atlasedNeedRendering, atlasedRecycled; 108 SkTDArray<GrHoistedLayer> atlasedNeedRendering, atlasedRecycled;
108 109
109 for (int i = 0; i < count; ++i) { 110 for (int i = 0; i < count; ++i) {
110 const DrawData& data = fGPUDrawData[i]; 111 const DrawData& data = fGPUDrawData[i];
111 // we only expect 1 context for all the canvases 112 // we only expect 1 context for all the canvases
112 SkASSERT(data.fCanvas->getGrContext() == context); 113 SkASSERT(data.fCanvas->getGrContext() == context);
113 114
114 if (!data.fPaint && data.fMatrix.isIdentity()) { 115 if (!data.fPaint) {
115 SkRect clipBounds; 116 SkRect clipBounds;
116 if (!data.fCanvas->getClipBounds(&clipBounds)) { 117 if (!data.fCanvas->getClipBounds(&clipBounds)) {
117 continue; 118 continue;
118 } 119 }
119 120
121 SkMatrix initialMatrix = data.fCanvas->getTotalMatrix();
122 initialMatrix.preConcat(data.fMatrix);
123
120 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe nderTarget(); 124 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe nderTarget();
121 SkASSERT(rt); 125 SkASSERT(rt);
122 126
123 // TODO: sorting the cacheable layers from smallest to largest 127 // TODO: sorting the cacheable layers from smallest to largest
124 // would improve the packing and reduce the number of swaps 128 // would improve the packing and reduce the number of swaps
125 // TODO: another optimization would be to make a first pass to 129 // TODO: another optimization would be to make a first pass to
126 // lock any required layer that is already in the atlas 130 // lock any required layer that is already in the atlas
127 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, 131 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, initialMat rix,
128 clipBounds, 132 clipBounds,
129 &atlasedNeedRendering, &atlasedRec ycled, 133 &atlasedNeedRendering, &atlasedRec ycled,
130 rt->numSamples()); 134 rt->numSamples());
131 } 135 }
132 } 136 }
133 137
134 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); 138 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering);
135 139
136 SkTDArray<GrHoistedLayer> needRendering, recycled; 140 SkTDArray<GrHoistedLayer> needRendering, recycled;
137 #endif 141 #endif
138 142
139 for (int i = 0; i < count; ++i) { 143 for (int i = 0; i < count; ++i) {
140 const DrawData& data = fGPUDrawData[i]; 144 const DrawData& data = fGPUDrawData[i];
141 SkCanvas* canvas = data.fCanvas; 145 SkCanvas* canvas = data.fCanvas;
142 const SkPicture* picture = data.fPicture; 146 const SkPicture* picture = data.fPicture;
143 147
144 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU 148 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU
145 if (!data.fPaint && data.fMatrix.isIdentity()) { 149 if (!data.fPaint) {
146 150
147 SkRect clipBounds; 151 SkRect clipBounds;
148 if (!canvas->getClipBounds(&clipBounds)) { 152 if (!canvas->getClipBounds(&clipBounds)) {
149 continue; 153 continue;
150 } 154 }
151 155
156 SkAutoCanvasMatrixPaint acmp(canvas, &data.fMatrix, data.fPaint, pic ture->cullRect());
157
158 const SkMatrix initialMatrix = canvas->getTotalMatrix();
159
152 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe nderTarget(); 160 GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRe nderTarget();
153 SkASSERT(rt); 161 SkASSERT(rt);
154 162
155 // Find the layers required by this canvas. It will return atlased 163 // Find the layers required by this canvas. It will return atlased
156 // layers in the 'recycled' list since they have already been drawn. 164 // layers in the 'recycled' list since they have already been drawn.
157 GrLayerHoister::FindLayersToHoist(context, picture, 165 GrLayerHoister::FindLayersToHoist(context, picture, initialMatrix,
158 clipBounds, &needRendering, &recyc led, 166 clipBounds, &needRendering, &recyc led,
159 rt->numSamples()); 167 rt->numSamples());
160 168
161 GrLayerHoister::DrawLayers(context, needRendering); 169 GrLayerHoister::DrawLayers(context, needRendering);
162 170
163 GrReplacements replacements; 171 GrReplacements replacements;
164 172
165 GrLayerHoister::ConvertLayersToReplacements(needRendering, &replacem ents); 173 GrLayerHoister::ConvertLayersToReplacements(needRendering, &replacem ents);
166 GrLayerHoister::ConvertLayersToReplacements(recycled, &replacements) ; 174 GrLayerHoister::ConvertLayersToReplacements(recycled, &replacements) ;
167 175
168 const SkMatrix initialMatrix = canvas->getTotalMatrix();
169
170 // Render the entire picture using new layers 176 // Render the entire picture using new layers
171 GrRecordReplaceDraw(picture, canvas, &replacements, initialMatrix, N ULL); 177 GrRecordReplaceDraw(picture, canvas, &replacements, initialMatrix, N ULL);
172 178
173 GrLayerHoister::UnlockLayers(context, needRendering); 179 GrLayerHoister::UnlockLayers(context, needRendering);
174 GrLayerHoister::UnlockLayers(context, recycled); 180 GrLayerHoister::UnlockLayers(context, recycled);
175 181
176 needRendering.rewind(); 182 needRendering.rewind();
177 recycled.rewind(); 183 recycled.rewind();
178 } else 184 } else
179 #endif 185 #endif
180 { 186 {
181 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); 187 canvas->drawPicture(picture, &data.fMatrix, data.fPaint);
182 } 188 }
183 } 189 }
184 190
185 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU 191 #if !defined(SK_IGNORE_GPU_LAYER_HOISTING) && SK_SUPPORT_GPU
186 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); 192 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering);
187 GrLayerHoister::UnlockLayers(context, atlasedRecycled); 193 GrLayerHoister::UnlockLayers(context, atlasedRecycled);
188 #if !GR_CACHE_HOISTED_LAYERS 194 #if !GR_CACHE_HOISTED_LAYERS
189 GrLayerHoister::PurgeCache(context); 195 GrLayerHoister::PurgeCache(context);
190 #endif 196 #endif
191 #endif 197 #endif
192 } 198 }
193 199
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrLayerHoister.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698