Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/skia_benchmarking_extension.h" | 5 #include "content/renderer/skia_benchmarking_extension.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "third_party/skia/include/core/SkGraphics.h" | 9 #include "third_party/skia/include/core/SkGraphics.h" |
| 10 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" | 10 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 SkGraphics::Init(); | 42 SkGraphics::Init(); |
| 43 | 43 |
| 44 // Prepare canvas and resources. | 44 // Prepare canvas and resources. |
| 45 SkDebugCanvas canvas(100, 100); | 45 SkDebugCanvas canvas(100, 100); |
| 46 SkPaint red_paint; | 46 SkPaint red_paint; |
| 47 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); | 47 red_paint.setColor(SkColorSetARGB(255, 255, 0, 0)); |
| 48 SkRect fullRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); | 48 SkRect fullRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 49 SkRect fillRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), | 49 SkRect fillRect = SkRect::MakeXYWH(SkIntToScalar(25), SkIntToScalar(25), |
| 50 SkIntToScalar(50), SkIntToScalar(50)); | 50 SkIntToScalar(50), SkIntToScalar(50)); |
| 51 | 51 |
| 52 SkMatrix trans; | |
| 53 trans.setTranslate(SkIntToScalar(10), SkIntToScalar(10)); | |
| 54 | |
| 52 // Draw a trivial scene. | 55 // Draw a trivial scene. |
| 53 canvas.save(); | 56 canvas.save(); |
| 54 canvas.clipRect(fullRect, SkRegion::kIntersect_Op, false); | 57 canvas.clipRect(fullRect, SkRegion::kIntersect_Op, false); |
| 55 canvas.translate(SkIntToScalar(10), SkIntToScalar(10)); | 58 canvas.setMatrix(trans); |
| 56 canvas.scale(SkIntToScalar(2), SkIntToScalar(2)); | |
| 57 canvas.drawRect(fillRect, red_paint); | 59 canvas.drawRect(fillRect, red_paint); |
| 58 canvas.restore(); | 60 canvas.restore(); |
| 59 | 61 |
| 60 // Verify the recorded commands. | 62 // Verify the recorded commands. |
| 61 DrawType cmd; | 63 SkDrawCommand::OpType cmd; |
| 62 int idx = 0; | 64 int idx = 0; |
| 63 ASSERT_EQ(canvas.getSize(), 6); | 65 ASSERT_EQ(canvas.getSize(), 5); |
| 64 | 66 |
| 65 ASSERT_TRUE(canvas.getDrawCommandAt(idx) != NULL); | 67 ASSERT_TRUE(canvas.getDrawCommandAt(idx) != NULL); |
| 66 cmd = canvas.getDrawCommandAt(idx)->getType(); | 68 cmd = canvas.getDrawCommandAt(idx)->getType(); |
| 67 EXPECT_EQ(cmd, SAVE); | 69 EXPECT_EQ(cmd, SkDrawCommand::kSave_OpType); |
| 68 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Save"); | 70 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Save"); |
| 69 | 71 |
| 70 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | 72 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); |
| 71 cmd = canvas.getDrawCommandAt(idx)->getType(); | 73 cmd = canvas.getDrawCommandAt(idx)->getType(); |
| 72 EXPECT_EQ(cmd, CLIP_RECT); | 74 EXPECT_EQ(cmd, SkDrawCommand::kClipRect_OpType); |
| 73 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Clip Rect"); | 75 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), |
| 76 SkDrawCommand::kClipRectString); | |
| 74 EXPECT_TRUE(HasInfoField(canvas, idx, "SkRect")); | 77 EXPECT_TRUE(HasInfoField(canvas, idx, "SkRect")); |
| 75 EXPECT_TRUE(HasInfoField(canvas, idx, "Op")); | 78 EXPECT_TRUE(HasInfoField(canvas, idx, "Op")); |
| 76 EXPECT_TRUE(HasInfoField(canvas, idx, "doAA")); | 79 EXPECT_TRUE(HasInfoField(canvas, idx, "doAA")); |
| 77 | 80 |
|
robertphillips
2015/02/11 23:01:45
Skia converts all the matrix calls to a setMatrix
| |
| 78 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | 81 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); |
| 79 cmd = canvas.getDrawCommandAt(idx)->getType(); | 82 cmd = canvas.getDrawCommandAt(idx)->getType(); |
| 80 EXPECT_EQ(cmd, TRANSLATE); | 83 EXPECT_EQ(cmd, SkDrawCommand::kSetMatrix_OpType); |
| 81 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Translate"); | 84 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "SetMatrix"); |
| 82 EXPECT_TRUE(HasInfoField(canvas, idx, "dx")); | |
| 83 EXPECT_TRUE(HasInfoField(canvas, idx, "dy")); | |
| 84 | 85 |
| 85 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | 86 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); |
| 86 cmd = canvas.getDrawCommandAt(idx)->getType(); | 87 cmd = canvas.getDrawCommandAt(idx)->getType(); |
| 87 EXPECT_EQ(cmd, SCALE); | 88 EXPECT_EQ(cmd, SkDrawCommand::kDrawRect_OpType); |
| 88 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Scale"); | 89 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), |
| 89 EXPECT_TRUE(HasInfoField(canvas, idx, "sx")); | 90 SkDrawCommand::kDrawRectString); |
| 90 EXPECT_TRUE(HasInfoField(canvas, idx, "sy")); | |
| 91 | |
| 92 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | |
| 93 cmd = canvas.getDrawCommandAt(idx)->getType(); | |
| 94 EXPECT_EQ(cmd, DRAW_RECT); | |
| 95 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Draw Rect"); | |
| 96 EXPECT_TRUE(HasInfoField(canvas, idx, "SkRect")); | 91 EXPECT_TRUE(HasInfoField(canvas, idx, "SkRect")); |
| 97 | 92 |
| 98 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); | 93 ASSERT_TRUE(canvas.getDrawCommandAt(++idx) != NULL); |
| 99 cmd = canvas.getDrawCommandAt(idx)->getType(); | 94 cmd = canvas.getDrawCommandAt(idx)->getType(); |
| 100 EXPECT_EQ(cmd, RESTORE); | 95 EXPECT_EQ(cmd, SkDrawCommand::kRestore_OpType); |
| 101 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Restore"); | 96 EXPECT_STREQ(SkDrawCommand::GetCommandString(cmd), "Restore"); |
| 102 } | 97 } |
| 103 | 98 |
| 104 } // namespace content | 99 } // namespace content |
| OLD | NEW |