1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/platform/graphics/paint/paint_record_builder.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_controller_test.h"
#include "third_party/blink/renderer/platform/graphics/test/mock_paint_canvas.h"
#include "third_party/blink/renderer/platform/testing/fake_display_item_client.h"
using testing::_;
namespace blink {
using PaintRecordBuilderTest = PaintControllerTestBase;
TEST_F(PaintRecordBuilderTest, TransientPaintController) {
PaintRecordBuilder builder;
auto& context = builder.Context();
FakeDisplayItemClient client("client", LayoutRect(10, 10, 20, 20));
DrawRect(context, client, kBackgroundType, FloatRect(10, 10, 20, 20));
DrawRect(context, client, kForegroundType, FloatRect(15, 15, 10, 10));
EXPECT_FALSE(ClientCacheIsValid(context.GetPaintController(), client));
MockPaintCanvas canvas;
PaintFlags flags;
EXPECT_CALL(canvas, drawPicture(_)).Times(1);
builder.EndRecording(canvas);
EXPECT_DISPLAY_LIST(context.GetPaintController().GetDisplayItemList(), 2,
TestDisplayItem(client, kBackgroundType),
TestDisplayItem(client, kForegroundType));
EXPECT_FALSE(ClientCacheIsValid(context.GetPaintController(), client));
}
TEST_F(PaintRecordBuilderTest, LastingPaintController) {
InitRootChunk();
PaintRecordBuilder builder(nullptr, nullptr, &GetPaintController());
auto& context = builder.Context();
EXPECT_EQ(&context.GetPaintController(), &GetPaintController());
FakeDisplayItemClient client("client", LayoutRect(10, 10, 20, 20));
DrawRect(context, client, kBackgroundType, FloatRect(10, 10, 20, 20));
DrawRect(context, client, kForegroundType, FloatRect(15, 15, 10, 10));
EXPECT_FALSE(ClientCacheIsValid(client));
MockPaintCanvas canvas;
PaintFlags flags;
EXPECT_CALL(canvas, drawPicture(_)).Times(1);
builder.EndRecording(canvas);
EXPECT_TRUE(ClientCacheIsValid(client));
EXPECT_DISPLAY_LIST(GetPaintController().GetDisplayItemList(), 2,
TestDisplayItem(client, kBackgroundType),
TestDisplayItem(client, kForegroundType));
InitRootChunk();
EXPECT_TRUE(DrawingRecorder::UseCachedDrawingIfPossible(context, client,
kBackgroundType));
EXPECT_TRUE(DrawingRecorder::UseCachedDrawingIfPossible(context, client,
kForegroundType));
EXPECT_CALL(canvas, drawPicture(_)).Times(1);
builder.EndRecording(canvas);
EXPECT_DISPLAY_LIST(GetPaintController().GetDisplayItemList(), 2,
TestDisplayItem(client, kBackgroundType),
TestDisplayItem(client, kForegroundType));
EXPECT_TRUE(ClientCacheIsValid(client));
}
TEST_F(PaintRecordBuilderTest, TransientAndAnotherPaintController) {
GraphicsContext context(GetPaintController());
InitRootChunk();
FakeDisplayItemClient client("client", LayoutRect(10, 10, 20, 20));
DrawRect(context, client, kBackgroundType, FloatRect(10, 10, 20, 20));
DrawRect(context, client, kForegroundType, FloatRect(15, 15, 10, 10));
CommitAndFinishCycle();
EXPECT_DISPLAY_LIST(GetPaintController().GetDisplayItemList(), 2,
TestDisplayItem(client, kBackgroundType),
TestDisplayItem(client, kForegroundType));
// EXPECT_TRUE(ClientCacheIsValid(client));
PaintRecordBuilder builder;
EXPECT_NE(&builder.Context().GetPaintController(), &GetPaintController());
DrawRect(builder.Context(), client, kBackgroundType,
FloatRect(10, 10, 20, 20));
builder.EndRecording();
// The transient PaintController in PaintRecordBuilder doesn't affect the
// client's cache status in another PaintController.
// EXPECT_TRUE(ClientCacheIsValid(client));
// EXPECT_FALSE(
// ClientCacheIsValid(builder.Context().GetPaintController(), client));
}
} // namespace blink
|