| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/surface.h" | 5 #include "components/exo/surface.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 14 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "cc/quads/render_pass.h" |
| 16 #include "cc/quads/shared_quad_state.h" |
| 17 #include "cc/quads/solid_color_draw_quad.h" |
| 18 #include "cc/quads/texture_draw_quad.h" |
| 15 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
| 20 #include "cc/surfaces/surface.h" |
| 21 #include "cc/surfaces/surface_factory.h" |
| 22 #include "cc/surfaces/surface_id_allocator.h" |
| 23 #include "cc/surfaces/surface_manager.h" |
| 16 #include "components/exo/buffer.h" | 24 #include "components/exo/buffer.h" |
| 17 #include "components/exo/surface_delegate.h" | 25 #include "components/exo/surface_delegate.h" |
| 18 #include "components/exo/surface_observer.h" | 26 #include "components/exo/surface_observer.h" |
| 27 #include "third_party/khronos/GLES2/gl2.h" |
| 28 #include "ui/aura/env.h" |
| 19 #include "ui/aura/window_delegate.h" | 29 #include "ui/aura/window_delegate.h" |
| 20 #include "ui/aura/window_property.h" | 30 #include "ui/aura/window_property.h" |
| 21 #include "ui/aura/window_targeter.h" | 31 #include "ui/aura/window_targeter.h" |
| 22 #include "ui/base/cursor/cursor.h" | 32 #include "ui/base/cursor/cursor.h" |
| 23 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
| 24 #include "ui/compositor/layer.h" | 34 #include "ui/compositor/layer.h" |
| 25 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
| 26 #include "ui/gfx/buffer_format_util.h" | 36 #include "ui/gfx/buffer_format_util.h" |
| 27 #include "ui/gfx/geometry/safe_integer_conversions.h" | 37 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 28 #include "ui/gfx/geometry/size_conversions.h" | 38 #include "ui/gfx/geometry/size_conversions.h" |
| 29 #include "ui/gfx/gpu_memory_buffer.h" | 39 #include "ui/gfx/gpu_memory_buffer.h" |
| 30 #include "ui/gfx/path.h" | 40 #include "ui/gfx/path.h" |
| 41 #include "ui/gfx/skia_util.h" |
| 31 #include "ui/gfx/transform_util.h" | 42 #include "ui/gfx/transform_util.h" |
| 32 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 33 | 44 |
| 34 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); | 45 DECLARE_WINDOW_PROPERTY_TYPE(exo::Surface*); |
| 35 | 46 |
| 36 namespace exo { | 47 namespace exo { |
| 37 namespace { | 48 namespace { |
| 38 | 49 |
| 39 // A property key containing the surface that is associated with | 50 // A property key containing the surface that is associated with |
| 40 // window. If unset, no surface is associated with window. | 51 // window. If unset, no surface is associated with window. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 if (window->parent()) | 131 if (window->parent()) |
| 121 aura::Window::ConvertPointToTarget(window->parent(), window, | 132 aura::Window::ConvertPointToTarget(window->parent(), window, |
| 122 &local_point); | 133 &local_point); |
| 123 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); | 134 return surface->HitTestRect(gfx::Rect(local_point, gfx::Size(1, 1))); |
| 124 } | 135 } |
| 125 | 136 |
| 126 private: | 137 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); | 138 DISALLOW_COPY_AND_ASSIGN(CustomWindowTargeter); |
| 128 }; | 139 }; |
| 129 | 140 |
| 141 void SatisfyCallback(cc::SurfaceManager* manager, |
| 142 cc::SurfaceSequence sequence) { |
| 143 std::vector<uint32_t> sequences; |
| 144 sequences.push_back(sequence.sequence); |
| 145 manager->DidSatisfySequences(sequence.id_namespace, &sequences); |
| 146 } |
| 147 |
| 148 void RequireCallback(cc::SurfaceManager* manager, |
| 149 cc::SurfaceId id, |
| 150 cc::SurfaceSequence sequence) { |
| 151 cc::Surface* surface = manager->GetSurfaceForId(id); |
| 152 if (!surface) { |
| 153 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 154 return; |
| 155 } |
| 156 surface->AddDestructionDependency(sequence); |
| 157 } |
| 158 |
| 130 } // namespace | 159 } // namespace |
| 131 | 160 |
| 161 SurfaceFactoryOwner::SurfaceFactoryOwner() {} |
| 162 SurfaceFactoryOwner::~SurfaceFactoryOwner() {} |
| 163 |
| 164 void SurfaceFactoryOwner::ReturnResources( |
| 165 const cc::ReturnedResourceArray& resources) { |
| 166 scoped_refptr<SurfaceFactoryOwner> holder(this); |
| 167 for (auto& resource : resources) { |
| 168 auto it = release_callbacks_.find(resource.id); |
| 169 DCHECK(it != release_callbacks_.end()); |
| 170 it->second.second->Run(resource.sync_token, resource.lost); |
| 171 release_callbacks_.erase(it); |
| 172 } |
| 173 } |
| 174 void SurfaceFactoryOwner::WillDrawSurface(cc::SurfaceId id, |
| 175 const gfx::Rect& damage_rect) { |
| 176 if (surface_) |
| 177 surface_->WillDraw(id); |
| 178 } |
| 179 |
| 180 void SurfaceFactoryOwner::SetBeginFrameSource( |
| 181 cc::BeginFrameSource* begin_frame_source) {} |
| 182 |
| 132 //////////////////////////////////////////////////////////////////////////////// | 183 //////////////////////////////////////////////////////////////////////////////// |
| 133 // Surface, public: | 184 // Surface, public: |
| 134 | 185 |
| 135 Surface::Surface() | 186 Surface::Surface() |
| 136 : aura::Window(new CustomWindowDelegate(this)), | 187 : aura::Window(new CustomWindowDelegate(this)), |
| 137 has_pending_contents_(false), | 188 has_pending_contents_(false), |
| 138 pending_input_region_(SkIRect::MakeLargest()), | 189 pending_input_region_(SkIRect::MakeLargest()), |
| 139 pending_buffer_scale_(1.0f), | 190 pending_buffer_scale_(1.0f), |
| 140 pending_only_visible_on_secure_output_(false), | 191 pending_only_visible_on_secure_output_(false), |
| 141 pending_blend_mode_(SkXfermode::kSrcOver_Mode), | 192 pending_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 142 pending_alpha_(1.0f), | 193 pending_alpha_(1.0f), |
| 143 alpha_(0.0f), | 194 alpha_(0.0f), |
| 144 input_region_(SkIRect::MakeLargest()), | 195 input_region_(SkIRect::MakeLargest()), |
| 145 needs_commit_surface_hierarchy_(false), | 196 needs_commit_surface_hierarchy_(false), |
| 146 update_contents_after_successful_compositing_(false), | 197 update_contents_after_successful_compositing_(false), |
| 147 compositor_(nullptr), | 198 compositor_(nullptr), |
| 148 delegate_(nullptr) { | 199 delegate_(nullptr) { |
| 149 SetType(ui::wm::WINDOW_TYPE_CONTROL); | 200 SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 150 SetName("ExoSurface"); | 201 SetName("ExoSurface"); |
| 151 SetProperty(kSurfaceKey, this); | 202 SetProperty(kSurfaceKey, this); |
| 152 Init(ui::LAYER_SOLID_COLOR); | 203 Init(ui::LAYER_SOLID_COLOR); |
| 153 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); | 204 SetEventTargeter(base::WrapUnique(new CustomWindowTargeter)); |
| 154 set_owned_by_parent(false); | 205 set_owned_by_parent(false); |
| 155 AddObserver(this); | 206 surface_manager_ = |
| 207 aura::Env::GetInstance()->context_factory()->GetSurfaceManager(); |
| 208 if (use_surface_layer_) { |
| 209 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner); |
| 210 factory_owner_->surface_ = this; |
| 211 factory_owner_->id_allocator_ = |
| 212 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator(); |
| 213 factory_owner_->surface_factory_.reset( |
| 214 new cc::SurfaceFactory(surface_manager_, factory_owner_.get())); |
| 215 } |
| 216 |
| 217 if (!factory_owner_) { |
| 218 AddObserver(this); |
| 219 } |
| 156 } | 220 } |
| 157 | 221 |
| 158 Surface::~Surface() { | 222 Surface::~Surface() { |
| 159 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this)); | 223 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this)); |
| 160 | 224 |
| 161 layer()->SetShowSolidColorContent(); | 225 layer()->SetShowSolidColorContent(); |
| 162 | 226 |
| 163 RemoveObserver(this); | 227 if (factory_owner_) { |
| 228 factory_owner_->surface_ = nullptr; |
| 229 } else { |
| 230 RemoveObserver(this); |
| 231 } |
| 164 if (compositor_) | 232 if (compositor_) |
| 165 compositor_->RemoveObserver(this); | 233 compositor_->RemoveObserver(this); |
| 166 | 234 |
| 167 // Call pending frame callbacks with a null frame time to indicate that they | 235 // Call pending frame callbacks with a null frame time to indicate that they |
| 168 // have been cancelled. | 236 // have been cancelled. |
| 169 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 237 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 170 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 238 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 171 frame_callbacks_); | 239 frame_callbacks_); |
| 172 for (const auto& frame_callback : active_frame_callbacks_) | 240 for (const auto& frame_callback : active_frame_callbacks_) |
| 173 frame_callback.Run(base::TimeTicks()); | 241 frame_callback.Run(base::TimeTicks()); |
| 242 |
| 243 if (!surface_id_.is_null()) |
| 244 factory_owner_->surface_factory_->Destroy(surface_id_); |
| 174 } | 245 } |
| 175 | 246 |
| 176 // static | 247 // static |
| 177 Surface* Surface::AsSurface(const aura::Window* window) { | 248 Surface* Surface::AsSurface(const aura::Window* window) { |
| 178 return window->GetProperty(kSurfaceKey); | 249 return window->GetProperty(kSurfaceKey); |
| 179 } | 250 } |
| 180 | 251 |
| 252 // static |
| 253 void Surface::SetUseSurfaceLayer(bool use_surface_layer) { |
| 254 use_surface_layer_ = use_surface_layer; |
| 255 } |
| 256 |
| 181 void Surface::Attach(Buffer* buffer) { | 257 void Surface::Attach(Buffer* buffer) { |
| 182 TRACE_EVENT1("exo", "Surface::Attach", "buffer", | 258 TRACE_EVENT1("exo", "Surface::Attach", "buffer", |
| 183 buffer ? buffer->GetSize().ToString() : "null"); | 259 buffer ? buffer->GetSize().ToString() : "null"); |
| 184 | 260 |
| 185 has_pending_contents_ = true; | 261 has_pending_contents_ = true; |
| 186 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>(); | 262 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>(); |
| 187 } | 263 } |
| 188 | 264 |
| 189 void Surface::Damage(const gfx::Rect& damage) { | 265 void Surface::Damage(const gfx::Rect& damage) { |
| 190 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString()); | 266 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 TRACE_EVENT0("exo", "Surface::Commit"); | 417 TRACE_EVENT0("exo", "Surface::Commit"); |
| 342 | 418 |
| 343 needs_commit_surface_hierarchy_ = true; | 419 needs_commit_surface_hierarchy_ = true; |
| 344 | 420 |
| 345 if (delegate_) | 421 if (delegate_) |
| 346 delegate_->OnSurfaceCommit(); | 422 delegate_->OnSurfaceCommit(); |
| 347 else | 423 else |
| 348 CommitSurfaceHierarchy(); | 424 CommitSurfaceHierarchy(); |
| 349 } | 425 } |
| 350 | 426 |
| 351 void Surface::CommitSurfaceHierarchy() { | 427 void Surface::CommitLayerContents() { |
| 352 DCHECK(needs_commit_surface_hierarchy_); | |
| 353 needs_commit_surface_hierarchy_ = false; | |
| 354 | |
| 355 // We update contents if Attach() has been called since last commit. | 428 // We update contents if Attach() has been called since last commit. |
| 356 if (has_pending_contents_) { | 429 if (has_pending_contents_) { |
| 357 has_pending_contents_ = false; | 430 has_pending_contents_ = false; |
| 358 | 431 |
| 359 current_buffer_ = pending_buffer_; | 432 current_buffer_ = pending_buffer_; |
| 360 pending_buffer_.reset(); | 433 pending_buffer_.reset(); |
| 361 | 434 |
| 362 // TODO(dcastagna): Make secure_output_only a layer property instead of a | 435 // TODO(dcastagna): Make secure_output_only a layer property instead of a |
| 363 // texture mailbox flag so this can be changed without have to provide | 436 // texture mailbox flag so this can be changed without have to provide |
| 364 // new contents. | 437 // new contents. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 483 } |
| 411 | 484 |
| 412 // Schedule redraw of the damage region. | 485 // Schedule redraw of the damage region. |
| 413 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) | 486 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) |
| 414 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); | 487 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); |
| 415 | 488 |
| 416 // Reset damage. | 489 // Reset damage. |
| 417 pending_damage_.setEmpty(); | 490 pending_damage_.setEmpty(); |
| 418 } | 491 } |
| 419 | 492 |
| 420 // Update current input region. | 493 if (layer()->has_external_content()) { |
| 421 input_region_ = pending_input_region_; | 494 layer()->SetTextureAlpha(pending_alpha_); |
| 495 alpha_ = pending_alpha_; |
| 496 } |
| 422 | 497 |
| 423 // Move pending frame callbacks to the end of |frame_callbacks_|. | 498 // Move pending frame callbacks to the end of |frame_callbacks_|. |
| 424 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); | 499 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); |
| 425 | 500 |
| 426 // Update alpha compositing properties. | 501 // Update alpha compositing properties. |
| 427 // TODO(reveman): Use a more reliable way to force blending off than setting | 502 // TODO(reveman): Use a more reliable way to force blending off than setting |
| 428 // fills-bounds-opaquely. | 503 // fills-bounds-opaquely. |
| 429 layer()->SetFillsBoundsOpaquely( | 504 layer()->SetFillsBoundsOpaquely( |
| 430 pending_blend_mode_ == SkXfermode::kSrc_Mode || | 505 pending_blend_mode_ == SkXfermode::kSrc_Mode || |
| 431 pending_opaque_region_.contains( | 506 pending_opaque_region_.contains( |
| 432 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); | 507 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); |
| 433 if (layer()->has_external_content()) { | 508 } |
| 434 layer()->SetTextureAlpha(pending_alpha_); | 509 |
| 510 void Surface::CommitSurfaceContents() { |
| 511 // We update contents if Attach() has been called since last commit. |
| 512 if (has_pending_contents_) { |
| 513 has_pending_contents_ = false; |
| 514 |
| 515 current_buffer_ = pending_buffer_; |
| 516 pending_buffer_.reset(); |
| 517 |
| 518 bool secure_output_only = pending_only_visible_on_secure_output_; |
| 519 pending_only_visible_on_secure_output_ = false; |
| 520 |
| 521 cc::TextureMailbox texture_mailbox; |
| 522 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback; |
| 523 if (current_buffer_) { |
| 524 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox( |
| 525 &texture_mailbox, secure_output_only, false); |
| 526 } |
| 527 |
| 528 cc::SurfaceId old_surface_id = surface_id_; |
| 529 surface_id_ = factory_owner_->id_allocator_->GenerateId(); |
| 530 factory_owner_->surface_factory_->Create(surface_id_); |
| 531 |
| 532 gfx::Size buffer_size = texture_mailbox.size_in_pixels(); |
| 533 gfx::SizeF scaled_buffer_size( |
| 534 gfx::ScaleSize(gfx::SizeF(buffer_size), 1.0f / pending_buffer_scale_)); |
| 535 |
| 536 gfx::Size layer_size; // Size of the output layer, in DIP. |
| 537 if (!pending_viewport_.IsEmpty()) { |
| 538 layer_size = pending_viewport_; |
| 539 } else if (!pending_crop_.IsEmpty()) { |
| 540 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(pending_crop_.width()) || |
| 541 !gfx::IsExpressibleAsInt(pending_crop_.height())) |
| 542 << "Crop rectangle size (" << pending_crop_.size().ToString() |
| 543 << ") most be expressible using integers when viewport is not set"; |
| 544 layer_size = gfx::ToCeiledSize(pending_crop_.size()); |
| 545 } else { |
| 546 layer_size = gfx::ToCeiledSize(scaled_buffer_size); |
| 547 } |
| 548 |
| 549 // TODO(jbauman): Figure out how this interacts with the pixel size of |
| 550 // CopyOutputRequests on the layer. |
| 551 float contents_surface_to_layer_scale = 1.0; |
| 552 gfx::Size contents_surface_size = layer_size; |
| 553 |
| 554 gfx::PointF uv_top_left(0.f, 0.f); |
| 555 gfx::PointF uv_bottom_right(1.f, 1.f); |
| 556 if (!pending_crop_.IsEmpty()) { |
| 557 uv_top_left = pending_crop_.origin(); |
| 558 |
| 559 uv_top_left.Scale(1.f / scaled_buffer_size.width(), |
| 560 1.f / scaled_buffer_size.height()); |
| 561 uv_bottom_right = pending_crop_.bottom_right(); |
| 562 uv_bottom_right.Scale(1.f / scaled_buffer_size.width(), |
| 563 1.f / scaled_buffer_size.height()); |
| 564 } |
| 565 |
| 566 // pending_damage_ is in Surface coordinates. |
| 567 gfx::Rect damage_rect = gfx::SkIRectToRect(pending_damage_.getBounds()); |
| 568 |
| 569 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); |
| 570 render_pass->SetAll(cc::RenderPassId(1, 1), |
| 571 gfx::Rect(contents_surface_size), damage_rect, |
| 572 gfx::Transform(), false); |
| 573 |
| 574 gfx::Rect quad_rect = gfx::Rect(contents_surface_size); |
| 575 cc::SharedQuadState* quad_state = |
| 576 render_pass->CreateAndAppendSharedQuadState(); |
| 577 quad_state->quad_layer_bounds = contents_surface_size; |
| 578 quad_state->visible_quad_layer_rect = quad_rect; |
| 579 quad_state->opacity = alpha_; |
| 435 alpha_ = pending_alpha_; | 580 alpha_ = pending_alpha_; |
| 581 |
| 582 bool frame_is_opaque = false; |
| 583 |
| 584 std::unique_ptr<cc::DelegatedFrameData> delegated_frame( |
| 585 new cc::DelegatedFrameData); |
| 586 if (texture_mailbox_release_callback) { |
| 587 cc::TransferableResource resource; |
| 588 resource.id = next_resource_id_++; |
| 589 resource.format = cc::RGBA_8888; |
| 590 resource.filter = |
| 591 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR; |
| 592 resource.size = texture_mailbox.size_in_pixels(); |
| 593 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(), |
| 594 texture_mailbox.sync_token(), |
| 595 texture_mailbox.target()); |
| 596 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate(); |
| 597 |
| 598 cc::TextureDrawQuad* texture_quad = |
| 599 render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>(); |
| 600 float vertex_opacity[4] = {1.0, 1.0, 1.0, 1.0}; |
| 601 gfx::Rect opaque_rect; |
| 602 frame_is_opaque = |
| 603 pending_blend_mode_ == SkXfermode::kSrc_Mode || |
| 604 pending_opaque_region_.contains(gfx::RectToSkIRect(quad_rect)); |
| 605 if (frame_is_opaque) { |
| 606 opaque_rect = quad_rect; |
| 607 } else if (pending_opaque_region_.isRect()) { |
| 608 opaque_rect = gfx::SkIRectToRect(pending_opaque_region_.getBounds()); |
| 609 } |
| 610 |
| 611 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect, |
| 612 resource.id, true, uv_top_left, uv_bottom_right, |
| 613 SK_ColorTRANSPARENT, vertex_opacity, false, false, |
| 614 secure_output_only); |
| 615 |
| 616 factory_owner_->release_callbacks_[resource.id] = std::make_pair( |
| 617 factory_owner_, std::move(texture_mailbox_release_callback)); |
| 618 delegated_frame->resource_list.push_back(resource); |
| 619 } else { |
| 620 cc::SolidColorDrawQuad* solid_quad = |
| 621 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>(); |
| 622 solid_quad->SetNew(quad_state, quad_rect, quad_rect, SK_ColorBLACK, |
| 623 false); |
| 624 frame_is_opaque = true; |
| 625 } |
| 626 |
| 627 delegated_frame->render_pass_list.push_back(std::move(render_pass)); |
| 628 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); |
| 629 frame->delegated_frame_data = std::move(delegated_frame); |
| 630 |
| 631 factory_owner_->surface_factory_->SubmitCompositorFrame( |
| 632 surface_id_, std::move(frame), cc::SurfaceFactory::DrawCallback()); |
| 633 |
| 634 if (!old_surface_id.is_null()) { |
| 635 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_, |
| 636 old_surface_id); |
| 637 factory_owner_->surface_factory_->Destroy(old_surface_id); |
| 638 } |
| 639 |
| 640 layer()->SetShowSurface( |
| 641 surface_id_, |
| 642 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)), |
| 643 base::Bind(&RequireCallback, base::Unretained(surface_manager_)), |
| 644 contents_surface_size, contents_surface_to_layer_scale, layer_size); |
| 645 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), layer_size)); |
| 646 layer()->SetFillsBoundsOpaquely(alpha_ == 1.0f && frame_is_opaque); |
| 647 |
| 648 // Reset damage. |
| 649 pending_damage_.setEmpty(); |
| 436 } | 650 } |
| 651 // Move pending frame callbacks to the end of active_frame_callbacks_ |
| 652 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 653 pending_frame_callbacks_); |
| 654 } |
| 655 |
| 656 void Surface::CommitSurfaceHierarchy() { |
| 657 DCHECK(needs_commit_surface_hierarchy_); |
| 658 needs_commit_surface_hierarchy_ = false; |
| 659 |
| 660 if (factory_owner_) { |
| 661 CommitSurfaceContents(); |
| 662 } else { |
| 663 CommitLayerContents(); |
| 664 } |
| 665 |
| 666 // Update current input region. |
| 667 input_region_ = pending_input_region_; |
| 437 | 668 |
| 438 // Synchronize window hierarchy. This will position and update the stacking | 669 // Synchronize window hierarchy. This will position and update the stacking |
| 439 // order of all sub-surfaces after committing all pending state of sub-surface | 670 // order of all sub-surfaces after committing all pending state of sub-surface |
| 440 // descendants. | 671 // descendants. |
| 441 aura::Window* stacking_target = nullptr; | 672 aura::Window* stacking_target = nullptr; |
| 442 for (auto& sub_surface_entry : pending_sub_surfaces_) { | 673 for (auto& sub_surface_entry : pending_sub_surfaces_) { |
| 443 Surface* sub_surface = sub_surface_entry.first; | 674 Surface* sub_surface = sub_surface_entry.first; |
| 444 | 675 |
| 445 // Synchronsouly commit all pending state of the sub-surface and its | 676 // Synchronsouly commit all pending state of the sub-surface and its |
| 446 // decendents. | 677 // decendents. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 new base::trace_event::TracedValue()); | 766 new base::trace_event::TracedValue()); |
| 536 value->SetString("name", layer()->name()); | 767 value->SetString("name", layer()->name()); |
| 537 return value; | 768 return value; |
| 538 } | 769 } |
| 539 | 770 |
| 540 //////////////////////////////////////////////////////////////////////////////// | 771 //////////////////////////////////////////////////////////////////////////////// |
| 541 // aura::WindowObserver overrides: | 772 // aura::WindowObserver overrides: |
| 542 | 773 |
| 543 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { | 774 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { |
| 544 DCHECK(!compositor_); | 775 DCHECK(!compositor_); |
| 776 DCHECK(!factory_owner_); |
| 545 compositor_ = layer()->GetCompositor(); | 777 compositor_ = layer()->GetCompositor(); |
| 546 compositor_->AddObserver(this); | 778 compositor_->AddObserver(this); |
| 547 } | 779 } |
| 548 | 780 |
| 549 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, | 781 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, |
| 550 aura::Window* new_root) { | 782 aura::Window* new_root) { |
| 551 DCHECK(compositor_); | 783 DCHECK(compositor_); |
| 552 compositor_->RemoveObserver(this); | 784 compositor_->RemoveObserver(this); |
| 553 compositor_ = nullptr; | 785 compositor_ = nullptr; |
| 554 } | 786 } |
| 555 | 787 |
| 556 //////////////////////////////////////////////////////////////////////////////// | 788 //////////////////////////////////////////////////////////////////////////////// |
| 557 // ui::CompositorObserver overrides: | 789 // ui::CompositorObserver overrides: |
| 558 | 790 |
| 559 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { | 791 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { |
| 792 DCHECK(!factory_owner_); |
| 560 // Move frame callbacks to the end of |active_frame_callbacks_|. | 793 // Move frame callbacks to the end of |active_frame_callbacks_|. |
| 561 active_frame_callbacks_.splice(active_frame_callbacks_.end(), | 794 active_frame_callbacks_.splice(active_frame_callbacks_.end(), |
| 562 frame_callbacks_); | 795 frame_callbacks_); |
| 563 } | 796 } |
| 564 | 797 |
| 565 void Surface::OnCompositingStarted(ui::Compositor* compositor, | 798 void Surface::OnCompositingStarted(ui::Compositor* compositor, |
| 566 base::TimeTicks start_time) { | 799 base::TimeTicks start_time) { |
| 567 last_compositing_start_time_ = start_time; | 800 last_compositing_start_time_ = start_time; |
| 568 } | 801 } |
| 569 | 802 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 // of a lost graphics context. We recover from this by updating the contents | 840 // of a lost graphics context. We recover from this by updating the contents |
| 608 // of the surface next time the compositor successfully ends compositing. | 841 // of the surface next time the compositor successfully ends compositing. |
| 609 update_contents_after_successful_compositing_ = true; | 842 update_contents_after_successful_compositing_ = true; |
| 610 } | 843 } |
| 611 | 844 |
| 612 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { | 845 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { |
| 613 compositor->RemoveObserver(this); | 846 compositor->RemoveObserver(this); |
| 614 compositor_ = nullptr; | 847 compositor_ = nullptr; |
| 615 } | 848 } |
| 616 | 849 |
| 850 void Surface::WillDraw(cc::SurfaceId id) { |
| 851 while (!active_frame_callbacks_.empty()) { |
| 852 active_frame_callbacks_.front().Run(base::TimeTicks::Now()); |
| 853 active_frame_callbacks_.pop_front(); |
| 854 } |
| 855 } |
| 856 |
| 857 bool Surface::use_surface_layer_ = false; |
| 858 |
| 617 } // namespace exo | 859 } // namespace exo |
| OLD | NEW |