[chromium] CanvasLayerTextureUpdater needs to convert opaque rects back to content...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jun 2012 15:55:54 +0000 (15:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 30 Jun 2012 15:55:54 +0000 (15:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90092

The CanvasLayerTextureUpdater currently receives its opaque rects in
layer space, but is expected to return them in content space and does
not convert them. This patch adds this conversion. To avoid numerical
errors, this patch also switches to using float rects to store opaque
rects where appropriate.

Patch by Ian Vollick <vollick@chromium.org> on 2012-06-30
Reviewed by Adrienne Walker.

Source/Platform:

* chromium/public/WebContentLayerClient.h:
(WebKit):
(WebContentLayerClient):

Source/WebCore:

Unit test: ContentLayerTest.ContentLayerPainterWithDeviceScale

* platform/graphics/chromium/CanvasLayerTextureUpdater.cpp:
(WebCore::CanvasLayerTextureUpdater::paintContents):
* platform/graphics/chromium/ContentLayerChromium.cpp:
(WebCore::ContentLayerPainter::ContentLayerPainter):
(WebCore::ContentLayerPainter::create):
(WebCore::ContentLayerPainter::paint):
* platform/graphics/chromium/ContentLayerChromium.h:
(WebCore):
(ContentLayerDelegate):
(ContentLayerPainter):
* platform/graphics/chromium/LayerPainterChromium.h:
(WebCore):
(LayerPainterChromium):
* platform/graphics/chromium/LinkHighlight.cpp:
(WebCore::LinkHighlight::paintContents):
* platform/graphics/chromium/LinkHighlight.h:
(LinkHighlight):
* platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp:
(WebCore::OpaqueRectTrackingContentLayerDelegate::paintContents):
* platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h:
(OpaqueRectTrackingContentLayerDelegate):
* platform/graphics/chromium/ScrollbarLayerChromium.cpp:

Source/WebKit/chromium:

* WebKit.gypi:
* src/WebContentLayerImpl.cpp:
(WebKit::WebContentLayerImpl::paintContents):
* src/WebContentLayerImpl.h:
(WebContentLayerImpl):
* tests/CCLayerTreeHostCommonTest.cpp:
* tests/CCLayerTreeHostTest.cpp:
(WTF::TestOpacityChangeLayerDelegate::paintContents):
(WTF::MockContentLayerDelegate::paintContents):
* tests/ContentLayerChromiumTest.cpp: Added.
(WebKit):
(OpaqueRectDrawingGraphicsContextPainter):
(WebKit::OpaqueRectDrawingGraphicsContextPainter::OpaqueRectDrawingGraphicsContextPainter):
(WebKit::OpaqueRectDrawingGraphicsContextPainter::~OpaqueRectDrawingGraphicsContextPainter):
(MockContentLayerDelegate):
(WebKit::MockContentLayerDelegate::MockContentLayerDelegate):
(WebKit::TEST):
* tests/LayerChromiumTest.cpp:
* tests/OpaqueRectTrackingContentLayerDelegateTest.cpp:
(WebCore::TEST_F):
* tests/TiledLayerChromiumTest.cpp:
* tests/WebLayerTest.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@121628 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
Source/Platform/ChangeLog
Source/Platform/chromium/public/WebContentLayerClient.h
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/CanvasLayerTextureUpdater.cpp
Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h
Source/WebCore/platform/graphics/chromium/LayerPainterChromium.h
Source/WebCore/platform/graphics/chromium/LinkHighlight.cpp
Source/WebCore/platform/graphics/chromium/LinkHighlight.h
Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp
Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h
Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/src/WebContentLayerImpl.cpp
Source/WebKit/chromium/src/WebContentLayerImpl.h
Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp
Source/WebKit/chromium/tests/ContentLayerChromiumTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/LayerChromiumTest.cpp
Source/WebKit/chromium/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp
Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp
Source/WebKit/chromium/tests/WebLayerTest.cpp

index 0b1a647..ab2cf9a 100644 (file)
@@ -1,3 +1,20 @@
+2012-06-30  Ian Vollick  <vollick@chromium.org>
+
+        [chromium] CanvasLayerTextureUpdater needs to convert opaque rects back to content space.
+        https://bugs.webkit.org/show_bug.cgi?id=90092
+
+        The CanvasLayerTextureUpdater currently receives its opaque rects in
+        layer space, but is expected to return them in content space and does
+        not convert them. This patch adds this conversion. To avoid numerical
+        errors, this patch also switches to using float rects to store opaque
+        rects where appropriate.
+
+        Reviewed by Adrienne Walker.
+
+        * chromium/public/WebContentLayerClient.h:
+        (WebKit):
+        (WebContentLayerClient):
+
 2012-06-29  Tony Payne  <tpayne@chromium.org>
 
         Remove type from screenColorProfile API
index 53f5c0a..5469bd2 100644 (file)
@@ -30,6 +30,7 @@
 
 namespace WebKit {
 struct WebRect;
+struct WebFloatRect;
 
 class WebContentLayerClient {
 public:
@@ -41,7 +42,8 @@ public:
     // the implementation knows are opaque. This information can be used for various
     // optimizations.
 #define WEBCONTENTLAYERCLIENT_HAS_OPAQUE 1
-    virtual void paintContents(WebCanvas*, const WebRect& clip, WebRect& opaque) = 0;
+#define WEBCONTENTLAYERCLIENT_FLOAT_OPAQUE_RECT 1
+    virtual void paintContents(WebCanvas*, const WebRect& clip, WebFloatRect& opaque) = 0;
 
 protected:
     virtual ~WebContentLayerClient() { }
index 72710c0..caf8a45 100644 (file)
@@ -1,3 +1,41 @@
+2012-06-30  Ian Vollick  <vollick@chromium.org>
+
+        [chromium] CanvasLayerTextureUpdater needs to convert opaque rects back to content space.
+        https://bugs.webkit.org/show_bug.cgi?id=90092
+
+        The CanvasLayerTextureUpdater currently receives its opaque rects in
+        layer space, but is expected to return them in content space and does
+        not convert them. This patch adds this conversion. To avoid numerical
+        errors, this patch also switches to using float rects to store opaque
+        rects where appropriate.
+
+        Reviewed by Adrienne Walker.
+
+        Unit test: ContentLayerTest.ContentLayerPainterWithDeviceScale
+
+        * platform/graphics/chromium/CanvasLayerTextureUpdater.cpp:
+        (WebCore::CanvasLayerTextureUpdater::paintContents):
+        * platform/graphics/chromium/ContentLayerChromium.cpp:
+        (WebCore::ContentLayerPainter::ContentLayerPainter):
+        (WebCore::ContentLayerPainter::create):
+        (WebCore::ContentLayerPainter::paint):
+        * platform/graphics/chromium/ContentLayerChromium.h:
+        (WebCore):
+        (ContentLayerDelegate):
+        (ContentLayerPainter):
+        * platform/graphics/chromium/LayerPainterChromium.h:
+        (WebCore):
+        (LayerPainterChromium):
+        * platform/graphics/chromium/LinkHighlight.cpp:
+        (WebCore::LinkHighlight::paintContents):
+        * platform/graphics/chromium/LinkHighlight.h:
+        (LinkHighlight):
+        * platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp:
+        (WebCore::OpaqueRectTrackingContentLayerDelegate::paintContents):
+        * platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h:
+        (OpaqueRectTrackingContentLayerDelegate):
+        * platform/graphics/chromium/ScrollbarLayerChromium.cpp:
+
 2012-06-30  Kwang Yul Seo  <skyul@company100.net>
 
         Unreviewed. Remove unused declaration.
index 81934ea..be8484b 100644 (file)
@@ -55,25 +55,29 @@ void CanvasLayerTextureUpdater::paintContents(SkCanvas* canvas, const IntRect& c
     canvas->save();
     canvas->translate(WebCoreFloatToSkScalar(-contentRect.x()), WebCoreFloatToSkScalar(-contentRect.y()));
 
-    IntRect scaledContentRect = contentRect;
+    IntRect layerRect = contentRect;
 
     if (contentsWidthScale != 1 || contentsHeightScale != 1) {
         canvas->scale(WebCoreFloatToSkScalar(contentsWidthScale), WebCoreFloatToSkScalar(contentsHeightScale));
 
         FloatRect rect = contentRect;
         rect.scale(1 / contentsWidthScale, 1 / contentsHeightScale);
-        scaledContentRect = enclosingIntRect(rect);
+        layerRect = enclosingIntRect(rect);
     }
 
     SkPaint paint;
     paint.setAntiAlias(false);
     paint.setXfermodeMode(SkXfermode::kClear_Mode);
-    canvas->drawRect(scaledContentRect, paint);
-    canvas->clipRect(scaledContentRect);
+    canvas->drawRect(layerRect, paint);
+    canvas->clipRect(layerRect);
 
-    m_painter->paint(canvas, scaledContentRect, resultingOpaqueRect);
+    FloatRect opaqueLayerRect;
+    m_painter->paint(canvas, layerRect, opaqueLayerRect);
     canvas->restore();
 
+    opaqueLayerRect.scale(contentsWidthScale, contentsHeightScale);
+    resultingOpaqueRect = enclosedIntRect(opaqueLayerRect);
+
     m_contentRect = contentRect;
 }
 
index 3a800e2..e1f1577 100644 (file)
 
 namespace WebCore {
 
-class ContentLayerPainter : public LayerPainterChromium {
-    WTF_MAKE_NONCOPYABLE(ContentLayerPainter);
-public:
-    static PassOwnPtr<ContentLayerPainter> create(ContentLayerDelegate* delegate)
-    {
-        return adoptPtr(new ContentLayerPainter(delegate));
-    }
-
-    virtual void paint(SkCanvas* canvas, const IntRect& contentRect, IntRect& opaque)
-    {
-        double paintStart = currentTime();
-        m_delegate->paintContents(canvas, contentRect, opaque);
-        double paintEnd = currentTime();
-        double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
-        WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
-        WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
-    }
-private:
-    explicit ContentLayerPainter(ContentLayerDelegate* delegate)
-        : m_delegate(delegate)
-    {
-    }
-
-    ContentLayerDelegate* m_delegate;
-};
+ContentLayerPainter::ContentLayerPainter(ContentLayerDelegate* delegate)
+    : m_delegate(delegate)
+{
+}
+
+PassOwnPtr<ContentLayerPainter> ContentLayerPainter::create(ContentLayerDelegate* delegate)
+{
+    return adoptPtr(new ContentLayerPainter(delegate));
+}
+
+void ContentLayerPainter::paint(SkCanvas* canvas, const IntRect& contentRect, FloatRect& opaque)
+{
+    double paintStart = currentTime();
+    m_delegate->paintContents(canvas, contentRect, opaque);
+    double paintEnd = currentTime();
+    double pixelsPerSec = (contentRect.width() * contentRect.height()) / (paintEnd - paintStart);
+    WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintDurationMS", (paintEnd - paintStart) * 1000, 0, 120, 30);
+    WebKit::Platform::current()->histogramCustomCounts("Renderer4.AccelContentPaintMegapixPerSecond", pixelsPerSec / 1000000, 10, 210, 30);
+}
 
 PassRefPtr<ContentLayerChromium> ContentLayerChromium::create(ContentLayerDelegate* delegate)
 {
index 2e82bec..313c387 100644 (file)
 
 #if USE(ACCELERATED_COMPOSITING)
 
+#include "LayerPainterChromium.h"
 #include "TiledLayerChromium.h"
 
 class SkCanvas;
 
 namespace WebCore {
 
+class FloatRect;
 class IntRect;
 class LayerTextureUpdater;
 
 class ContentLayerDelegate {
 public:
-    virtual void paintContents(SkCanvas*, const IntRect& clip, IntRect& opaque) = 0;
+    virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque) = 0;
 
 protected:
     virtual ~ContentLayerDelegate() { }
 };
 
+class ContentLayerPainter : public LayerPainterChromium {
+    WTF_MAKE_NONCOPYABLE(ContentLayerPainter);
+public:
+    static PassOwnPtr<ContentLayerPainter> create(ContentLayerDelegate*);
+
+    virtual void paint(SkCanvas*, const IntRect& contentRect, FloatRect& opaque) OVERRIDE;
+
+private:
+    explicit ContentLayerPainter(ContentLayerDelegate*);
+
+    ContentLayerDelegate* m_delegate;
+};
+
 // A layer that renders its contents into an SkCanvas.
 class ContentLayerChromium : public TiledLayerChromium {
 public:
index db6a884..bc0352e 100644 (file)
@@ -33,12 +33,13 @@ class SkCanvas;
 
 namespace WebCore {
 
+class FloatRect;
 class IntRect;
 
 class LayerPainterChromium {
 public:
     virtual ~LayerPainterChromium() { }
-    virtual void paint(SkCanvas*, const IntRect& contentRect, IntRect& opaque) = 0;
+    virtual void paint(SkCanvas*, const IntRect& contentRect, FloatRect& opaque) = 0;
 };
 
 } // namespace WebCore
index 3bc1e63..1b2c61e 100644 (file)
@@ -92,7 +92,7 @@ ContentLayerChromium* LinkHighlight::contentLayer()
     return m_contentLayer.get();
 }
 
-void LinkHighlight::paintContents(SkCanvas* canvas, const IntRect&, IntRect&)
+void LinkHighlight::paintContents(SkCanvas* canvas, const IntRect&, FloatRect&)
 {
     PlatformContextSkia platformContext(canvas);
     GraphicsContext gc(&platformContext);
index 1fbef9b..1ccc3eb 100644 (file)
@@ -45,7 +45,7 @@ public:
     ContentLayerChromium* contentLayer();
 
     // ContentLayerDelegate implementation.
-    virtual void paintContents(SkCanvas*, const IntRect& clipRect, IntRect& opaque) OVERRIDE;
+    virtual void paintContents(SkCanvas*, const IntRect& clipRect, FloatRect& opaque) OVERRIDE;
 
     // CCLayerAnimationDelegate implementation.
     virtual void notifyAnimationStarted(double time) OVERRIDE;
index 04548ae..a5155e2 100644 (file)
 #include "GraphicsContext.h"
 #include "IntRect.h"
 #include "PlatformContextSkia.h"
+#include <public/WebFloatRect.h>
 #include <public/WebRect.h>
 
+using WebKit::WebFloatRect;
 using WebKit::WebRect;
 
 namespace WebCore {
@@ -47,7 +49,7 @@ OpaqueRectTrackingContentLayerDelegate::~OpaqueRectTrackingContentLayerDelegate(
 {
 }
 
-void OpaqueRectTrackingContentLayerDelegate::paintContents(SkCanvas* canvas, const WebRect& clip, WebRect& opaque)
+void OpaqueRectTrackingContentLayerDelegate::paintContents(SkCanvas* canvas, const WebRect& clip, WebFloatRect& opaque)
 {
     PlatformContextSkia platformContext(canvas);
     platformContext.setTrackOpaqueRegion(!m_opaque);
@@ -62,8 +64,7 @@ void OpaqueRectTrackingContentLayerDelegate::paintContents(SkCanvas* canvas, con
     // Transform tracked opaque paints back to our layer's content space.
     ASSERT(canvasToContentTransform.isInvertible());
     ASSERT(canvasToContentTransform.preservesAxisAlignment());
-    FloatRect opaqueCanvasRect = platformContext.opaqueRegion().asRect();
-    opaque = enclosedIntRect(canvasToContentTransform.mapRect(opaqueCanvasRect));
+    opaque = canvasToContentTransform.mapRect(platformContext.opaqueRegion().asRect());
 }
 
 }
index e325b36..bb5c2ae 100644 (file)
@@ -55,7 +55,7 @@ public:
     void setOpaque(bool opaque) { m_opaque = opaque; }
 
     // WebKit::WebContentLayerClient implementation.
-    virtual void paintContents(SkCanvas*, const WebKit::WebRect& clip, WebKit::WebRect& opaque) OVERRIDE;
+    virtual void paintContents(SkCanvas*, const WebKit::WebRect& clip, WebKit::WebFloatRect& opaque) OVERRIDE;
 
 private:
     GraphicsContextPainter* m_painter;
index a917272..dd6a43d 100644 (file)
@@ -116,7 +116,7 @@ public:
         return adoptPtr(new ScrollbarBackgroundPainter(scrollbar, theme, trackPart));
     }
 
-    virtual void paint(SkCanvas* canvas, const IntRect& contentRect, IntRect&) OVERRIDE
+    virtual void paint(SkCanvas* canvas, const IntRect& contentRect, FloatRect&) OVERRIDE
     {
         PlatformContextSkia platformContext(canvas);
         platformContext.setDrawingToImageBuffer(true);
@@ -169,7 +169,7 @@ public:
         return adoptPtr(new ScrollbarThumbPainter(scrollbar, theme));
     }
 
-    virtual void paint(SkCanvas* canvas, const IntRect& contentRect, IntRect& opaque) OVERRIDE
+    virtual void paint(SkCanvas* canvas, const IntRect& contentRect, FloatRect& opaque) OVERRIDE
     {
         PlatformContextSkia platformContext(canvas);
         platformContext.setDrawingToImageBuffer(true);
index 3ebaf0f..722569f 100644 (file)
@@ -1,3 +1,39 @@
+2012-06-30  Ian Vollick  <vollick@chromium.org>
+
+        [chromium] CanvasLayerTextureUpdater needs to convert opaque rects back to content space.
+        https://bugs.webkit.org/show_bug.cgi?id=90092
+
+        The CanvasLayerTextureUpdater currently receives its opaque rects in
+        layer space, but is expected to return them in content space and does
+        not convert them. This patch adds this conversion. To avoid numerical
+        errors, this patch also switches to using float rects to store opaque
+        rects where appropriate.
+
+        Reviewed by Adrienne Walker.
+
+        * WebKit.gypi:
+        * src/WebContentLayerImpl.cpp:
+        (WebKit::WebContentLayerImpl::paintContents):
+        * src/WebContentLayerImpl.h:
+        (WebContentLayerImpl):
+        * tests/CCLayerTreeHostCommonTest.cpp:
+        * tests/CCLayerTreeHostTest.cpp:
+        (WTF::TestOpacityChangeLayerDelegate::paintContents):
+        (WTF::MockContentLayerDelegate::paintContents):
+        * tests/ContentLayerChromiumTest.cpp: Added.
+        (WebKit):
+        (OpaqueRectDrawingGraphicsContextPainter):
+        (WebKit::OpaqueRectDrawingGraphicsContextPainter::OpaqueRectDrawingGraphicsContextPainter):
+        (WebKit::OpaqueRectDrawingGraphicsContextPainter::~OpaqueRectDrawingGraphicsContextPainter):
+        (MockContentLayerDelegate):
+        (WebKit::MockContentLayerDelegate::MockContentLayerDelegate):
+        (WebKit::TEST):
+        * tests/LayerChromiumTest.cpp:
+        * tests/OpaqueRectTrackingContentLayerDelegateTest.cpp:
+        (WebCore::TEST_F):
+        * tests/TiledLayerChromiumTest.cpp:
+        * tests/WebLayerTest.cpp:
+
 2012-06-29  Joshua Bell  <jsbell@chromium.org>
 
         IndexedDB: Keep direction on IDBCursor to avoid calls to back end
index 8bfce9c..5e28903 100644 (file)
@@ -97,6 +97,7 @@
             'tests/CCTimerTest.cpp',
             'tests/ClipboardChromiumTest.cpp',
             'tests/CompositorFakeWebGraphicsContext3D.h',
+            'tests/ContentLayerChromiumTest.cpp',
             'tests/DateTimeFormatTest.cpp',
             'tests/DecimalTest.cpp',
             'tests/DragImageTest.cpp',
index 8c8122f..ecf099a 100644 (file)
@@ -27,6 +27,7 @@
 #include "WebContentLayerImpl.h"
 
 #include "platform/WebContentLayerClient.h"
+#include "platform/WebFloatRect.h"
 #include "platform/WebRect.h"
 #include "GraphicsContext.h"
 #include "platform/WebCanvas.h"
@@ -53,11 +54,11 @@ WebContentLayerImpl::~WebContentLayerImpl()
     clearDelegate();
 }
 
-void WebContentLayerImpl::paintContents(SkCanvas* canvas, const IntRect& clip, IntRect& opaque)
+void WebContentLayerImpl::paintContents(SkCanvas* canvas, const IntRect& clip, FloatRect& opaque)
 {
     if (!m_contentClient)
         return;
-    WebRect webOpaque;
+    WebFloatRect webOpaque;
     m_contentClient->paintContents(canvas, WebRect(clip), webOpaque);
     opaque = webOpaque;
 }
index 542bd9b..97729ea 100644 (file)
@@ -41,7 +41,7 @@ protected:
     virtual ~WebContentLayerImpl();
 
     // ContentLayerDelegate implementation.
-    virtual void paintContents(SkCanvas*, const WebCore::IntRect& clip, WebCore::IntRect& opaque);
+    virtual void paintContents(SkCanvas*, const WebCore::IntRect& clip, WebCore::FloatRect& opaque) OVERRIDE;
 
     WebContentLayerClient* m_contentClient;
     bool m_drawsContent;
index 78448a5..e1691df 100644 (file)
@@ -3667,7 +3667,7 @@ class MockContentLayerDelegate : public ContentLayerDelegate {
 public:
     MockContentLayerDelegate() { }
     virtual ~MockContentLayerDelegate() { }
-    virtual void paintContents(SkCanvas*, const IntRect& clip, IntRect& opaque) { }
+    virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque) OVERRIDE { }
 };
 
 PassRefPtr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayerDelegate* delegate)
index 9af9780..a1dea26 100644 (file)
@@ -1142,7 +1142,7 @@ public:
     {
     }
 
-    virtual void paintContents(SkCanvas*, const IntRect&, IntRect&)
+    virtual void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE
     {
         // Set layer opacity to 0.
         m_test->layerTreeHost()->rootLayer()->setOpacity(0);
@@ -1236,7 +1236,7 @@ class MockContentLayerDelegate : public ContentLayerDelegate {
 public:
     bool drawsContent() const { return true; }
     MOCK_CONST_METHOD0(preserves3D, bool());
-    void paintContents(SkCanvas*, const IntRect&, IntRect&) { }
+    void paintContents(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { }
     void notifySyncRequired() { }
 };
 
diff --git a/Source/WebKit/chromium/tests/ContentLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/ContentLayerChromiumTest.cpp
new file mode 100644 (file)
index 0000000..7504185
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * 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 "ContentLayerChromium.h"
+
+#include "BitmapCanvasLayerTextureUpdater.h"
+#include "CCLayerTreeTestCommon.h"
+#include "GraphicsContext.h"
+#include "OpaqueRectTrackingContentLayerDelegate.h"
+#include "skia/ext/platform_canvas.h"
+
+#include <gtest/gtest.h>
+#include <public/WebFloatRect.h>
+#include <public/WebRect.h>
+#include <wtf/OwnPtr.h>
+#include <wtf/RefPtr.h>
+
+using namespace WebCore;
+using namespace WebKit;
+
+namespace {
+
+class OpaqueRectDrawingGraphicsContextPainter : public GraphicsContextPainter {
+public:
+    explicit OpaqueRectDrawingGraphicsContextPainter(const IntRect& opaqueRect, const IntRect& contentRect)
+        : m_opaqueRect(opaqueRect)
+        , m_contentRect(contentRect)
+    {
+    }
+
+    virtual ~OpaqueRectDrawingGraphicsContextPainter()
+    {
+    }
+
+    virtual void paint(GraphicsContext& context, const IntRect& clip) OVERRIDE
+    {
+        Color alpha(0, 0, 0, 0);
+        context.fillRect(m_contentRect, alpha, ColorSpaceDeviceRGB);
+
+        Color white(255, 255, 255, 255);
+        context.fillRect(m_opaqueRect, white, ColorSpaceDeviceRGB);
+    }
+
+private:
+    IntRect m_opaqueRect;
+    IntRect m_contentRect;
+};
+
+class MockContentLayerDelegate : public ContentLayerDelegate {
+public:
+    explicit MockContentLayerDelegate(OpaqueRectTrackingContentLayerDelegate* client)
+        : m_client(client)
+    {
+    }
+
+    virtual void paintContents(SkCanvas* canvas, const IntRect& clip, FloatRect& opaque) OVERRIDE
+    {
+        WebFloatRect resultingOpaqueRect(opaque.x(), opaque.y(), opaque.width(), opaque.height());
+        WebRect webClipRect(clip.x(), clip.y(), clip.width(), clip.height());
+        m_client->paintContents(canvas, webClipRect, resultingOpaqueRect);
+        opaque = FloatRect(resultingOpaqueRect.x, resultingOpaqueRect.y, resultingOpaqueRect.width, resultingOpaqueRect.height);
+    }
+
+private:
+    OpaqueRectTrackingContentLayerDelegate* m_client;
+};
+
+TEST(ContentLayerChromiumTest, ContentLayerPainterWithDeviceScale)
+{
+    float contentsScale = 2;
+    IntRect contentRect(10, 10, 100, 100);
+    IntRect opaqueRectInLayerSpace(5, 5, 20, 20);
+    IntRect opaqueRectInContentSpace = opaqueRectInLayerSpace;
+    opaqueRectInContentSpace.scale(contentsScale);
+    OwnPtr<SkCanvas> canvas = adoptPtr(skia::CreateBitmapCanvas(contentRect.width(), contentRect.height(), false));
+    OpaqueRectDrawingGraphicsContextPainter painter(opaqueRectInLayerSpace, contentRect);
+    OpaqueRectTrackingContentLayerDelegate opaqueRectTrackingContentLayerDelegate(&painter);
+    MockContentLayerDelegate delegate(&opaqueRectTrackingContentLayerDelegate);
+    RefPtr<BitmapCanvasLayerTextureUpdater> updater = BitmapCanvasLayerTextureUpdater::create(ContentLayerPainter::create(&delegate), false);
+
+    IntRect resultingOpaqueRect;
+    updater->prepareToUpdate(contentRect, IntSize(256, 256), contentsScale, contentsScale, resultingOpaqueRect);
+
+    EXPECT_INT_RECT_EQ(opaqueRectInContentSpace, resultingOpaqueRect);
+}
+
+} // namespace
index 86d08ab..e7c6552 100644 (file)
@@ -70,7 +70,7 @@ private:
 
 class MockLayerPainterChromium : public LayerPainterChromium {
 public:
-    virtual void paint(SkCanvas*, const IntRect&, IntRect&) { }
+    virtual void paint(SkCanvas*, const IntRect&, FloatRect&) OVERRIDE { }
 };
 
 
index dd60a97..38b0c98 100644 (file)
 #include "GraphicsContext.h"
 #include "IntRect.h"
 #include "skia/ext/platform_canvas.h"
+#include <public/WebFloatRect.h>
 #include <public/WebRect.h>
 
 #include <gtest/gtest.h>
 
 using WebKit::WebRect;
+using WebKit::WebFloatRect;
 using namespace WebCore;
 
 namespace {
@@ -125,9 +127,9 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectPresentAfterOpa
 
     OpaqueRectTrackingContentLayerDelegate delegate(&painter);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     delegate.paintContents(skCanvas(), canvasRect(), opaqueRect);
-    EXPECT_EQ_RECT(WebRect(0, 0, 400, 400), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(0, 0, 400, 400), opaqueRect);
 }
 
 TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentAfterNonOpaquePaint)
@@ -136,9 +138,9 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentAfter
     TestLayerPainterChromium painter(fillAlpha);
     OpaqueRectTrackingContentLayerDelegate delegate(&painter);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     delegate.paintContents(skCanvas(), canvasRect(), opaqueRect);
-    EXPECT_EQ_RECT(WebRect(0, 0, 0, 0), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
 }
 
 TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOpaqueLayerWithOpaquePaint)
@@ -149,9 +151,9 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOp
 
     delegate.setOpaque(true);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     delegate.paintContents(skCanvas(), canvasRect(), opaqueRect);
-    EXPECT_EQ_RECT(WebRect(0, 0, 0, 0), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
 }
 
 TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOpaqueLayerWithNonOpaquePaint)
@@ -162,9 +164,9 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOp
 
     delegate.setOpaque(true);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     delegate.paintContents(skCanvas(), canvasRect(), opaqueRect);
-    EXPECT_EQ_RECT(WebRect(0, 0, 0, 0), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
 }
 
 TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectNoTransform)
@@ -174,9 +176,9 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectNoTransf
     TestLayerPainterChromium painter(fillPartial);
     OpaqueRectTrackingContentLayerDelegate delegate(&painter);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     delegate.paintContents(skCanvas(), canvasRect(), opaqueRect);
-    EXPECT_EQ_RECT(WebRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
 }
 
 TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectTranslation)
@@ -186,10 +188,10 @@ TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectTranslat
     TestLayerPainterChromium painter(fillPartial);
     OpaqueRectTrackingContentLayerDelegate delegate(&painter);
 
-    WebRect opaqueRect;
+    WebFloatRect opaqueRect;
     WebRect contentRect(11, 12, 389, 388);
     delegate.paintContents(skCanvas(), contentRect, opaqueRect);
-    EXPECT_EQ_RECT(WebRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
+    EXPECT_EQ_RECT(WebFloatRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
 }
 
 } // namespace
index 8476224..25b3d5e 100644 (file)
@@ -1505,7 +1505,7 @@ class TrackingLayerPainter : public LayerPainterChromium {
 public:
     static PassOwnPtr<TrackingLayerPainter> create() { return adoptPtr(new TrackingLayerPainter()); }
 
-    virtual void paint(SkCanvas*, const IntRect& contentRect, IntRect&)
+    virtual void paint(SkCanvas*, const IntRect& contentRect, FloatRect&) OVERRIDE
     {
         m_paintedRect = contentRect;
     }
index bc49293..12deb59 100644 (file)
@@ -65,7 +65,7 @@ public:
 
 class MockWebContentLayerClient : public WebContentLayerClient {
 public:
-    MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebRect& opaque));
+    MOCK_METHOD3(paintContents, void(WebCanvas*, const WebRect& clip, WebFloatRect& opaque));
 };
 
 class WebLayerTest : public Test {