Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp

Issue 1956853002: [SPv2] Build trivial cc property trees in PaintArtifactCompositor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix DCHECK in unit tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "platform/graphics/compositing/PaintArtifactCompositor.h" 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h"
6 6
7 #include "base/test/test_simple_task_runner.h"
8 #include "base/thread_task_runner_handle.h"
7 #include "cc/layers/layer.h" 9 #include "cc/layers/layer.h"
10 #include "cc/test/fake_output_surface.h"
11 #include "cc/trees/layer_tree_host.h"
12 #include "cc/trees/layer_tree_settings.h"
8 #include "platform/RuntimeEnabledFeatures.h" 13 #include "platform/RuntimeEnabledFeatures.h"
9 #include "platform/graphics/paint/PaintArtifact.h" 14 #include "platform/graphics/paint/PaintArtifact.h"
10 #include "platform/testing/PictureMatchers.h" 15 #include "platform/testing/PictureMatchers.h"
11 #include "platform/testing/TestPaintArtifact.h" 16 #include "platform/testing/TestPaintArtifact.h"
17 #include "platform/testing/WebLayerTreeViewImplForTesting.h"
12 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
14 20
15 namespace blink { 21 namespace blink {
16 namespace { 22 namespace {
17 23
18 using ::testing::Pointee; 24 using ::testing::Pointee;
19 25
20 gfx::Transform translation(SkMScalar x, SkMScalar y) 26 gfx::Transform translation(SkMScalar x, SkMScalar y)
21 { 27 {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 artifact.chunk(PaintChunkProperties()) 348 artifact.chunk(PaintChunkProperties())
343 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); 349 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer);
344 update(artifact.build()); 350 update(artifact.build());
345 351
346 ASSERT_EQ(1u, rootLayer()->children().size()); 352 ASSERT_EQ(1u, rootLayer()->children().size());
347 EXPECT_EQ(layer, rootLayer()->child_at(0)); 353 EXPECT_EQ(layer, rootLayer()->child_at(0));
348 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); 354 EXPECT_EQ(gfx::Size(400, 300), layer->bounds());
349 EXPECT_EQ(translation(50, 100), layer->transform()); 355 EXPECT_EQ(translation(50, 100), layer->transform());
350 } 356 }
351 357
358 // Similar to the above, but for the path where we build cc property trees
359 // directly. This will eventually supersede the above.
360
361 class WebLayerTreeViewWithOutputSurface : public WebLayerTreeViewImplForTesting {
362 public:
363 WebLayerTreeViewWithOutputSurface(const cc::LayerTreeSettings& settings)
364 : WebLayerTreeViewImplForTesting(settings) {}
365
366 // cc::LayerTreeHostClient
367 void RequestNewOutputSurface() override
368 {
369 layerTreeHost()->SetOutputSurface(cc::FakeOutputSurface::CreateDelegatin g3d());
370 }
371 };
372
373 class PaintArtifactCompositorTestWithPropertyTrees : public PaintArtifactComposi torTest {
374 protected:
375 PaintArtifactCompositorTestWithPropertyTrees()
376 : m_taskRunner(new base::TestSimpleTaskRunner)
377 , m_taskRunnerHandle(m_taskRunner)
378 {
379 }
380
381 void SetUp() override
382 {
383 PaintArtifactCompositorTest::SetUp();
384
385 cc::LayerTreeSettings settings = WebLayerTreeViewImplForTesting::default LayerTreeSettings();
386 settings.single_thread_proxy_scheduler = false;
387 settings.use_layer_lists = true;
388 m_webLayerTreeView = adoptPtr(new WebLayerTreeViewWithOutputSurface(sett ings));
389 m_webLayerTreeView->setRootLayer(*getPaintArtifactCompositor().getWebLay er());
390 }
391
392 const cc::PropertyTrees& propertyTrees()
393 {
394 return *m_webLayerTreeView->layerTreeHost()->property_trees();
395 }
396
397 void update(const PaintArtifact& artifact)
398 {
399 PaintArtifactCompositorTest::update(artifact);
400 m_webLayerTreeView->layerTreeHost()->LayoutAndUpdateLayers();
401 }
402
403 private:
404 scoped_refptr<base::TestSimpleTaskRunner> m_taskRunner;
405 base::ThreadTaskRunnerHandle m_taskRunnerHandle;
406 OwnPtr<WebLayerTreeViewWithOutputSurface> m_webLayerTreeView;
407 };
408
409 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EmptyPaintArtifact)
410 {
411 PaintArtifact emptyArtifact;
412 update(emptyArtifact);
413 EXPECT_TRUE(rootLayer()->children().empty());
414 }
415
416 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset)
417 {
418 TestPaintArtifact artifact;
419 artifact.chunk(PaintChunkProperties())
420 .rectDrawing(FloatRect(50, -50, 100, 100), Color::white);
421 update(artifact.build());
422
423 ASSERT_EQ(1u, rootLayer()->children().size());
424 const cc::Layer* child = rootLayer()->child_at(0);
425 EXPECT_THAT(child->GetPicture(),
426 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white)));
427 EXPECT_EQ(translation(50, -50), child->screen_space_transform());
428 EXPECT_EQ(gfx::Size(100, 100), child->bounds());
429 }
430
352 } // namespace 431 } // namespace
353 } // namespace blink 432 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698