Title: [105314] trunk/Source
Revision
105314
Author
commit-qu...@webkit.org
Date
2012-01-18 13:41:51 -0800 (Wed, 18 Jan 2012)

Log Message

[chromium] Enable tracking opaque region in Skia graphics context, return it from LayerTextureUpdater
https://bugs.webkit.org/show_bug.cgi?id=76211

Patch by Dana Jansens <dan...@chromium.org> on 2012-01-18
Reviewed by James Robinson.

Source/WebCore:

New unit tests in LayerTextureUpdaterTest.cpp

* platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp:
(WebCore::BitmapCanvasLayerTextureUpdater::prepareToUpdate):
* platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h:
* platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp:
(WebCore::BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate):
* platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h:
* platform/graphics/chromium/ContentLayerChromium.cpp:
(WebCore::ContentLayerChromium::createTextureUpdater):
* platform/graphics/chromium/LayerTextureUpdater.h:
(WebCore::LayerTextureUpdater::prepareToUpdate):
* platform/graphics/chromium/PlatformCanvas.h:
(WebCore::PlatformCanvas::Painter::skiaContext):
* platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp:
(WebCore::SkPictureCanvasLayerTextureUpdater::SkPictureCanvasLayerTextureUpdater):
(WebCore::SkPictureCanvasLayerTextureUpdater::prepareToUpdate):
(WebCore::SkPictureCanvasLayerTextureUpdater::setOpaque):
* platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.h:
* platform/graphics/chromium/TiledLayerChromium.cpp:
(WebCore::TiledLayerChromium::prepareToUpdateTiles):

Source/WebKit/chromium:

* WebKit.gypi:
* tests/LayerTextureUpdaterTest.cpp: Added.
(WebCore::TestLayerPainterChromium::TestLayerPainterChromium):
(WebCore::TestLayerPainterChromium::paint):
(WebCore::PaintFillOpaque::operator()):
(WebCore::PaintFillAlpha::operator()):
(WebCore::TEST):
* tests/TiledLayerChromiumTest.cpp:
(WTF::FakeLayerTextureUpdater::prepareToUpdate):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (105313 => 105314)


--- trunk/Source/WebCore/ChangeLog	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/ChangeLog	2012-01-18 21:41:51 UTC (rev 105314)
@@ -1,3 +1,32 @@
+2012-01-18  Dana Jansens  <dan...@chromium.org>
+
+        [chromium] Enable tracking opaque region in Skia graphics context, return it from LayerTextureUpdater
+        https://bugs.webkit.org/show_bug.cgi?id=76211
+
+        Reviewed by James Robinson.
+
+        New unit tests in LayerTextureUpdaterTest.cpp
+
+        * platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp:
+        (WebCore::BitmapCanvasLayerTextureUpdater::prepareToUpdate):
+        * platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h:
+        * platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp:
+        (WebCore::BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate):
+        * platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h:
+        * platform/graphics/chromium/ContentLayerChromium.cpp:
+        (WebCore::ContentLayerChromium::createTextureUpdater):
+        * platform/graphics/chromium/LayerTextureUpdater.h:
+        (WebCore::LayerTextureUpdater::prepareToUpdate):
+        * platform/graphics/chromium/PlatformCanvas.h:
+        (WebCore::PlatformCanvas::Painter::skiaContext):
+        * platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp:
+        (WebCore::SkPictureCanvasLayerTextureUpdater::SkPictureCanvasLayerTextureUpdater):
+        (WebCore::SkPictureCanvasLayerTextureUpdater::prepareToUpdate):
+        (WebCore::SkPictureCanvasLayerTextureUpdater::setOpaque):
+        * platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.h:
+        * platform/graphics/chromium/TiledLayerChromium.cpp:
+        (WebCore::TiledLayerChromium::prepareToUpdateTiles):
+
 2012-01-18  Tim Dresser  <tdres...@chromium.org>
 
         [chromium] Refactor canvas, plugin, and video drawing to be more data-driven

