Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: components/exo/surface.cc

Issue 2008153002: Add initial implementation of cc::Surfaces backend for exo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 CHECK(aura::Env::GetInstance());
207 CHECK(aura::Env::GetInstance()->context_factory());
reveman 2016/05/27 18:25:41 do we need these CHECKs? can they be DCHECKs at le
208 surface_manager_ =
209 aura::Env::GetInstance()->context_factory()->GetSurfaceManager();
210 if (use_surface_layer_) {
211 factory_owner_ = make_scoped_refptr(new SurfaceFactoryOwner);
212 factory_owner_->surface_ = this;
213 CHECK(surface_manager_);
214 factory_owner_->id_allocator_ =
215 aura::Env::GetInstance()->context_factory()->CreateSurfaceIdAllocator();
216 factory_owner_->surface_factory_.reset(
217 new cc::SurfaceFactory(surface_manager_, factory_owner_.get()));
218 }
219
220 if (!factory_owner_) {
221 AddObserver(this);
222 }
156 } 223 }
157 224
158 Surface::~Surface() { 225 Surface::~Surface() {
159 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this)); 226 FOR_EACH_OBSERVER(SurfaceObserver, observers_, OnSurfaceDestroying(this));
160 227
161 layer()->SetShowSolidColorContent(); 228 layer()->SetShowSolidColorContent();
162 229
163 RemoveObserver(this); 230 if (factory_owner_) {
231 factory_owner_->surface_ = nullptr;
232 } else {
233 RemoveObserver(this);
234 }
164 if (compositor_) 235 if (compositor_)
165 compositor_->RemoveObserver(this); 236 compositor_->RemoveObserver(this);
166 237
167 // Call pending frame callbacks with a null frame time to indicate that they 238 // Call pending frame callbacks with a null frame time to indicate that they
168 // have been cancelled. 239 // have been cancelled.
169 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 240 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
170 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 241 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
171 frame_callbacks_); 242 frame_callbacks_);
172 for (const auto& frame_callback : active_frame_callbacks_) 243 for (const auto& frame_callback : active_frame_callbacks_)
173 frame_callback.Run(base::TimeTicks()); 244 frame_callback.Run(base::TimeTicks());
245
246 if (!surface_id_.is_null())
247 factory_owner_->surface_factory_->Destroy(surface_id_);
174 } 248 }
175 249
176 // static 250 // static
177 Surface* Surface::AsSurface(const aura::Window* window) { 251 Surface* Surface::AsSurface(const aura::Window* window) {
178 return window->GetProperty(kSurfaceKey); 252 return window->GetProperty(kSurfaceKey);
179 } 253 }
180 254
255 // static
256 void Surface::SetUseSurfaceLayer(bool use_surface_layer) {
257 use_surface_layer_ = use_surface_layer;
258 }
259
181 void Surface::Attach(Buffer* buffer) { 260 void Surface::Attach(Buffer* buffer) {
182 TRACE_EVENT1("exo", "Surface::Attach", "buffer", 261 TRACE_EVENT1("exo", "Surface::Attach", "buffer",
183 buffer ? buffer->GetSize().ToString() : "null"); 262 buffer ? buffer->GetSize().ToString() : "null");
184 263
185 has_pending_contents_ = true; 264 has_pending_contents_ = true;
186 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>(); 265 pending_buffer_ = buffer ? buffer->AsWeakPtr() : base::WeakPtr<Buffer>();
187 } 266 }
188 267
189 void Surface::Damage(const gfx::Rect& damage) { 268 void Surface::Damage(const gfx::Rect& damage) {
190 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString()); 269 TRACE_EVENT1("exo", "Surface::Damage", "damage", damage.ToString());
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 TRACE_EVENT0("exo", "Surface::Commit"); 420 TRACE_EVENT0("exo", "Surface::Commit");
342 421
343 needs_commit_surface_hierarchy_ = true; 422 needs_commit_surface_hierarchy_ = true;
344 423
345 if (delegate_) 424 if (delegate_)
346 delegate_->OnSurfaceCommit(); 425 delegate_->OnSurfaceCommit();
347 else 426 else
348 CommitSurfaceHierarchy(); 427 CommitSurfaceHierarchy();
349 } 428 }
350 429
351 void Surface::CommitSurfaceHierarchy() { 430 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. 431 // We update contents if Attach() has been called since last commit.
356 if (has_pending_contents_) { 432 if (has_pending_contents_) {
357 has_pending_contents_ = false; 433 has_pending_contents_ = false;
358 434
359 current_buffer_ = pending_buffer_; 435 current_buffer_ = pending_buffer_;
360 pending_buffer_.reset(); 436 pending_buffer_.reset();
361 437
362 // TODO(dcastagna): Make secure_output_only a layer property instead of a 438 // 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 439 // texture mailbox flag so this can be changed without have to provide
364 // new contents. 440 // new contents.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 486 }
411 487
412 // Schedule redraw of the damage region. 488 // Schedule redraw of the damage region.
413 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next()) 489 for (SkRegion::Iterator it(pending_damage_); !it.done(); it.next())
414 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect())); 490 layer()->SchedulePaint(gfx::SkIRectToRect(it.rect()));
415 491
416 // Reset damage. 492 // Reset damage.
417 pending_damage_.setEmpty(); 493 pending_damage_.setEmpty();
418 } 494 }
419 495
420 // Update current input region. 496 if (layer()->has_external_content()) {
421 input_region_ = pending_input_region_; 497 layer()->SetTextureAlpha(pending_alpha_);
498 alpha_ = pending_alpha_;
499 }
422 500
423 // Move pending frame callbacks to the end of |frame_callbacks_|. 501 // Move pending frame callbacks to the end of |frame_callbacks_|.
424 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_); 502 frame_callbacks_.splice(frame_callbacks_.end(), pending_frame_callbacks_);
425 503
426 // Update alpha compositing properties. 504 // Update alpha compositing properties.
427 // TODO(reveman): Use a more reliable way to force blending off than setting 505 // TODO(reveman): Use a more reliable way to force blending off than setting
428 // fills-bounds-opaquely. 506 // fills-bounds-opaquely.
429 layer()->SetFillsBoundsOpaquely( 507 layer()->SetFillsBoundsOpaquely(
430 pending_blend_mode_ == SkXfermode::kSrc_Mode || 508 pending_blend_mode_ == SkXfermode::kSrc_Mode ||
431 pending_opaque_region_.contains( 509 pending_opaque_region_.contains(
432 gfx::RectToSkIRect(gfx::Rect(layer()->size())))); 510 gfx::RectToSkIRect(gfx::Rect(layer()->size()))));
433 if (layer()->has_external_content()) { 511 }
434 layer()->SetTextureAlpha(pending_alpha_); 512
513 void Surface::CommitSurfaceContents() {
514 // We update contents if Attach() has been called since last commit.
515 if (has_pending_contents_) {
516 has_pending_contents_ = false;
517
518 current_buffer_ = pending_buffer_;
519 pending_buffer_.reset();
520
521 bool secure_output_only = pending_only_visible_on_secure_output_;
522 pending_only_visible_on_secure_output_ = false;
523
524 cc::TextureMailbox texture_mailbox;
525 std::unique_ptr<cc::SingleReleaseCallback> texture_mailbox_release_callback;
526 if (current_buffer_) {
527 texture_mailbox_release_callback = current_buffer_->ProduceTextureMailbox(
528 &texture_mailbox, secure_output_only, false);
529 }
530
531 cc::SurfaceId old_surface_id = surface_id_;
532 surface_id_ = factory_owner_->id_allocator_->GenerateId();
533 factory_owner_->surface_factory_->Create(surface_id_);
534
535 gfx::Size texture_size_in_dip = gfx::ScaleToFlooredSize(
536 texture_mailbox.size_in_pixels(), 1.0f / pending_buffer_scale_);
537 gfx::Size contents_size = texture_size_in_dip;
538 if (!pending_viewport_.IsEmpty()) {
539 contents_size = pending_viewport_;
540 } else if (!pending_crop_.IsEmpty()) {
541 DLOG_IF(WARNING, !gfx::IsExpressibleAsInt(pending_crop_.width()) ||
542 !gfx::IsExpressibleAsInt(pending_crop_.height()))
543 << "Crop rectangle size (" << pending_crop_.size().ToString()
544 << ") most be expressible using integers when viewport is not set";
545 contents_size = gfx::ToCeiledSize(pending_crop_.size());
546 }
547
548 float frame_device_scale_factor = 1.0;
reveman 2016/05/27 18:25:41 is this correct when display DSF is 2? e.g. chrome
549
550 std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
551 render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(contents_size),
552 gfx::Rect(contents_size), gfx::Transform(), false);
553
554 gfx::Rect quad_rect = gfx::Rect(contents_size);
555 cc::SharedQuadState* quad_state =
556 render_pass->CreateAndAppendSharedQuadState();
557 quad_state->quad_layer_bounds = contents_size;
558 quad_state->visible_quad_layer_rect = quad_rect;
559 quad_state->opacity = alpha_;
435 alpha_ = pending_alpha_; 560 alpha_ = pending_alpha_;
561
562 bool frame_is_opaque = false;
563
564 std::unique_ptr<cc::DelegatedFrameData> delegated_frame(
565 new cc::DelegatedFrameData);
566 if (texture_mailbox_release_callback) {
567 cc::TransferableResource resource;
568 resource.id = next_resource_id_++;
569 resource.format = cc::RGBA_8888;
570 resource.filter =
571 texture_mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR;
572 resource.size = texture_mailbox.size_in_pixels();
573 resource.mailbox_holder = gpu::MailboxHolder(texture_mailbox.mailbox(),
574 texture_mailbox.sync_token(),
575 texture_mailbox.target());
576 resource.is_overlay_candidate = texture_mailbox.is_overlay_candidate();
577
578 cc::TextureDrawQuad* texture_quad =
579 render_pass->CreateAndAppendDrawQuad<cc::TextureDrawQuad>();
580 float vertex_opacity[4] = {1.0, 1.0, 1.0, 1.0};
581 gfx::Rect opaque_rect;
582 frame_is_opaque =
583 pending_blend_mode_ == SkXfermode::kSrc_Mode ||
584 pending_opaque_region_.contains(gfx::RectToSkIRect(quad_rect));
585 if (frame_is_opaque) {
586 opaque_rect = quad_rect;
587 } else if (pending_opaque_region_.isRect()) {
588 opaque_rect = gfx::SkIRectToRect(pending_opaque_region_.getBounds());
589 }
590
591 gfx::PointF uv_top_left(0.f, 0.f);
592 gfx::PointF uv_bottom_right(1.f, 1.f);
593 if (!pending_crop_.IsEmpty()) {
594 uv_top_left = pending_crop_.origin();
595 uv_top_left.Scale(1.f / texture_size_in_dip.width(),
596 1.f / texture_size_in_dip.height());
597 uv_bottom_right = pending_crop_.bottom_right();
598 uv_bottom_right.Scale(1.f / texture_size_in_dip.width(),
599 1.f / texture_size_in_dip.height());
600 }
601
602 texture_quad->SetNew(quad_state, quad_rect, opaque_rect, quad_rect,
603 resource.id, true, uv_top_left, uv_bottom_right,
604 SK_ColorTRANSPARENT, vertex_opacity, false, false,
605 secure_output_only);
606
607 factory_owner_->release_callbacks_[resource.id] = std::make_pair(
608 factory_owner_, std::move(texture_mailbox_release_callback));
609 delegated_frame->resource_list.push_back(resource);
610 } else {
611 cc::SolidColorDrawQuad* surface_quad =
612 render_pass->CreateAndAppendDrawQuad<cc::SolidColorDrawQuad>();
613 surface_quad->SetNew(quad_state, gfx::Rect(quad_state->quad_layer_bounds),
614 gfx::Rect(quad_state->quad_layer_bounds),
615 SK_ColorBLACK, false);
616 frame_is_opaque = true;
617 }
618
619 delegated_frame->render_pass_list.push_back(std::move(render_pass));
620 std::unique_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
621 frame->delegated_frame_data = std::move(delegated_frame);
622
623 factory_owner_->surface_factory_->SubmitCompositorFrame(
624 surface_id_, std::move(frame), cc::SurfaceFactory::DrawCallback());
625
626 if (!old_surface_id.is_null()) {
627 factory_owner_->surface_factory_->SetPreviousFrameSurface(surface_id_,
628 old_surface_id);
629 factory_owner_->surface_factory_->Destroy(old_surface_id);
630 }
631
632 layer()->SetShowSurface(
633 surface_id_,
634 base::Bind(&SatisfyCallback, base::Unretained(surface_manager_)),
635 base::Bind(&RequireCallback, base::Unretained(surface_manager_)),
636 contents_size, frame_device_scale_factor, contents_size);
637 layer()->SetBounds(gfx::Rect(layer()->bounds().origin(), contents_size));
638 layer()->SetFillsBoundsOpaquely(alpha_ == 1.0f && frame_is_opaque);
639
640 // Reset damage.
641 pending_damage_.setEmpty();
436 } 642 }
643 // Move pending frame callbacks to the end of active_frame_callbacks_
644 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
645 pending_frame_callbacks_);
646 }
647
648 void Surface::CommitSurfaceHierarchy() {
649 DCHECK(needs_commit_surface_hierarchy_);
650 needs_commit_surface_hierarchy_ = false;
651
652 if (factory_owner_) {
653 CommitSurfaceContents();
654 } else {
655 CommitLayerContents();
656 }
657
658 // Update current input region.
659 input_region_ = pending_input_region_;
437 660
438 // Synchronize window hierarchy. This will position and update the stacking 661 // Synchronize window hierarchy. This will position and update the stacking
439 // order of all sub-surfaces after committing all pending state of sub-surface 662 // order of all sub-surfaces after committing all pending state of sub-surface
440 // descendants. 663 // descendants.
441 aura::Window* stacking_target = nullptr; 664 aura::Window* stacking_target = nullptr;
442 for (auto& sub_surface_entry : pending_sub_surfaces_) { 665 for (auto& sub_surface_entry : pending_sub_surfaces_) {
443 Surface* sub_surface = sub_surface_entry.first; 666 Surface* sub_surface = sub_surface_entry.first;
444 667
445 // Synchronsouly commit all pending state of the sub-surface and its 668 // Synchronsouly commit all pending state of the sub-surface and its
446 // decendents. 669 // decendents.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 new base::trace_event::TracedValue()); 758 new base::trace_event::TracedValue());
536 value->SetString("name", layer()->name()); 759 value->SetString("name", layer()->name());
537 return value; 760 return value;
538 } 761 }
539 762
540 //////////////////////////////////////////////////////////////////////////////// 763 ////////////////////////////////////////////////////////////////////////////////
541 // aura::WindowObserver overrides: 764 // aura::WindowObserver overrides:
542 765
543 void Surface::OnWindowAddedToRootWindow(aura::Window* window) { 766 void Surface::OnWindowAddedToRootWindow(aura::Window* window) {
544 DCHECK(!compositor_); 767 DCHECK(!compositor_);
768 DCHECK(!factory_owner_);
545 compositor_ = layer()->GetCompositor(); 769 compositor_ = layer()->GetCompositor();
546 compositor_->AddObserver(this); 770 compositor_->AddObserver(this);
547 } 771 }
548 772
549 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window, 773 void Surface::OnWindowRemovingFromRootWindow(aura::Window* window,
550 aura::Window* new_root) { 774 aura::Window* new_root) {
551 DCHECK(compositor_); 775 DCHECK(compositor_);
552 compositor_->RemoveObserver(this); 776 compositor_->RemoveObserver(this);
553 compositor_ = nullptr; 777 compositor_ = nullptr;
554 } 778 }
555 779
556 //////////////////////////////////////////////////////////////////////////////// 780 ////////////////////////////////////////////////////////////////////////////////
557 // ui::CompositorObserver overrides: 781 // ui::CompositorObserver overrides:
558 782
559 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) { 783 void Surface::OnCompositingDidCommit(ui::Compositor* compositor) {
784 DCHECK(!factory_owner_);
560 // Move frame callbacks to the end of |active_frame_callbacks_|. 785 // Move frame callbacks to the end of |active_frame_callbacks_|.
561 active_frame_callbacks_.splice(active_frame_callbacks_.end(), 786 active_frame_callbacks_.splice(active_frame_callbacks_.end(),
562 frame_callbacks_); 787 frame_callbacks_);
563 } 788 }
564 789
565 void Surface::OnCompositingStarted(ui::Compositor* compositor, 790 void Surface::OnCompositingStarted(ui::Compositor* compositor,
566 base::TimeTicks start_time) { 791 base::TimeTicks start_time) {
567 last_compositing_start_time_ = start_time; 792 last_compositing_start_time_ = start_time;
568 } 793 }
569 794
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 // of a lost graphics context. We recover from this by updating the contents 832 // of a lost graphics context. We recover from this by updating the contents
608 // of the surface next time the compositor successfully ends compositing. 833 // of the surface next time the compositor successfully ends compositing.
609 update_contents_after_successful_compositing_ = true; 834 update_contents_after_successful_compositing_ = true;
610 } 835 }
611 836
612 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) { 837 void Surface::OnCompositingShuttingDown(ui::Compositor* compositor) {
613 compositor->RemoveObserver(this); 838 compositor->RemoveObserver(this);
614 compositor_ = nullptr; 839 compositor_ = nullptr;
615 } 840 }
616 841
842 void Surface::WillDraw(cc::SurfaceId id) {
843 while (!active_frame_callbacks_.empty()) {
844 active_frame_callbacks_.front().Run(base::TimeTicks::Now());
845 active_frame_callbacks_.pop_front();
846 }
847 }
848
849 bool Surface::use_surface_layer_ = false;
850
617 } // namespace exo 851 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698