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) { |
| 30 Initialize(); |
| 31 } |
| 32 |
| 33 BrowserCompositorOutputSurface::BrowserCompositorOutputSurface( |
| 34 scoped_ptr<cc::SoftwareOutputDevice> software_device, |
| 35 int surface_id, |
| 36 IDMap<BrowserCompositorOutputSurface>* output_surface_map, |
| 37 base::MessageLoopProxy* compositor_message_loop, |
| 38 base::WeakPtr<ui::Compositor> compositor) |
| 39 : OutputSurface(software_device.Pass()), |
| 40 surface_id_(surface_id), |
| 41 output_surface_map_(output_surface_map), |
| 42 compositor_message_loop_(compositor_message_loop), |
| 43 compositor_(compositor) { |
| 44 Initialize(); |
| 45 } |
| 46 |
| 47 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { |
| 48 DCHECK(CalledOnValidThread()); |
| 49 if (!HasClient()) |
| 50 return; |
| 51 output_surface_map_->Remove(surface_id_); |
| 52 } |
| 53 |
| 54 void BrowserCompositorOutputSurface::Initialize() { |
32 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 55 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
33 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { | 56 if (command_line->HasSwitch(switches::kUIMaxFramesPending)) { |
34 std::string string_value = command_line->GetSwitchValueASCII( | 57 std::string string_value = command_line->GetSwitchValueASCII( |
35 switches::kUIMaxFramesPending); | 58 switches::kUIMaxFramesPending); |
36 int int_value; | 59 int int_value; |
37 if (base::StringToInt(string_value, &int_value)) | 60 if (base::StringToInt(string_value, &int_value)) |
38 capabilities_.max_frames_pending = int_value; | 61 capabilities_.max_frames_pending = int_value; |
39 else | 62 else |
40 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; | 63 LOG(ERROR) << "Trouble parsing --" << switches::kUIMaxFramesPending; |
41 } | 64 } |
42 capabilities_.adjust_deadline_for_parent = false; | 65 capabilities_.adjust_deadline_for_parent = false; |
| 66 |
43 DetachFromThread(); | 67 DetachFromThread(); |
44 } | 68 } |
45 | 69 |
46 BrowserCompositorOutputSurface::~BrowserCompositorOutputSurface() { | |
47 DCHECK(CalledOnValidThread()); | |
48 if (!HasClient()) | |
49 return; | |
50 output_surface_map_->Remove(surface_id_); | |
51 } | |
52 | |
53 bool BrowserCompositorOutputSurface::BindToClient( | 70 bool BrowserCompositorOutputSurface::BindToClient( |
54 cc::OutputSurfaceClient* client) { | 71 cc::OutputSurfaceClient* client) { |
55 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
56 | 73 |
57 if (!OutputSurface::BindToClient(client)) | 74 if (!OutputSurface::BindToClient(client)) |
58 return false; | 75 return false; |
59 | 76 |
60 output_surface_map_->AddWithID(this, surface_id_); | 77 output_surface_map_->AddWithID(this, surface_id_); |
61 if (reflector_) | 78 if (reflector_) |
62 reflector_->OnSourceSurfaceReady(surface_id_); | 79 reflector_->OnSourceSurfaceReady(surface_id_); |
63 return true; | 80 return true; |
64 } | 81 } |
65 | 82 |
66 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, | 83 void BrowserCompositorOutputSurface::Reshape(gfx::Size size, |
67 float scale_factor) { | 84 float scale_factor) { |
68 OutputSurface::Reshape(size, scale_factor); | 85 OutputSurface::Reshape(size, scale_factor); |
69 if (reflector_.get()) | 86 if (reflector_.get()) |
70 reflector_->OnReshape(size); | 87 reflector_->OnReshape(size); |
71 } | 88 } |
72 | 89 |
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( | 90 void BrowserCompositorOutputSurface::OnUpdateVSyncParameters( |
97 base::TimeTicks timebase, | 91 base::TimeTicks timebase, |
98 base::TimeDelta interval) { | 92 base::TimeDelta interval) { |
99 DCHECK(CalledOnValidThread()); | 93 DCHECK(CalledOnValidThread()); |
100 DCHECK(HasClient()); | 94 DCHECK(HasClient()); |
101 OnVSyncParametersChanged(timebase, interval); | 95 OnVSyncParametersChanged(timebase, interval); |
102 compositor_message_loop_->PostTask( | 96 compositor_message_loop_->PostTask( |
103 FROM_HERE, | 97 FROM_HERE, |
104 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, | 98 base::Bind(&ui::Compositor::OnUpdateVSyncParameters, |
105 compositor_, timebase, interval)); | 99 compositor_, timebase, interval)); |
106 } | 100 } |
107 | 101 |
108 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { | 102 void BrowserCompositorOutputSurface::SetReflector(ReflectorImpl* reflector) { |
109 reflector_ = reflector; | 103 reflector_ = reflector; |
110 } | 104 } |
111 | 105 |
112 } // namespace content | 106 } // namespace content |
OLD | NEW |