Modified: trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -32,6 +32,7 @@
 
 #include "LayerPainterChromium.h"
 #include "PlatformColor.h"
+#include "PlatformContextSkia.h"
 
 namespace WebCore {
 
@@ -77,10 +78,12 @@
             LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
 }
 
-void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale)
+void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect)
 {
     m_texSubImage.setSubImageSize(tileSize);
 
+    bool layerIsOpaque = m_canvas.opaque();
+
     m_canvas.resize(contentRect.size());
     // Assumption: if a tiler is using border texels, then it is because the
     // layer is likely to be filtered or transformed. Because of it might be
@@ -88,7 +91,11 @@
     PlatformCanvas::Painter::TextOption textOption =
         borderTexels ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
     PlatformCanvas::Painter canvasPainter(&m_canvas, textOption);
+    canvasPainter.skiaContext()->setTrackOpaqueRegion(!layerIsOpaque);
     paintContents(*canvasPainter.context(), contentRect, contentsScale);
+
+    if (!layerIsOpaque)
+        *resultingOpaqueRect = canvasPainter.skiaContext()->opaqueRegion().asRect();
 }
 
 void BitmapCanvasLayerTextureUpdater::updateTextureRect(GraphicsContext3D* context, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)

Modified: trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.h	2012-01-18 21:41:51 UTC (rev 105314)
@@ -60,7 +60,7 @@
 
     virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager*);
     virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
-    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale);
+    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect);
     void updateTextureRect(GraphicsContext3D*, TextureAllocator*, ManagedTexture*, const IntRect& sourceRect, const IntRect& destRect);
 
     virtual void setOpaque(bool);

Modified: trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -86,10 +86,10 @@
             LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
 }
 
-void BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale)
+void BitmapSkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect)
 {
     m_texSubImage.setSubImageSize(tileSize);
-    SkPictureCanvasLayerTextureUpdater::prepareToUpdate(contentRect, tileSize, borderTexels, contentsScale);
+    SkPictureCanvasLayerTextureUpdater::prepareToUpdate(contentRect, tileSize, borderTexels, contentsScale, resultingOpaqueRect);
 }
 
 void BitmapSkPictureCanvasLayerTextureUpdater::paintContentsRect(SkCanvas* canvas, const IntRect& sourceRect)

Modified: trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/BitmapSkPictureCanvasLayerTextureUpdater.h	2012-01-18 21:41:51 UTC (rev 105314)
@@ -59,7 +59,7 @@
 
     virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager*);
     virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat);
-    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale);
+    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect);
     void paintContentsRect(SkCanvas*, const IntRect& sourceRect);
     void updateTextureRect(GraphicsContext3D*, GC3Denum format, const IntRect& destRect, const uint8_t* pixels);
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -119,18 +119,13 @@
 void ContentLayerChromium::createTextureUpdater(const CCLayerTreeHost* host)
 {
 #if USE(SKIA)
-    if (host->settings().acceleratePainting) {
+    if (host->settings().acceleratePainting)
         m_textureUpdater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate));
-        return;
-    }
-
-    if (host->settings().perTilePainting) {
+    else if (host->settings().perTilePainting)
         m_textureUpdater = BitmapSkPictureCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
-        return;
-    }
+    else
 #endif // USE(SKIA)
-
-    m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
+        m_textureUpdater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(m_delegate), host->layerRendererCapabilities().usingMapSub);
     m_textureUpdater->setOpaque(opaque());
 }
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/LayerTextureUpdater.h	2012-01-18 21:41:51 UTC (rev 105314)
@@ -71,8 +71,12 @@
     // This format specifies the component order in the sampled texel.
     // If the format is TexelFormatBGRA, vec4.x is blue and vec4.z is red.
     virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) = 0;
