OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "content/renderer/skia_benchmarking_extension.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 #include "third_party/skia/include/core/SkCanvas.h" | |
9 #include "third_party/skia/include/core/SkGraphics.h" | |
10 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" | |
11 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h" | |
12 | |
13 // FIXME: loose info paramter test. | |
14 #define EXPECT_INFO(info, key) do { \ | |
15 ASSERT_TRUE(info != NULL); \ | |
16 bool key##_found = false; \ | |
17 for (int i = 0; i < info->count(); ++i) { \ | |
18 const SkString* info_str = (*info)[i]; \ | |
19 ASSERT_TRUE(info_str != NULL); \ | |
20 if (strstr(info_str->c_str(), #key ) != NULL) { \ | |
21 key##_found = true; \ | |
22 break; \ | |
23 } \ | |
24 } \ | |
25 EXPECT_TRUE(key##_found); \ | |
26 } while (0) | |
piman
2013/06/20 18:30:52
nit: Why the need to make this a macro? Can't it b
f(malita)
2013/06/20 18:48:15
The only reason I went with a macro was to be able
piman
2013/06/20 19:35:03
gtest.h defines the AssertionResult class which lo
f(malita)
2013/06/20 20:05:20
That's perfect, thanks!
| |
27 | |
28 namespace content { | |
29 | |
30 TEST(SkiaBenchmarkingExtensionTest, SkDebugCanvas) { | |
31 SkGraphics::Init(); | |
32 | |
33 // Prepare canvas and resources. | |
34 SkDebugCanvas canvas(100, 100); | |
35 SkPaint red_paint; | |
36 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); | |
37 SkRect fullRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | |
38 SkRect fillRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), | |
39 SkIntToScalar(50), SkIntToScalar(50)); | |
40 | |
41 // Draw a trivial scene. | |
42 canvas.save(SkCanvas::kMatrixClip_SaveFlag); | |
43 canvas.clipRect(fullRect, SkRegion::kIntersect_Op, false); | |
44 canvas.translate(SkIntToScalar(10), SkIntToScalar(10)); | |
45 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); | |
46 canvas.drawRect(fillRect, red_paint); | |
47 canvas.restore(); | |
48 | |
49 // Verify the recorded commands. | |
50 DrawType cmd; | |
51 int idx = 0; | |
52 ASSERT_EQ(canvas.getSize(), 6); | |
53 | |
54 ASSERT_TRUE(canvas.getDrawCommandAt(idx) != NULL); | |
55 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
56 EXPECT_EQ(cmd, SAVE); | |
57 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Save"); | |
58 EXPECT_INFO(canvas.getCommandInfo(idx), SaveFlags); | |
59 | |
60 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
61 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
62 EXPECT_EQ(cmd, CLIP_RECT); | |
63 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Clip Rect"); | |
64 EXPECT_INFO(canvas.getCommandInfo(idx), SkRect); | |
65 EXPECT_INFO(canvas.getCommandInfo(idx), Op); | |
66 EXPECT_INFO(canvas.getCommandInfo(idx), doAA); | |
67 | |
68 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
69 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
70 EXPECT_EQ(cmd, TRANSLATE); | |
71 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Translate"); | |
72 EXPECT_INFO(canvas.getCommandInfo(idx), dx); | |
73 EXPECT_INFO(canvas.getCommandInfo(idx), dy); | |
74 | |
75 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
76 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
77 EXPECT_EQ(cmd, SCALE); | |
78 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Scale"); | |
79 EXPECT_INFO(canvas.getCommandInfo(idx), sx); | |
80 EXPECT_INFO(canvas.getCommandInfo(idx), sy); | |
81 | |
82 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
83 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
84 EXPECT_EQ(cmd, DRAW_RECT); | |
85 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Draw Rect"); | |
86 EXPECT_INFO(canvas.getCommandInfo(idx), SkRect); | |
87 | |
88 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
89 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
90 EXPECT_EQ(cmd, RESTORE); | |
91 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Restore"); | |
92 } | |
93 | |
94 } // namespace content | |
OLD | NEW |