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

Side by Side Diff: ui/compositor/compositor.cc

Issue 553213003: Avoid destroying surface before the parent surface stops referencing it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/compositor.h" 5 #include "ui/compositor/compositor.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "cc/base/latency_info_swap_promise.h" 17 #include "cc/base/latency_info_swap_promise.h"
18 #include "cc/base/switches.h" 18 #include "cc/base/switches.h"
19 #include "cc/input/input_handler.h" 19 #include "cc/input/input_handler.h"
20 #include "cc/layers/layer.h" 20 #include "cc/layers/layer.h"
21 #include "cc/output/begin_frame_args.h" 21 #include "cc/output/begin_frame_args.h"
22 #include "cc/output/context_provider.h" 22 #include "cc/output/context_provider.h"
23 #include "cc/surfaces/surface_id_allocator.h"
23 #include "cc/trees/layer_tree_host.h" 24 #include "cc/trees/layer_tree_host.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/compositor/compositor_observer.h" 26 #include "ui/compositor/compositor_observer.h"
26 #include "ui/compositor/compositor_switches.h" 27 #include "ui/compositor/compositor_switches.h"
27 #include "ui/compositor/compositor_vsync_manager.h" 28 #include "ui/compositor/compositor_vsync_manager.h"
28 #include "ui/compositor/dip_util.h" 29 #include "ui/compositor/dip_util.h"
29 #include "ui/compositor/layer.h" 30 #include "ui/compositor/layer.h"
30 #include "ui/compositor/layer_animator_collection.h" 31 #include "ui/compositor/layer_animator_collection.h"
31 #include "ui/gfx/frame_time.h" 32 #include "ui/gfx/frame_time.h"
32 #include "ui/gl/gl_context.h" 33 #include "ui/gl/gl_context.h"
(...skipping 28 matching lines...) Expand all
61 compositor_->UnlockCompositor(); 62 compositor_->UnlockCompositor();
62 compositor_ = NULL; 63 compositor_ = NULL;
63 } 64 }
64 65
65 } // namespace ui 66 } // namespace ui
66 67
67 namespace {} // namespace 68 namespace {} // namespace
68 69
69 namespace ui { 70 namespace ui {
70 71
72 class SatisfySwapPromise : public cc::SwapPromise {
73 public:
74 explicit SatisfySwapPromise(uint32_t id) : id_(id) {}
75
76 private:
77 virtual void DidSwap(cc::CompositorFrameMetadata* metadata) OVERRIDE {
78 metadata->satisfies_sequences.push_back(id_);
79 }
80
81 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE {
82 // TODO: Send to the SurfaceManager immediately.
danakj 2014/10/02 01:53:45 put a name on the todo
83 DCHECK(false);
84 }
85 virtual int64 TraceId() const OVERRIDE { return 0; }
86 uint32_t id_;
87 };
88
71 Compositor::Compositor(gfx::AcceleratedWidget widget, 89 Compositor::Compositor(gfx::AcceleratedWidget widget,
72 ui::ContextFactory* context_factory, 90 ui::ContextFactory* context_factory,
73 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 91 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
74 : context_factory_(context_factory), 92 : context_factory_(context_factory),
75 root_layer_(NULL), 93 root_layer_(NULL),
76 widget_(widget), 94 widget_(widget),
95 surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
96 surface_sequence_number_(0),
77 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()), 97 compositor_thread_loop_(context_factory->GetCompositorMessageLoop()),
78 task_runner_(task_runner), 98 task_runner_(task_runner),
79 vsync_manager_(new CompositorVSyncManager()), 99 vsync_manager_(new CompositorVSyncManager()),
80 device_scale_factor_(0.0f), 100 device_scale_factor_(0.0f),
81 last_started_frame_(0), 101 last_started_frame_(0),
82 last_ended_frame_(0), 102 last_ended_frame_(0),
83 disable_schedule_composite_(false), 103 disable_schedule_composite_(false),
84 compositor_lock_(NULL), 104 compositor_lock_(NULL),
85 defer_draw_scheduling_(false), 105 defer_draw_scheduling_(false),
86 waiting_on_compositing_end_(false), 106 waiting_on_compositing_end_(false),
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 420
401 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const { 421 const cc::LayerTreeDebugState& Compositor::GetLayerTreeDebugState() const {
402 return host_->debug_state(); 422 return host_->debug_state();
403 } 423 }
404 424
405 void Compositor::SetLayerTreeDebugState( 425 void Compositor::SetLayerTreeDebugState(
406 const cc::LayerTreeDebugState& debug_state) { 426 const cc::LayerTreeDebugState& debug_state) {
407 host_->SetDebugState(debug_state); 427 host_->SetDebugState(debug_state);
408 } 428 }
409 429
430 cc::SurfaceSequence Compositor::CreateSurfaceSequence() {
danakj 2014/10/09 00:23:52 Can you give this a name that says its going to us
431 cc::SurfaceSequence sequence;
432 sequence.id_namespace = surface_id_allocator_->id_namespace();
433 sequence.sequence = ++surface_sequence_number_;
434 scoped_ptr<cc::SwapPromise> promise(
435 new SatisfySwapPromise(surface_sequence_number_));
436 host_->QueueSwapPromise(promise.Pass());
437 return sequence;
438 }
439
410 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() { 440 scoped_refptr<CompositorLock> Compositor::GetCompositorLock() {
411 if (!compositor_lock_) { 441 if (!compositor_lock_) {
412 compositor_lock_ = new CompositorLock(this); 442 compositor_lock_ = new CompositorLock(this);
413 if (compositor_thread_loop_.get()) 443 if (compositor_thread_loop_.get())
414 host_->SetDeferCommits(true); 444 host_->SetDeferCommits(true);
415 FOR_EACH_OBSERVER(CompositorObserver, 445 FOR_EACH_OBSERVER(CompositorObserver,
416 observer_list_, 446 observer_list_,
417 OnCompositingLockStateChanged(this)); 447 OnCompositingLockStateChanged(this));
418 } 448 }
419 return compositor_lock_; 449 return compositor_lock_;
(...skipping 24 matching lines...) Expand all
444 // Call ScheduleDraw() instead of Draw() in order to allow other 474 // Call ScheduleDraw() instead of Draw() in order to allow other
445 // CompositorObservers to be notified before starting another 475 // CompositorObservers to be notified before starting another
446 // draw cycle. 476 // draw cycle.
447 ScheduleDraw(); 477 ScheduleDraw();
448 } 478 }
449 FOR_EACH_OBSERVER( 479 FOR_EACH_OBSERVER(
450 CompositorObserver, observer_list_, OnCompositingEnded(this)); 480 CompositorObserver, observer_list_, OnCompositingEnded(this));
451 } 481 }
452 482
453 } // namespace ui 483 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698