| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return; | 64 return; |
| 65 | 65 |
| 66 last_committed_compositor_frame_sink_id_ = | 66 last_committed_compositor_frame_sink_id_ = |
| 67 child_frame->compositor_frame_sink_id; | 67 child_frame->compositor_frame_sink_id; |
| 68 ReturnResourcesInChildFrame(); | 68 ReturnResourcesInChildFrame(); |
| 69 child_frame_ = std::move(child_frame); | 69 child_frame_ = std::move(child_frame); |
| 70 DCHECK(child_frame_->frame.get()); | 70 DCHECK(child_frame_->frame.get()); |
| 71 DCHECK(!child_frame_->frame->gl_frame_data); | 71 DCHECK(!child_frame_->frame->gl_frame_data); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info, | 74 void HardwareRenderer::DrawGL(AwDrawGLInfo* draw_info) { |
| 75 const ScopedAppGLStateRestore& gl_state) { | |
| 76 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); | 75 TRACE_EVENT0("android_webview", "HardwareRenderer::DrawGL"); |
| 77 | 76 |
| 78 // We need to watch if the current Android context has changed and enforce | 77 // We need to watch if the current Android context has changed and enforce |
| 79 // a clean-up in the compositor. | 78 // a clean-up in the compositor. |
| 80 EGLContext current_context = eglGetCurrentContext(); | 79 EGLContext current_context = eglGetCurrentContext(); |
| 81 DCHECK(current_context) << "DrawGL called without EGLContext"; | 80 DCHECK(current_context) << "DrawGL called without EGLContext"; |
| 82 | 81 |
| 83 // TODO(boliu): Handle context loss. | 82 // TODO(boliu): Handle context loss. |
| 84 if (last_egl_context_ != current_context) | 83 if (last_egl_context_ != current_context) |
| 85 DLOG(WARNING) << "EGLContextChanged"; | 84 DLOG(WARNING) << "EGLContextChanged"; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( | 136 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( |
| 138 draw_constraints); | 137 draw_constraints); |
| 139 } | 138 } |
| 140 | 139 |
| 141 if (child_id_.is_null()) | 140 if (child_id_.is_null()) |
| 142 return; | 141 return; |
| 143 | 142 |
| 144 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, | 143 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, |
| 145 draw_info->clip_right - draw_info->clip_left, | 144 draw_info->clip_right - draw_info->clip_left, |
| 146 draw_info->clip_bottom - draw_info->clip_top); | 145 draw_info->clip_bottom - draw_info->clip_top); |
| 147 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, child_id_, | 146 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, child_id_); |
| 148 gl_state); | |
| 149 } | 147 } |
| 150 | 148 |
| 151 void HardwareRenderer::AllocateSurface() { | 149 void HardwareRenderer::AllocateSurface() { |
| 152 DCHECK(child_id_.is_null()); | 150 DCHECK(child_id_.is_null()); |
| 153 DCHECK(surface_factory_); | 151 DCHECK(surface_factory_); |
| 154 child_id_ = surface_id_allocator_->GenerateId(); | 152 child_id_ = surface_id_allocator_->GenerateId(); |
| 155 surface_factory_->Create(child_id_); | 153 surface_factory_->Create(child_id_); |
| 156 surfaces_->AddChildId(child_id_); | 154 surfaces_->AddChildId(child_id_); |
| 157 } | 155 } |
| 158 | 156 |
| 159 void HardwareRenderer::DestroySurface() { | 157 void HardwareRenderer::DestroySurface() { |
| 160 DCHECK(!child_id_.is_null()); | 158 DCHECK(!child_id_.is_null()); |
| 161 DCHECK(surface_factory_); | 159 DCHECK(surface_factory_); |
| 162 surfaces_->RemoveChildId(child_id_); | 160 surfaces_->RemoveChildId(child_id_); |
| 163 surface_factory_->Destroy(child_id_); | 161 surface_factory_->Destroy(child_id_); |
| 164 child_id_ = cc::SurfaceId(); | 162 child_id_ = cc::SurfaceId(); |
| 165 } | 163 } |
| 166 | 164 |
| 167 void HardwareRenderer::ReturnResources( | 165 void HardwareRenderer::ReturnResources( |
| 168 const cc::ReturnedResourceArray& resources) { | 166 const cc::ReturnedResourceArray& resources) { |
| 169 ReturnResourcesToCompositor(resources, compositor_id_, | 167 ReturnResourcesToCompositor(resources, compositor_id_, |
| 170 last_submitted_compositor_frame_sink_id_); | 168 last_submitted_compositor_frame_sink_id_); |
| 171 } | 169 } |
| 172 | 170 |
| 173 void HardwareRenderer::SetBeginFrameSource( | 171 void HardwareRenderer::SetBeginFrameSource( |
| 174 cc::BeginFrameSource* begin_frame_source) { | 172 cc::BeginFrameSource* begin_frame_source) { |
| 175 // TODO(tansell): Hook this up. | 173 // TODO(tansell): Hook this up. |
| 176 } | 174 } |
| 177 | 175 |
| 178 void HardwareRenderer::SetBackingFrameBufferObject( | |
| 179 int framebuffer_binding_ext) { | |
| 180 surfaces_->SetBackingFrameBufferObject(framebuffer_binding_ext); | |
| 181 } | |
| 182 | |
| 183 void HardwareRenderer::ReturnResourcesInChildFrame() { | 176 void HardwareRenderer::ReturnResourcesInChildFrame() { |
| 184 if (child_frame_.get() && child_frame_->frame.get()) { | 177 if (child_frame_.get() && child_frame_->frame.get()) { |
| 185 cc::ReturnedResourceArray resources_to_return; | 178 cc::ReturnedResourceArray resources_to_return; |
| 186 cc::TransferableResource::ReturnResources( | 179 cc::TransferableResource::ReturnResources( |
| 187 child_frame_->frame->delegated_frame_data->resource_list, | 180 child_frame_->frame->delegated_frame_data->resource_list, |
| 188 &resources_to_return); | 181 &resources_to_return); |
| 189 | 182 |
| 190 // The child frame's compositor id is not necessarily same as | 183 // The child frame's compositor id is not necessarily same as |
| 191 // compositor_id_. | 184 // compositor_id_. |
| 192 ReturnResourcesToCompositor(resources_to_return, | 185 ReturnResourcesToCompositor(resources_to_return, |
| 193 child_frame_->compositor_id, | 186 child_frame_->compositor_id, |
| 194 child_frame_->compositor_frame_sink_id); | 187 child_frame_->compositor_frame_sink_id); |
| 195 } | 188 } |
| 196 child_frame_.reset(); | 189 child_frame_.reset(); |
| 197 } | 190 } |
| 198 | 191 |
| 199 void HardwareRenderer::ReturnResourcesToCompositor( | 192 void HardwareRenderer::ReturnResourcesToCompositor( |
| 200 const cc::ReturnedResourceArray& resources, | 193 const cc::ReturnedResourceArray& resources, |
| 201 const CompositorID& compositor_id, | 194 const CompositorID& compositor_id, |
| 202 uint32_t compositor_frame_sink_id) { | 195 uint32_t compositor_frame_sink_id) { |
| 203 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) | 196 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) |
| 204 return; | 197 return; |
| 205 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, | 198 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, |
| 206 compositor_frame_sink_id); | 199 compositor_frame_sink_id); |
| 207 } | 200 } |
| 208 | 201 |
| 209 } // namespace android_webview | 202 } // namespace android_webview |
| OLD | NEW |