OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "cc/paint/paint_op_buffer.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace cc { |
| 9 |
| 10 TEST(PaintOpBufferTest, Empty) { |
| 11 PaintOpBuffer buffer; |
| 12 EXPECT_EQ(buffer.approximateOpCount(), 0); |
| 13 EXPECT_EQ(buffer.approximateBytesUsed(), 0u); |
| 14 |
| 15 buffer.Reset(); |
| 16 EXPECT_EQ(buffer.approximateOpCount(), 0); |
| 17 EXPECT_EQ(buffer.approximateBytesUsed(), 0u); |
| 18 } |
| 19 |
| 20 TEST(PaintOpBufferTest, SimpleAppend) { |
| 21 SkRect rect = SkRect::MakeXYWH(2, 3, 4, 5); |
| 22 PaintFlags flags; |
| 23 flags.setColor(SK_ColorMAGENTA); |
| 24 flags.setAlpha(100); |
| 25 SkColor draw_color = SK_ColorRED; |
| 26 SkBlendMode blend = SkBlendMode::kSrc; |
| 27 |
| 28 PaintOpBuffer buffer; |
| 29 buffer.push<SaveLayerOp>(&rect, &flags); |
| 30 buffer.push<SaveOp>(); |
| 31 buffer.push<DrawColorOp>(draw_color, blend); |
| 32 buffer.push<RestoreOp>(); |
| 33 |
| 34 EXPECT_EQ(buffer.approximateOpCount(), 4); |
| 35 |
| 36 PaintOpBuffer::Iterator iter(&buffer); |
| 37 ASSERT_EQ(iter->GetType(), PaintOpType::SaveLayer); |
| 38 SaveLayerOp* save_op = static_cast<SaveLayerOp*>(*iter); |
| 39 EXPECT_EQ(save_op->bounds, rect); |
| 40 EXPECT_TRUE(save_op->flags == flags); |
| 41 ++iter; |
| 42 |
| 43 ASSERT_EQ(iter->GetType(), PaintOpType::Save); |
| 44 ++iter; |
| 45 |
| 46 ASSERT_EQ(iter->GetType(), PaintOpType::DrawColor); |
| 47 DrawColorOp* op = static_cast<DrawColorOp*>(*iter); |
| 48 EXPECT_EQ(op->color, draw_color); |
| 49 EXPECT_EQ(op->mode, blend); |
| 50 ++iter; |
| 51 |
| 52 ASSERT_EQ(iter->GetType(), PaintOpType::Restore); |
| 53 ++iter; |
| 54 |
| 55 EXPECT_FALSE(iter); |
| 56 } |
| 57 |
| 58 // TODO(enne) |
| 59 // * First op with data |
| 60 // * First op no data |
| 61 // * Resetting and appending |
| 62 // * Appending every kind of op, make sure data is stored |
| 63 // * Save/restore optimization (need an overridden device, mabye? |
| 64 // * Slow path counting |
| 65 |
| 66 } // namespace cc |
OLD | NEW |