-    virtual void prepareToUpdate(const IntRect& /* contentRect */, const IntSize& /* tileSize */, int /* borderTexels */, float /* contentsScale */) { }
+    // The |resultingOpaqueRect| gives back a region of the layer that was painted opaque. If the layer is marked opaque in the updater,
+    // then this region should be ignored in preference for the entire layer's area.
+    virtual void prepareToUpdate(const IntRect& /* contentRect */, const IntSize& /* tileSize */, int /* borderTexels */, float /* contentsScale */,
+                                 IntRect* /* resultingOpaqueRect */) { }
 
+    // Set true by the layer when it is known that the entire output is going to be opaque.
     virtual void setOpaque(bool) { }
 };
 

Modified: trunk/Source/WebCore/platform/graphics/chromium/PlatformCanvas.h (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/PlatformCanvas.h	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/PlatformCanvas.h	2012-01-18 21:41:51 UTC (rev 105314)
@@ -85,6 +85,7 @@
         ~Painter();
 
         GraphicsContext* context() const { return m_context.get(); }
+        PlatformContextSkia* skiaContext() const { return m_skiaContext.get(); }
     private:
         OwnPtr<GraphicsContext> m_context;
 #if USE(SKIA)

Modified: trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -41,6 +41,7 @@
 
 SkPictureCanvasLayerTextureUpdater::SkPictureCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium> painter)
     : CanvasLayerTextureUpdater(painter)
+    , m_layerIsOpaque(false)
 {
 }
 
@@ -48,14 +49,18 @@
 {
 }
 
-void SkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& /* tileSize */, int /* borderTexels */, float contentsScale)
+void SkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize& /* tileSize */, int /* borderTexels */, float contentsScale, IntRect* resultingOpaqueRect)
 {
     SkCanvas* canvas = m_picture.beginRecording(contentRect.width(), contentRect.height());
     PlatformContextSkia platformContext(canvas);
     platformContext.setDeferred(true);
+    platformContext.setTrackOpaqueRegion(!m_layerIsOpaque);
     GraphicsContext graphicsContext(&platformContext);
     paintContents(graphicsContext, contentRect, contentsScale);
     m_picture.endRecording();
+
+    if (!m_layerIsOpaque)
+        *resultingOpaqueRect = platformContext.opaqueRegion().asRect();
 }
 
 void SkPictureCanvasLayerTextureUpdater::drawPicture(SkCanvas* canvas)
@@ -64,6 +69,11 @@
     canvas->drawPicture(m_picture);
 }
 
+void SkPictureCanvasLayerTextureUpdater::setOpaque(bool opaque)
+{
+    m_layerIsOpaque = opaque;
+}
+
 } // namespace WebCore
 #endif // USE(SKIA)
 #endif // USE(ACCELERATED_COMPOSITING)

Modified: trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.h (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.h	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.h	2012-01-18 21:41:51 UTC (rev 105314)
@@ -51,11 +51,16 @@
 protected:
     explicit SkPictureCanvasLayerTextureUpdater(PassOwnPtr<LayerPainterChromium>);
 
-    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale);
+    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize& tileSize, int borderTexels, float contentsScale, IntRect* resultingOpaqueRect);
     void drawPicture(SkCanvas*);
 
+    virtual void setOpaque(bool);
+
 private:
-    SkPicture m_picture; // Recording canvas.
+    // Recording canvas.
+    SkPicture m_picture;
+    // True when it is known that all output pixels will be opaque.
+    bool m_layerIsOpaque;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp (105313 => 105314)


--- trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -412,7 +412,8 @@
     // However, we can't free the memory backing the GraphicsContext until the paint finishes,
     // so we grab a local reference here to hold the updater alive until the paint completes.
     RefPtr<LayerTextureUpdater> protector(textureUpdater());
