| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 | 111 |
| 112 CreateNewCompositorFrameSinkSupport(); | 112 CreateNewCompositorFrameSinkSupport(); |
| 113 compositor_id_ = child_frame_->compositor_id; | 113 compositor_id_ = child_frame_->compositor_id; |
| 114 last_submitted_compositor_frame_sink_id_ = | 114 last_submitted_compositor_frame_sink_id_ = |
| 115 child_frame_->compositor_frame_sink_id; | 115 child_frame_->compositor_frame_sink_id; |
| 116 } | 116 } |
| 117 | 117 |
| 118 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = | 118 std::unique_ptr<cc::CompositorFrame> child_compositor_frame = |
| 119 std::move(child_frame_->frame); | 119 std::move(child_frame_->frame); |
| 120 | 120 |
| 121 float device_scale_factor = | |
| 122 child_compositor_frame->metadata.device_scale_factor; | |
| 123 gfx::Size frame_size = | 121 gfx::Size frame_size = |
| 124 child_compositor_frame->render_pass_list.back()->output_rect.size(); | 122 child_compositor_frame->render_pass_list.back()->output_rect.size(); |
| 125 if (!child_id_.is_valid() || surface_size_ != frame_size || | 123 bool size_changed = frame_size != frame_size_; |
| 126 device_scale_factor_ != device_scale_factor) { | 124 frame_size_ = frame_size; |
| 125 if (!child_id_.is_valid() || size_changed) { |
| 127 if (child_id_.is_valid()) | 126 if (child_id_.is_valid()) |
| 128 DestroySurface(); | 127 DestroySurface(); |
| 129 AllocateSurface(); | 128 AllocateSurface(); |
| 130 surface_size_ = frame_size; | |
| 131 device_scale_factor_ = device_scale_factor; | |
| 132 } | 129 } |
| 133 | 130 |
| 134 bool result = support_->SubmitCompositorFrame( | 131 support_->SubmitCompositorFrame(child_id_, |
| 135 child_id_, std::move(*child_compositor_frame)); | 132 std::move(*child_compositor_frame)); |
| 136 DCHECK(result); | |
| 137 } | 133 } |
| 138 | 134 |
| 139 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 135 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 140 transform.matrix().setColMajorf(draw_info->transform); | 136 transform.matrix().setColMajorf(draw_info->transform); |
| 141 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); | 137 transform.Translate(scroll_offset_.x(), scroll_offset_.y()); |
| 142 | 138 |
| 143 gfx::Size viewport(draw_info->width, draw_info->height); | 139 gfx::Size viewport(draw_info->width, draw_info->height); |
| 144 // Need to post the new transform matrix back to child compositor | 140 // Need to post the new transform matrix back to child compositor |
| 145 // because there is no onDraw during a Render Thread animation, and child | 141 // because there is no onDraw during a Render Thread animation, and child |
| 146 // compositor might not have the tiles rasterized as the animation goes on. | 142 // compositor might not have the tiles rasterized as the animation goes on. |
| 147 ParentCompositorDrawConstraints draw_constraints( | 143 ParentCompositorDrawConstraints draw_constraints( |
| 148 draw_info->is_layer, transform, viewport.IsEmpty()); | 144 draw_info->is_layer, transform, viewport.IsEmpty()); |
| 149 if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { | 145 if (!child_frame_.get() || draw_constraints.NeedUpdate(*child_frame_)) { |
| 150 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( | 146 render_thread_manager_->PostExternalDrawConstraintsToChildCompositorOnRT( |
| 151 draw_constraints); | 147 draw_constraints); |
| 152 } | 148 } |
| 153 | 149 |
| 154 if (!child_id_.is_valid()) | 150 if (!child_id_.is_valid()) |
| 155 return; | 151 return; |
| 156 | 152 |
| 157 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, | 153 gfx::Rect clip(draw_info->clip_left, draw_info->clip_top, |
| 158 draw_info->clip_right - draw_info->clip_left, | 154 draw_info->clip_right - draw_info->clip_left, |
| 159 draw_info->clip_bottom - draw_info->clip_top); | 155 draw_info->clip_bottom - draw_info->clip_top); |
| 160 surfaces_->DrawAndSwap(viewport, clip, transform, surface_size_, | 156 surfaces_->DrawAndSwap(viewport, clip, transform, frame_size_, |
| 161 cc::SurfaceId(frame_sink_id_, child_id_)); | 157 cc::SurfaceId(frame_sink_id_, child_id_)); |
| 162 } | 158 } |
| 163 | 159 |
| 164 void HardwareRenderer::AllocateSurface() { | 160 void HardwareRenderer::AllocateSurface() { |
| 165 DCHECK(!child_id_.is_valid()); | 161 DCHECK(!child_id_.is_valid()); |
| 166 child_id_ = local_surface_id_allocator_->GenerateId(); | 162 child_id_ = local_surface_id_allocator_->GenerateId(); |
| 167 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 163 surfaces_->AddChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 168 } | 164 } |
| 169 | 165 |
| 170 void HardwareRenderer::DestroySurface() { | 166 void HardwareRenderer::DestroySurface() { |
| 171 DCHECK(child_id_.is_valid()); | 167 DCHECK(child_id_.is_valid()); |
| 172 | 168 |
| 173 // Submit an empty frame to force any existing resources to be returned. | 169 // Submit an empty frame to force any existing resources to be returned. |
| 174 gfx::Rect rect(surface_size_); | 170 gfx::Rect rect(frame_size_); |
| 175 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 171 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 176 render_pass->SetNew(1, rect, rect, gfx::Transform()); | 172 render_pass->SetNew(1, rect, rect, gfx::Transform()); |
| 177 cc::CompositorFrame frame; | 173 cc::CompositorFrame frame; |
| 178 frame.render_pass_list.push_back(std::move(render_pass)); | 174 frame.render_pass_list.push_back(std::move(render_pass)); |
| 179 // We submit without a prior BeginFrame, so acknowledge a manual BeginFrame. | 175 // We submit without a prior BeginFrame, so acknowledge a manual BeginFrame. |
| 180 frame.metadata.begin_frame_ack = | 176 frame.metadata.begin_frame_ack = |
| 181 cc::BeginFrameAck::CreateManualAckWithDamage(); | 177 cc::BeginFrameAck::CreateManualAckWithDamage(); |
| 182 frame.metadata.device_scale_factor = device_scale_factor_; | 178 support_->SubmitCompositorFrame(child_id_, std::move(frame)); |
| 183 bool result = support_->SubmitCompositorFrame(child_id_, std::move(frame)); | |
| 184 DCHECK(result); | |
| 185 | 179 |
| 186 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); | 180 surfaces_->RemoveChildId(cc::SurfaceId(frame_sink_id_, child_id_)); |
| 187 support_->EvictCurrentSurface(); | 181 support_->EvictCurrentSurface(); |
| 188 child_id_ = cc::LocalSurfaceId(); | 182 child_id_ = cc::LocalSurfaceId(); |
| 189 } | 183 } |
| 190 | 184 |
| 191 void HardwareRenderer::DidReceiveCompositorFrameAck( | 185 void HardwareRenderer::DidReceiveCompositorFrameAck( |
| 192 const cc::ReturnedResourceArray& resources) { | 186 const cc::ReturnedResourceArray& resources) { |
| 193 ReturnResourcesToCompositor(resources, compositor_id_, | 187 ReturnResourcesToCompositor(resources, compositor_id_, |
| 194 last_submitted_compositor_frame_sink_id_); | 188 last_submitted_compositor_frame_sink_id_); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 constexpr bool is_root = false; | 268 constexpr bool is_root = false; |
| 275 constexpr bool handles_frame_sink_id_invalidation = false; | 269 constexpr bool handles_frame_sink_id_invalidation = false; |
| 276 constexpr bool needs_sync_points = true; | 270 constexpr bool needs_sync_points = true; |
| 277 support_.reset(); | 271 support_.reset(); |
| 278 support_ = cc::CompositorFrameSinkSupport::Create( | 272 support_ = cc::CompositorFrameSinkSupport::Create( |
| 279 this, surfaces_->GetSurfaceManager(), frame_sink_id_, is_root, | 273 this, surfaces_->GetSurfaceManager(), frame_sink_id_, is_root, |
| 280 handles_frame_sink_id_invalidation, needs_sync_points); | 274 handles_frame_sink_id_invalidation, needs_sync_points); |
| 281 } | 275 } |
| 282 | 276 |
| 283 } // namespace android_webview | 277 } // namespace android_webview |
| OLD | NEW |