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