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" | |
13 #include "content/browser/aura/reflector_impl.h" | 12 #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" | |
16 #include "ui/compositor/compositor.h" | 14 #include "ui/compositor/compositor.h" |
17 #include "ui/compositor/compositor_switches.h" | 15 #include "ui/compositor/compositor_switches.h" |
18 | 16 |
19 namespace content { | 17 namespace content { |
20 | 18 |
21 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | 19 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
22 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, | 20 const scoped_refptr<ContextProviderCommandBuffer>& context_provider, |
23 int surface_id, | 21 int surface_id, |
24 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | 22 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
25 base::MessageLoopProxy* compositor_message_loop, | 23 base::MessageLoopProxy* compositor_message_loop, |
26 base::WeakPtr<ui::Compositor> compositor) | 24 base::WeakPtr<ui::Compositor> compositor) |
27 : OutputSurface(context_provider), | 25 : OutputSurface(context_provider), |
28 surface_id_(surface_id), | 26 surface_id_(surface_id), |
29 output_surface_map_(output_surface_map), | 27 output_surface_map_(output_surface_map), |
30 compositor_message_loop_(compositor_message_loop), | 28 compositor_message_loop_(compositor_message_loop), |
31 compositor_(compositor) { | 29 compositor_(compositor) { |
32 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 30 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
33 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { | 31 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { |
34 std::string string_value = command_line->GetSwitchValueASCII( | 32 std::string string_value = command_line->GetSwitchValueASCII( |
35 switches::kUIMaxFramesPending); | 33 switches::kUIMaxFramesPending); |
36 int int_value; | 34 int int_value; |
37 if (base::StringToInt(string_value, &int_value)) | 35 if (base::StringToInt(string_value, &int_value)) |
38 capabilities_.max_frames_pending = int_value; | 36 capabilities_.max_frames_pending = int_value; |
39 else | 37 else |
40 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; | 38 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; |
41 } | 39 } |
42 capabilities_.adjust_deadline_for_parent = false; | 40 capabilities_.adjust_deadline_for_parent = false; |
piman
2013/11/07 00:45:12
nit: Can we share this code between the 2 construc
dnicoara
2013/11/07 15:17:41
Done.
| |
43 DetachFromThread(); | 41 } |
42 | |
43 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( | |
44 scoped_ptr<cc::SoftwareOutputDevice> software_device, | |
45 int surface_id, | |
46 IDMap<BrowserCompositorOutputSurface>* output_surface_map, | |
47 base::MessageLoopProxy* compositor_message_loop, | |
48 base::WeakPtr<ui::Compositor> compositor) | |
49 : OutputSurface(software_device.Pass()), | |
50 surface_id_(surface_id), | |
51 output_surface_map_(output_surface_map), | |
52 compositor_message_loop_(compositor_message_loop), | |
53 compositor_(compositor) { | |
54 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
55 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { | |
56 std::string string_value = | |
57 command_line->GetSwitchValueASCII(switches::kUIMaxFramesPending); | |
58 int int_value; | |
59 if (base::StringToInt(string_value, &int_value)) | |
60 capabilities_.max_frames_pending = int_value; | |
61 else | |
62 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; | |
63 } | |
64 capabilities_.adjust_deadline_for_parent = false; | |
44 } | 65 } |
45 | 66 |
46 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { | 67 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { |
47 DCHECK(CalledOnValidThread()); | 68 DCHECK(CalledOnValidThread()); |
48 if (!HasClient()) | 69 if (!HasClient()) |
49 return; | 70 return; |
50 output_surface_map_->Remove(surface_id_); | 71 output_surface_map_->Remove(surface_id_); |
51 } | 72 } |
52 | 73 |
53 bool BrowserCompositorOutputSurface::BindToClient( | 74 bool BrowserCompositorOutputSurface::BindToClient( |
54 cc::OutputSurfaceClient* client) { | 75 cc::OutputSurfaceClient* client) { |
55 DCHECK(CalledOnValidThread()); | 76 DCHECK(CalledOnValidThread()); |
56 | 77 |
57 if (!OutputSurface::BindToClient(client)) | 78 if (!OutputSurface::BindToClient(client)) |
58 return false; | 79 return false; |
59 | 80 |
60 output_surface_map_->AddWithID(this, surface_id_); | 81 output_surface_map_->AddWithID(this, surface_id_); |
61 if (reflector_) | 82 if (reflector_) |
62 reflector_->OnSourceSurfaceReady(surface_id_); | 83 reflector_->OnSourceSurfaceReady(surface_id_); |
63 return true; | 84 return true; |
64 } | 85 } |
65 | 86 |
66 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, | 87 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, |
67 float scale_factor) { | 88 float scale_factor) { |
68 OutputSurface::Reshape(size, scale_factor); | 89 OutputSurface::Reshape(size, scale_factor); |
69 if (reflector_.get()) | 90 if (reflector_.get()) |
70 reflector_->OnReshape(size); | 91 reflector_->OnReshape(size); |
71 } | 92 } |
72 | 93 |
73 void BrowserCompositorOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { | |
74 DCHECK(frame->gl_frame_data); | |
75 | |
76 WebGraphicsContext3DCommandBufferImpl* command_buffer_context = | |
77 static_cast<WebGraphicsContext3DCommandBufferImpl*>( | |
78 context_provider_->Context3d()); | |
79 CommandBufferProxyImpl* command_buffer_proxy = | |
80 command_buffer_context->GetCommandBufferProxy(); | |
81 DCHECK(command_buffer_proxy); | |
82 context_provider_->Context3d()->shallowFlushCHROMIUM(); | |
83 command_buffer_proxy->SetLatencyInfo(frame->metadata.latency_info); | |
84 | |
85 if (reflector_.get()) { | |
86 if (frame->gl_frame_data->sub_buffer_rect == | |
87 gfx::Rect(frame->gl_frame_data->size)) | |
88 reflector_->OnSwapBuffers(); | |
89 else | |
90 reflector_->OnPostSubBuffer(frame->gl_frame_data->sub_buffer_rect); | |
91 } | |
92 | |
93 OutputSurface::SwapBuffers(frame); | |
94 } | |
95 | |
96 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( | 94 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( |
97 base::TimeTicks timebase, | 95 base::TimeTicks timebase, |
98 base::TimeDelta interval) { | 96 base::TimeDelta interval) { |
99 DCHECK(CalledOnValidThread()); | 97 DCHECK(CalledOnValidThread()); |
100 DCHECK(HasClient()); | 98 DCHECK(HasClient()); |
101 OnVSyncParametersChanged(timebase, interval); | 99 OnVSyncParametersChanged(timebase, interval); |
102 compositor_message_loop_->PostTask( | 100 compositor_message_loop_->PostTask( |
103 FROM_HERE, | 101 FROM_HERE, |
104 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, | 102 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, |
105 compositor_, timebase, interval)); | 103 compositor_, timebase, interval)); |
106 } | 104 } |
107 | 105 |
108 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { | 106 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { |
109 reflector_ = reflector; | 107 reflector_ = reflector; |
110 } | 108 } |
111 | 109 |
112 } // namespace content | 110 } // namespace content |
OLD | NEW |