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

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 634083002: gpu: Compositor management of GpuMemoryBuffer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cc-pre-chromium-image-refactor
Patch Set: rebase Created 6 years, 2 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 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "cc/test/fake_output_surface.h" 44 #include "cc/test/fake_output_surface.h"
45 #include "cc/test/fake_output_surface_client.h" 45 #include "cc/test/fake_output_surface_client.h"
46 #include "cc/test/fake_picture_layer_impl.h" 46 #include "cc/test/fake_picture_layer_impl.h"
47 #include "cc/test/fake_picture_pile_impl.h" 47 #include "cc/test/fake_picture_pile_impl.h"
48 #include "cc/test/fake_proxy.h" 48 #include "cc/test/fake_proxy.h"
49 #include "cc/test/fake_rendering_stats_instrumentation.h" 49 #include "cc/test/fake_rendering_stats_instrumentation.h"
50 #include "cc/test/fake_video_frame_provider.h" 50 #include "cc/test/fake_video_frame_provider.h"
51 #include "cc/test/geometry_test_utils.h" 51 #include "cc/test/geometry_test_utils.h"
52 #include "cc/test/layer_test_common.h" 52 #include "cc/test/layer_test_common.h"
53 #include "cc/test/render_pass_test_common.h" 53 #include "cc/test/render_pass_test_common.h"
54 #include "cc/test/test_gpu_memory_buffer_manager.h"
54 #include "cc/test/test_shared_bitmap_manager.h" 55 #include "cc/test/test_shared_bitmap_manager.h"
55 #include "cc/test/test_web_graphics_context_3d.h" 56 #include "cc/test/test_web_graphics_context_3d.h"
56 #include "cc/trees/layer_tree_impl.h" 57 #include "cc/trees/layer_tree_impl.h"
57 #include "cc/trees/single_thread_proxy.h" 58 #include "cc/trees/single_thread_proxy.h"
58 #include "media/base/media.h" 59 #include "media/base/media.h"
59 #include "testing/gmock/include/gmock/gmock.h" 60 #include "testing/gmock/include/gmock/gmock.h"
60 #include "testing/gtest/include/gtest/gtest.h" 61 #include "testing/gtest/include/gtest/gtest.h"
61 #include "third_party/skia/include/core/SkMallocPixelRef.h" 62 #include "third_party/skia/include/core/SkMallocPixelRef.h"
62 #include "ui/gfx/frame_time.h" 63 #include "ui/gfx/frame_time.h"
63 #include "ui/gfx/rect_conversions.h" 64 #include "ui/gfx/rect_conversions.h"
(...skipping 11 matching lines...) Expand all
75 namespace { 76 namespace {
76 77
77 class LayerTreeHostImplTest : public testing::Test, 78 class LayerTreeHostImplTest : public testing::Test,
78 public LayerTreeHostImplClient { 79 public LayerTreeHostImplClient {
79 public: 80 public:
80 LayerTreeHostImplTest() 81 LayerTreeHostImplTest()
81 : proxy_(base::MessageLoopProxy::current(), 82 : proxy_(base::MessageLoopProxy::current(),
82 base::MessageLoopProxy::current()), 83 base::MessageLoopProxy::current()),
83 always_impl_thread_(&proxy_), 84 always_impl_thread_(&proxy_),
84 always_main_thread_blocked_(&proxy_), 85 always_main_thread_blocked_(&proxy_),
85 shared_bitmap_manager_(new TestSharedBitmapManager()), 86 shared_bitmap_manager_(new TestSharedBitmapManager),
87 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager),
86 on_can_draw_state_changed_called_(false), 88 on_can_draw_state_changed_called_(false),
87 did_notify_ready_to_activate_(false), 89 did_notify_ready_to_activate_(false),
88 did_request_commit_(false), 90 did_request_commit_(false),
89 did_request_redraw_(false), 91 did_request_redraw_(false),
90 did_request_animate_(false), 92 did_request_animate_(false),
91 did_request_manage_tiles_(false), 93 did_request_manage_tiles_(false),
92 did_upload_visible_tile_(false), 94 did_upload_visible_tile_(false),
93 reduce_memory_result_(true), 95 reduce_memory_result_(true),
94 current_limit_bytes_(0), 96 current_limit_bytes_(0),
95 current_priority_cutoff_value_(0) { 97 current_priority_cutoff_value_(0) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 reduce_memory_result_ = reduce_memory_result; 170 reduce_memory_result_ = reduce_memory_result;
169 } 171 }
170 172
171 bool CreateHostImpl(const LayerTreeSettings& settings, 173 bool CreateHostImpl(const LayerTreeSettings& settings,
172 scoped_ptr<OutputSurface> output_surface) { 174 scoped_ptr<OutputSurface> output_surface) {
173 host_impl_ = LayerTreeHostImpl::Create(settings, 175 host_impl_ = LayerTreeHostImpl::Create(settings,
174 this, 176 this,
175 &proxy_, 177 &proxy_,
176 &stats_instrumentation_, 178 &stats_instrumentation_,
177 shared_bitmap_manager_.get(), 179 shared_bitmap_manager_.get(),
180 gpu_memory_buffer_manager_.get(),
178 0); 181 0);
179 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); 182 bool init = host_impl_->InitializeRenderer(output_surface.Pass());
180 host_impl_->SetViewportSize(gfx::Size(10, 10)); 183 host_impl_->SetViewportSize(gfx::Size(10, 10));
181 return init; 184 return init;
182 } 185 }
183 186
184 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { 187 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) {
185 root->SetPosition(gfx::PointF()); 188 root->SetPosition(gfx::PointF());
186 root->SetBounds(gfx::Size(10, 10)); 189 root->SetBounds(gfx::Size(10, 10));
187 root->SetContentBounds(gfx::Size(10, 10)); 190 root->SetContentBounds(gfx::Size(10, 10));
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 void DrawOneFrame() { 388 void DrawOneFrame() {
386 LayerTreeHostImpl::FrameData frame_data; 389 LayerTreeHostImpl::FrameData frame_data;
387 host_impl_->PrepareToDraw(&frame_data); 390 host_impl_->PrepareToDraw(&frame_data);
388 host_impl_->DidDrawAllLayers(frame_data); 391 host_impl_->DidDrawAllLayers(frame_data);
389 } 392 }
390 393
391 FakeProxy proxy_; 394 FakeProxy proxy_;
392 DebugScopedSetImplThread always_impl_thread_; 395 DebugScopedSetImplThread always_impl_thread_;
393 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; 396 DebugScopedSetMainThreadBlocked always_main_thread_blocked_;
394 397
395 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; 398 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
399 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
396 scoped_ptr<LayerTreeHostImpl> host_impl_; 400 scoped_ptr<LayerTreeHostImpl> host_impl_;
397 FakeRenderingStatsInstrumentation stats_instrumentation_; 401 FakeRenderingStatsInstrumentation stats_instrumentation_;
398 bool on_can_draw_state_changed_called_; 402 bool on_can_draw_state_changed_called_;
399 bool did_notify_ready_to_activate_; 403 bool did_notify_ready_to_activate_;
400 bool did_request_commit_; 404 bool did_request_commit_;
401 bool did_request_redraw_; 405 bool did_request_redraw_;
402 bool did_request_animate_; 406 bool did_request_animate_;
403 bool did_request_manage_tiles_; 407 bool did_request_manage_tiles_;
404 bool did_upload_visible_tile_; 408 bool did_upload_visible_tile_;
405 bool reduce_memory_result_; 409 bool reduce_memory_result_;
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 const LayerTreeSettings& settings, 1363 const LayerTreeSettings& settings,
1360 LayerTreeHostImplClient* client, 1364 LayerTreeHostImplClient* client,
1361 Proxy* proxy, 1365 Proxy* proxy,
1362 SharedBitmapManager* manager, 1366 SharedBitmapManager* manager,
1363 RenderingStatsInstrumentation* rendering_stats_instrumentation) 1367 RenderingStatsInstrumentation* rendering_stats_instrumentation)
1364 : LayerTreeHostImpl(settings, 1368 : LayerTreeHostImpl(settings,
1365 client, 1369 client,
1366 proxy, 1370 proxy,
1367 rendering_stats_instrumentation, 1371 rendering_stats_instrumentation,
1368 manager, 1372 manager,
1373 NULL,
1369 0) {} 1374 0) {}
1370 1375
1371 virtual BeginFrameArgs CurrentBeginFrameArgs() const override { 1376 virtual BeginFrameArgs CurrentBeginFrameArgs() const override {
1372 return CreateBeginFrameArgsForTesting(fake_current_physical_time_); 1377 return CreateBeginFrameArgsForTesting(fake_current_physical_time_);
1373 } 1378 }
1374 1379
1375 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { 1380 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) {
1376 fake_current_physical_time_ = fake_now; 1381 fake_current_physical_time_ = fake_now;
1377 } 1382 }
1378 1383
(...skipping 3024 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 LayerTreeSettings settings; 4408 LayerTreeSettings settings;
4404 settings.partial_swap_enabled = true; 4409 settings.partial_swap_enabled = true;
4405 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( 4410 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
4406 new TestSharedBitmapManager()); 4411 new TestSharedBitmapManager());
4407 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = 4412 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl =
4408 LayerTreeHostImpl::Create(settings, 4413 LayerTreeHostImpl::Create(settings,
4409 this, 4414 this,
4410 &proxy_, 4415 &proxy_,
4411 &stats_instrumentation_, 4416 &stats_instrumentation_,
4412 shared_bitmap_manager.get(), 4417 shared_bitmap_manager.get(),
4418 NULL,
4413 0); 4419 0);
4414 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); 4420 layer_tree_host_impl->InitializeRenderer(output_surface.Pass());
4415 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); 4421 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500));
4416 4422
4417 scoped_ptr<LayerImpl> root = 4423 scoped_ptr<LayerImpl> root =
4418 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); 4424 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1);
4419 scoped_ptr<LayerImpl> child = 4425 scoped_ptr<LayerImpl> child =
4420 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); 4426 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2);
4421 child->SetPosition(gfx::PointF(12.f, 13.f)); 4427 child->SetPosition(gfx::PointF(12.f, 13.f));
4422 child->SetBounds(gfx::Size(14, 15)); 4428 child->SetBounds(gfx::Size(14, 15));
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
4692 RenderingStatsInstrumentation* stats_instrumentation) { 4698 RenderingStatsInstrumentation* stats_instrumentation) {
4693 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 4699 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create());
4694 scoped_ptr<OutputSurface> output_surface( 4700 scoped_ptr<OutputSurface> output_surface(
4695 FakeOutputSurface::Create3d(provider)); 4701 FakeOutputSurface::Create3d(provider));
4696 provider->BindToCurrentThread(); 4702 provider->BindToCurrentThread();
4697 provider->TestContext3d()->set_have_post_sub_buffer(true); 4703 provider->TestContext3d()->set_have_post_sub_buffer(true);
4698 4704
4699 LayerTreeSettings settings; 4705 LayerTreeSettings settings;
4700 settings.partial_swap_enabled = partial_swap; 4706 settings.partial_swap_enabled = partial_swap;
4701 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( 4707 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create(
4702 settings, client, proxy, stats_instrumentation, manager, 0); 4708 settings, client, proxy, stats_instrumentation, manager, NULL, 0);
4703 my_host_impl->InitializeRenderer(output_surface.Pass()); 4709 my_host_impl->InitializeRenderer(output_surface.Pass());
4704 my_host_impl->SetViewportSize(gfx::Size(100, 100)); 4710 my_host_impl->SetViewportSize(gfx::Size(100, 100));
4705 4711
4706 /* 4712 /*
4707 Layers are created as follows: 4713 Layers are created as follows:
4708 4714
4709 +--------------------+ 4715 +--------------------+
4710 | 1 | 4716 | 1 |
4711 | +-----------+ | 4717 | +-----------+ |
4712 | | 2 | | 4718 | | 2 | |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
5976 5982
5977 // Checks that we have a non-0 default allocation if we pass a context that 5983 // Checks that we have a non-0 default allocation if we pass a context that
5978 // doesn't support memory management extensions. 5984 // doesn't support memory management extensions.
5979 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { 5985 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) {
5980 LayerTreeSettings settings; 5986 LayerTreeSettings settings;
5981 host_impl_ = LayerTreeHostImpl::Create(settings, 5987 host_impl_ = LayerTreeHostImpl::Create(settings,
5982 this, 5988 this,
5983 &proxy_, 5989 &proxy_,
5984 &stats_instrumentation_, 5990 &stats_instrumentation_,
5985 shared_bitmap_manager_.get(), 5991 shared_bitmap_manager_.get(),
5992 gpu_memory_buffer_manager_.get(),
5986 0); 5993 0);
5987 5994
5988 scoped_ptr<OutputSurface> output_surface( 5995 scoped_ptr<OutputSurface> output_surface(
5989 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); 5996 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create()));
5990 host_impl_->InitializeRenderer(output_surface.Pass()); 5997 host_impl_->InitializeRenderer(output_surface.Pass());
5991 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); 5998 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes());
5992 } 5999 }
5993 6000
5994 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { 6001 TEST_F(LayerTreeHostImplTest, MemoryPolicy) {
5995 ManagedMemoryPolicy policy1( 6002 ManagedMemoryPolicy policy1(
(...skipping 21 matching lines...) Expand all
6017 6024
6018 host_impl_->SetVisible(true); 6025 host_impl_->SetVisible(true);
6019 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 6026 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
6020 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); 6027 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_);
6021 6028
6022 // Now enable GPU rasterization and test if we get nice to have cutoff, 6029 // Now enable GPU rasterization and test if we get nice to have cutoff,
6023 // when visible. 6030 // when visible.
6024 LayerTreeSettings settings; 6031 LayerTreeSettings settings;
6025 settings.gpu_rasterization_enabled = true; 6032 settings.gpu_rasterization_enabled = true;
6026 host_impl_ = LayerTreeHostImpl::Create( 6033 host_impl_ = LayerTreeHostImpl::Create(
6027 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); 6034 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, 0);
6028 host_impl_->SetUseGpuRasterization(true); 6035 host_impl_->SetUseGpuRasterization(true);
6029 host_impl_->SetVisible(true); 6036 host_impl_->SetVisible(true);
6030 host_impl_->SetMemoryPolicy(policy1); 6037 host_impl_->SetMemoryPolicy(policy1);
6031 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 6038 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
6032 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); 6039 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_);
6033 6040
6034 host_impl_->SetVisible(false); 6041 host_impl_->SetVisible(false);
6035 EXPECT_EQ(0u, current_limit_bytes_); 6042 EXPECT_EQ(0u, current_limit_bytes_);
6036 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); 6043 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_);
6037 } 6044 }
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
7267 // surface. 7274 // surface.
7268 EXPECT_EQ(0, num_lost_surfaces_); 7275 EXPECT_EQ(0, num_lost_surfaces_);
7269 host_impl_->DidLoseOutputSurface(); 7276 host_impl_->DidLoseOutputSurface();
7270 EXPECT_EQ(1, num_lost_surfaces_); 7277 EXPECT_EQ(1, num_lost_surfaces_);
7271 host_impl_->DidLoseOutputSurface(); 7278 host_impl_->DidLoseOutputSurface();
7272 EXPECT_LE(1, num_lost_surfaces_); 7279 EXPECT_LE(1, num_lost_surfaces_);
7273 } 7280 }
7274 7281
7275 } // namespace 7282 } // namespace
7276 } // namespace cc 7283 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698