OLD | NEW |
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 "SkBBoxHierarchy.h" |
10 #include "SkPaintPriv.h" | 11 #include "SkPaintPriv.h" |
11 #include "SkPatchUtils.h" | 12 #include "SkPatchUtils.h" |
12 #include "SkRecord.h" | 13 #include "SkRecord.h" |
13 #include "SkRecords.h" | 14 #include "SkRecords.h" |
14 | 15 |
15 SkPicture::AccelData::Key GrAccelData::ComputeAccelDataKey() { | 16 SkPicture::AccelData::Key GrAccelData::ComputeAccelDataKey() { |
16 static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::Genera
teDomain(); | 17 static const SkPicture::AccelData::Key gGPUID = SkPicture::AccelData::Genera
teDomain(); |
17 | 18 |
18 return gGPUID; | 19 return gGPUID; |
19 } | 20 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // Any control ops not part of any Save/Restore block draw everywhere. | 55 // Any control ops not part of any Save/Restore block draw everywhere. |
55 while (!fControlIndices.isEmpty()) { | 56 while (!fControlIndices.isEmpty()) { |
56 this->popControl(kUnbounded); | 57 this->popControl(kUnbounded); |
57 } | 58 } |
58 | 59 |
59 //--------- LAYER HOISTING | 60 //--------- LAYER HOISTING |
60 while (!fSaveLayerStack.isEmpty()) { | 61 while (!fSaveLayerStack.isEmpty()) { |
61 this->popSaveLayerInfo(); | 62 this->popSaveLayerInfo(); |
62 } | 63 } |
63 //--------- LAYER HOISTING | 64 //--------- LAYER HOISTING |
| 65 |
| 66 // Finally feed all stored bounds into the BBH. They'll be returned in
this order. |
| 67 SkASSERT(bbh); |
| 68 bbh->insert(&fBounds, record.count()); |
64 } | 69 } |
65 | 70 |
66 template <typename T> void operator()(const T& op) { | 71 template <typename T> void operator()(const T& op) { |
67 this->updateCTM(op); | 72 this->updateCTM(op); |
68 this->updateClipBounds(op); | 73 this->updateClipBounds(op); |
69 this->trackBounds(op); | 74 this->trackBounds(op); |
70 //--------- LAYER HOISTING | 75 //--------- LAYER HOISTING |
71 this->trackSaveLayers(op); | 76 this->trackSaveLayers(op); |
72 //--------- LAYER HOISTING | 77 //--------- LAYER HOISTING |
73 } | 78 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 423 } |
419 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } | 424 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } |
420 void trackSaveLayers(const DrawPicture& dp) { | 425 void trackSaveLayers(const DrawPicture& dp) { |
421 // For sub-pictures, we wrap their layer information within the parent | 426 // For sub-pictures, we wrap their layer information within the parent |
422 // picture's rendering hierarchy | 427 // picture's rendering hierarchy |
423 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 428 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
424 | 429 |
425 const GrAccelData* childData = | 430 const GrAccelData* childData = |
426 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat
a(key)); | 431 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat
a(key)); |
427 if (!childData) { | 432 if (!childData) { |
428 childData = GPUOptimize(dp.picture); | 433 // If the child layer hasn't been generated with saveLayer data we |
| 434 // assume the worst (i.e., that it does contain layers which nest |
| 435 // inside existing layers). Layers within sub-pictures that don't |
| 436 // have saveLayer data cannot be hoisted. |
| 437 // TODO: could the analysis data be use to fine tune this? |
| 438 this->updateStackForSaveLayer(); |
| 439 return; |
429 } | 440 } |
430 | 441 |
431 for (int i = 0; i < childData->numSaveLayers(); ++i) { | 442 for (int i = 0; i < childData->numSaveLayers(); ++i) { |
432 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); | 443 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); |
433 | 444 |
434 Bounds newClip(fCurrentClipBounds); | 445 Bounds newClip(fCurrentClipBounds); |
435 | 446 |
436 if (!newClip.intersect(this->adjustAndMap(src.fBounds, dp.paint))) { | 447 if (!newClip.intersect(this->adjustAndMap(src.fBounds, dp.paint))) { |
437 continue; | 448 continue; |
438 } | 449 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 //--------- LAYER HOISTING | 591 //--------- LAYER HOISTING |
581 // Used to collect saveLayer information for layer hoisting | 592 // Used to collect saveLayer information for layer hoisting |
582 int fSaveLayersInStack; | 593 int fSaveLayersInStack; |
583 SkTDArray<SaveLayerInfo> fSaveLayerStack; | 594 SkTDArray<SaveLayerInfo> fSaveLayerStack; |
584 GrAccelData* fAccelData; | 595 GrAccelData* fAccelData; |
585 //--------- LAYER HOISTING | 596 //--------- LAYER HOISTING |
586 }; | 597 }; |
587 | 598 |
588 } // namespace SkRecords | 599 } // namespace SkRecords |
589 | 600 |
590 | |
591 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, | 601 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, |
592 SkBBoxHierarchy* bbh, GrAccelData* data) { | 602 SkBBoxHierarchy* bbh, GrAccelData* data) { |
593 | |
594 SkRecords::CollectLayers collector(cullRect, record, bbh, data); | 603 SkRecords::CollectLayers collector(cullRect, record, bbh, data); |
595 } | 604 } |
596 | 605 |
597 const GrAccelData* GPUOptimize(const SkPicture* pict) { | |
598 if (NULL == pict || pict->cullRect().isEmpty()) { | |
599 return NULL; | |
600 } | |
601 | 606 |
602 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | |
603 | |
604 const GrAccelData* existing = | |
605 static_cast<const GrAccelData*>(pict->EXPERIMENTAL_g
etAccelData(key)); | |
606 if (existing) { | |
607 return existing; | |
608 } | |
609 | |
610 SkAutoTUnref<GrAccelData> data(SkNEW_ARGS(GrAccelData, (key))); | |
611 | |
612 pict->EXPERIMENTAL_addAccelData(data); | |
613 | |
614 SkRecordComputeLayers(pict->cullRect(), *pict->fRecord, NULL, data); | |
615 | |
616 return data; | |
617 } | |
OLD | NEW |