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