OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/browser/aura/browser_compositor_output_surface.h" | 5 #include "content/browser/aura/browser_compositor_output_surface.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "cc/output/compositor_frame.h" | 12 #include "cc/output/compositor_frame.h" |
13 #include "content/browser/aura/reflector_impl.h" | |
14 #include "content/common/gpu/client/context_provider_command_buffer.h" | 13 #include "content/common/gpu/client/context_provider_command_buffer.h" |
15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
16 #include "ui/compositor/compositor.h" | 15 #include "ui/compositor/compositor.h" |
17 #include "ui/compositor/compositor_switches.h" | 16 #include "ui/compositor/compositor_switches.h" |
18 | 17 |
19 namespace content { | 18 namespace content { |
20 | 19 |
21 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | 20 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
22 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 21 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
23 int surface_id, | 22 int surface_id, |
24 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 23 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
25 base::MessageLoopProxy* compositor_message_loop, | 24 const scoped_refptr<base::MessageLoopProxy>& compositor_message_loop, |
26 base::WeakPtr<ui::Compositor> compositor) | 25 base::WeakPtr<ui::Compositor> compositor) |
27 : OutputSurface(context_provider), | 26 : OutputSurface(context_provider), |
28 surface_id_(surface_id), | 27 surface_id_(surface_id), |
29 output_surface_map_(output_surface_map), | 28 output_surface_map_(output_surface_map), |
30 compositor_message_loop_(compositor_message_loop), | 29 compositor_message_loop_(compositor_message_loop), |
31 compositor_(compositor) { | 30 compositor_(compositor) { |
32 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 31 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
33 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { | 32 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { |
34 std::string string_value = command_line->GetSwitchValueASCII( | 33 std::string string_value = command_line->GetSwitchValueASCII( |
35 switches::kUIMaxFramesPending); | 34 switches::kUIMaxFramesPending); |
36 int int_value; | 35 int int_value; |
37 if (base::StringToInt(string_value, &int_value)) | 36 if (base::StringToInt(string_value, &int_value)) |
38 capabilities_.max_frames_pending = int_value; | 37 capabilities_.max_frames_pending = int_value; |
39 else | 38 else |
40 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; | 39 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; |
41 } | 40 } |
42 capabilities_.adjust_deadline_for_parent = false; | 41 capabilities_.adjust_deadline_for_parent = false; |
43 DetachFromThread(); | 42 DetachFromThread(); |
44 } | 43 } |
45 | 44 |
46 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { | 45 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { |
47 DCHECK(CalledOnValidThread()); | 46 DCHECK(CalledOnValidThread()); |
48 if (!HasClient()) | 47 if (!HasClient()) { |
| 48 DCHECK(!observer_list_.might_have_observers()); |
49 return; | 49 return; |
| 50 } |
50 output_surface_map_->Remove(surface_id_); | 51 output_surface_map_->Remove(surface_id_); |
| 52 // Don't delete the actual objects; we don't own them. |
| 53 FOR_EACH_OBSERVER(Observer, observer_list_, OnDelete()); |
51 } | 54 } |
52 | 55 |
53 bool BrowserCompositorOutputSurface::BindToClient( | 56 bool BrowserCompositorOutputSurface::BindToClient( |
54 cc::OutputSurfaceClient* client) { | 57 cc::OutputSurfaceClient* client) { |
55 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
56 | 59 |
57 if (!OutputSurface::BindToClient(client)) | 60 if (!OutputSurface::BindToClient(client)) |
58 return false; | 61 return false; |
59 | 62 |
60 output_surface_map_->AddWithID(this, surface_id_); | 63 output_surface_map_->AddWithID(this, surface_id_); |
61 return true; | 64 return true; |
62 } | 65 } |
63 | 66 |
64 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, | 67 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, |
65 float scale_factor) { | 68 float scale_factor) { |
66 OutputSurface::Reshape(size, scale_factor); | 69 OutputSurface::Reshape(size, scale_factor); |
67 if (reflector_.get()) | 70 FOR_EACH_OBSERVER(Observer, observer_list_, OnReshape(size)); |
68 reflector_->OnReshape(size); | |
69 } | 71 } |
70 | 72 |
71 void BrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 73 void BrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
72 DCHECK(frame->gl_frame_data); | 74 DCHECK(frame->gl_frame_data); |
73 | 75 |
74 WebGraphicsContext3DCommandBufferImpl* command_buffer_context = | 76 WebGraphicsContext3DCommandBufferImpl* command_buffer_context = |
75 static_cast<WebGraphicsContext3DCommandBufferImpl*>( | 77 static_cast<WebGraphicsContext3DCommandBufferImpl*>( |
76 context_provider_->Context3d()); | 78 context_provider_->Context3d()); |
77 CommandBufferProxyImpl* command_buffer_proxy = | 79 CommandBufferProxyImpl* command_buffer_proxy = |
78 command_buffer_context->GetCommandBufferProxy(); | 80 command_buffer_context->GetCommandBufferProxy(); |
79 DCHECK(command_buffer_proxy); | 81 DCHECK(command_buffer_proxy); |
80 context_provider_->Context3d()->shallowFlushCHROMIUM(); | 82 context_provider_->Context3d()->shallowFlushCHROMIUM(); |
81 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 83 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
82 | 84 |
83 if (reflector_.get()) { | 85 if (frame->gl_frame_data->sub_buffer_rect == |
84 if (frame->gl_frame_data->sub_buffer_rect == | 86 gfx::Rect(frame->gl_frame_data->size)) { |
85 gfx::Rect(frame->gl_frame_data->size)) | 87 FOR_EACH_OBSERVER(Observer, observer_list_, OnSwapBuffers()); |
86 reflector_->OnSwapBuffers(); | 88 } else { |
87 else | 89 FOR_EACH_OBSERVER(Observer, |
88 reflector_->OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | 90 observer_list_, |
| 91 OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect)); |
89 } | 92 } |
90 | 93 |
91 OutputSurface::SwapBuffers(frame); | 94 OutputSurface::SwapBuffers(frame); |
92 } | 95 } |
93 | 96 |
94 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( | 97 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( |
95 base::TimeTicks timebase, | 98 base::TimeTicks timebase, |
96 base::TimeDelta interval) { | 99 base::TimeDelta interval) { |
97 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
98 DCHECK(HasClient()); | 101 DCHECK(HasClient()); |
99 OnVSyncParametersChanged(timebase, interval); | 102 OnVSyncParametersChanged(timebase, interval); |
100 compositor_message_loop_->PostTask( | 103 compositor_message_loop_->PostTask( |
101 FROM_HERE, | 104 FROM_HERE, |
102 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, | 105 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, |
103 compositor_, timebase, interval)); | 106 compositor_, timebase, interval)); |
104 } | 107 } |
105 | 108 |
106 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { | 109 void BrowserCompositorOutputSurface::AddObserver(Observer* observer) { |
107 reflector_ = reflector; | 110 DCHECK(CalledOnValidThread()); |
| 111 DCHECK(HasClient()); |
| 112 observer_list_.AddObserver(observer); |
| 113 } |
| 114 |
| 115 void BrowserCompositorOutputSurface::RemoveObserver(Observer* observer) { |
| 116 DCHECK(CalledOnValidThread()); |
| 117 observer_list_.RemoveObserver(observer); |
108 } | 118 } |
109 | 119 |
110 } // namespace content | 120 } // namespace content |
OLD | NEW |