Address MSAA rendering in layer hoisting
authorrobertphillips <robertphillips@google.com>
Mon, 10 Nov 2014 16:10:42 +0000 (08:10 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 10 Nov 2014 16:10:42 +0000 (08:10 -0800)
This became relevant whilst attempting to rebaseline the multipicturedraw GMs after turning on layer hoisting inside Skia.

Review URL: https://codereview.chromium.org/709943003

src/core/SkMultiPictureDraw.cpp
src/gpu/GrLayerCache.cpp
src/gpu/GrLayerHoister.cpp
src/gpu/GrLayerHoister.h
src/gpu/SkGpuDevice.cpp

index fe41243d6b3ab2b111f84d8c33a689dd4828d998..0e21b5c54aa85f15d510aaead644ef812941c938 100644 (file)
@@ -16,6 +16,7 @@
 #if SK_SUPPORT_GPU
 #include "GrLayerHoister.h"
 #include "GrRecordReplaceDraw.h"
+#include "GrRenderTarget.h"
 #endif
 
 void SkMultiPictureDraw::DrawData::draw() {
@@ -120,13 +121,17 @@ void SkMultiPictureDraw::draw() {
                 continue;
             }
 
+            GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRenderTarget();
+            SkASSERT(rt);
+
             // TODO: sorting the cacheable layers from smallest to largest
             // would improve the packing and reduce the number of swaps
             // TODO: another optimization would be to make a first pass to
             // lock any required layer that is already in the atlas
             GrLayerHoister::FindLayersToAtlas(context, data.fPicture,
                                               clipBounds,
-                                              &atlasedNeedRendering, &atlasedRecycled);
+                                              &atlasedNeedRendering, &atlasedRecycled,
+                                              rt->numSamples());
         }
     }
 
@@ -148,10 +153,14 @@ void SkMultiPictureDraw::draw() {
                 continue;
             }
 
+            GrRenderTarget* rt = data.fCanvas->internal_private_accessTopLayerRenderTarget();
+            SkASSERT(rt);
+
             // Find the layers required by this canvas. It will return atlased
             // layers in the 'recycled' list since they have already been drawn.
             GrLayerHoister::FindLayersToHoist(context, picture,
-                                              clipBounds, &needRendering, &recycled);
+                                              clipBounds, &needRendering, &recycled,
+                                              rt->numSamples());
 
             GrLayerHoister::DrawLayers(context, needRendering);
 
