From 068ecbdde66b4e6d4a8526e40256a7f523eff931 Mon Sep 17 00:00:00 2001 From: "commit-queue@webkit.org" Date: Sat, 30 Jun 2012 15:55:54 +0000 Subject: [PATCH] [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. Patch by Ian Vollick 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 --- Source/Platform/ChangeLog | 17 ++++ .../chromium/public/WebContentLayerClient.h | 4 +- Source/WebCore/ChangeLog | 38 +++++++ .../chromium/CanvasLayerTextureUpdater.cpp | 14 ++- .../graphics/chromium/ContentLayerChromium.cpp | 44 ++++----- .../graphics/chromium/ContentLayerChromium.h | 17 +++- .../graphics/chromium/LayerPainterChromium.h | 3 +- .../platform/graphics/chromium/LinkHighlight.cpp | 2 +- .../platform/graphics/chromium/LinkHighlight.h | 2 +- .../OpaqueRectTrackingContentLayerDelegate.cpp | 7 +- .../OpaqueRectTrackingContentLayerDelegate.h | 2 +- .../graphics/chromium/ScrollbarLayerChromium.cpp | 4 +- Source/WebKit/chromium/ChangeLog | 36 +++++++ Source/WebKit/chromium/WebKit.gypi | 1 + Source/WebKit/chromium/src/WebContentLayerImpl.cpp | 5 +- Source/WebKit/chromium/src/WebContentLayerImpl.h | 2 +- .../chromium/tests/CCLayerTreeHostCommonTest.cpp | 2 +- .../WebKit/chromium/tests/CCLayerTreeHostTest.cpp | 4 +- .../chromium/tests/ContentLayerChromiumTest.cpp | 110 +++++++++++++++++++++ Source/WebKit/chromium/tests/LayerChromiumTest.cpp | 2 +- .../OpaqueRectTrackingContentLayerDelegateTest.cpp | 26 ++--- .../chromium/tests/TiledLayerChromiumTest.cpp | 2 +- Source/WebKit/chromium/tests/WebLayerTest.cpp | 2 +- 23 files changed, 284 insertions(+), 62 deletions(-) create mode 100644 Source/WebKit/chromium/tests/ContentLayerChromiumTest.cpp diff --git a/Source/Platform/ChangeLog b/Source/Platform/ChangeLog index 0b1a647..ab2cf9a 100644 --- a/Source/Platform/ChangeLog +++ b/Source/Platform/ChangeLog @@ -1,3 +1,20 @@ +2012-06-30 Ian Vollick + + [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 Remove type from screenColorProfile API diff --git a/Source/Platform/chromium/public/WebContentLayerClient.h b/Source/Platform/chromium/public/WebContentLayerClient.h index 53f5c0a..5469bd2 100644 --- a/Source/Platform/chromium/public/WebContentLayerClient.h +++ b/Source/Platform/chromium/public/WebContentLayerClient.h @@ -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() { } diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 72710c0..caf8a45 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,41 @@ +2012-06-30 Ian Vollick + + [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 Unreviewed. Remove unused declaration. diff --git a/Source/WebCore/platform/graphics/chromium/CanvasLayerTextureUpdater.cpp b/Source/WebCore/platform/graphics/chromium/CanvasLayerTextureUpdater.cpp index 81934ea..be8484b 100644 --- a/Source/WebCore/platform/graphics/chromium/CanvasLayerTextureUpdater.cpp +++ b/Source/WebCore/platform/graphics/chromium/CanvasLayerTextureUpdater.cpp @@ -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; } diff --git a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp index 3a800e2..e1f1577 100644 --- a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp +++ b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp @@ -45,31 +45,25 @@ namespace WebCore { -class ContentLayerPainter : public LayerPainterChromium { - WTF_MAKE_NONCOPYABLE(ContentLayerPainter); -public: - static PassOwnPtr 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::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::create(ContentLayerDelegate* delegate) { diff --git a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h index 2e82bec..313c387 100644 --- a/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h +++ b/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h @@ -34,23 +34,38 @@ #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 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: diff --git a/Source/WebCore/platform/graphics/chromium/LayerPainterChromium.h b/Source/WebCore/platform/graphics/chromium/LayerPainterChromium.h index db6a884..bc0352e 100644 --- a/Source/WebCore/platform/graphics/chromium/LayerPainterChromium.h +++ b/Source/WebCore/platform/graphics/chromium/LayerPainterChromium.h @@ -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 diff --git a/Source/WebCore/platform/graphics/chromium/LinkHighlight.cpp b/Source/WebCore/platform/graphics/chromium/LinkHighlight.cpp index 3bc1e63..1b2c61e 100644 --- a/Source/WebCore/platform/graphics/chromium/LinkHighlight.cpp +++ b/Source/WebCore/platform/graphics/chromium/LinkHighlight.cpp @@ -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); diff --git a/Source/WebCore/platform/graphics/chromium/LinkHighlight.h b/Source/WebCore/platform/graphics/chromium/LinkHighlight.h index 1fbef9b..1ccc3eb 100644 --- a/Source/WebCore/platform/graphics/chromium/LinkHighlight.h +++ b/Source/WebCore/platform/graphics/chromium/LinkHighlight.h @@ -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; diff --git a/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp b/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp index 04548ae..a5155e2 100644 --- a/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp +++ b/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.cpp @@ -31,8 +31,10 @@ #include "GraphicsContext.h" #include "IntRect.h" #include "PlatformContextSkia.h" +#include #include +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()); } } diff --git a/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h b/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h index e325b36..bb5c2ae 100644 --- a/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h +++ b/Source/WebCore/platform/graphics/chromium/OpaqueRectTrackingContentLayerDelegate.h @@ -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; diff --git a/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp b/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp index a917272..dd6a43d 100644 --- a/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp +++ b/Source/WebCore/platform/graphics/chromium/ScrollbarLayerChromium.cpp @@ -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); diff --git a/Source/WebKit/chromium/ChangeLog b/Source/WebKit/chromium/ChangeLog index 3ebaf0f..722569f 100644 --- a/Source/WebKit/chromium/ChangeLog +++ b/Source/WebKit/chromium/ChangeLog @@ -1,3 +1,39 @@ +2012-06-30 Ian Vollick + + [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 IndexedDB: Keep direction on IDBCursor to avoid calls to back end diff --git a/Source/WebKit/chromium/WebKit.gypi b/Source/WebKit/chromium/WebKit.gypi index 8bfce9c..5e28903 100644 --- a/Source/WebKit/chromium/WebKit.gypi +++ b/Source/WebKit/chromium/WebKit.gypi @@ -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', diff --git a/Source/WebKit/chromium/src/WebContentLayerImpl.cpp b/Source/WebKit/chromium/src/WebContentLayerImpl.cpp index 8c8122f..ecf099a 100644 --- a/Source/WebKit/chromium/src/WebContentLayerImpl.cpp +++ b/Source/WebKit/chromium/src/WebContentLayerImpl.cpp @@ -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; } diff --git a/Source/WebKit/chromium/src/WebContentLayerImpl.h b/Source/WebKit/chromium/src/WebContentLayerImpl.h index 542bd9b..97729ea 100644 --- a/Source/WebKit/chromium/src/WebContentLayerImpl.h +++ b/Source/WebKit/chromium/src/WebContentLayerImpl.h @@ -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; diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp index 78448a5..e1691df 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp @@ -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 createDrawableContentLayerChromium(ContentLayerDelegate* delegate) diff --git a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp index 9af9780..a1dea26 100644 --- a/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp +++ b/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp @@ -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 index 0000000..7504185 --- /dev/null +++ b/Source/WebKit/chromium/tests/ContentLayerChromiumTest.cpp @@ -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 +#include +#include +#include +#include + +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 canvas = adoptPtr(skia::CreateBitmapCanvas(contentRect.width(), contentRect.height(), false)); + OpaqueRectDrawingGraphicsContextPainter painter(opaqueRectInLayerSpace, contentRect); + OpaqueRectTrackingContentLayerDelegate opaqueRectTrackingContentLayerDelegate(&painter); + MockContentLayerDelegate delegate(&opaqueRectTrackingContentLayerDelegate); + RefPtr 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 diff --git a/Source/WebKit/chromium/tests/LayerChromiumTest.cpp b/Source/WebKit/chromium/tests/LayerChromiumTest.cpp index 86d08ab..e7c6552 100644 --- a/Source/WebKit/chromium/tests/LayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/LayerChromiumTest.cpp @@ -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 { } }; diff --git a/Source/WebKit/chromium/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp b/Source/WebKit/chromium/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp index dd60a97..38b0c98 100644 --- a/Source/WebKit/chromium/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp +++ b/Source/WebKit/chromium/tests/OpaqueRectTrackingContentLayerDelegateTest.cpp @@ -30,11 +30,13 @@ #include "GraphicsContext.h" #include "IntRect.h" #include "skia/ext/platform_canvas.h" +#include #include #include 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 diff --git a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp index 8476224..25b3d5e 100644 --- a/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp +++ b/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp @@ -1505,7 +1505,7 @@ class TrackingLayerPainter : public LayerPainterChromium { public: static PassOwnPtr 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; } diff --git a/Source/WebKit/chromium/tests/WebLayerTest.cpp b/Source/WebKit/chromium/tests/WebLayerTest.cpp index bc49293..12deb59 100644 --- a/Source/WebKit/chromium/tests/WebLayerTest.cpp +++ b/Source/WebKit/chromium/tests/WebLayerTest.cpp @@ -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 { -- 2.7.4