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

Side by Side Diff: content/browser/renderer_host/compositor_impl_android.cc

Issue 2716193002: android: Add draw completion for CompositorView (Closed)
Patch Set: another fix, doing a bad job rebasing here.. Created 3 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/renderer_host/compositor_impl_android.h" 5 #include "content/browser/renderer_host/compositor_impl_android.h"
6 6
7 #include <android/bitmap.h> 7 #include <android/bitmap.h>
8 #include <android/native_window_jni.h> 8 #include <android/native_window_jni.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <unordered_set> 10 #include <unordered_set>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 attributes.red_size = 5; 179 attributes.red_size = 5;
180 attributes.green_size = 6; 180 attributes.green_size = 6;
181 attributes.blue_size = 5; 181 attributes.blue_size = 5;
182 } 182 }
183 183
184 return attributes; 184 return attributes;
185 } 185 }
186 186
187 class AndroidOutputSurface : public cc::OutputSurface { 187 class AndroidOutputSurface : public cc::OutputSurface {
188 public: 188 public:
189 explicit AndroidOutputSurface( 189 AndroidOutputSurface(
190 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider) 190 scoped_refptr<ui::ContextProviderCommandBuffer> context_provider,
191 base::Closure swap_buffers_callback)
191 : cc::OutputSurface(std::move(context_provider)), 192 : cc::OutputSurface(std::move(context_provider)),
193 swap_buffers_callback_(std::move(swap_buffers_callback)),
192 overlay_candidate_validator_( 194 overlay_candidate_validator_(
193 new display_compositor:: 195 new display_compositor::
194 CompositorOverlayCandidateValidatorAndroid()), 196 CompositorOverlayCandidateValidatorAndroid()),
195 weak_ptr_factory_(this) { 197 weak_ptr_factory_(this) {
196 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers; 198 capabilities_.max_frames_pending = kMaxDisplaySwapBuffers;
197 } 199 }
198 200
199 ~AndroidOutputSurface() override = default; 201 ~AndroidOutputSurface() override = default;
200 202
201 void SwapBuffers(cc::OutputSurfaceFrame frame) override { 203 void SwapBuffers(cc::OutputSurfaceFrame frame) override {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 DCHECK(command_buffer_proxy); 263 DCHECK(command_buffer_proxy);
262 return command_buffer_proxy; 264 return command_buffer_proxy;
263 } 265 }
264 266
265 void OnSwapBuffersCompleted( 267 void OnSwapBuffersCompleted(
266 const std::vector<ui::LatencyInfo>& latency_info, 268 const std::vector<ui::LatencyInfo>& latency_info,
267 gfx::SwapResult result, 269 gfx::SwapResult result,
268 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) { 270 const gpu::GpuProcessHostedCALayerTreeParamsMac* params_mac) {
269 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); 271 RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
270 client_->DidReceiveSwapBuffersAck(); 272 client_->DidReceiveSwapBuffersAck();
273 swap_buffers_callback_.Run();
271 } 274 }
272 275
273 private: 276 private:
274 cc::OutputSurfaceClient* client_ = nullptr; 277 cc::OutputSurfaceClient* client_ = nullptr;
278 base::Closure swap_buffers_callback_;
275 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_; 279 std::unique_ptr<cc::OverlayCandidateValidator> overlay_candidate_validator_;
276 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_; 280 base::WeakPtrFactory<AndroidOutputSurface> weak_ptr_factory_;
277 }; 281 };
278 282
279 #if defined(ENABLE_VULKAN) 283 #if defined(ENABLE_VULKAN)
280 class VulkanOutputSurface : public cc::OutputSurface { 284 class VulkanOutputSurface : public cc::OutputSurface {
281 public: 285 public:
282 explicit VulkanOutputSurface( 286 explicit VulkanOutputSurface(
283 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, 287 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
284 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 288 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 GetCompositorContextAttributes(has_transparent_background_), 679 GetCompositorContextAttributes(has_transparent_background_),
676 shared_context, 680 shared_context,
677 ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT); 681 ui::command_buffer_metrics::DISPLAY_COMPOSITOR_ONSCREEN_CONTEXT);
678 if (!context_provider->BindToCurrentThread()) { 682 if (!context_provider->BindToCurrentThread()) {
679 LOG(ERROR) << "Failed to init ContextProvider for compositor."; 683 LOG(ERROR) << "Failed to init ContextProvider for compositor.";
680 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2) 684 LOG_IF(FATAL, ++num_successive_context_creation_failures_ >= 2)
681 << "Too many context creation failures. Giving up... "; 685 << "Too many context creation failures. Giving up... ";
682 HandlePendingCompositorFrameSinkRequest(); 686 HandlePendingCompositorFrameSinkRequest();
683 } 687 }
684 688
685 auto display_output_surface = 689 // Unretained is safe this owns cc::Display which owns OutputSurface.
686 base::MakeUnique<AndroidOutputSurface>(context_provider); 690 InitializeDisplay(
687 InitializeDisplay(std::move(display_output_surface), nullptr, 691 base::MakeUnique<AndroidOutputSurface>(
688 std::move(context_provider)); 692 context_provider,
boliu 2017/03/09 20:24:09 ahh, for anyone wondering why this is x86 crash on
Peter Wen 2017/03/13 14:07:55 Thanks for getting to the root of this bug and the
693 base::Bind(&CompositorImpl::DidSwapBuffers, base::Unretained(this))),
694 nullptr, std::move(context_provider));
689 } 695 }
690 696
691 void CompositorImpl::InitializeDisplay( 697 void CompositorImpl::InitializeDisplay(
692 std::unique_ptr<cc::OutputSurface> display_output_surface, 698 std::unique_ptr<cc::OutputSurface> display_output_surface,
693 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider, 699 scoped_refptr<cc::VulkanContextProvider> vulkan_context_provider,
694 scoped_refptr<cc::ContextProvider> context_provider) { 700 scoped_refptr<cc::ContextProvider> context_provider) {
695 DCHECK(compositor_frame_sink_request_pending_); 701 DCHECK(compositor_frame_sink_request_pending_);
696 702
697 pending_frames_ = 0; 703 pending_frames_ = 0;
698 num_successive_context_creation_failures_ = 0; 704 num_successive_context_creation_failures_ = 0;
(...skipping 25 matching lines...) Expand all
724 : base::MakeUnique<cc::DirectCompositorFrameSink>( 730 : base::MakeUnique<cc::DirectCompositorFrameSink>(
725 frame_sink_id_, manager, display_.get(), context_provider, 731 frame_sink_id_, manager, display_.get(), context_provider,
726 nullptr, BrowserGpuMemoryBufferManager::current(), 732 nullptr, BrowserGpuMemoryBufferManager::current(),
727 HostSharedBitmapManager::current()); 733 HostSharedBitmapManager::current());
728 734
729 display_->SetVisible(true); 735 display_->SetVisible(true);
730 display_->Resize(size_); 736 display_->Resize(size_);
731 host_->SetCompositorFrameSink(std::move(compositor_frame_sink)); 737 host_->SetCompositorFrameSink(std::move(compositor_frame_sink));
732 } 738 }
733 739
740 void CompositorImpl::DidSwapBuffers() {
741 client_->DidSwapBuffers();
742 }
743
734 cc::UIResourceId CompositorImpl::CreateUIResource( 744 cc::UIResourceId CompositorImpl::CreateUIResource(
735 cc::UIResourceClient* client) { 745 cc::UIResourceClient* client) {
736 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource"); 746 TRACE_EVENT0("compositor", "CompositorImpl::CreateUIResource");
737 return host_->GetUIResourceManager()->CreateUIResource(client); 747 return host_->GetUIResourceManager()->CreateUIResource(client);
738 } 748 }
739 749
740 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) { 750 void CompositorImpl::DeleteUIResource(cc::UIResourceId resource_id) {
741 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource"); 751 TRACE_EVENT0("compositor", "CompositorImpl::DeleteUIResource");
742 host_->GetUIResourceManager()->DeleteUIResource(resource_id); 752 host_->GetUIResourceManager()->DeleteUIResource(resource_id);
743 } 753 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 } 818 }
809 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_, 819 GetSurfaceManager()->UnregisterFrameSinkHierarchy(frame_sink_id_,
810 frame_sink_id); 820 frame_sink_id);
811 } 821 }
812 822
813 bool CompositorImpl::HavePendingReadbacks() { 823 bool CompositorImpl::HavePendingReadbacks() {
814 return !readback_layer_tree_->children().empty(); 824 return !readback_layer_tree_->children().empty();
815 } 825 }
816 826
817 } // namespace content 827 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698