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

Side by Side Diff: src/gpu/GrLayerHoister.cpp

Issue 783493002: Change clear() to respect the clip (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkRecords.h ('k') | src/gpu/SkGpuDevice.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 #include "GrLayerCache.h" 8 #include "GrLayerCache.h"
9 #include "GrLayerHoister.h" 9 #include "GrLayerHoister.h"
10 #include "GrRecordReplaceDraw.h" 10 #include "GrRecordReplaceDraw.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 void GrLayerHoister::DrawLayersToAtlas(GrContext* context, 187 void GrLayerHoister::DrawLayersToAtlas(GrContext* context,
188 const SkTDArray<GrHoistedLayer>& atlased) { 188 const SkTDArray<GrHoistedLayer>& atlased) {
189 if (atlased.count() > 0) { 189 if (atlased.count() > 0) {
190 // All the atlased layers are rendered into the same GrTexture 190 // All the atlased layers are rendered into the same GrTexture
191 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 191 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
192 atlased[0].fLayer->texture()->asRenderTa rget(), NULL)); 192 atlased[0].fLayer->texture()->asRenderTa rget(), NULL));
193 193
194 SkCanvas* atlasCanvas = surface->getCanvas(); 194 SkCanvas* atlasCanvas = surface->getCanvas();
195 195
196 SkPaint clearPaint;
197 clearPaint.setColor(SK_ColorTRANSPARENT);
198 clearPaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref ();
199
200 for (int i = 0; i < atlased.count(); ++i) { 196 for (int i = 0; i < atlased.count(); ++i) {
201 const GrCachedLayer* layer = atlased[i].fLayer; 197 const GrCachedLayer* layer = atlased[i].fLayer;
202 const SkPicture* pict = atlased[i].fPicture; 198 const SkPicture* pict = atlased[i].fPicture;
203 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer-> bound().fTop); 199 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer-> bound().fTop);
204 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();) 200 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();)
205 201
206 SkASSERT(!layerPaint || !layerPaint->getImageFilter()); 202 SkASSERT(!layerPaint || !layerPaint->getImageFilter());
207 203
208 atlasCanvas->save(); 204 atlasCanvas->save();
209 205
210 // Add a rect clip to make sure the rendering doesn't 206 // Add a rect clip to make sure the rendering doesn't
211 // extend beyond the boundaries of the atlased sub-rect 207 // extend beyond the boundaries of the atlased sub-rect
212 const SkRect bound = SkRect::Make(layer->rect()); 208 const SkRect bound = SkRect::Make(layer->rect());
213 atlasCanvas->clipRect(bound); 209 atlasCanvas->clipRect(bound);
214 210 atlasCanvas->clear(0);
215 // Since 'clear' doesn't respect the clip we need to draw a rect
216 atlasCanvas->drawRect(bound, clearPaint);
217 211
218 // '-offset' maps the layer's top/left to the origin. 212 // '-offset' maps the layer's top/left to the origin.
219 // Since this layer is atlased, the top/left corner needs 213 // Since this layer is atlased, the top/left corner needs
220 // to be offset to the correct location in the backing texture. 214 // to be offset to the correct location in the backing texture.
221 SkMatrix initialCTM; 215 SkMatrix initialCTM;
222 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY)); 216 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY));
223 initialCTM.preTranslate(bound.fLeft, bound.fTop); 217 initialCTM.preTranslate(bound.fLeft, bound.fTop);
224 initialCTM.preConcat(atlased[i].fPreMat); 218 initialCTM.preConcat(atlased[i].fPreMat);
225 219
226 atlasCanvas->setMatrix(initialCTM); 220 atlasCanvas->setMatrix(initialCTM);
227 atlasCanvas->concat(atlased[i].fLocalMat); 221 atlasCanvas->concat(atlased[i].fLocalMat);
228 222
229 SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas, 223 SkRecordPartialDraw(*pict->fRecord.get(), atlasCanvas,
230 pict->drawablePicts(), pict->drawableCount(), 224 pict->drawablePicts(), pict->drawableCount(),
231 bound, layer->start() + 1, layer->stop(), initia lCTM); 225 layer->start() + 1, layer->stop(), initialCTM);
232 226
233 atlasCanvas->restore(); 227 atlasCanvas->restore();
234 } 228 }
235 229
236 atlasCanvas->flush(); 230 atlasCanvas->flush();
237 } 231 }
238 } 232 }
239 233
240 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) { 234 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) {
241 for (int i = 0; i < layers.count(); ++i) { 235 for (int i = 0; i < layers.count(); ++i) {
242 GrCachedLayer* layer = layers[i].fLayer; 236 GrCachedLayer* layer = layers[i].fLayer;
243 const SkPicture* pict = layers[i].fPicture; 237 const SkPicture* pict = layers[i].fPicture;
244 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer->boun d().fTop); 238 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer->boun d().fTop);
245 239
246 // Each non-atlased layer has its own GrTexture 240 // Each non-atlased layer has its own GrTexture
247 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 241 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
248 layer->texture()->asRenderTarget(), NULL )); 242 layer->texture()->asRenderTarget(), NULL ));
249 243
250 SkCanvas* layerCanvas = surface->getCanvas(); 244 SkCanvas* layerCanvas = surface->getCanvas();
251 245
252 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 246 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
253 247
254 // Add a rect clip to make sure the rendering doesn't 248 // Add a rect clip to make sure the rendering doesn't
255 // extend beyond the boundaries of the layer 249 // extend beyond the boundaries of the layer
256 const SkRect bound = SkRect::Make(layer->rect()); 250 const SkRect bound = SkRect::Make(layer->rect());
257 layerCanvas->clipRect(bound); 251 layerCanvas->clipRect(bound);
258
259 layerCanvas->clear(SK_ColorTRANSPARENT); 252 layerCanvas->clear(SK_ColorTRANSPARENT);
260 253
261 SkMatrix initialCTM; 254 SkMatrix initialCTM;
262 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY)); 255 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY));
263 initialCTM.preConcat(layers[i].fPreMat); 256 initialCTM.preConcat(layers[i].fPreMat);
264 257
265 layerCanvas->setMatrix(initialCTM); 258 layerCanvas->setMatrix(initialCTM);
266 layerCanvas->concat(layers[i].fLocalMat); 259 layerCanvas->concat(layers[i].fLocalMat);
267 260
268 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas, 261 SkRecordPartialDraw(*pict->fRecord.get(), layerCanvas,
269 pict->drawablePicts(), pict->drawableCount(), 262 pict->drawablePicts(), pict->drawableCount(),
270 bound, layer->start()+1, layer->stop(), initialCTM); 263 layer->start()+1, layer->stop(), initialCTM);
271 264
272 layerCanvas->flush(); 265 layerCanvas->flush();
273 } 266 }
274 } 267 }
275 268
276 void GrLayerHoister::UnlockLayers(GrContext* context, 269 void GrLayerHoister::UnlockLayers(GrContext* context,
277 const SkTDArray<GrHoistedLayer>& layers) { 270 const SkTDArray<GrHoistedLayer>& layers) {
278 GrLayerCache* layerCache = context->getLayerCache(); 271 GrLayerCache* layerCache = context->getLayerCache();
279 272
280 for (int i = 0; i < layers.count(); ++i) { 273 for (int i = 0; i < layers.count(); ++i) {
281 layerCache->removeUse(layers[i].fLayer); 274 layerCache->removeUse(layers[i].fLayer);
282 } 275 }
283 276
284 SkDEBUGCODE(layerCache->validate();) 277 SkDEBUGCODE(layerCache->validate();)
285 } 278 }
286 279
287 void GrLayerHoister::PurgeCache(GrContext* context) { 280 void GrLayerHoister::PurgeCache(GrContext* context) {
288 #if !GR_CACHE_HOISTED_LAYERS 281 #if !GR_CACHE_HOISTED_LAYERS
289 GrLayerCache* layerCache = context->getLayerCache(); 282 GrLayerCache* layerCache = context->getLayerCache();
290 283
291 // This code completely clears out the atlas. It is required when 284 // This code completely clears out the atlas. It is required when
292 // caching is disabled so the atlas doesn't fill up and force more 285 // caching is disabled so the atlas doesn't fill up and force more
293 // free floating layers 286 // free floating layers
294 layerCache->purgeAll(); 287 layerCache->purgeAll();
295 #endif 288 #endif
296 } 289 }
OLDNEW
« no previous file with comments | « src/core/SkRecords.h ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698