index d4f8b70b393858cf8db77f1f116fe893a551b5dd..e4e086a7d82eed757d5ddf6cede31a9263d3c28a 100644 (file)
@@ -164,6 +164,7 @@ bool GrLayerCache::tryToAtlas(GrCachedLayer* layer,
     SkDEBUGCODE(GrAutoValidateLayer avl(fAtlas ? fAtlas->getTexture() : NULL, layer);)
 
     SkASSERT(PlausiblyAtlasable(desc.fWidth, desc.fHeight));
+    SkASSERT(0 == desc.fSampleCnt);
 
     if (layer->locked()) {
         // This layer is already locked
index 5d3a383b474e9ff6f61b193fe13709e5f48e472b..c74913d757108c766b7a0052e06ba1b77aa2d2d4 100644 (file)
@@ -22,7 +22,8 @@ static void prepare_for_hoisting(GrLayerCache* layerCache,
                                  const SkIRect& layerRect,
                                  SkTDArray<GrHoistedLayer>* needRendering,
                                  SkTDArray<GrHoistedLayer>* recycled,
-                                 bool attemptToAtlas) {
+                                 bool attemptToAtlas,
+                                 int numSamples) {
     const SkPicture* pict = info.fPicture ? info.fPicture : topLevelPicture;
 
     SkMatrix combined = SkMatrix::Concat(info.fPreMat, info.fLocalMat);
@@ -38,7 +39,7 @@ static void prepare_for_hoisting(GrLayerCache* layerCache,
     desc.fWidth = layerRect.width();
     desc.fHeight = layerRect.height();
     desc.fConfig = kSkia8888_GrPixelConfig;
-    // TODO: need to deal with sample count
+    desc.fSampleCnt = numSamples;
 
     bool locked, needsRendering;
     if (attemptToAtlas) {
@@ -81,7 +82,13 @@ void GrLayerHoister::FindLayersToAtlas(GrContext* context,
                                        const SkPicture* topLevelPicture,
                                        const SkRect& query,
                                        SkTDArray<GrHoistedLayer>* atlased,
-                                       SkTDArray<GrHoistedLayer>* recycled) {
+                                       SkTDArray<GrHoistedLayer>* recycled,
+                                       int numSamples) {
+    if (0 != numSamples) {
+        // MSAA layers are currently never atlased
+        return;
+    }
+
     GrLayerCache* layerCache = context->getLayerCache();
 
     layerCache->processDeletedPictures();
@@ -123,7 +130,7 @@ void GrLayerHoister::FindLayersToAtlas(GrContext* context,
             continue;
         }
 
-        prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, recycled, true);
+        prepare_for_hoisting(layerCache, topLevelPicture, info, ir, atlased, recycled, true, 0);
     }
 
 }
@@ -132,7 +139,8 @@ void GrLayerHoister::FindLayersToHoist(GrContext* context,
                                        const SkPicture* topLevelPicture,
                                        const SkRect& query,
                                        SkTDArray<GrHoistedLayer>* needRendering,
-                                       SkTDArray<GrHoistedLayer>* recycled) {
+                                       SkTDArray<GrHoistedLayer>* recycled,
+                                       int numSamples) {
     GrLayerCache* layerCache = context->getLayerCache();
 
     layerCache->processDeletedPictures();
@@ -166,7 +174,7 @@ void GrLayerHoister::FindLayersToHoist(GrContext* context,
         layerRect.roundOut(&ir);
 
         prepare_for_hoisting(layerCache, topLevelPicture, info, ir, 
-                             needRendering, recycled, false);
+                             needRendering, recycled, false, numSamples);
     }
 }
 
index c3a451df572583fcb8db4d60c4b9a1b77dd2c62f..0780c1e801283316dc62bf64964f6289be1c91c8 100644 (file)
@@ -41,12 +41,14 @@ public:
         @param atlasedNeedRendering Out parameter storing the layers that 
                                     should be hoisted to the atlas
         @param recycled    Out parameter storing layers that are atlased but do not need rendering
+        @param numSamples  The number if MSAA samples required
         */
     static void FindLayersToAtlas(GrContext* context,
                                   const SkPicture* topLevelPicture,
                                   const SkRect& query,
                                   SkTDArray<GrHoistedLayer>* atlasedNeedRendering,
-                                  SkTDArray<GrHoistedLayer>* recycled);
+                                  SkTDArray<GrHoistedLayer>* recycled,
+                                  int numSamples);
 
     /** Find the layers in 'topLevelPicture' that need hoisting. Note that the discovered
         layers can be inside nested sub-pictures.
@@ -56,12 +58,14 @@ public:
         @param needRendering Out parameter storing the layers that need rendering.
                              This should never include atlased layers.
         @param recycled    Out parameter storing layers that need hoisting but not rendering
+        @param numSamples  The number if MSAA samples required
     */
     static void FindLayersToHoist(GrContext* context,
                                   const SkPicture* topLevelPicture,
                                   const SkRect& query,
                                   SkTDArray<GrHoistedLayer>* needRendering,
-                                  SkTDArray<GrHoistedLayer>* recycled);
+                                  SkTDArray<GrHoistedLayer>* recycled,
+                                  int numSamples);
 
     /** Draw the specified layers into the atlas.
         @param context      Owner of the layer cache (and thus the layers)
index 96c071473ca303630f692c7da39d1cbd9caf8001..b072142a0bd6383520be33a4bc0357f76471289c 100644 (file)
@@ -1824,7 +1824,8 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
 
     GrLayerHoister::FindLayersToAtlas(fContext, mainPicture,
                                       clipBounds,
-                                      &atlasedNeedRendering, &atlasedRecycled);
+                                      &atlasedNeedRendering, &atlasedRecycled,
+                                      fRenderTarget->numSamples());
 
     GrLayerHoister::DrawLayersToAtlas(fContext, atlasedNeedRendering);
 
@@ -1832,7 +1833,8 @@ bool SkGpuDevice::EXPERIMENTAL_drawPicture(SkCanvas* mainCanvas, const SkPicture
 
     GrLayerHoister::FindLayersToHoist(fContext, mainPicture,
                                       clipBounds,
-                                      &needRendering, &recycled);
+                                      &needRendering, &recycled,
+                                      fRenderTarget->numSamples());
 
     GrLayerHoister::DrawLayers(fContext, needRendering);