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

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

Issue 714533002: Small refactoring of layer discovery code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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/GrPictureUtils.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 "GrPictureUtils.h" 8 #include "GrPictureUtils.h"
9 9
10 #include "SkPaintPriv.h" 10 #include "SkPaintPriv.h"
(...skipping 11 matching lines...) Expand all
22 // In practice, this is well large enough, and it has a few extra advantages: 22 // In practice, this is well large enough, and it has a few extra advantages:
23 // it fits in an SkIRect, and we can munge it a little in both SkRect and 23 // it fits in an SkIRect, and we can munge it a little in both SkRect and
24 // SKIRect space without worrying about overflow. 24 // SKIRect space without worrying about overflow.
25 static const SkRect kUnbounded = { -2e9f, -2e9f, 2e9f, 2e9f }; 25 static const SkRect kUnbounded = { -2e9f, -2e9f, 2e9f, 2e9f };
26 26
27 namespace SkRecords { 27 namespace SkRecords {
28 28
29 // SkRecord visitor to gather saveLayer/restore information. 29 // SkRecord visitor to gather saveLayer/restore information.
30 class CollectLayers : SkNoncopyable { 30 class CollectLayers : SkNoncopyable {
31 public: 31 public:
32 CollectLayers(const SkPicture* pict, GrAccelData* accelData) 32 CollectLayers(const SkRect& cullRect, const SkRecord& record,
33 : fPictureID(pict->uniqueID()) 33 SkBBoxHierarchy* bbh, GrAccelData* accelData)
34 , fSaveLayersInStack(0) 34 : fSaveLayersInStack(0)
35 , fAccelData(accelData) { 35 , fAccelData(accelData) {
36 36
37 // Calculate bounds for all ops. This won't go quite in order, so we'll need 37 // Calculate bounds for all ops. This won't go quite in order, so we'll need
38 // to store the bounds separately then feed them in to the BBH later in order. 38 // to store the bounds separately then feed them in to the BBH later in order.
39 fCTM = &SkMatrix::I(); 39 fCTM = &SkMatrix::I();
40 fCurrentClipBounds = kUnbounded; 40 fCurrentClipBounds = kUnbounded;
41 41
42 if (NULL == pict->fRecord.get()) { 42 fBounds.reset(record.count());
43 return;
44 }
45 43
46 fBounds.reset(pict->fRecord->count()); 44 for (fCurrentOp = 0; fCurrentOp < record.count(); ++fCurrentOp) {
47 45 record.visit<void>(fCurrentOp, *this);
48 for (fCurrentOp = 0; fCurrentOp < pict->fRecord->count(); ++fCurrentOp) {
49 pict->fRecord->visit<void>(fCurrentOp, *this);
50 } 46 }
51 47
52 // If we have any lingering unpaired Saves, simulate restores to make 48 // If we have any lingering unpaired Saves, simulate restores to make
53 // sure all ops in those Save blocks have their bounds calculated. 49 // sure all ops in those Save blocks have their bounds calculated.
54 while (!fSaveStack.isEmpty()) { 50 while (!fSaveStack.isEmpty()) {
55 this->popSaveBlock(); 51 this->popSaveBlock();
56 } 52 }
57 53
58 // Any control ops not part of any Save/Restore block draw everywhere. 54 // Any control ops not part of any Save/Restore block draw everywhere.
59 while (!fControlIndices.isEmpty()) { 55 while (!fControlIndices.isEmpty()) {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 /* most ops aren't involved in saveLayers */ 413 /* most ops aren't involved in saveLayers */
418 } 414 }
419 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL); } 415 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL); }
420 void trackSaveLayers(const SaveLayer& sl) { 416 void trackSaveLayers(const SaveLayer& sl) {
421 this->pushSaveLayerInfo(true, sl.paint); 417 this->pushSaveLayerInfo(true, sl.paint);
422 } 418 }
423 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } 419 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); }
424 void trackSaveLayers(const DrawPicture& dp) { 420 void trackSaveLayers(const DrawPicture& dp) {
425 // For sub-pictures, we wrap their layer information within the parent 421 // For sub-pictures, we wrap their layer information within the parent
426 // picture's rendering hierarchy 422 // picture's rendering hierarchy
427 const GrAccelData* childData = GPUOptimize(dp.picture); 423 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
424
425 const GrAccelData* childData =
426 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat a(key));
427 if (!childData) {
428 childData = GPUOptimize(dp.picture);
429 }
428 430
429 for (int i = 0; i < childData->numSaveLayers(); ++i) { 431 for (int i = 0; i < childData->numSaveLayers(); ++i) {
430 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); 432 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i);
431 433
432 Bounds newClip(fCurrentClipBounds); 434 Bounds newClip(fCurrentClipBounds);
433 435
434 if (!newClip.intersect(this->adjustAndMap(src.fBounds, dp.paint))) { 436 if (!newClip.intersect(this->adjustAndMap(src.fBounds, dp.paint))) {
435 continue; 437 continue;
436 } 438 }
437 439
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 unsigned fCurrentOp; 572 unsigned fCurrentOp;
571 const SkMatrix* fCTM; 573 const SkMatrix* fCTM;
572 Bounds fCurrentClipBounds; 574 Bounds fCurrentClipBounds;
573 575
574 // Used to track the bounds of Save/Restore blocks and the control ops insid e them. 576 // Used to track the bounds of Save/Restore blocks and the control ops insid e them.
575 SkTDArray<SaveBounds> fSaveStack; 577 SkTDArray<SaveBounds> fSaveStack;
576 SkTDArray<unsigned> fControlIndices; 578 SkTDArray<unsigned> fControlIndices;
577 579
578 //--------- LAYER HOISTING 580 //--------- LAYER HOISTING
579 // Used to collect saveLayer information for layer hoisting 581 // Used to collect saveLayer information for layer hoisting
580 uint32_t fPictureID;
581 int fSaveLayersInStack; 582 int fSaveLayersInStack;
582 SkTDArray<SaveLayerInfo> fSaveLayerStack; 583 SkTDArray<SaveLayerInfo> fSaveLayerStack;
583 GrAccelData* fAccelData; 584 GrAccelData* fAccelData;
584 //--------- LAYER HOISTING 585 //--------- LAYER HOISTING
585 }; 586 };
586 587
587 } // namespace SkRecords 588 } // namespace SkRecords
588 589
589 // GPUOptimize is only intended to be called within the context of SkGpuDevice's 590
590 // EXPERIMENTAL_optimize method. 591 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record,
592 SkBBoxHierarchy* bbh, GrAccelData* data) {
593
594 SkRecords::CollectLayers collector(cullRect, record, bbh, data);
595 }
596
591 const GrAccelData* GPUOptimize(const SkPicture* pict) { 597 const GrAccelData* GPUOptimize(const SkPicture* pict) {
592 if (NULL == pict || pict->cullRect().isEmpty()) { 598 if (NULL == pict || pict->cullRect().isEmpty()) {
593 return NULL; 599 return NULL;
594 } 600 }
595 601
596 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); 602 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
597 603
598 const GrAccelData* existing = 604 const GrAccelData* existing =
599 static_cast<const GrAccelData*>(pict->EXPERIMENTAL_g etAccelData(key)); 605 static_cast<const GrAccelData*>(pict->EXPERIMENTAL_g etAccelData(key));
600 if (existing) { 606 if (existing) {
601 return existing; 607 return existing;
602 } 608 }
603 609
604 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key))); 610 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key)));
605 611
606 pict->EXPERIMENTAL_addAccelData(data); 612 pict->EXPERIMENTAL_addAccelData(data);
607 613
608 SkRecords::CollectLayers collector(pict, data); 614 SkRecordComputeLayers(pict->cullRect(), *pict->fRecord, NULL, data);
609 615
610 return data; 616 return data;
611 } 617 }
OLDNEW
« no previous file with comments | « src/gpu/GrPictureUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698