-    textureUpdater()->prepareToUpdate(m_paintRect, m_tiler->tileSize(), m_tiler->hasBorderTexels(), contentsScale());
+    IntRect opaqueRect; // FIXME: unused. remove this and store in the layer to pass to impl for draw culling
+    textureUpdater()->prepareToUpdate(m_paintRect, m_tiler->tileSize(), m_tiler->hasBorderTexels(), contentsScale(), &opaqueRect);
     for (int j = top; j <= bottom; ++j) {
         for (int i = left; i <= right; ++i) {
             UpdatableTile* tile = tileAt(i, j);

Modified: trunk/Source/WebKit/chromium/ChangeLog (105313 => 105314)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-01-18 21:41:51 UTC (rev 105314)
@@ -1,3 +1,20 @@
+2012-01-18  Dana Jansens  <dan...@chromium.org>
+
+        [chromium] Enable tracking opaque region in Skia graphics context, return it from LayerTextureUpdater
+        https://bugs.webkit.org/show_bug.cgi?id=76211
+
+        Reviewed by James Robinson.
+
+        * WebKit.gypi:
+        * tests/LayerTextureUpdaterTest.cpp: Added.
+        (WebCore::TestLayerPainterChromium::TestLayerPainterChromium):
+        (WebCore::TestLayerPainterChromium::paint):
+        (WebCore::PaintFillOpaque::operator()):
+        (WebCore::PaintFillAlpha::operator()):
+        (WebCore::TEST):
+        * tests/TiledLayerChromiumTest.cpp:
+        (WTF::FakeLayerTextureUpdater::prepareToUpdate):
+
 2012-01-18  Tim Dresser  <tdres...@chromium.org>
 
         [chromium] Refactor canvas, plugin, and video drawing to be more data-driven

Modified: trunk/Source/WebKit/chromium/WebKit.gypi (105313 => 105314)


--- trunk/Source/WebKit/chromium/WebKit.gypi	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebKit/chromium/WebKit.gypi	2012-01-18 21:41:51 UTC (rev 105314)
@@ -93,6 +93,7 @@
             'tests/KeyboardTest.cpp',
             'tests/KURLTest.cpp',
             'tests/LayerChromiumTest.cpp',
+            'tests/LayerTextureUpdaterTest.cpp',
             'tests/PODArenaTest.cpp',
             'tests/PODIntervalTreeTest.cpp',
             'tests/PODRedBlackTreeTest.cpp',

Added: trunk/Source/WebKit/chromium/tests/LayerTextureUpdaterTest.cpp (0 => 105314)


--- trunk/Source/WebKit/chromium/tests/LayerTextureUpdaterTest.cpp	                        (rev 0)
+++ trunk/Source/WebKit/chromium/tests/LayerTextureUpdaterTest.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "LayerTextureUpdater.h"
+
+#include "BitmapCanvasLayerTextureUpdater.h"
+#include "BitmapSkPictureCanvasLayerTextureUpdater.h"
+#include "FrameBufferSkPictureCanvasLayerTextureUpdater.h"
+#include "GraphicsContext.h"
+#include "LayerPainterChromium.h"
+#include "PlatformContextSkia.h"
+#include "SkPictureCanvasLayerTextureUpdater.h"
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+using namespace WebCore;
+
+namespace {
+
+struct PaintCallback {
+    virtual void operator()(GraphicsContext&, const IntRect&) = 0;
+};
+
+class TestLayerPainterChromium : public LayerPainterChromium {
+public:
+    TestLayerPainterChromium(PaintCallback& callback) : m_callback(callback) { }
+
+    virtual void paint(GraphicsContext& context, const IntRect& contentRect)
+    {
+        m_callback(context, contentRect);
+    }
+
+  private:
+    PaintCallback& m_callback;
+};
+
+// Paint callback functions
+
+struct PaintFillOpaque : public PaintCallback {
+    virtual void operator()(GraphicsContext& context, const IntRect& contentRect)
+    {
+        Color opaque(255, 0, 0, 255);
+        IntRect top(contentRect.x(), contentRect.y(), contentRect.width(), contentRect.height() / 2);
+        IntRect bottom(contentRect.x(), contentRect.y() + contentRect.height() / 2, contentRect.width(), contentRect.height() / 2);
+        context.fillRect(top, opaque, ColorSpaceDeviceRGB);
+        context.fillRect(bottom, opaque, ColorSpaceDeviceRGB);
+    }
+};
+
+struct PaintFillAlpha : public PaintCallback {
+    virtual void operator()(GraphicsContext& context, const IntRect& contentRect)
+    {
+        Color alpha(0, 0, 0, 0);
+        context.fillRect(contentRect, alpha, ColorSpaceDeviceRGB);
+    }
+};
+
+#define EXPECT_EQ_RECT(a, b) \
+    EXPECT_EQ(a.x(), b.x()); \
+    EXPECT_EQ(a.maxX(), b.maxX()); \
+    EXPECT_EQ(a.y(), b.y()); \
+    EXPECT_EQ(a.maxY(), b.maxY());
+
+TEST(LayerTextureUpdaterTest, testOpaqueRectPresentAfterOpaquePaint)
+{
+    PaintFillOpaque fillOpaque;
+    RefPtr<LayerTextureUpdater> updater;
+    IntRect opaqueRect;
+    OwnPtr<TestLayerPainterChromium> painter;
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = BitmapCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 400, 400), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = BitmapSkPictureCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 400, 400), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(painter.release());
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 400, 400), opaqueRect);
+}
+
+TEST(LayerTextureUpdaterTest, testOpaqueRectNotPresentAfterNonOpaquePaint)
+{
+    PaintFillAlpha fillAlpha;
+    RefPtr<LayerTextureUpdater> updater;
+    IntRect opaqueRect;
+    OwnPtr<TestLayerPainterChromium> painter;
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = BitmapCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = BitmapSkPictureCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(painter.release());
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+}
+
+TEST(LayerTextureUpdaterTest, testOpaqueRectNotPresentForOpaqueLayerWithOpaquePaint)
+{
+    PaintFillOpaque fillOpaque;
+    RefPtr<LayerTextureUpdater> updater;
+    IntRect opaqueRect;
+    OwnPtr<TestLayerPainterChromium> painter;
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = BitmapCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = BitmapSkPictureCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillOpaque));
+    updater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(painter.release());
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+}
+
+TEST(LayerTextureUpdaterTest, testOpaqueRectNotPresentForOpaqueLayerWithNonOpaquePaint)
+{
+    PaintFillAlpha fillAlpha;
+    RefPtr<LayerTextureUpdater> updater;
+    IntRect opaqueRect;
+    OwnPtr<TestLayerPainterChromium> painter;
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = BitmapCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = BitmapSkPictureCanvasLayerTextureUpdater::create(painter.release(), false);
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+
+    opaqueRect = IntRect();
+    painter = adoptPtr(new TestLayerPainterChromium(fillAlpha));
+    updater = FrameBufferSkPictureCanvasLayerTextureUpdater::create(painter.release());
+    updater->setOpaque(true);
+    updater->prepareToUpdate(IntRect(0, 0, 400, 400), IntSize(400, 400), 0, 1, &opaqueRect);
+    EXPECT_EQ_RECT(IntRect(0, 0, 0, 0), opaqueRect);
+}
+
+} // namespace

Modified: trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp (105313 => 105314)


--- trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp	2012-01-18 21:34:28 UTC (rev 105313)
+++ trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp	2012-01-18 21:41:51 UTC (rev 105314)
@@ -72,7 +72,7 @@
 
     virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager* manager) { return adoptPtr(new Texture(ManagedTexture::create(manager))); }
     virtual SampledTexelFormat sampledTexelFormat(GC3Denum) { return SampledTexelFormatRGBA; }
-    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float);
+    virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect*);
 
 private:
     int m_prepareCount;
@@ -149,7 +149,7 @@
     m_layer = layer;
 }
 
-void FakeLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float)
+void FakeLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect)
 {
     m_prepareCount++;
     m_lastUpdateRect = contentRect;
@@ -158,6 +158,7 @@
         m_rectToInvalidate = IntRect();
         m_layer = 0;
     }
+    *resultingOpaqueRect = IntRect();
 }
 
 TEST(TiledLayerChromiumTest, pushDirtyTiles)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to