OLD | NEW |
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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/gl/gl_bindings.h" | 22 #include "ui/gl/gl_bindings.h" |
23 | 23 |
24 namespace android_webview { | 24 namespace android_webview { |
25 | 25 |
26 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) | 26 HardwareRenderer::HardwareRenderer(RenderThreadManager* state) |
27 : render_thread_manager_(state), | 27 : render_thread_manager_(state), |
28 last_egl_context_(eglGetCurrentContext()), | 28 last_egl_context_(eglGetCurrentContext()), |
29 surfaces_(SurfacesInstance::GetOrCreateInstance()), | 29 surfaces_(SurfacesInstance::GetOrCreateInstance()), |
30 surface_id_allocator_( | 30 surface_id_allocator_( |
31 new cc::SurfaceIdAllocator(surfaces_->AllocateSurfaceClientId())), | 31 new cc::SurfaceIdAllocator(surfaces_->AllocateSurfaceClientId())), |
32 last_committed_output_surface_id_(0u), | 32 last_committed_compositor_frame_sink_id_(0u), |
33 last_submitted_output_surface_id_(0u) { | 33 last_submitted_compositor_frame_sink_id_(0u) { |
34 DCHECK(last_egl_context_); | 34 DCHECK(last_egl_context_); |
35 surfaces_->GetSurfaceManager()->RegisterSurfaceClientId( | 35 surfaces_->GetSurfaceManager()->RegisterSurfaceClientId( |
36 surface_id_allocator_->client_id()); | 36 surface_id_allocator_->client_id()); |
37 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient( | 37 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient( |
38 surface_id_allocator_->client_id(), this); | 38 surface_id_allocator_->client_id(), this); |
39 } | 39 } |
40 | 40 |
41 HardwareRenderer::~HardwareRenderer() { | 41 HardwareRenderer::~HardwareRenderer() { |
42 // Must reset everything before |surface_factory_| to ensure all | 42 // Must reset everything before |surface_factory_| to ensure all |
43 // resources are returned before resetting. | 43 // resources are returned before resetting. |
(...skipping 12 matching lines...) Expand all Loading... |
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(); |
61 std::unique_ptr<ChildFrame> child_frame = | 61 std::unique_ptr<ChildFrame> child_frame = |
62 render_thread_manager_->PassFrameOnRT(); | 62 render_thread_manager_->PassFrameOnRT(); |
63 if (!child_frame.get()) | 63 if (!child_frame.get()) |
64 return; | 64 return; |
65 | 65 |
66 last_committed_output_surface_id_ = child_frame->output_surface_id; | 66 last_committed_compositor_frame_sink_id_ = |
| 67 child_frame->compositor_frame_sink_id; |
67 ReturnResourcesInChildFrame(); | 68 ReturnResourcesInChildFrame(); |
68 child_frame_ = std::move(child_frame); | 69 child_frame_ = std::move(child_frame); |
69 DCHECK(child_frame_->frame.get()); | 70 DCHECK(child_frame_->frame.get()); |
70 DCHECK(!child_frame_->frame->gl_frame_data); | 71 DCHECK(!child_frame_->frame->gl_frame_data); |
71 } | 72 } |
72 | 73 |
73 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, | 74 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, |
74 const ScopedAppGLStateRestore& gl_state) { | 75 const ScopedAppGLStateRestore& gl_state) { |
75 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); | 76 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); |
76 | 77 |
77 // We need to watch if the current Android context has changed and enforce | 78 // We need to watch if the current Android context has changed and enforce |
78 // a clean-up in the compositor. | 79 // a clean-up in the compositor. |
79 EGLContext current_context = eglGetCurrentContext(); | 80 EGLContext current_context = eglGetCurrentContext(); |
80 DCHECK(current_context) << "DrawGL called without EGLContext"; | 81 DCHECK(current_context) << "DrawGL called without EGLContext"; |
81 | 82 |
82 // TODO(boliu): Handle context loss. | 83 // TODO(boliu): Handle context loss. |
83 if (last_egl_context_ != current_context) | 84 if (last_egl_context_ != current_context) |
84 DLOG(WARNING) << "EGLContextChanged"; | 85 DLOG(WARNING) << "EGLContextChanged"; |
85 | 86 |
86 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it | 87 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it |
87 // during "kModeSync" stage (which does not allow GL) might result in extra | 88 // during "kModeSync" stage (which does not allow GL) might result in extra |
88 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | 89 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
89 // unnecessary kModeProcess. | 90 // unnecessary kModeProcess. |
90 if (child_frame_.get() && child_frame_->frame.get()) { | 91 if (child_frame_.get() && child_frame_->frame.get()) { |
91 if (!compositor_id_.Equals(child_frame_->compositor_id) || | 92 if (!compositor_id_.Equals(child_frame_->compositor_id) || |
92 last_submitted_output_surface_id_ != child_frame_->output_surface_id) { | 93 last_submitted_compositor_frame_sink_id_ != |
| 94 child_frame_->compositor_frame_sink_id) { |
93 if (!child_id_.is_null()) | 95 if (!child_id_.is_null()) |
94 DestroySurface(); | 96 DestroySurface(); |
95 | 97 |
96 // This will return all the resources to the previous compositor. | 98 // This will return all the resources to the previous compositor. |
97 surface_factory_.reset(); | 99 surface_factory_.reset(); |
98 compositor_id_ = child_frame_->compositor_id; | 100 compositor_id_ = child_frame_->compositor_id; |
99 last_submitted_output_surface_id_ = child_frame_->output_surface_id; | 101 last_submitted_compositor_frame_sink_id_ = |
| 102 child_frame_->compositor_frame_sink_id; |
100 surface_factory_.reset( | 103 surface_factory_.reset( |
101 new cc::SurfaceFactory(surfaces_->GetSurfaceManager(), this)); | 104 new cc::SurfaceFactory(surfaces_->GetSurfaceManager(), this)); |
102 } | 105 } |
103 | 106 |
104 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = | 107 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = |
105 std::move(child_frame_->frame); | 108 std::move(child_frame_->frame); |
106 | 109 |
107 gfx::Size frame_size = | 110 gfx::Size frame_size = |
108 child_compositor_frame->delegated_frame_data->render_pass_list.back() | 111 child_compositor_frame->delegated_frame_data->render_pass_list.back() |
109 ->output_rect.size(); | 112 ->output_rect.size(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 DCHECK(!child_id_.is_null()); | 160 DCHECK(!child_id_.is_null()); |
158 DCHECK(surface_factory_); | 161 DCHECK(surface_factory_); |
159 surfaces_->RemoveChildId(child_id_); | 162 surfaces_->RemoveChildId(child_id_); |
160 surface_factory_->Destroy(child_id_); | 163 surface_factory_->Destroy(child_id_); |
161 child_id_ = cc::SurfaceId(); | 164 child_id_ = cc::SurfaceId(); |
162 } | 165 } |
163 | 166 |
164 void HardwareRenderer::ReturnResources( | 167 void HardwareRenderer::ReturnResources( |
165 const cc::ReturnedResourceArray& resources) { | 168 const cc::ReturnedResourceArray& resources) { |
166 ReturnResourcesToCompositor(resources, compositor_id_, | 169 ReturnResourcesToCompositor(resources, compositor_id_, |
167 last_submitted_output_surface_id_); | 170 last_submitted_compositor_frame_sink_id_); |
168 } | 171 } |
169 | 172 |
170 void HardwareRenderer::SetBeginFrameSource( | 173 void HardwareRenderer::SetBeginFrameSource( |
171 cc::BeginFrameSource* begin_frame_source) { | 174 cc::BeginFrameSource* begin_frame_source) { |
172 // TODO(tansell): Hook this up. | 175 // TODO(tansell): Hook this up. |
173 } | 176 } |
174 | 177 |
175 void HardwareRenderer::SetBackingFrameBufferObject( | 178 void HardwareRenderer::SetBackingFrameBufferObject( |
176 int framebuffer_binding_ext) { | 179 int framebuffer_binding_ext) { |
177 surfaces_->SetBackingFrameBufferObject(framebuffer_binding_ext); | 180 surfaces_->SetBackingFrameBufferObject(framebuffer_binding_ext); |
178 } | 181 } |
179 | 182 |
180 void HardwareRenderer::ReturnResourcesInChildFrame() { | 183 void HardwareRenderer::ReturnResourcesInChildFrame() { |
181 if (child_frame_.get() && child_frame_->frame.get()) { | 184 if (child_frame_.get() && child_frame_->frame.get()) { |
182 cc::ReturnedResourceArray resources_to_return; | 185 cc::ReturnedResourceArray resources_to_return; |
183 cc::TransferableResource::ReturnResources( | 186 cc::TransferableResource::ReturnResources( |
184 child_frame_->frame->delegated_frame_data->resource_list, | 187 child_frame_->frame->delegated_frame_data->resource_list, |
185 &resources_to_return); | 188 &resources_to_return); |
186 | 189 |
187 // The child frame's compositor id is not necessarily same as | 190 // The child frame's compositor id is not necessarily same as |
188 // compositor_id_. | 191 // compositor_id_. |
189 ReturnResourcesToCompositor(resources_to_return, | 192 ReturnResourcesToCompositor(resources_to_return, |
190 child_frame_->compositor_id, | 193 child_frame_->compositor_id, |
191 child_frame_->output_surface_id); | 194 child_frame_->compositor_frame_sink_id); |
192 } | 195 } |
193 child_frame_.reset(); | 196 child_frame_.reset(); |
194 } | 197 } |
195 | 198 |
196 void HardwareRenderer::ReturnResourcesToCompositor( | 199 void HardwareRenderer::ReturnResourcesToCompositor( |
197 const cc::ReturnedResourceArray& resources, | 200 const cc::ReturnedResourceArray& resources, |
198 const CompositorID& compositor_id, | 201 const CompositorID& compositor_id, |
199 uint32_t output_surface_id) { | 202 uint32_t compositor_frame_sink_id) { |
200 if (output_surface_id != last_committed_output_surface_id_) | 203 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) |
201 return; | 204 return; |
202 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, | 205 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, |
203 output_surface_id); | 206 compositor_frame_sink_id); |
204 } | 207 } |
205 | 208 |
206 } // namespace android_webview | 209 } // namespace android_webview |
OLD | NEW |