This source file includes following definitions.
- paint
- skCanvas
- canvasRect
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include "platform/graphics/OpaqueRectTrackingContentLayerDelegate.h"
#include "platform/geometry/IntRect.h"
#include "platform/graphics/Color.h"
#include "platform/graphics/GraphicsContext.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebRect.h"
#include "skia/ext/platform_canvas.h"
#include <gtest/gtest.h>
using blink::WebRect;
using blink::WebFloatRect;
using namespace WebCore;
namespace {
struct PaintCallback {
virtual void operator()(GraphicsContext&, const IntRect&) = 0;
};
class TestLayerPainterChromium : public GraphicsContextPainter {
public:
TestLayerPainterChromium(PaintCallback& callback) : m_callback(callback) { }
virtual void paint(GraphicsContext& context, const IntRect& contentRect) OVERRIDE
{
m_callback(context, contentRect);
}
private:
PaintCallback& m_callback;
};
struct PaintFillOpaque : public PaintCallback {
virtual void operator()(GraphicsContext& context, const IntRect& contentRect) OVERRIDE
{
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);
context.fillRect(bottom, opaque);
}
};
struct PaintFillAlpha : public PaintCallback {
virtual void operator()(GraphicsContext& context, const IntRect& contentRect)
{
Color alpha(0, 0, 0, 0);
context.fillRect(contentRect, alpha);
}
};
struct PaintFillPartialOpaque : public PaintCallback {
PaintFillPartialOpaque(IntRect opaqueRect)
: m_opaqueRect(opaqueRect)
{
}
virtual void operator()(GraphicsContext& context, const IntRect& contentRect)
{
Color alpha(0, 0, 0, 0);
context.fillRect(contentRect, alpha);
IntRect fillOpaque = m_opaqueRect;
fillOpaque.intersect(contentRect);
Color opaque(255, 255, 255, 255);
context.fillRect(fillOpaque, opaque);
}
IntRect m_opaqueRect;
};
#define EXPECT_EQ_RECT(a, b) \
EXPECT_EQ(a.x, b.x); \
EXPECT_EQ(a.width, b.width); \
EXPECT_EQ(a.y, b.y); \
EXPECT_EQ(a.height, b.height);
class OpaqueRectTrackingContentLayerDelegateTest : public testing::Test {
public:
OpaqueRectTrackingContentLayerDelegateTest()
: m_skCanvas(adoptPtr(skia::CreateBitmapCanvas(canvasRect().width, canvasRect().height, false)))
{
}
SkCanvas* skCanvas() { return m_skCanvas.get(); }
WebRect canvasRect() { return WebRect(0, 0, 400, 400); }
private:
OwnPtr<SkCanvas> m_skCanvas;
};
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectPresentAfterOpaquePaint)
{
PaintFillOpaque fillOpaque;
TestLayerPainterChromium painter(fillOpaque);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
WebFloatRect opaqueRect;
delegate.paintContents(skCanvas(), canvasRect(), false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(0, 0, 400, 400), opaqueRect);
}
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentAfterNonOpaquePaint)
{
PaintFillAlpha fillAlpha;
TestLayerPainterChromium painter(fillAlpha);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
WebFloatRect opaqueRect;
delegate.paintContents(skCanvas(), canvasRect(), false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
}
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOpaqueLayerWithOpaquePaint)
{
PaintFillOpaque fillOpaque;
TestLayerPainterChromium painter(fillOpaque);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
delegate.setOpaque(true);
WebFloatRect opaqueRect;
delegate.paintContents(skCanvas(), canvasRect(), false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
}
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testOpaqueRectNotPresentForOpaqueLayerWithNonOpaquePaint)
{
PaintFillOpaque fillAlpha;
TestLayerPainterChromium painter(fillAlpha);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
delegate.setOpaque(true);
WebFloatRect opaqueRect;
delegate.paintContents(skCanvas(), canvasRect(), false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(0, 0, 0, 0), opaqueRect);
}
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectNoTransform)
{
IntRect partialRect(100, 200, 50, 75);
PaintFillPartialOpaque fillPartial(partialRect);
TestLayerPainterChromium painter(fillPartial);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
WebFloatRect opaqueRect;
delegate.paintContents(skCanvas(), canvasRect(), false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
}
TEST_F(OpaqueRectTrackingContentLayerDelegateTest, testPartialOpaqueRectTranslation)
{
IntRect partialRect(100, 200, 50, 75);
PaintFillPartialOpaque fillPartial(partialRect);
TestLayerPainterChromium painter(fillPartial);
OpaqueRectTrackingContentLayerDelegate delegate(&painter);
WebFloatRect opaqueRect;
WebRect contentRect(11, 12, 389, 388);
delegate.paintContents(skCanvas(), contentRect, false, opaqueRect);
EXPECT_EQ_RECT(WebFloatRect(partialRect.x(), partialRect.y(), partialRect.width(), partialRect.height()), opaqueRect);
}
}