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

Side by Side Diff: android_webview/browser/hardware_renderer.cc

Issue 2383373002: Reduce SurfaceIdAllocator usage and tie SurfaceFactory to a single FrameSinkId (Closed)
Patch Set: Rebased 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "android_webview/browser/hardware_renderer.h" 5 #include "android_webview/browser/hardware_renderer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/aw_gl_surface.h" 9 #include "android_webview/browser/aw_gl_surface.h"
10 #include "android_webview/browser/aw_render_thread_context_provider.h" 10 #include "android_webview/browser/aw_render_thread_context_provider.h"
11 #include "android_webview/browser/child_frame.h" 11 #include "android_webview/browser/child_frame.h"
12 #include "android_webview/browser/parent_compositor_draw_constraints.h" 12 #include "android_webview/browser/parent_compositor_draw_constraints.h"
13 #include "android_webview/browser/render_thread_manager.h" 13 #include "android_webview/browser/render_thread_manager.h"
14 #include "android_webview/browser/surfaces_instance.h" 14 #include "android_webview/browser/surfaces_instance.h"
15 #include "android_webview/public/browser/draw_gl.h" 15 #include "android_webview/public/browser/draw_gl.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
17 #include "cc/output/compositor_frame.h" 18 #include "cc/output/compositor_frame.h"
18 #include "cc/surfaces/surface_factory.h" 19 #include "cc/surfaces/surface_factory.h"
19 #include "cc/surfaces/surface_id_allocator.h" 20 #include "cc/surfaces/surface_id_allocator.h"
20 #include "cc/surfaces/surface_manager.h" 21 #include "cc/surfaces/surface_manager.h"
21 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
22 #include "ui/gl/gl_bindings.h" 23 #include "ui/gl/gl_bindings.h"
23 24
24 namespace android_webview { 25 namespace android_webview {
25 26
26 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) 27 HardwareRenderer::HardwareRenderer(RenderThreadManager* state)
27 : render_thread_manager_(state), 28 : render_thread_manager_(state),
28 last_egl_context_(eglGetCurrentContext()), 29 last_egl_context_(eglGetCurrentContext()),
29 surfaces_(SurfacesInstance::GetOrCreateInstance()), 30 surfaces_(SurfacesInstance::GetOrCreateInstance()),
31 frame_sink_id_(surfaces_->AllocateFrameSinkId()),
30 surface_id_allocator_( 32 surface_id_allocator_(
31 new cc::SurfaceIdAllocator(surfaces_->AllocateFrameSinkId())), 33 base::MakeUnique<cc::SurfaceIdAllocator>(frame_sink_id_)),
32 last_committed_compositor_frame_sink_id_(0u), 34 last_committed_compositor_frame_sink_id_(0u),
33 last_submitted_compositor_frame_sink_id_(0u) { 35 last_submitted_compositor_frame_sink_id_(0u) {
34 DCHECK(last_egl_context_); 36 DCHECK(last_egl_context_);
35 surfaces_->GetSurfaceManager()->RegisterFrameSinkId( 37 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_);
36 surface_id_allocator_->frame_sink_id()); 38 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_,
37 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient( 39 this);
38 surface_id_allocator_->frame_sink_id(), this);
39 } 40 }
40 41
41 HardwareRenderer::~HardwareRenderer() { 42 HardwareRenderer::~HardwareRenderer() {
42 // Must reset everything before |surface_factory_| to ensure all 43 // Must reset everything before |surface_factory_| to ensure all
43 // resources are returned before resetting. 44 // resources are returned before resetting.
44 if (!child_id_.is_null()) 45 if (!child_id_.is_null())
45 DestroySurface(); 46 DestroySurface();
46 surface_factory_.reset(); 47 surface_factory_.reset();
47 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient( 48 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient(
48 surface_id_allocator_->frame_sink_id()); 49 frame_sink_id_);
49 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId( 50 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_);
50 surface_id_allocator_->frame_sink_id());
51 51
52 // Reset draw constraints. 52 // Reset draw constraints.
53 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( 53 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT(
54 ParentCompositorDrawConstraints()); 54 ParentCompositorDrawConstraints());
55 ReturnResourcesInChildFrame(); 55 ReturnResourcesInChildFrame();
56 } 56 }
57 57
58 void HardwareRenderer::CommitFrame() { 58 void HardwareRenderer::CommitFrame() {
59 TRACE_EVENT0("android_webview", "CommitFrame"); 59 TRACE_EVENT0("android_webview", "CommitFrame");
60 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT(); 60 scroll_offset_ = render_thread_manager_->GetScrollOffsetOnRT();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 last_submitted_compositor_frame_sink_id_ != 92 last_submitted_compositor_frame_sink_id_ !=
93 child_frame_->compositor_frame_sink_id) { 93 child_frame_->compositor_frame_sink_id) {
94 if (!child_id_.is_null()) 94 if (!child_id_.is_null())
95 DestroySurface(); 95 DestroySurface();
96 96
97 // This will return all the resources to the previous compositor. 97 // This will return all the resources to the previous compositor.
98 surface_factory_.reset(); 98 surface_factory_.reset();
99 compositor_id_ = child_frame_->compositor_id; 99 compositor_id_ = child_frame_->compositor_id;
100 last_submitted_compositor_frame_sink_id_ = 100 last_submitted_compositor_frame_sink_id_ =
101 child_frame_->compositor_frame_sink_id; 101 child_frame_->compositor_frame_sink_id;
102 surface_factory_.reset( 102 surface_factory_.reset(new cc::SurfaceFactory(
103 new cc::SurfaceFactory(surfaces_->GetSurfaceManager(), this)); 103 frame_sink_id_, surfaces_->GetSurfaceManager(), this));
104 } 104 }
105 105
106 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = 106 std::unique_ptr<cc::CompositorFrame> child_compositor_frame =
107 std::move(child_frame_->frame); 107 std::move(child_frame_->frame);
108 108
109 gfx::Size frame_size = 109 gfx::Size frame_size =
110 child_compositor_frame->delegated_frame_data->render_pass_list.back() 110 child_compositor_frame->delegated_frame_data->render_pass_list.back()
111 ->output_rect.size(); 111 ->output_rect.size();
112 bool size_changed = frame_size != frame_size_; 112 bool size_changed = frame_size != frame_size_;
113 frame_size_ = frame_size; 113 frame_size_ = frame_size;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 const cc::ReturnedResourceArray& resources, 193 const cc::ReturnedResourceArray& resources,
194 const CompositorID& compositor_id, 194 const CompositorID& compositor_id,
195 uint32_t compositor_frame_sink_id) { 195 uint32_t compositor_frame_sink_id) {
196 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) 196 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_)
197 return; 197 return;
198 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, 198 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id,
199 compositor_frame_sink_id); 199 compositor_frame_sink_id);
200 } 200 }
201 201
202 } // namespace android_webview 202 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/hardware_renderer.h ('k') | android_webview/browser/surfaces_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698