Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "cc/input/selection.h" | 6 #include "cc/input/selection.h" |
| 7 #include "cc/ipc/traits_test_service.mojom.h" | 7 #include "cc/ipc/traits_test_service.mojom.h" |
| 8 #include "cc/quads/render_pass_id.h" | 8 #include "cc/quads/render_pass_id.h" |
| 9 #include "mojo/public/cpp/bindings/binding_set.h" | 9 #include "mojo/public/cpp/bindings/binding_set.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "third_party/skia/include/core/SkString.h" | |
| 12 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | |
| 11 | 13 |
| 12 namespace cc { | 14 namespace cc { |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 | 17 |
| 16 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | 18 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { |
| 17 public: | 19 public: |
| 18 StructTraitsTest() {} | 20 StructTraitsTest() {} |
| 19 | 21 |
| 20 protected: | 22 protected: |
| 21 mojom::TraitsTestServicePtr GetTraitsTestProxy() { | 23 mojom::TraitsTestServicePtr GetTraitsTestProxy() { |
| 22 return traits_test_bindings_.CreateInterfacePtrAndBind(this); | 24 return traits_test_bindings_.CreateInterfacePtrAndBind(this); |
| 23 } | 25 } |
| 24 | 26 |
| 25 private: | 27 private: |
| 26 // TraitsTestService: | 28 // TraitsTestService: |
| 27 void EchoBeginFrameArgs(const BeginFrameArgs& b, | 29 void EchoBeginFrameArgs(const BeginFrameArgs& b, |
| 28 const EchoBeginFrameArgsCallback& callback) override { | 30 const EchoBeginFrameArgsCallback& callback) override { |
| 29 callback.Run(b); | 31 callback.Run(b); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void EchoCompositorFrameMetadata( | 34 void EchoCompositorFrameMetadata( |
| 33 const CompositorFrameMetadata& c, | 35 const CompositorFrameMetadata& c, |
| 34 const EchoCompositorFrameMetadataCallback& callback) override { | 36 const EchoCompositorFrameMetadataCallback& callback) override { |
| 35 callback.Run(c); | 37 callback.Run(c); |
| 36 } | 38 } |
| 37 | 39 |
| 40 void EchoFilterOperation( | |
| 41 const FilterOperation& f, | |
| 42 const EchoFilterOperationCallback& callback) override { | |
| 43 callback.Run(f); | |
| 44 } | |
| 45 | |
| 38 void EchoRenderPassId(const RenderPassId& r, | 46 void EchoRenderPassId(const RenderPassId& r, |
| 39 const EchoRenderPassIdCallback& callback) override { | 47 const EchoRenderPassIdCallback& callback) override { |
| 40 callback.Run(r); | 48 callback.Run(r); |
| 41 } | 49 } |
| 42 | 50 |
| 43 void EchoReturnedResource( | 51 void EchoReturnedResource( |
| 44 const ReturnedResource& r, | 52 const ReturnedResource& r, |
| 45 const EchoReturnedResourceCallback& callback) override { | 53 const EchoReturnedResourceCallback& callback) override { |
| 46 callback.Run(r); | 54 callback.Run(r); |
| 47 } | 55 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 &component)); | 179 &component)); |
| 172 EXPECT_EQ(7331, component.sequence_number); | 180 EXPECT_EQ(7331, component.sequence_number); |
| 173 EXPECT_EQ(satisfies_sequences.size(), output.satisfies_sequences.size()); | 181 EXPECT_EQ(satisfies_sequences.size(), output.satisfies_sequences.size()); |
| 174 for (uint32_t i = 0; i < satisfies_sequences.size(); ++i) | 182 for (uint32_t i = 0; i < satisfies_sequences.size(); ++i) |
| 175 EXPECT_EQ(satisfies_sequences[i], output.satisfies_sequences[i]); | 183 EXPECT_EQ(satisfies_sequences[i], output.satisfies_sequences[i]); |
| 176 EXPECT_EQ(referenced_surfaces.size(), output.referenced_surfaces.size()); | 184 EXPECT_EQ(referenced_surfaces.size(), output.referenced_surfaces.size()); |
| 177 for (uint32_t i = 0; i < referenced_surfaces.size(); ++i) | 185 for (uint32_t i = 0; i < referenced_surfaces.size(); ++i) |
| 178 EXPECT_EQ(referenced_surfaces[i], output.referenced_surfaces[i]); | 186 EXPECT_EQ(referenced_surfaces[i], output.referenced_surfaces[i]); |
| 179 } | 187 } |
| 180 | 188 |
| 189 TEST_F(StructTraitsTest, FilterOperation) { | |
| 190 const FilterOperation inputs[] = { | |
| 191 FilterOperation::CreateBlurFilter(20), | |
| 192 FilterOperation::CreateDropShadowFilter(gfx::Point(4, 4), 4.0f, | |
| 193 SkColorSetARGB(255, 40, 0, 0)), | |
| 194 FilterOperation::CreateReferenceFilter(SkDropShadowImageFilter::Make( | |
| 195 SkIntToScalar(3), SkIntToScalar(8), SkIntToScalar(4), | |
| 196 SkIntToScalar(9), SK_ColorBLACK, | |
| 197 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, | |
| 198 nullptr))}; | |
| 199 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | |
| 200 for (const auto& input : inputs) { | |
| 201 FilterOperation output; | |
| 202 proxy->EchoFilterOperation(input, &output); | |
| 203 EXPECT_EQ(input.type(), output.type()); | |
| 204 switch (input.type()) { | |
| 205 case FilterOperation::GRAYSCALE: | |
| 206 case FilterOperation::SEPIA: | |
| 207 case FilterOperation::SATURATE: | |
| 208 case FilterOperation::HUE_ROTATE: | |
| 209 case FilterOperation::INVERT: | |
| 210 case FilterOperation::BRIGHTNESS: | |
| 211 case FilterOperation::SATURATING_BRIGHTNESS: | |
| 212 case FilterOperation::CONTRAST: | |
| 213 case FilterOperation::OPACITY: | |
| 214 case FilterOperation::BLUR: | |
| 215 EXPECT_EQ(input.amount(), output.amount()); | |
| 216 continue; | |
|
yzshen1
2016/06/08 16:25:16
It seems more common to use "break;" here.
Fady Samuel
2016/06/08 17:04:19
Done.
| |
| 217 case FilterOperation::DROP_SHADOW: | |
| 218 EXPECT_EQ(input.amount(), output.amount()); | |
| 219 EXPECT_EQ(input.drop_shadow_offset(), output.drop_shadow_offset()); | |
| 220 EXPECT_EQ(input.drop_shadow_color(), output.drop_shadow_color()); | |
| 221 continue; | |
| 222 case FilterOperation::COLOR_MATRIX: | |
| 223 EXPECT_EQ(0, memcmp(input.matrix(), output.matrix(), 20)); | |
| 224 continue; | |
| 225 case FilterOperation::ZOOM: | |
| 226 EXPECT_EQ(input.amount(), output.amount()); | |
| 227 EXPECT_EQ(input.zoom_inset(), output.zoom_inset()); | |
| 228 continue; | |
| 229 case FilterOperation::REFERENCE: { | |
| 230 SkString input_str; | |
| 231 input.image_filter()->toString(&input_str); | |
| 232 SkString output_str; | |
| 233 output.image_filter()->toString(&output_str); | |
| 234 EXPECT_EQ(input_str, output_str); | |
| 235 continue; | |
| 236 } | |
| 237 case FilterOperation::ALPHA_THRESHOLD: | |
| 238 NOTREACHED(); | |
| 239 continue; | |
| 240 } | |
| 241 } | |
| 242 } | |
| 243 | |
| 181 TEST_F(StructTraitsTest, RenderPassId) { | 244 TEST_F(StructTraitsTest, RenderPassId) { |
| 182 const int layer_id = 1337; | 245 const int layer_id = 1337; |
| 183 const uint32_t index = 0xdeadbeef; | 246 const uint32_t index = 0xdeadbeef; |
| 184 RenderPassId input(layer_id, index); | 247 RenderPassId input(layer_id, index); |
| 185 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 248 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 186 RenderPassId output; | 249 RenderPassId output; |
| 187 proxy->EchoRenderPassId(input, &output); | 250 proxy->EchoRenderPassId(input, &output); |
| 188 EXPECT_EQ(layer_id, output.layer_id); | 251 EXPECT_EQ(layer_id, output.layer_id); |
| 189 EXPECT_EQ(index, output.index); | 252 EXPECT_EQ(index, output.index); |
| 190 } | 253 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 EXPECT_EQ(mailbox_holder.sync_token, output.mailbox_holder.sync_token); | 391 EXPECT_EQ(mailbox_holder.sync_token, output.mailbox_holder.sync_token); |
| 329 EXPECT_EQ(mailbox_holder.texture_target, | 392 EXPECT_EQ(mailbox_holder.texture_target, |
| 330 output.mailbox_holder.texture_target); | 393 output.mailbox_holder.texture_target); |
| 331 EXPECT_EQ(read_lock_fences_enabled, output.read_lock_fences_enabled); | 394 EXPECT_EQ(read_lock_fences_enabled, output.read_lock_fences_enabled); |
| 332 EXPECT_EQ(is_software, output.is_software); | 395 EXPECT_EQ(is_software, output.is_software); |
| 333 EXPECT_EQ(gpu_memory_buffer_id, output.gpu_memory_buffer_id.id); | 396 EXPECT_EQ(gpu_memory_buffer_id, output.gpu_memory_buffer_id.id); |
| 334 EXPECT_EQ(is_overlay_candidate, output.is_overlay_candidate); | 397 EXPECT_EQ(is_overlay_candidate, output.is_overlay_candidate); |
| 335 } | 398 } |
| 336 | 399 |
| 337 } // namespace cc | 400 } // namespace cc |
| OLD | NEW |