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

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

Issue 769533004: Fuse GrReplacements and GrLayerCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clang 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/gpu/GrLayerHoister.h ('k') | src/gpu/GrRecordReplaceDraw.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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 SkASSERT(!layer->isAtlased()); 65 SkASSERT(!layer->isAtlased());
66 } 66 }
67 hl = needRendering->append(); 67 hl = needRendering->append();
68 } else { 68 } else {
69 hl = recycled->append(); 69 hl = recycled->append();
70 } 70 }
71 71
72 layerCache->addUse(layer); 72 layerCache->addUse(layer);
73 hl->fLayer = layer; 73 hl->fLayer = layer;
74 hl->fPicture = pict; 74 hl->fPicture = pict;
75 hl->fOffset = SkIPoint::Make(layerRect.fLeft, layerRect.fTop);
76 hl->fLocalMat = info.fLocalMat; 75 hl->fLocalMat = info.fLocalMat;
77 hl->fInitialMat = initialMat; 76 hl->fInitialMat = initialMat;
78 hl->fPreMat = initialMat; 77 hl->fPreMat = initialMat;
79 hl->fPreMat.preConcat(info.fPreMat); 78 hl->fPreMat.preConcat(info.fPreMat);
80 } 79 }
81 80
82 // Atlased layers must be small enough to fit in the atlas, not have a 81 // Atlased layers must be small enough to fit in the atlas, not have a
83 // paint with an image filter and be neither nested nor nesting. 82 // paint with an image filter and be neither nested nor nesting.
84 // TODO: allow leaf nested layers to appear in the atlas. 83 // TODO: allow leaf nested layers to appear in the atlas.
85 void GrLayerHoister::FindLayersToAtlas(GrContext* context, 84 void GrLayerHoister::FindLayersToAtlas(GrContext* context,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 continue; 177 continue;
179 } 178 }
180 179
181 const SkIRect ir = layerRect.roundOut(); 180 const SkIRect ir = layerRect.roundOut();
182 181
183 prepare_for_hoisting(layerCache, topLevelPicture, initialMat, info, ir, 182 prepare_for_hoisting(layerCache, topLevelPicture, initialMat, info, ir,
184 needRendering, recycled, false, numSamples); 183 needRendering, recycled, false, numSamples);
185 } 184 }
186 } 185 }
187 186
188 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re sult) {
189 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
190 result->setInfo(info);
191 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
192 }
193
194 void GrLayerHoister::ConvertLayersToReplacements(const SkPicture* topLevelPictur e,
195 const SkTDArray<GrHoistedLayer> & layers,
196 GrReplacements* replacements) {
197 // TODO: just replace GrReplacements::ReplacementInfo with GrCachedLayer?
198 for (int i = 0; i < layers.count(); ++i) {
199 GrCachedLayer* layer = layers[i].fLayer;
200
201 GrReplacements::ReplacementInfo* layerInfo =
202 replacements->newReplacement(topLevelPicture->uniqueID(),
203 layers[i].fInitialMat,
204 layer->key(), layer->keySize()) ;
205 layerInfo->fStop = layer->stop();
206 layerInfo->fPos = layers[i].fOffset;
207
208 SkBitmap bm;
209 wrap_texture(layers[i].fLayer->texture(),
210 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().w idth()
211 : layers[i].fLayer->texture( )->width(),
212 !layers[i].fLayer->isAtlased() ? layers[i].fLayer->rect().h eight()
213 : layers[i].fLayer->texture( )->height(),
214 &bm);
215 layerInfo->fImage = SkImage::NewTexture(bm);
216
217 layerInfo->fPaint = layers[i].fLayer->paint()
218 ? SkNEW_ARGS(SkPaint, (*layers[i].fLayer->paint( )))
219 : NULL;
220
221 layerInfo->fSrcRect = SkIRect::MakeXYWH(layers[i].fLayer->rect().fLeft,
222 layers[i].fLayer->rect().fTop,
223 layers[i].fLayer->rect().width() ,
224 layers[i].fLayer->rect().height( ));
225 }
226 }
227
228 void GrLayerHoister::DrawLayersToAtlas(GrContext* context, 187 void GrLayerHoister::DrawLayersToAtlas(GrContext* context,
229 const SkTDArray<GrHoistedLayer>& atlased) { 188 const SkTDArray<GrHoistedLayer>& atlased) {
230 if (atlased.count() > 0) { 189 if (atlased.count() > 0) {
231 // All the atlased layers are rendered into the same GrTexture 190 // All the atlased layers are rendered into the same GrTexture
232 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 191 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
233 atlased[0].fLayer->texture()->asRenderTa rget(), NULL)); 192 atlased[0].fLayer->texture()->asRenderTa rget(), NULL));
234 193
235 SkCanvas* atlasCanvas = surface->getCanvas(); 194 SkCanvas* atlasCanvas = surface->getCanvas();
236 195
237 SkPaint clearPaint; 196 SkPaint clearPaint;
238 clearPaint.setColor(SK_ColorTRANSPARENT); 197 clearPaint.setColor(SK_ColorTRANSPARENT);
239 clearPaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref (); 198 clearPaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref ();
240 199
241 for (int i = 0; i < atlased.count(); ++i) { 200 for (int i = 0; i < atlased.count(); ++i) {
242 const GrCachedLayer* layer = atlased[i].fLayer; 201 const GrCachedLayer* layer = atlased[i].fLayer;
243 const SkPicture* pict = atlased[i].fPicture; 202 const SkPicture* pict = atlased[i].fPicture;
244 const SkIPoint offset = atlased[i].fOffset; 203 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer-> bound().fTop);
245 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();) 204 SkDEBUGCODE(const SkPaint* layerPaint = layer->paint();)
246 205
247 SkASSERT(!layerPaint || !layerPaint->getImageFilter()); 206 SkASSERT(!layerPaint || !layerPaint->getImageFilter());
248 207
249 atlasCanvas->save(); 208 atlasCanvas->save();
250 209
251 // Add a rect clip to make sure the rendering doesn't 210 // Add a rect clip to make sure the rendering doesn't
252 // extend beyond the boundaries of the atlased sub-rect 211 // extend beyond the boundaries of the atlased sub-rect
253 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), 212 const SkRect bound = SkRect::Make(layer->rect());
254 SkIntToScalar(layer->rect().fTop),
255 SkIntToScalar(layer->rect().width()) ,
256 SkIntToScalar(layer->rect().height() ));
257 atlasCanvas->clipRect(bound); 213 atlasCanvas->clipRect(bound);
258 214
259 // Since 'clear' doesn't respect the clip we need to draw a rect 215 // Since 'clear' doesn't respect the clip we need to draw a rect
260 atlasCanvas->drawRect(bound, clearPaint); 216 atlasCanvas->drawRect(bound, clearPaint);
261 217
262 // '-offset' maps the layer's top/left to the origin. 218 // '-offset' maps the layer's top/left to the origin.
263 // Since this layer is atlased, the top/left corner needs 219 // Since this layer is atlased, the top/left corner needs
264 // to be offset to the correct location in the backing texture. 220 // to be offset to the correct location in the backing texture.
265 SkMatrix initialCTM; 221 SkMatrix initialCTM;
266 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY)); 222 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-of fset.fY));
(...skipping 11 matching lines...) Expand all
278 } 234 }
279 235
280 atlasCanvas->flush(); 236 atlasCanvas->flush();
281 } 237 }
282 } 238 }
283 239
284 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) { 240 void GrLayerHoister::DrawLayers(GrContext* context, const SkTDArray<GrHoistedLay er>& layers) {
285 for (int i = 0; i < layers.count(); ++i) { 241 for (int i = 0; i < layers.count(); ++i) {
286 GrCachedLayer* layer = layers[i].fLayer; 242 GrCachedLayer* layer = layers[i].fLayer;
287 const SkPicture* pict = layers[i].fPicture; 243 const SkPicture* pict = layers[i].fPicture;
288 const SkIPoint& offset = layers[i].fOffset; 244 const SkIPoint offset = SkIPoint::Make(layer->bound().fLeft, layer->boun d().fTop);
289 245
290 // Each non-atlased layer has its own GrTexture 246 // Each non-atlased layer has its own GrTexture
291 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect( 247 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(
292 layer->texture()->asRenderTarget(), NULL )); 248 layer->texture()->asRenderTarget(), NULL ));
293 249
294 SkCanvas* layerCanvas = surface->getCanvas(); 250 SkCanvas* layerCanvas = surface->getCanvas();
295 251
296 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop); 252 SkASSERT(0 == layer->rect().fLeft && 0 == layer->rect().fTop);
297 253
298 // Add a rect clip to make sure the rendering doesn't 254 // Add a rect clip to make sure the rendering doesn't
299 // extend beyond the boundaries of the layer 255 // extend beyond the boundaries of the layer
300 SkRect bound = SkRect::MakeXYWH(SkIntToScalar(layer->rect().fLeft), 256 const SkRect bound = SkRect::Make(layer->rect());
301 SkIntToScalar(layer->rect().fTop),
302 SkIntToScalar(layer->rect().width()),
303 SkIntToScalar(layer->rect().height()));
304
305 layerCanvas->clipRect(bound); 257 layerCanvas->clipRect(bound);
306 258
307 layerCanvas->clear(SK_ColorTRANSPARENT); 259 layerCanvas->clear(SK_ColorTRANSPARENT);
308 260
309 SkMatrix initialCTM; 261 SkMatrix initialCTM;
310 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY)); 262 initialCTM.setTranslate(SkIntToScalar(-offset.fX), SkIntToScalar(-offset .fY));
311 initialCTM.preConcat(layers[i].fPreMat); 263 initialCTM.preConcat(layers[i].fPreMat);
312 264
313 layerCanvas->setMatrix(initialCTM); 265 layerCanvas->setMatrix(initialCTM);
314 layerCanvas->concat(layers[i].fLocalMat); 266 layerCanvas->concat(layers[i].fLocalMat);
(...skipping 20 matching lines...) Expand all
335 void GrLayerHoister::PurgeCache(GrContext* context) { 287 void GrLayerHoister::PurgeCache(GrContext* context) {
336 #if !GR_CACHE_HOISTED_LAYERS 288 #if !GR_CACHE_HOISTED_LAYERS
337 GrLayerCache* layerCache = context->getLayerCache(); 289 GrLayerCache* layerCache = context->getLayerCache();
338 290
339 // This code completely clears out the atlas. It is required when 291 // This code completely clears out the atlas. It is required when
340 // caching is disabled so the atlas doesn't fill up and force more 292 // caching is disabled so the atlas doesn't fill up and force more
341 // free floating layers 293 // free floating layers
342 layerCache->purgeAll(); 294 layerCache->purgeAll();
343 #endif 295 #endif
344 } 296 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerHoister.h ('k') | src/gpu/GrRecordReplaceDraw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698