Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: cc/output/output_surface.cc

Issue 16304003: Unified OutputSurface::SwapBuffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "cc/output/compositor_frame.h"
14 #include "cc/output/output_surface_client.h" 15 #include "cc/output/output_surface_client.h"
15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
16 #include "third_party/khronos/GLES2/gl2.h" 17 #include "third_party/khronos/GLES2/gl2.h"
17 #include "third_party/khronos/GLES2/gl2ext.h" 18 #include "third_party/khronos/GLES2/gl2ext.h"
18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
19 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
20 21
21 using std::set; 22 using std::set;
22 using std::string; 23 using std::string;
23 using std::vector; 24 using std::vector;
24 25
25 namespace cc { 26 namespace cc {
26 27
27 class OutputSurfaceCallbacks 28 class OutputSurfaceCallbacks
28 : public WebKit::WebGraphicsContext3D:: 29 : public WebKit::WebGraphicsContext3D::
29 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM, 30 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM,
30 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback { 31 public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
31 public: 32 public:
32 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client) 33 explicit OutputSurfaceCallbacks(OutputSurfaceClient* client)
33 : client_(client) { 34 : client_(client) {
34 DCHECK(client_); 35 DCHECK(client_);
35 } 36 }
36 37
37 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation. 38 // WK:WGC3D::WGSwapBuffersCompleteCallbackCHROMIUM implementation.
38 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(); } 39 virtual void onSwapBuffersComplete() { client_->OnSwapBuffersComplete(NULL); }
39 40
40 // WK:WGC3D::WGContextLostCallback implementation. 41 // WK:WGC3D::WGContextLostCallback implementation.
41 virtual void onContextLost() { client_->DidLoseOutputSurface(); } 42 virtual void onContextLost() { client_->DidLoseOutputSurface(); }
42 43
43 private: 44 private:
44 OutputSurfaceClient* client_; 45 OutputSurfaceClient* client_;
45 }; 46 };
46 47
47 OutputSurface::OutputSurface( 48 OutputSurface::OutputSurface(
48 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 49 scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
49 : client_(NULL), 50 : client_(NULL),
50 context3d_(context3d.Pass()), 51 context3d_(context3d.Pass()),
51 has_gl_discard_backbuffer_(false), 52 has_gl_discard_backbuffer_(false),
53 has_swap_buffers_complete_callback_(false),
52 device_scale_factor_(-1) { 54 device_scale_factor_(-1) {
53 } 55 }
54 56
55 OutputSurface::OutputSurface( 57 OutputSurface::OutputSurface(
56 scoped_ptr<cc::SoftwareOutputDevice> software_device) 58 scoped_ptr<cc::SoftwareOutputDevice> software_device)
57 : client_(NULL), 59 : client_(NULL),
58 software_device_(software_device.Pass()), 60 software_device_(software_device.Pass()),
59 has_gl_discard_backbuffer_(false), 61 has_gl_discard_backbuffer_(false),
62 has_swap_buffers_complete_callback_(false),
60 device_scale_factor_(-1) { 63 device_scale_factor_(-1) {
61 } 64 }
62 65
63 OutputSurface::OutputSurface( 66 OutputSurface::OutputSurface(
64 scoped_ptr<WebKit::WebGraphicsContext3D> context3d, 67 scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
65 scoped_ptr<cc::SoftwareOutputDevice> software_device) 68 scoped_ptr<cc::SoftwareOutputDevice> software_device)
66 : client_(NULL), 69 : client_(NULL),
67 context3d_(context3d.Pass()), 70 context3d_(context3d.Pass()),
68 software_device_(software_device.Pass()), 71 software_device_(software_device.Pass()),
69 has_gl_discard_backbuffer_(false), 72 has_gl_discard_backbuffer_(false),
73 has_swap_buffers_complete_callback_(false),
70 device_scale_factor_(-1) { 74 device_scale_factor_(-1) {
71 } 75 }
72 76
73 OutputSurface::~OutputSurface() { 77 OutputSurface::~OutputSurface() {
74 } 78 }
75 79
76 bool OutputSurface::ForcedDrawToSoftwareDevice() const { 80 bool OutputSurface::ForcedDrawToSoftwareDevice() const {
77 return false; 81 return false;
78 } 82 }
79 83
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DCHECK(!context3d_); 126 DCHECK(!context3d_);
123 DCHECK(context3d); 127 DCHECK(context3d);
124 DCHECK(client_); 128 DCHECK(client_);
125 129
126 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS)); 130 string extensions_string = UTF16ToASCII(context3d->getString(GL_EXTENSIONS));
127 vector<string> extensions_list; 131 vector<string> extensions_list;
128 base::SplitString(extensions_string, ' ', &extensions_list); 132 base::SplitString(extensions_string, ' ', &extensions_list);
129 set<string> extensions(extensions_list.begin(), extensions_list.end()); 133 set<string> extensions(extensions_list.begin(), extensions_list.end());
130 has_gl_discard_backbuffer_ = 134 has_gl_discard_backbuffer_ =
131 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0; 135 extensions.count("GL_CHROMIUM_discard_backbuffer") > 0;
136 has_swap_buffers_complete_callback_ =
137 extensions.count("GL_CHROMIUM_swapbuffers_complete_callback") > 0;
138
132 139
133 context3d_ = context3d.Pass(); 140 context3d_ = context3d.Pass();
134 callbacks_.reset(new OutputSurfaceCallbacks(client_)); 141 callbacks_.reset(new OutputSurfaceCallbacks(client_));
135 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get()); 142 context3d_->setSwapBuffersCompleteCallbackCHROMIUM(callbacks_.get());
136 context3d_->setContextLostCallback(callbacks_.get()); 143 context3d_->setContextLostCallback(callbacks_.get());
137 } 144 }
138 145
139 void OutputSurface::SendFrameToParentCompositor(CompositorFrame* frame) {
140 NOTIMPLEMENTED();
141 }
142
143 void OutputSurface::EnsureBackbuffer() { 146 void OutputSurface::EnsureBackbuffer() {
144 DCHECK(context3d_); 147 DCHECK(context3d_);
145 if (has_gl_discard_backbuffer_) 148 if (has_gl_discard_backbuffer_)
146 context3d_->ensureBackbufferCHROMIUM(); 149 context3d_->ensureBackbufferCHROMIUM();
147 } 150 }
148 151
149 void OutputSurface::DiscardBackbuffer() { 152 void OutputSurface::DiscardBackbuffer() {
150 DCHECK(context3d_); 153 DCHECK(context3d_);
151 if (has_gl_discard_backbuffer_) 154 if (has_gl_discard_backbuffer_)
152 context3d_->discardBackbufferCHROMIUM(); 155 context3d_->discardBackbufferCHROMIUM();
153 } 156 }
154 157
155 void OutputSurface::Reshape(gfx::Size size, float scale_factor) { 158 void OutputSurface::Reshape(gfx::Size size, float scale_factor) {
156 if (size == surface_size_ && scale_factor == device_scale_factor_) 159 if (size == surface_size_ && scale_factor == device_scale_factor_)
157 return; 160 return;
158 161
159 surface_size_ = size; 162 surface_size_ = size;
160 device_scale_factor_ = scale_factor; 163 device_scale_factor_ = scale_factor;
161 if (context3d_) { 164 if (context3d_) {
162 context3d_->reshapeWithScaleFactor( 165 context3d_->reshapeWithScaleFactor(
163 size.width(), size.height(), scale_factor); 166 size.width(), size.height(), scale_factor);
164 } 167 }
168 if (software_device_)
169 software_device_->Resize(size);
165 } 170 }
166 171
167 gfx::Size OutputSurface::SurfaceSize() const { 172 gfx::Size OutputSurface::SurfaceSize() const {
168 return surface_size_; 173 return surface_size_;
169 } 174 }
170 175
171 void OutputSurface::BindFramebuffer() { 176 void OutputSurface::BindFramebuffer() {
172 DCHECK(context3d_); 177 DCHECK(context3d_);
173 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0); 178 context3d_->bindFramebuffer(GL_FRAMEBUFFER, 0);
174 } 179 }
175 180
176 void OutputSurface::SwapBuffers(const ui::LatencyInfo& latency_info) { 181 void OutputSurface::SwapBuffers(cc::CompositorFrame* frame) {
177 DCHECK(context3d_); 182 DCHECK(context3d_);
178 // Note that currently this has the same effect as SwapBuffers; we should 183 DCHECK(frame->gl_frame_data);
179 // consider exposing a different entry point on WebGraphicsContext3D.
180 context3d_->prepareTexture();
181 }
182 184
183 void OutputSurface::PostSubBuffer(gfx::Rect rect, 185 gfx::Rect sub_buffer_rect = frame->gl_frame_data->sub_buffer_rect;
184 const ui::LatencyInfo& latency_info) { 186 if (!sub_buffer_rect.IsEmpty()) {
185 DCHECK(context3d_); 187 context3d()->postSubBufferCHROMIUM(sub_buffer_rect.x(),
186 context3d_->postSubBufferCHROMIUM( 188 sub_buffer_rect.y(),
187 rect.x(), rect.y(), rect.width(), rect.height()); 189 sub_buffer_rect.width(),
190 sub_buffer_rect.height());
191 } else {
192 // Note that currently this has the same effect as SwapBuffers; we should
193 // consider exposing a different entry point on WebGraphicsContext3D.
194 context3d()->prepareTexture();
195 }
joth 2013/06/10 18:43:32 fwiw, I found I had to wrap this lot in "if contex
aelias_OOO_until_Jul13 2013/06/10 18:57:57 cc_unittests package is already passing as of Patc
joth 2013/06/10 19:04:49 oh yes! Nice. I totally missed that somehow :)
196
197 if (client_ && !has_swap_buffers_complete_callback_)
198 client_->OnSwapBuffersComplete(NULL);
188 } 199 }
189 200
190 } // namespace cc 201 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698