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