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/browser_compositor_output_surface_capturer.h" |
13 #include "content/browser/aura/reflector_impl.h" | 14 #include "content/browser/aura/reflector_impl.h" |
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
15 #include "ui/compositor/compositor.h" | 16 #include "ui/compositor/compositor.h" |
16 #include "ui/compositor/compositor_switches.h" | 17 #include "ui/compositor/compositor_switches.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | 21 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
21 scoped_ptr<WebKit::WebGraphicsContext3D> context, | 22 scoped_ptr<WebKit::WebGraphicsContext3D> context, |
22 int surface_id, | 23 int surface_id, |
23 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 24 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
24 base::MessageLoopProxy* compositor_message_loop, | 25 const scoped_refptr<base::MessageLoopProxy>& compositor_message_loop, |
25 base::WeakPtr<ui::Compositor> compositor) | 26 base::WeakPtr<ui::Compositor> compositor) |
26 : OutputSurface(context.Pass()), | 27 : OutputSurface(context.Pass()), |
27 surface_id_(surface_id), | 28 surface_id_(surface_id), |
28 output_surface_map_(output_surface_map), | 29 output_surface_map_(output_surface_map), |
29 compositor_message_loop_(compositor_message_loop), | 30 compositor_message_loop_(compositor_message_loop), |
30 compositor_(compositor) { | 31 compositor_(compositor) { |
31 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 32 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
32 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { | 33 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { |
33 std::string string_value = command_line->GetSwitchValueASCII( | 34 std::string string_value = command_line->GetSwitchValueASCII( |
34 switches::kUIMaxFramesPending); | 35 switches::kUIMaxFramesPending); |
35 int int_value; | 36 int int_value; |
36 if (base::StringToInt(string_value, &int_value)) | 37 if (base::StringToInt(string_value, &int_value)) |
37 capabilities_.max_frames_pending = int_value; | 38 capabilities_.max_frames_pending = int_value; |
38 else | 39 else |
39 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; | 40 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; |
40 } | 41 } |
41 capabilities_.adjust_deadline_for_parent = false; | 42 capabilities_.adjust_deadline_for_parent = false; |
42 DetachFromThread(); | 43 DetachFromThread(); |
43 } | 44 } |
44 | 45 |
45 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { | 46 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { |
46 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
47 if (!HasClient()) | 48 if (!HasClient()) |
48 return; | 49 return; |
49 output_surface_map_->Remove(surface_id_); | 50 output_surface_map_->Remove(surface_id_); |
| 51 // Don't delete the actual object; we don't own it. |
| 52 FOR_EACH_OBSERVER(BrowserCompositorOutputSurfaceCapturer, |
| 53 capturer_list_, |
| 54 DoDestroyOnImplThread()); |
50 } | 55 } |
51 | 56 |
52 bool BrowserCompositorOutputSurface::BindToClient( | 57 bool BrowserCompositorOutputSurface::BindToClient( |
53 cc::OutputSurfaceClient* client) { | 58 cc::OutputSurfaceClient* client) { |
54 DCHECK(CalledOnValidThread()); | 59 DCHECK(CalledOnValidThread()); |
55 | 60 |
56 if (!OutputSurface::BindToClient(client)) | 61 if (!OutputSurface::BindToClient(client)) |
57 return false; | 62 return false; |
58 | 63 |
59 output_surface_map_->AddWithID(this, surface_id_); | 64 output_surface_map_->AddWithID(this, surface_id_); |
60 return true; | 65 return true; |
61 } | 66 } |
62 | 67 |
63 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, | 68 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, |
64 float scale_factor) { | 69 float scale_factor) { |
65 OutputSurface::Reshape(size, scale_factor); | 70 OutputSurface::Reshape(size, scale_factor); |
66 if (reflector_.get()) | 71 if (reflector_.get()) |
67 reflector_->OnReshape(size); | 72 reflector_->OnReshape(size); |
68 } | 73 } |
69 | 74 |
70 void BrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | 75 void BrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
71 DCHECK(frame->gl_frame_data); | 76 DCHECK(frame->gl_frame_data); |
72 | 77 |
73 WebGraphicsContext3DCommandBufferImpl* command_buffer = | |
74 static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); | |
75 CommandBufferProxyImpl* command_buffer_proxy = | 78 CommandBufferProxyImpl* command_buffer_proxy = |
76 command_buffer->GetCommandBufferProxy(); | 79 GetContext3DCommandBufferImpl()->GetCommandBufferProxy(); |
77 DCHECK(command_buffer_proxy); | 80 DCHECK(command_buffer_proxy); |
78 context3d()->shallowFlushCHROMIUM(); | 81 context3d()->shallowFlushCHROMIUM(); |
79 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | 82 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); |
80 | 83 |
| 84 FOR_EACH_OBSERVER(BrowserCompositorOutputSurfaceCapturer, |
| 85 capturer_list_, |
| 86 NotifySwapBuffersOnImplThread()); |
| 87 |
81 if (reflector_.get()) { | 88 if (reflector_.get()) { |
82 if (frame->gl_frame_data->sub_buffer_rect == | 89 if (frame->gl_frame_data->sub_buffer_rect == |
83 gfx::Rect(frame->gl_frame_data->size)) | 90 gfx::Rect(frame->gl_frame_data->size)) |
84 reflector_->OnSwapBuffers(); | 91 reflector_->OnSwapBuffers(); |
85 else | 92 else |
86 reflector_->OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | 93 reflector_->OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect); |
87 } | 94 } |
88 | 95 |
89 OutputSurface::SwapBuffers(frame); | 96 OutputSurface::SwapBuffers(frame); |
90 } | 97 } |
91 | 98 |
92 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( | 99 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( |
93 base::TimeTicks timebase, | 100 base::TimeTicks timebase, |
94 base::TimeDelta interval) { | 101 base::TimeDelta interval) { |
95 DCHECK(CalledOnValidThread()); | 102 DCHECK(CalledOnValidThread()); |
96 DCHECK(HasClient()); | 103 DCHECK(HasClient()); |
97 OnVSyncParametersChanged(timebase, interval); | 104 OnVSyncParametersChanged(timebase, interval); |
98 compositor_message_loop_->PostTask( | 105 compositor_message_loop_->PostTask( |
99 FROM_HERE, | 106 FROM_HERE, |
100 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, | 107 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, |
101 compositor_, timebase, interval)); | 108 compositor_, timebase, interval)); |
102 } | 109 } |
103 | 110 |
104 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { | 111 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { |
105 reflector_ = reflector; | 112 reflector_ = reflector; |
106 } | 113 } |
107 | 114 |
| 115 void BrowserCompositorOutputSurface::AddCapturer( |
| 116 BrowserCompositorOutputSurfaceCapturer* capturer) { |
| 117 DCHECK(CalledOnValidThread()); |
| 118 capturer_list_.AddObserver(capturer); |
| 119 } |
| 120 |
| 121 void BrowserCompositorOutputSurface::RemoveCapturer( |
| 122 BrowserCompositorOutputSurfaceCapturer* capturer) { |
| 123 DCHECK(CalledOnValidThread()); |
| 124 capturer_list_.RemoveObserver(capturer); |
| 125 } |
| 126 |
| 127 WebGraphicsContext3DCommandBufferImpl* |
| 128 BrowserCompositorOutputSurface::GetContext3DCommandBufferImpl() { |
| 129 return static_cast<WebGraphicsContext3DCommandBufferImpl*>(context3d()); |
| 130 } |
| 131 |
108 } // namespace content | 132 } // namespace content |
OLD | NEW |