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 "cc/output/output_surface.h" | 5 #include "cc/output/output_surface.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | |
12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
13 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "cc/output/compositor_frame.h" | |
14 #include "cc/output/output_surface_client.h" | 17 #include "cc/output/output_surface_client.h" |
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 18 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
16 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
17 #include "third_party/khronos/GLES2/gl2ext.h" | 20 #include "third_party/khronos/GLES2/gl2ext.h" |
18 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
19 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
20 | 23 |
21 using std::set; | 24 using std::set; |
22 using std::string; | 25 using std::string; |
23 using std::vector; | 26 using std::vector; |
24 | 27 |
25 namespace cc { | 28 namespace cc { |
26 | 29 |
27 class OutputSurfaceCallbacks | 30 class OutputSurfaceCallbacks |
28 : public WebKit::WebGraphicsContext3D:: | 31 : public WebKit::WebGraphicsContext3D:: |
29 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, | 32 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, |
30 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { | 33 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { |
31 public: | 34 public: |
32 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) | 35 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) |
33 : client_(client) { | 36 : client_(client) { |
34 DCHECK(client_); | 37 DCHECK(client_); |
35 } | 38 } |
36 | 39 |
37 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. | 40 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. |
38 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } | 41 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(NULL); } |
39 | 42 |
40 // WK:WGC3D::WGContextLostCallback implementation. | 43 // WK:WGC3D::WGContextLostCallback implementation. |
41 virtual void onContextLost() { client_->DidLoseOutputSurface(); } | 44 virtual void onContextLost() { client_->DidLoseOutputSurface(); } |
42 | 45 |
43 private: | 46 private: |
44 OutputSurfaceClient* client_; | 47 OutputSurfaceClient* client_; |
45 }; | 48 }; |
46 | 49 |
47 OutputSurface::OutputSurface( | 50 OutputSurface::OutputSurface( |
48 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) | 51 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) |
49 : client_(NULL), | 52 : client_(NULL), |
50 context3d_(context3d.Pass()), | 53 context3d_(context3d.Pass()), |
51 has_gl_discard_backbuffer_(false), | 54 has_gl_discard_backbuffer_(false), |
52 device_scale_factor_(-1) { | 55 has_swap_buffers_complete_callback_(false), |
56 device_scale_factor_(-1), | |
57 weak_ptr_factory_(this) { | |
53 } | 58 } |
54 | 59 |
55 OutputSurface::OutputSurface( | 60 OutputSurface::OutputSurface( |
56 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 61 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
57 : client_(NULL), | 62 : client_(NULL), |
58 software_device_(software_device.Pass()), | 63 software_device_(software_device.Pass()), |
59 has_gl_discard_backbuffer_(false), | 64 has_gl_discard_backbuffer_(false), |
60 device_scale_factor_(-1) { | 65 has_swap_buffers_complete_callback_(false), |
66 device_scale_factor_(-1), | |
67 weak_ptr_factory_(this) { | |
61 } | 68 } |
62 | 69 |
63 OutputSurface::OutputSurface( | 70 OutputSurface::OutputSurface( |
64 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, | 71 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, |
65 scoped_ptr<cc::SoftwareOutputDevice> software_device) | 72 scoped_ptr<cc::SoftwareOutputDevice> software_device) |
66 : client_(NULL), | 73 : client_(NULL), |
67 context3d_(context3d.Pass()), | 74 context3d_(context3d.Pass()), |
68 software_device_(software_device.Pass()), | 75 software_device_(software_device.Pass()), |
69 has_gl_discard_backbuffer_(false), | 76 has_gl_discard_backbuffer_(false), |
70 device_scale_factor_(-1) { | 77 has_swap_buffers_complete_callback_(false), |
78 device_scale_factor_(-1), | |
79 weak_ptr_factory_(this) { | |
71 } | 80 } |
72 | 81 |
73 OutputSurface::~OutputSurface() { | 82 OutputSurface::~OutputSurface() { |
74 } | 83 } |
75 | 84 |
76 bool OutputSurface::ForcedDrawToSoftwareDevice() const { | 85 bool OutputSurface::ForcedDrawToSoftwareDevice() const { |
77 return false; | 86 return false; |
78 } | 87 } |
79 | 88 |
80 bool OutputSurface::BindToClient( | 89 bool OutputSurface::BindToClient( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 DCHECK(!context3d_); | 131 DCHECK(!context3d_); |
123 DCHECK(context3d); | 132 DCHECK(context3d); |
124 DCHECK(client_); | 133 DCHECK(client_); |
125 | 134 |
126 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); | 135 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); |
127 vector<string> extensions_list; | 136 vector<string> extensions_list; |
128 base::SplitString(extensions_string, ' ', &extensions_list); | 137 base::SplitString(extensions_string, ' ', &extensions_list); |
129 set<string> extensions(extensions_list.begin(), extensions_list.end()); | 138 set<string> extensions(extensions_list.begin(), extensions_list.end()); |
130 has_gl_discard_backbuffer_ = | 139 has_gl_discard_backbuffer_ = |
131 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; | 140 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; |
141 has_swap_buffers_complete_callback_ = | |
142 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback") > 0; | |
143 | |
132 | 144 |
133 context3d_ = context3d.Pass(); | 145 context3d_ = context3d.Pass(); |
134 callbacks_.reset(new OutputSurfaceCallbacks(client_)); | 146 callbacks_.reset(new OutputSurfaceCallbacks(client_)); |
135 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); | 147 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); |
136 context3d_->setContextLostCallback(callbacks_.get()); | 148 context3d_->setContextLostCallback(callbacks_.get()); |
137 } | 149 } |
138 | 150 |
139 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) { | |
140 NOTIMPLEMENTED(); | |
141 } | |
142 | |
143 void OutputSurface::EnsureBackbuffer() { | 151 void OutputSurface::EnsureBackbuffer() { |
144 DCHECK(context3d_); | 152 DCHECK(context3d_); |
145 if (has_gl_discard_backbuffer_) | 153 if (has_gl_discard_backbuffer_) |
146 context3d_->ensureBackbufferCHROMIUM(); | 154 context3d_->ensureBackbufferCHROMIUM(); |
147 } | 155 } |
148 | 156 |
149 void OutputSurface::DiscardBackbuffer() { | 157 void OutputSurface::DiscardBackbuffer() { |
150 DCHECK(context3d_); | 158 DCHECK(context3d_); |
151 if (has_gl_discard_backbuffer_) | 159 if (has_gl_discard_backbuffer_) |
152 context3d_->discardBackbufferCHROMIUM(); | 160 context3d_->discardBackbufferCHROMIUM(); |
153 } | 161 } |
154 | 162 |
155 void OutputSurface::Reshape(gfx::Size size, float scale_factor) { | 163 void OutputSurface::Reshape(gfx::Size size, float scale_factor) { |
156 if (size == surface_size_ && scale_factor == device_scale_factor_) | 164 if (size == surface_size_ && scale_factor == device_scale_factor_) |
157 return; | 165 return; |
158 | 166 |
159 surface_size_ = size; | 167 surface_size_ = size; |
160 device_scale_factor_ = scale_factor; | 168 device_scale_factor_ = scale_factor; |
161 if (context3d_) { | 169 if (context3d_) { |
162 context3d_->reshapeWithScaleFactor( | 170 context3d_->reshapeWithScaleFactor( |
163 size.width(), size.height(), scale_factor); | 171 size.width(), size.height(), scale_factor); |
164 } | 172 } |
173 if (software_device_) | |
174 software_device_->Resize(size); | |
165 } | 175 } |
166 | 176 |
167 gfx::Size OutputSurface::SurfaceSize() const { | 177 gfx::Size OutputSurface::SurfaceSize() const { |
168 return surface_size_; | 178 return surface_size_; |
169 } | 179 } |
170 | 180 |
171 void OutputSurface::BindFramebuffer() { | 181 void OutputSurface::BindFramebuffer() { |
172 DCHECK(context3d_); | 182 DCHECK(context3d_); |
173 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); | 183 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); |
174 } | 184 } |
175 | 185 |
176 void OutputSurface::SwapBuffers(const ui::LatencyInfo& latency_info) { | 186 void OutputSurface::SwapBuffers(cc::CompositorFrame* frame) { |
177 DCHECK(context3d_); | 187 DCHECK(context3d_); |
jbauman
2013/06/11 06:52:28
This won't necessarily be the case in the software
aelias_OOO_until_Jul13
2013/06/11 07:12:46
Hmm, you're right, thanks. I added an early out h
| |
178 // Note that currently this has the same effect as SwapBuffers; we should | 188 DCHECK(frame->gl_frame_data); |
179 // consider exposing a different entry point on WebGraphicsContext3D. | 189 |
180 context3d_->prepareTexture(); | 190 if (frame->gl_frame_data->partial_swap_allowed) { |
191 gfx::Rect sub_buffer_rect = frame->gl_frame_data->sub_buffer_rect; | |
192 context3d()->postSubBufferCHROMIUM(sub_buffer_rect.x(), | |
193 sub_buffer_rect.y(), | |
194 sub_buffer_rect.width(), | |
195 sub_buffer_rect.height()); | |
196 } else { | |
197 // Note that currently this has the same effect as SwapBuffers; we should | |
198 // consider exposing a different entry point on WebGraphicsContext3D. | |
199 context3d()->prepareTexture(); | |
200 } | |
201 | |
202 if (!has_swap_buffers_complete_callback_) | |
203 PostSwapBuffersComplete(); | |
181 } | 204 } |
182 | 205 |
183 void OutputSurface::PostSubBuffer(gfx::Rect rect, | 206 void OutputSurface::PostSwapBuffersComplete() { |
184 const ui::LatencyInfo& latency_info) { | 207 base::MessageLoop::current()->PostTask( |
185 DCHECK(context3d_); | 208 FROM_HERE, |
186 context3d_->postSubBufferCHROMIUM( | 209 base::Bind(&OutputSurface::SwapBuffersComplete, |
187 rect.x(), rect.y(), rect.width(), rect.height()); | 210 weak_ptr_factory_.GetWeakPtr())); |
211 } | |
212 | |
213 void OutputSurface::SwapBuffersComplete() { | |
214 if (!client_) | |
215 return; | |
216 | |
217 client_->OnSwapBuffersComplete(NULL); | |
188 } | 218 } |
189 | 219 |
190 } // namespace cc | 220 } // namespace cc |
OLD | NEW |