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