| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "services/ui/ws/frame_generator.h" | 5 #include "services/ui/ws/frame_generator.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/containers/adapters.h" | 9 #include "base/containers/adapters.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // TODO(fsamuel, staraz): Implement this. | 123 // TODO(fsamuel, staraz): Implement this. |
| 124 } | 124 } |
| 125 | 125 |
| 126 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( | 126 cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( |
| 127 const gfx::Rect& output_rect) { | 127 const gfx::Rect& output_rect) { |
| 128 const int render_pass_id = 1; | 128 const int render_pass_id = 1; |
| 129 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); | 129 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 130 render_pass->SetNew(render_pass_id, output_rect, output_rect, | 130 render_pass->SetNew(render_pass_id, output_rect, output_rect, |
| 131 gfx::Transform()); | 131 gfx::Transform()); |
| 132 | 132 |
| 133 DrawWindowTree(render_pass.get(), root_window_, gfx::Vector2d(), 1.0f); | 133 DrawWindow(render_pass.get(), delegate_->GetActiveRootWindow()); |
| 134 | 134 |
| 135 cc::CompositorFrame frame; | 135 cc::CompositorFrame frame; |
| 136 frame.render_pass_list.push_back(std::move(render_pass)); | 136 frame.render_pass_list.push_back(std::move(render_pass)); |
| 137 if (delegate_->IsInHighContrastMode()) { | 137 if (delegate_->IsInHighContrastMode()) { |
| 138 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create(); | 138 std::unique_ptr<cc::RenderPass> invert_pass = cc::RenderPass::Create(); |
| 139 invert_pass->SetNew(2, output_rect, output_rect, gfx::Transform()); | 139 invert_pass->SetNew(2, output_rect, output_rect, gfx::Transform()); |
| 140 cc::SharedQuadState* shared_state = | 140 cc::SharedQuadState* shared_state = |
| 141 invert_pass->CreateAndAppendSharedQuadState(); | 141 invert_pass->CreateAndAppendSharedQuadState(); |
| 142 shared_state->SetAll(gfx::Transform(), output_rect.size(), output_rect, | 142 shared_state->SetAll(gfx::Transform(), output_rect.size(), output_rect, |
| 143 output_rect, false, 1.f, SkBlendMode::kSrcOver, 0); | 143 output_rect, false, 1.f, SkBlendMode::kSrcOver, 0); |
| 144 auto* quad = invert_pass->CreateAndAppendDrawQuad<cc::RenderPassDrawQuad>(); | 144 auto* quad = invert_pass->CreateAndAppendDrawQuad<cc::RenderPassDrawQuad>(); |
| 145 render_pass->filters.Append(cc::FilterOperation::CreateInvertFilter(1.f)); | 145 render_pass->filters.Append(cc::FilterOperation::CreateInvertFilter(1.f)); |
| 146 quad->SetNew(shared_state, output_rect, output_rect, render_pass_id, | 146 quad->SetNew(shared_state, output_rect, output_rect, render_pass_id, |
| 147 0 /* mask_resource_id */, gfx::Vector2dF() /* mask_uv_scale */, | 147 0 /* mask_resource_id */, gfx::Vector2dF() /* mask_uv_scale */, |
| 148 gfx::Size() /* mask_texture_size */, | 148 gfx::Size() /* mask_texture_size */, |
| 149 gfx::Vector2dF() /* filters_scale */, | 149 gfx::Vector2dF() /* filters_scale */, |
| 150 gfx::PointF() /* filters_origin */); | 150 gfx::PointF() /* filters_origin */); |
| 151 frame.render_pass_list.push_back(std::move(invert_pass)); | 151 frame.render_pass_list.push_back(std::move(invert_pass)); |
| 152 } | 152 } |
| 153 frame.metadata.device_scale_factor = device_scale_factor_; | 153 frame.metadata.device_scale_factor = device_scale_factor_; |
| 154 | 154 |
| 155 return frame; | 155 return frame; |
| 156 } | 156 } |
| 157 | 157 |
| 158 void FrameGenerator::DrawWindowTree( | 158 void FrameGenerator::DrawWindow(cc::RenderPass* pass, ServerWindow* window) { |
| 159 cc::RenderPass* pass, | |
| 160 ServerWindow* window, | |
| 161 const gfx::Vector2d& parent_to_root_origin_offset, | |
| 162 float opacity) { | |
| 163 if (!window->visible()) | 159 if (!window->visible()) |
| 164 return; | 160 return; |
| 165 | 161 |
| 166 const gfx::Rect absolute_bounds = | |
| 167 window->bounds() + parent_to_root_origin_offset; | |
| 168 const ServerWindow::Windows& children = window->children(); | |
| 169 const float combined_opacity = opacity * window->opacity(); | |
| 170 for (ServerWindow* child : base::Reversed(children)) { | |
| 171 DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(), | |
| 172 combined_opacity); | |
| 173 } | |
| 174 | |
| 175 if (!window->compositor_frame_sink_manager() || | 162 if (!window->compositor_frame_sink_manager() || |
| 176 !window->compositor_frame_sink_manager()->ShouldDraw()) | 163 !window->compositor_frame_sink_manager()->ShouldDraw()) |
| 177 return; | 164 return; |
| 178 | 165 |
| 179 cc::SurfaceId underlay_surface_id = | |
| 180 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | |
| 181 mojom::CompositorFrameSinkType::UNDERLAY); | |
| 182 cc::SurfaceId default_surface_id = | 166 cc::SurfaceId default_surface_id = |
| 183 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 167 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 184 mojom::CompositorFrameSinkType::DEFAULT); | 168 mojom::CompositorFrameSinkType::DEFAULT); |
| 185 | 169 |
| 186 if (!underlay_surface_id.is_valid() && !default_surface_id.is_valid()) | 170 if (!default_surface_id.is_valid()) |
| 187 return; | 171 return; |
| 188 | 172 |
| 189 if (default_surface_id.is_valid()) { | 173 gfx::Transform quad_to_target_transform; |
| 190 gfx::Transform quad_to_target_transform; | 174 quad_to_target_transform.Translate(window->bounds().x(), |
| 191 quad_to_target_transform.Translate(absolute_bounds.x(), | 175 window->bounds().y()); |
| 192 absolute_bounds.y()); | |
| 193 | 176 |
| 194 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | 177 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); |
| 195 | 178 |
| 196 const gfx::Rect bounds_at_origin(window->bounds().size()); | 179 const gfx::Rect bounds_at_origin(window->bounds().size()); |
| 197 // TODO(fsamuel): These clipping and visible rects are incorrect. They need | 180 // TODO(fsamuel): These clipping and visible rects are incorrect. They need |
| 198 // to be populated from CompositorFrame structs. | 181 // to be populated from CompositorFrame structs. |
| 199 sqs->SetAll( | 182 sqs->SetAll( |
| 200 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | 183 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, |
| 201 bounds_at_origin /* visible_layer_bounds */, | 184 bounds_at_origin /* visible_layer_bounds */, |
| 202 bounds_at_origin /* clip_rect */, false /* is_clipped */, | 185 bounds_at_origin /* clip_rect */, false /* is_clipped */, |
| 203 combined_opacity, SkBlendMode::kSrcOver, 0 /* sorting-context_id */); | 186 1.0f /* opacity */, SkBlendMode::kSrcOver, 0 /* sorting-context_id */); |
| 204 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 187 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 205 quad->SetAll(sqs, bounds_at_origin /* rect */, | 188 quad->SetAll(sqs, bounds_at_origin /* rect */, |
| 206 gfx::Rect() /* opaque_rect */, | 189 gfx::Rect() /* opaque_rect */, |
| 207 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | 190 bounds_at_origin /* visible_rect */, true /* needs_blending*/, |
| 208 default_surface_id); | 191 default_surface_id); |
| 209 } | |
| 210 if (underlay_surface_id.is_valid()) { | |
| 211 const gfx::Rect underlay_absolute_bounds = | |
| 212 absolute_bounds - window->underlay_offset(); | |
| 213 gfx::Transform quad_to_target_transform; | |
| 214 quad_to_target_transform.Translate(underlay_absolute_bounds.x(), | |
| 215 underlay_absolute_bounds.y()); | |
| 216 cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); | |
| 217 const gfx::Rect bounds_at_origin( | |
| 218 window->compositor_frame_sink_manager()->GetLatestFrameSize( | |
| 219 mojom::CompositorFrameSinkType::UNDERLAY)); | |
| 220 sqs->SetAll( | |
| 221 quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, | |
| 222 bounds_at_origin /* visible_layer_bounds */, | |
| 223 bounds_at_origin /* clip_rect */, false /* is_clipped */, | |
| 224 combined_opacity, SkBlendMode::kSrcOver, 0 /* sorting-context_id */); | |
| 225 | |
| 226 auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | |
| 227 quad->SetAll(sqs, bounds_at_origin /* rect */, | |
| 228 gfx::Rect() /* opaque_rect */, | |
| 229 bounds_at_origin /* visible_rect */, true /* needs_blending*/, | |
| 230 underlay_surface_id); | |
| 231 } | |
| 232 } | 192 } |
| 233 | 193 |
| 234 cc::SurfaceId FrameGenerator::FindParentSurfaceId(ServerWindow* window) { | 194 cc::SurfaceId FrameGenerator::FindParentSurfaceId(ServerWindow* window) { |
| 235 if (window == root_window_) | 195 if (window == root_window_) |
| 236 return root_window_->delegate()->GetRootSurfaceId(); | 196 return root_window_->delegate()->GetRootSurfaceId(); |
| 237 | 197 |
| 238 // The root window holds the parent SurfaceId. This SurfaceId will have an | 198 // The root window holds the parent SurfaceId. This SurfaceId will have an |
| 239 // invalid LocalFrameId before FrameGenerator has submitted a CompositorFrame. | 199 // invalid LocalFrameId before FrameGenerator has submitted a CompositorFrame. |
| 240 // After the first frame is submitted it will always be a valid SurfaceId. | 200 // After the first frame is submitted it will always be a valid SurfaceId. |
| 241 return root_window_->compositor_frame_sink_manager()->GetLatestSurfaceId( | 201 return root_window_->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 cc::SurfaceId underlay_surface_id = | 302 cc::SurfaceId underlay_surface_id = |
| 343 window->compositor_frame_sink_manager()->GetLatestSurfaceId( | 303 window->compositor_frame_sink_manager()->GetLatestSurfaceId( |
| 344 mojom::CompositorFrameSinkType::UNDERLAY); | 304 mojom::CompositorFrameSinkType::UNDERLAY); |
| 345 if (underlay_surface_id.is_valid()) | 305 if (underlay_surface_id.is_valid()) |
| 346 RemoveFrameSinkReference(underlay_surface_id.frame_sink_id()); | 306 RemoveFrameSinkReference(underlay_surface_id.frame_sink_id()); |
| 347 } | 307 } |
| 348 | 308 |
| 349 } // namespace ws | 309 } // namespace ws |
| 350 | 310 |
| 351 } // namespace ui | 311 } // namespace ui |
| OLD | NEW |