[Chromium] Use the current clip when marking paints as opaque

https://bugs.webkit.org/show_bug.cgi?id=77582

Patch by Dana Jansens <danakj@chromium.org> on 2012-02-03
Reviewed by Stephen White.

Source/WebCore:

New unit test in PlatformContextSkiaTest.cpp

* platform/graphics/skia/OpaqueRegionSkia.cpp:
(WebCore::OpaqueRegionSkia::markRectAsOpaque):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore::PlatformContextSkia::canvas):

Source/WebKit/chromium:

* tests/PlatformContextSkiaTest.cpp:
(WebCore::TEST):
(WebCore):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106663 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0a0e576d
2012-02-03 Dana Jansens <danakj@chromium.org>
[Chromium] Use the current clip when marking paints as opaque
https://bugs.webkit.org/show_bug.cgi?id=77582
Reviewed by Stephen White.
New unit test in PlatformContextSkiaTest.cpp
* platform/graphics/skia/OpaqueRegionSkia.cpp:
(WebCore::OpaqueRegionSkia::markRectAsOpaque):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore::PlatformContextSkia::canvas):
2012-02-03 Yury Semikhatsky <yurys@chromium.org>
inspector/debugger/pause-in-inline-script.html asserts in chromium debug
......@@ -34,6 +34,7 @@
#include "PlatformContextSkia.h"
#include "SkCanvas.h"
#include "SkShader.h"
namespace WebCore {
......@@ -236,19 +237,29 @@ void OpaqueRegionSkia::didDrawUnbounded(const SkPaint& paint, bool drawsOpaque)
}
}
void OpaqueRegionSkia::markRectAsOpaque(const PlatformContextSkia* context, const SkRect& rect)
void OpaqueRegionSkia::markRectAsOpaque(const PlatformContextSkia* context, const SkRect& paintRect)
{
// We want to keep track of an opaque region but bound its complexity at a constant size.
// We keep track of the largest rectangle seen by area. If we can add the new rect to this
// rectangle then we do that, as that is the cheapest way to increase the area returned
// without increasing the complexity.
if (rect.isEmpty())
if (paintRect.isEmpty())
return;
if (!context->clippedToImage().isOpaque())
return;
if (m_opaqueRect.contains(rect))
if (context->canvas()->getClipType() != SkCanvas::kRect_ClipType)
return;
if (m_opaqueRect.contains(paintRect))
return;
// Apply the current clip.
SkIRect deviceClip;
context->canvas()->getClipDeviceBounds(&deviceClip);
SkRect rect = paintRect;
if (!rect.intersect(SkIntToScalar(deviceClip.fLeft), SkIntToScalar(deviceClip.fTop), SkIntToScalar(deviceClip.fRight), SkIntToScalar(deviceClip.fBottom)))
return;
if (rect.contains(m_opaqueRect)) {
m_opaqueRect = rect;
return;
......
......@@ -152,6 +152,7 @@ public:
// Returns the canvas used for painting, NOT guaranteed to be non-null.
SkCanvas* canvas() { return m_canvas; }
const SkCanvas* canvas() const { return m_canvas; }
InterpolationQuality interpolationQuality() const;
void setInterpolationQuality(InterpolationQuality interpolationQuality);
......
2012-02-03 Dana Jansens <danakj@chromium.org>
[Chromium] Use the current clip when marking paints as opaque
https://bugs.webkit.org/show_bug.cgi?id=77582
Reviewed by Stephen White.
* tests/PlatformContextSkiaTest.cpp:
(WebCore::TEST):
(WebCore):
2012-02-03 Yury Semikhatsky <yurys@chromium.org>
Unreviewed. Update Chromium deps.
......@@ -28,6 +28,7 @@
#include "BitmapImageSingleFrameSkia.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "NativeImageSkia.h"
#include "SkCanvas.h"
#include <gtest/gtest.h>
......@@ -111,6 +112,89 @@ TEST(PlatformContextSkiaTest, trackOpaqueTest)
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
}
TEST(PlatformContextSkiaTest, trackOpaqueClipTest)
{
SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, 400, 400);
bitmap.allocPixels();
SkCanvas canvas(bitmap);
PlatformContextSkia platformContext(&canvas);
platformContext.setTrackOpaqueRegion(true);
GraphicsContext context(&platformContext);
Color opaque(1.0f, 0.0f, 0.0f, 1.0f);
Color alpha(0.0f, 0.0f, 0.0f, 0.0f);
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(10, 10, 90, 90), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.clearRect(FloatRect(10, 10, 90, 90));
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
context.save();
context.clip(FloatRect(0, 0, 10, 10));
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.restore();
context.clearRect(FloatRect(10, 10, 90, 90));
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
context.save();
context.clip(FloatRect(20, 20, 10, 10));
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(20, 20, 10, 10), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.clearRect(FloatRect(10, 10, 90, 90));
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
// The intersection of the two clips becomes empty.
context.clip(FloatRect(30, 20, 10, 10));
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.restore();
context.clearRect(FloatRect(10, 10, 90, 90));
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
Path path;
path.moveTo(FloatPoint(0, 0));
path.addLineTo(FloatPoint(100, 0));
// Non-rectangular clips just cause the paint to be considered non-opaque.
context.save();
context.clipPath(path, RULE_EVENODD);
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.restore();
// Another non-rectangular clip.
context.save();
context.clip(IntRect(30, 30, 20, 20));
context.clipOut(IntRect(30, 30, 10, 10));
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.restore();
OwnPtr<ImageBuffer> alphaImage = ImageBuffer::create(IntSize(100, 100));
alphaImage->context()->fillRect(IntRect(0, 0, 100, 100), alpha, ColorSpaceDeviceRGB);
// Clipping with a non-opaque Image (there is no way to mark an ImageBuffer as opaque today).
context.save();
context.clipToImageBuffer(alphaImage.get(), FloatRect(30, 30, 10, 10));
context.fillRect(FloatRect(10, 10, 90, 90), opaque, ColorSpaceDeviceRGB, CompositeSourceOver);
EXPECT_EQ_RECT(IntRect(), platformContext.opaqueRegion().asRect());
EXPECT_PIXELS_MATCH(bitmap, platformContext.opaqueRegion().asRect());
context.restore();
}
TEST(PlatformContextSkiaTest, trackOpaqueJoinTest)
{
SkBitmap bitmap;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment