| 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 26 matching lines...) Expand all Loading... |
| 37 last_submitted_compositor_frame_sink_id_(0u) { | 37 last_submitted_compositor_frame_sink_id_(0u) { |
| 38 DCHECK(last_egl_context_); | 38 DCHECK(last_egl_context_); |
| 39 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); | 39 surfaces_->GetSurfaceManager()->RegisterFrameSinkId(frame_sink_id_); |
| 40 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, | 40 surfaces_->GetSurfaceManager()->RegisterSurfaceFactoryClient(frame_sink_id_, |
| 41 this); | 41 this); |
| 42 } | 42 } |
| 43 | 43 |
| 44 HardwareRenderer::~HardwareRenderer() { | 44 HardwareRenderer::~HardwareRenderer() { |
| 45 // Must reset everything before |surface_factory_| to ensure all | 45 // Must reset everything before |surface_factory_| to ensure all |
| 46 // resources are returned before resetting. | 46 // resources are returned before resetting. |
| 47 if (!child_id_.is_null()) | 47 if (child_id_.is_valid()) |
| 48 DestroySurface(); | 48 DestroySurface(); |
| 49 surface_factory_.reset(); | 49 surface_factory_.reset(); |
| 50 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient( | 50 surfaces_->GetSurfaceManager()->UnregisterSurfaceFactoryClient( |
| 51 frame_sink_id_); | 51 frame_sink_id_); |
| 52 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); | 52 surfaces_->GetSurfaceManager()->InvalidateFrameSinkId(frame_sink_id_); |
| 53 | 53 |
| 54 // Reset draw constraints. | 54 // Reset draw constraints. |
| 55 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( | 55 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( |
| 56 ParentCompositorDrawConstraints()); | 56 ParentCompositorDrawConstraints()); |
| 57 ReturnResourcesInChildFrame(); | 57 ReturnResourcesInChildFrame(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 87 DLOG(WARNING) << "EGLContextChanged"; | 87 DLOG(WARNING) << "EGLContextChanged"; |
| 88 | 88 |
| 89 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it | 89 // SurfaceFactory::SubmitCompositorFrame might call glFlush. So calling it |
| 90 // during "kModeSync" stage (which does not allow GL) might result in extra | 90 // during "kModeSync" stage (which does not allow GL) might result in extra |
| 91 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid | 91 // kModeProcess. Instead, submit the frame in "kModeDraw" stage to avoid |
| 92 // unnecessary kModeProcess. | 92 // unnecessary kModeProcess. |
| 93 if (child_frame_.get() && child_frame_->frame.get()) { | 93 if (child_frame_.get() && child_frame_->frame.get()) { |
| 94 if (!compositor_id_.Equals(child_frame_->compositor_id) || | 94 if (!compositor_id_.Equals(child_frame_->compositor_id) || |
| 95 last_submitted_compositor_frame_sink_id_ != | 95 last_submitted_compositor_frame_sink_id_ != |
| 96 child_frame_->compositor_frame_sink_id) { | 96 child_frame_->compositor_frame_sink_id) { |
| 97 if (!child_id_.is_null()) | 97 if (child_id_.is_valid()) |
| 98 DestroySurface(); | 98 DestroySurface(); |
| 99 | 99 |
| 100 // This will return all the resources to the previous compositor. | 100 // This will return all the resources to the previous compositor. |
| 101 surface_factory_->Reset(); | 101 surface_factory_->Reset(); |
| 102 compositor_id_ = child_frame_->compositor_id; | 102 compositor_id_ = child_frame_->compositor_id; |
| 103 last_submitted_compositor_frame_sink_id_ = | 103 last_submitted_compositor_frame_sink_id_ = |
| 104 child_frame_->compositor_frame_sink_id; | 104 child_frame_->compositor_frame_sink_id; |
| 105 } | 105 } |
| 106 | 106 |
| 107 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = | 107 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = |
| 108 std::move(child_frame_->frame); | 108 std::move(child_frame_->frame); |
| 109 | 109 |
| 110 gfx::Size frame_size = | 110 gfx::Size frame_size = |
| 111 child_compositor_frame->render_pass_list.back()->output_rect.size(); | 111 child_compositor_frame->render_pass_list.back()->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; |
| 114 if (child_id_.is_null() || size_changed) { | 114 if (!child_id_.is_valid() || size_changed) { |
| 115 if (!child_id_.is_null()) | 115 if (child_id_.is_valid()) |
| 116 DestroySurface(); | 116 DestroySurface(); |
| 117 AllocateSurface(); | 117 AllocateSurface(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 surface_factory_->SubmitCompositorFrame(child_id_, | 120 surface_factory_->SubmitCompositorFrame(child_id_, |
| 121 std::move(*child_compositor_frame), | 121 std::move(*child_compositor_frame), |
| 122 cc::SurfaceFactory::DrawCallback()); | 122 cc::SurfaceFactory::DrawCallback()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 125 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 126 transform.matrix().setColMajorf(draw_info->transform); | 126 transform.matrix().setColMajorf(draw_info->transform); |
| 127 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 127 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); |
| 128 | 128 |
| 129 gfx::Size viewport(draw_info->width, draw_info->height); | 129 gfx::Size viewport(draw_info->width, draw_info->height); |
| 130 // Need to post the new transform matrix back to child compositor | 130 // Need to post the new transform matrix back to child compositor |
| 131 // because there is no onDraw during a Render Thread animation, and child | 131 // because there is no onDraw during a Render Thread animation, and child |
| 132 // compositor might not have the tiles rasterized as the animation goes on. | 132 // compositor might not have the tiles rasterized as the animation goes on. |
| 133 ParentCompositorDrawConstraints draw_constraints( | 133 ParentCompositorDrawConstraints draw_constraints( |
| 134 draw_info->is_layer, transform, viewport.IsEmpty()); | 134 draw_info->is_layer, transform, viewport.IsEmpty()); |
| 135 if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { | 135 if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { |
| 136 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( | 136 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( |
| 137 draw_constraints); | 137 draw_constraints); |
| 138 } | 138 } |
| 139 | 139 |
| 140 if (child_id_.is_null()) | 140 if (!child_id_.is_valid()) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, | 143 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, |
| 144 draw_info->clip_right - draw_info->clip_left, | 144 draw_info->clip_right - draw_info->clip_left, |
| 145 draw_info->clip_bottom - draw_info->clip_top); | 145 draw_info->clip_bottom - draw_info->clip_top); |
| 146 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, | 146 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, |
| 147 cc::SurfaceId(frame_sink_id_, child_id_)); | 147 cc::SurfaceId(frame_sink_id_, child_id_)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void HardwareRenderer::AllocateSurface() { | 150 void HardwareRenderer::AllocateSurface() { |
| 151 DCHECK(child_id_.is_null()); | 151 DCHECK(!child_id_.is_valid()); |
| 152 child_id_ = surface_id_allocator_->GenerateId(); | 152 child_id_ = surface_id_allocator_->GenerateId(); |
| 153 surface_factory_->Create(child_id_); | 153 surface_factory_->Create(child_id_); |
| 154 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 154 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void HardwareRenderer::DestroySurface() { | 157 void HardwareRenderer::DestroySurface() { |
| 158 DCHECK(!child_id_.is_null()); | 158 DCHECK(child_id_.is_valid()); |
| 159 | 159 |
| 160 // Submit an empty frame to force any existing resources to be returned. | 160 // Submit an empty frame to force any existing resources to be returned. |
| 161 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), | 161 surface_factory_->SubmitCompositorFrame(child_id_, cc::CompositorFrame(), |
| 162 cc::SurfaceFactory::DrawCallback()); | 162 cc::SurfaceFactory::DrawCallback()); |
| 163 | 163 |
| 164 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 164 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 165 surface_factory_->Destroy(child_id_); | 165 surface_factory_->Destroy(child_id_); |
| 166 child_id_ = cc::LocalFrameId(); | 166 child_id_ = cc::LocalFrameId(); |
| 167 } | 167 } |
| 168 | 168 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 196 const cc::ReturnedResourceArray& resources, | 196 const cc::ReturnedResourceArray& resources, |
| 197 const CompositorID& compositor_id, | 197 const CompositorID& compositor_id, |
| 198 uint32_t compositor_frame_sink_id) { | 198 uint32_t compositor_frame_sink_id) { |
| 199 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) | 199 if (compositor_frame_sink_id != last_committed_compositor_frame_sink_id_) |
| 200 return; | 200 return; |
| 201 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, | 201 render_thread_manager_->InsertReturnedResourcesOnRT(resources, compositor_id, |
| 202 compositor_frame_sink_id); | 202 compositor_frame_sink_id); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace android_webview | 205 } // namespace android_webview |
| OLD | NEW |