Index: src/core/SkMultiPictureDraw.cpp |
diff --git a/src/core/SkMultiPictureDraw.cpp b/src/core/SkMultiPictureDraw.cpp |
index eb1e55e5508a749d3908111cc2748c0929137ba8..19b26ca60775e1b03d89cfd34952a936254525d2 100644 |
--- a/src/core/SkMultiPictureDraw.cpp |
+++ b/src/core/SkMultiPictureDraw.cpp |
@@ -5,6 +5,11 @@ |
* found in the LICENSE file. |
*/ |
+#if SK_SUPPORT_GPU |
+#include "GrLayerHoister.h" |
+#include "GrRecordReplaceDraw.h" |
+#endif |
+ |
#include "SkCanvas.h" |
#include "SkMultiPictureDraw.h" |
#include "SkPicture.h" |
@@ -50,12 +55,66 @@ void SkMultiPictureDraw::add(SkCanvas* canvas, |
} |
} |
+#undef SK_IGNORE_GPU_LAYER_HOISTING |
+#define SK_IGNORE_GPU_LAYER_HOISTING 1 |
+ |
void SkMultiPictureDraw::draw() { |
+ |
+#ifndef SK_IGNORE_GPU_LAYER_HOISTING |
+ GrContext* context = NULL; |
+ |
+ SkTDArray<GrHoistedLayer> atlased, nonAtlased, recycled; |
+ |
for (int i = 0; i < fDrawData.count(); ++i) { |
- fDrawData[i].canvas->drawPicture(fDrawData[i].picture, |
- &fDrawData[i].matrix, |
- fDrawData[i].paint); |
+ if (fDrawData[i].canvas->getGrContext() && |
+ !fDrawData[i].paint && fDrawData[i].matrix.isIdentity()) { |
+ SkASSERT(NULL == context || context == fDrawData[i].canvas->getGrContext()); |
+ context = fDrawData[i].canvas->getGrContext(); |
+ |
+ // TODO: this path always tries to optimize pictures. Should we |
+ // switch to this API approach (vs. SkCanvas::EXPERIMENTAL_optimize)? |
+ fDrawData[i].canvas->EXPERIMENTAL_optimize(fDrawData[i].picture); |
+ |
+ SkRect clipBounds; |
+ if (!fDrawData[i].canvas->getClipBounds(&clipBounds)) { |
+ continue; |
+ } |
+ |
+ GrLayerHoister::FindLayersToHoist(context, fDrawData[i].picture, |
+ clipBounds, &atlased, &nonAtlased, &recycled); |
+ } |
+ } |
+ |
+ GrReplacements replacements; |
+ |
+ if (NULL != context) { |
+ GrLayerHoister::DrawLayers(atlased, nonAtlased, recycled, &replacements); |
+ } |
+#endif |
+ |
+ for (int i = 0; i < fDrawData.count(); ++i) { |
+#ifndef SK_IGNORE_GPU_LAYER_HOISTING |
+ if (fDrawData[i].canvas->getGrContext() && |
+ !fDrawData[i].paint && fDrawData[i].matrix.isIdentity()) { |
+ // Render the entire picture using new layers |
+ const SkMatrix initialMatrix = fDrawData[i].canvas->getTotalMatrix(); |
+ |
+ GrRecordReplaceDraw(fDrawData[i].picture, fDrawData[i].canvas, |
+ &replacements, initialMatrix, NULL); |
+ } else |
+#endif |
+ { |
+ fDrawData[i].canvas->drawPicture(fDrawData[i].picture, |
+ &fDrawData[i].matrix, |
+ fDrawData[i].paint); |
+ } |
+ } |
+ |
+#ifndef SK_IGNORE_GPU_LAYER_HOISTING |
+ if (NULL != context) { |
+ GrLayerHoister::UnlockLayers(context, atlased, nonAtlased, recycled); |
} |
+#endif |
this->reset(); |
} |