1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/paint/LayerClipRecorder.h"
8 #include "core/layout/LayoutTestHelper.h"
9 #include "core/layout/LayoutView.h"
10 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
11 #include "core/paint/DeprecatedPaintLayer.h"
12 #include "core/paint/LayoutObjectDrawingRecorder.h"
13 #include "platform/graphics/GraphicsContext.h"
14 #include "platform/graphics/GraphicsLayer.h"
15 #include "platform/graphics/paint/DisplayItemList.h"
16 #include <gtest/gtest.h>
21 class LayerClipRecorderTest
: public RenderingTest
{
23 LayerClipRecorderTest()
24 : m_layoutView(nullptr) { }
27 LayoutView
& layoutView() { return *m_layoutView
; }
28 DisplayItemList
& rootDisplayItemList() { return *layoutView().layer()->graphicsLayerBacking()->displayItemList(); }
33 RenderingTest::SetUp();
36 m_layoutView
= document().view()->layoutView();
37 ASSERT_TRUE(m_layoutView
);
40 LayoutView
* m_layoutView
;
43 void drawEmptyClip(GraphicsContext
& context
, LayoutView
& layoutView
, PaintPhase phase
)
45 LayoutRect
rect(1, 1, 9, 9);
46 ClipRect
clipRect(rect
);
47 LayerClipRecorder
LayerClipRecorder(context
, *layoutView
.compositor()->rootLayer()->layoutObject(), DisplayItem::ClipLayerForeground
, clipRect
, 0, LayoutPoint(), PaintLayerFlags());
50 void drawRectInClip(GraphicsContext
& context
, LayoutView
& layoutView
, PaintPhase phase
, const LayoutRect
& bound
)
52 IntRect
rect(1, 1, 9, 9);
53 ClipRect
clipRect((LayoutRect(rect
)));
54 LayerClipRecorder
LayerClipRecorder(context
, *layoutView
.compositor()->rootLayer()->layoutObject(), DisplayItem::ClipLayerForeground
, clipRect
, 0, LayoutPoint(), PaintLayerFlags());
55 if (!LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context
, layoutView
, phase
, LayoutPoint())) {
56 LayoutObjectDrawingRecorder
drawingRecorder(context
, layoutView
, phase
, bound
, LayoutPoint());
57 context
.drawRect(rect
);
61 TEST_F(LayerClipRecorderTest
, Single
)
63 GraphicsContext
context(&rootDisplayItemList());
64 LayoutRect bound
= layoutView().viewRect();
65 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());
67 drawRectInClip(context
, layoutView(), PaintPhaseForeground
, bound
);
68 rootDisplayItemList().commitNewDisplayItems();
69 EXPECT_EQ((size_t)3, rootDisplayItemList().displayItems().size());
70 EXPECT_TRUE(DisplayItem::isClipType(rootDisplayItemList().displayItems()[0].type()));
71 EXPECT_TRUE(DisplayItem::isDrawingType(rootDisplayItemList().displayItems()[1].type()));
72 EXPECT_TRUE(DisplayItem::isEndClipType(rootDisplayItemList().displayItems()[2].type()));
75 TEST_F(LayerClipRecorderTest
, Empty
)
77 GraphicsContext
context(&rootDisplayItemList());
78 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());
80 drawEmptyClip(context
, layoutView(), PaintPhaseForeground
);
81 rootDisplayItemList().commitNewDisplayItems();
82 EXPECT_EQ((size_t)0, rootDisplayItemList().displayItems().size());