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

Side by Side Diff: cc/test/fake_compositor_frame_sink.cc

Issue 2404993002: cc: Stop calling DetachFromClient if bind failed. (Closed)
Patch Set: detachinternal: rebase Created 4 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/test/fake_compositor_frame_sink.h" 5 #include "cc/test/fake_compositor_frame_sink.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "cc/output/compositor_frame_sink_client.h" 9 #include "cc/output/compositor_frame_sink_client.h"
10 #include "cc/resources/returned_resource.h" 10 #include "cc/resources/returned_resource.h"
11 #include "cc/test/begin_frame_args_test.h" 11 #include "cc/test/begin_frame_args_test.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace cc { 14 namespace cc {
15 15
16 FakeCompositorFrameSink::FakeCompositorFrameSink( 16 FakeCompositorFrameSink::FakeCompositorFrameSink(
17 scoped_refptr<ContextProvider> context_provider, 17 scoped_refptr<ContextProvider> context_provider,
18 scoped_refptr<ContextProvider> worker_context_provider) 18 scoped_refptr<ContextProvider> worker_context_provider)
19 : CompositorFrameSink(std::move(context_provider), 19 : CompositorFrameSink(std::move(context_provider),
20 std::move(worker_context_provider)), 20 std::move(worker_context_provider)),
21 weak_ptr_factory_(this) {} 21 weak_ptr_factory_(this) {}
22 22
23 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default; 23 FakeCompositorFrameSink::~FakeCompositorFrameSink() = default;
24 24
25 void FakeCompositorFrameSink::DetachFromClient() {
26 ReturnResourcesHeldByParent();
27 CompositorFrameSink::DetachFromClient();
28 }
29
25 void FakeCompositorFrameSink::SwapBuffers(CompositorFrame frame) { 30 void FakeCompositorFrameSink::SwapBuffers(CompositorFrame frame) {
26 ReturnResourcesHeldByParent(); 31 ReturnResourcesHeldByParent();
27 32
28 last_sent_frame_.reset(new CompositorFrame(std::move(frame))); 33 last_sent_frame_.reset(new CompositorFrame(std::move(frame)));
29 ++num_sent_frames_; 34 ++num_sent_frames_;
30 35
31 if (last_sent_frame_->delegated_frame_data) { 36 if (last_sent_frame_->delegated_frame_data) {
32 auto* frame_data = last_sent_frame_->delegated_frame_data.get(); 37 auto* frame_data = last_sent_frame_->delegated_frame_data.get();
33 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect; 38 last_swap_rect_ = frame_data->render_pass_list.back()->damage_rect;
34 last_swap_rect_valid_ = true; 39 last_swap_rect_valid_ = true;
(...skipping 13 matching lines...) Expand all
48 53
49 base::ThreadTaskRunnerHandle::Get()->PostTask( 54 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE, base::Bind(&FakeCompositorFrameSink::SwapBuffersAck, 55 FROM_HERE, base::Bind(&FakeCompositorFrameSink::SwapBuffersAck,
51 weak_ptr_factory_.GetWeakPtr())); 56 weak_ptr_factory_.GetWeakPtr()));
52 } 57 }
53 58
54 void FakeCompositorFrameSink::SwapBuffersAck() { 59 void FakeCompositorFrameSink::SwapBuffersAck() {
55 client_->DidSwapBuffersComplete(); 60 client_->DidSwapBuffersComplete();
56 } 61 }
57 62
58 bool FakeCompositorFrameSink::BindToClient(CompositorFrameSinkClient* client) {
59 if (CompositorFrameSink::BindToClient(client)) {
60 client_ = client;
61 return true;
62 } else {
63 return false;
64 }
65 }
66
67 void FakeCompositorFrameSink::DetachFromClient() {
68 ReturnResourcesHeldByParent();
69 CompositorFrameSink::DetachFromClient();
70 }
71
72 void FakeCompositorFrameSink::ReturnResourcesHeldByParent() { 63 void FakeCompositorFrameSink::ReturnResourcesHeldByParent() {
73 // Check |delegated_frame_data| because we shouldn't reclaim resources 64 // Check |delegated_frame_data| because we shouldn't reclaim resources
74 // for the Display which does not swap delegated frames. 65 // for the Display which does not swap delegated frames.
75 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) { 66 if (last_sent_frame_ && last_sent_frame_->delegated_frame_data) {
76 // Return the last frame's resources immediately. 67 // Return the last frame's resources immediately.
77 ReturnedResourceArray resources; 68 ReturnedResourceArray resources;
78 for (const auto& resource : resources_held_by_parent_) 69 for (const auto& resource : resources_held_by_parent_)
79 resources.push_back(resource.ToReturnedResource()); 70 resources.push_back(resource.ToReturnedResource());
80 resources_held_by_parent_.clear(); 71 resources_held_by_parent_.clear();
81 client_->ReclaimResources(resources); 72 client_->ReclaimResources(resources);
82 } 73 }
83 } 74 }
84 75
85 } // namespace cc 76 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/fake_compositor_frame_sink.h ('k') | content/renderer/android/synchronous_compositor_frame_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698