Index: cc/paint/paint_op_buffer_unittest.cc |
diff --git a/cc/paint/paint_op_buffer_unittest.cc b/cc/paint/paint_op_buffer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0e1d87ae1025560f4b81654cc7aee73532d08ace |
--- /dev/null |
+++ b/cc/paint/paint_op_buffer_unittest.cc |
@@ -0,0 +1,66 @@ |
+// 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 "cc/paint/paint_op_buffer.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace cc { |
+ |
+TEST(PaintOpBufferTest, Empty) { |
+ PaintOpBuffer buffer; |
+ EXPECT_EQ(buffer.approximateOpCount(), 0); |
+ EXPECT_EQ(buffer.approximateBytesUsed(), 0u); |
+ |
+ buffer.Reset(); |
+ EXPECT_EQ(buffer.approximateOpCount(), 0); |
+ EXPECT_EQ(buffer.approximateBytesUsed(), 0u); |
+} |
+ |
+TEST(PaintOpBufferTest, SimpleAppend) { |
+ SkRect rect = SkRect::MakeXYWH(2, 3, 4, 5); |
+ PaintFlags flags; |
+ flags.setColor(SK_ColorMAGENTA); |
+ flags.setAlpha(100); |
+ SkColor draw_color = SK_ColorRED; |
+ SkBlendMode blend = SkBlendMode::kSrc; |
+ |
+ PaintOpBuffer buffer; |
+ buffer.push<SaveLayerOp>(&rect, &flags); |
+ buffer.push<SaveOp>(); |
+ buffer.push<DrawColorOp>(draw_color, blend); |
+ buffer.push<RestoreOp>(); |
+ |
+ EXPECT_EQ(buffer.approximateOpCount(), 4); |
+ |
+ PaintOpBuffer::Iterator iter(&buffer); |
+ ASSERT_EQ(iter->GetType(), PaintOpType::SaveLayer); |
+ SaveLayerOp* save_op = static_cast<SaveLayerOp*>(*iter); |
+ EXPECT_EQ(save_op->bounds, rect); |
+ EXPECT_TRUE(save_op->flags == flags); |
+ ++iter; |
+ |
+ ASSERT_EQ(iter->GetType(), PaintOpType::Save); |
+ ++iter; |
+ |
+ ASSERT_EQ(iter->GetType(), PaintOpType::DrawColor); |
+ DrawColorOp* op = static_cast<DrawColorOp*>(*iter); |
+ EXPECT_EQ(op->color, draw_color); |
+ EXPECT_EQ(op->mode, blend); |
+ ++iter; |
+ |
+ ASSERT_EQ(iter->GetType(), PaintOpType::Restore); |
+ ++iter; |
+ |
+ EXPECT_FALSE(iter); |
+} |
+ |
+// TODO(enne) |
+// * First op with data |
+// * First op no data |
+// * Resetting and appending |
+// * Appending every kind of op, make sure data is stored |
+// * Save/restore optimization (need an overridden device, mabye? |
+// * Slow path counting |
+ |
+} // namespace cc |