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

Side by Side Diff: webkit/common/gpu/webgraphicscontext3d_impl.cc

Issue 305643004: Reducing code duplication between WGC3D(InProcess)CommandBufferImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added WEBKIT_GPU_EXPORT Created 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 5 #include "webkit/common/gpu/webgraphicscontext3d_impl.h"
6
7 #include "base/atomicops.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10 #include "gpu/GLES2/gl2extchromium.h"
11 #include "gpu/command_buffer/client/gles2_implementation.h"
12 #include "gpu/command_buffer/client/gles2_lib.h"
13 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
6 14
7 #include "third_party/khronos/GLES2/gl2.h" 15 #include "third_party/khronos/GLES2/gl2.h"
8 #ifndef GL_GLEXT_PROTOTYPES 16 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1 17 #define GL_GLEXT_PROTOTYPES 1
10 #endif 18 #endif
11 #include "third_party/khronos/GLES2/gl2ext.h" 19 #include "third_party/khronos/GLES2/gl2ext.h"
12 20
13 #include <algorithm>
14 #include <map>
15
16 #include "base/atomicops.h"
17 #include "base/bind.h"
18 #include "base/command_line.h"
19 #include "base/debug/trace_event.h"
20 #include "base/lazy_instance.h"
21 #include "base/logging.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/metrics/field_trial.h"
24 #include "base/metrics/histogram.h"
25 #include "content/common/gpu/client/gpu_channel_host.h"
26 #include "content/public/common/content_constants.h"
27 #include "content/public/common/content_switches.h"
28 #include "gpu/GLES2/gl2extchromium.h"
29 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
30 #include "gpu/command_buffer/client/gles2_implementation.h"
31 #include "gpu/command_buffer/client/gles2_lib.h"
32 #include "gpu/command_buffer/client/gles2_trace_implementation.h"
33 #include "gpu/command_buffer/client/transfer_buffer.h"
34 #include "gpu/command_buffer/common/constants.h"
35 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
36 #include "gpu/command_buffer/common/mailbox.h"
37 #include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
38 #include "third_party/skia/include/core/SkTypes.h"
39
40 namespace content { 21 namespace content {
41 22
42 namespace { 23 namespace {
43 24
44 static base::LazyInstance<base::Lock>::Leaky
45 g_default_share_groups_lock = LAZY_INSTANCE_INITIALIZER;
46
47 typedef std::map<GpuChannelHost*,
48 scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> >
49 ShareGroupMap;
50 static base::LazyInstance<ShareGroupMap> g_default_share_groups =
51 LAZY_INSTANCE_INITIALIZER;
52
53 scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>
54 GetDefaultShareGroupForHost(GpuChannelHost* host) {
55 base::AutoLock lock(g_default_share_groups_lock.Get());
56
57 ShareGroupMap& share_groups = g_default_share_groups.Get();
58 ShareGroupMap::iterator it = share_groups.find(host);
59 if (it == share_groups.end()) {
60 scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup> group =
61 new WebGraphicsContext3DCommandBufferImpl::ShareGroup();
62 share_groups[host] = group;
63 return group;
64 }
65 return it->second;
66 }
67
68 uint32_t GenFlushID() { 25 uint32_t GenFlushID() {
69 static base::subtle::Atomic32 flush_id = 0; 26 static base::subtle::Atomic32 flush_id = 0;
70 27
71 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement( 28 base::subtle::Atomic32 my_id = base::subtle::Barrier_AtomicIncrement(
72 &flush_id, 1); 29 &flush_id, 1);
73 return static_cast<uint32_t>(my_id); 30 return static_cast<uint32_t>(my_id);
74 } 31 }
75 32
76 // Singleton used to initialize and terminate the gles2 library.
77 class GLES2Initializer {
78 public:
79 GLES2Initializer() {
80 gles2::Initialize();
81 }
82
83 ~GLES2Initializer() {
84 gles2::Terminate();
85 }
86
87 private:
88 DISALLOW_COPY_AND_ASSIGN(GLES2Initializer);
89 };
90
91 ////////////////////////////////////////////////////////////////////////////////
92
93 base::LazyInstance<GLES2Initializer> g_gles2_initializer =
94 LAZY_INSTANCE_INITIALIZER;
95
96 ////////////////////////////////////////////////////////////////////////////////
97
98 } // namespace anonymous 33 } // namespace anonymous
99 34
100 // Helper macros to reduce the amount of code.
101
102 #define DELEGATE_TO_GL(name, glname) \
103 void WebGraphicsContext3DCommandBufferImpl::name() { \
104 gl_->glname(); \
105 }
106
107 #define DELEGATE_TO_GL_R(name, glname, rt) \
108 rt WebGraphicsContext3DCommandBufferImpl::name() { \
109 return gl_->glname(); \
110 }
111
112 #define DELEGATE_TO_GL_1(name, glname, t1) \
113 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
114 gl_->glname(a1); \
115 }
116
117 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
118 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
119 return gl_->glname(a1); \
120 }
121
122 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
123 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1) { \
124 return gl_->glname(a1) ? true : false; \
125 }
126
127 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
128 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
129 gl_->glname(a1, a2); \
130 }
131
132 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
133 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2) { \
134 return gl_->glname(a1, a2); \
135 }
136
137 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
138 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
139 gl_->glname(a1, a2, a3); \
140 }
141
142 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
143 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3) { \
144 return gl_->glname(a1, a2, a3); \
145 }
146
147 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
148 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
149 t4 a4) { \
150 gl_->glname(a1, a2, a3, a4); \
151 }
152
153 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
154 rt WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
155 t4 a4) { \
156 return gl_->glname(a1, a2, a3, a4); \
157 }
158
159 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
160 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
161 t4 a4, t5 a5) { \
162 gl_->glname(a1, a2, a3, a4, a5); \
163 }
164
165 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
166 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
167 t4 a4, t5 a5, t6 a6) { \
168 gl_->glname(a1, a2, a3, a4, a5, a6); \
169 }
170
171 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
172 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
173 t4 a4, t5 a5, t6 a6, \
174 t7 a7) { \
175 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
176 }
177
178 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
179 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
180 t4 a4, t5 a5, t6 a6, \
181 t7 a7, t8 a8) { \
182 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
183 }
184
185 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
186 void WebGraphicsContext3DCommandBufferImpl::name(t1 a1, t2 a2, t3 a3, \
187 t4 a4, t5 a5, t6 a6, \
188 t7 a7, t8 a8, t9 a9) { \
189 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
190 }
191
192 class WebGraphicsContext3DErrorMessageCallback 35 class WebGraphicsContext3DErrorMessageCallback
193 : public gpu::gles2::GLES2Implementation::ErrorMessageCallback { 36 : public gpu::gles2::GLES2ImplementationErrorMessageCallback {
194 public: 37 public:
195 WebGraphicsContext3DErrorMessageCallback( 38 WebGraphicsContext3DErrorMessageCallback(
196 WebGraphicsContext3DCommandBufferImpl* context) 39 WebGraphicsContext3DImpl* context)
197 : graphics_context_(context) { 40 : graphics_context_(context) {
198 } 41 }
199 42
200 virtual void OnErrorMessage(const char* msg, int id) OVERRIDE; 43 virtual void OnErrorMessage(const char* msg, int id) OVERRIDE;
201 44
202 private: 45 private:
203 WebGraphicsContext3DCommandBufferImpl* graphics_context_; 46 WebGraphicsContext3DImpl* graphics_context_;
204 47
205 DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback); 48 DISALLOW_COPY_AND_ASSIGN(WebGraphicsContext3DErrorMessageCallback);
206 }; 49 };
207 50
208 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage( 51 void WebGraphicsContext3DErrorMessageCallback::OnErrorMessage(
209 const char* msg, int id) { 52 const char* msg, int id) {
210 graphics_context_->OnErrorMessage(msg, id); 53 graphics_context_->OnErrorMessage(msg, id);
211 } 54 }
212 55
213 WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits::SharedMemoryLimits() 56 // Helper macros to reduce the amount of code.
214 : command_buffer_size(kDefaultCommandBufferSize),
215 start_transfer_buffer_size(kDefaultStartTransferBufferSize),
216 min_transfer_buffer_size(kDefaultMinTransferBufferSize),
217 max_transfer_buffer_size(kDefaultMaxTransferBufferSize),
218 mapped_memory_reclaim_limit(gpu::gles2::GLES2Implementation::kNoLimit) {}
219 57
220 WebGraphicsContext3DCommandBufferImpl::ShareGroup::ShareGroup() { 58 #define DELEGATE_TO_GL(name, glname) \
59 void WebGraphicsContext3DImpl::name() { \
60 gl_->glname(); \
221 } 61 }
222 62
223 WebGraphicsContext3DCommandBufferImpl::ShareGroup::~ShareGroup() { 63 #define DELEGATE_TO_GL_R(name, glname, rt) \
224 DCHECK(contexts_.empty()); 64 rt WebGraphicsContext3DImpl::name() { \
65 return gl_->glname(); \
225 } 66 }
226 67
227 WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( 68 #define DELEGATE_TO_GL_1(name, glname, t1) \
228 int surface_id, 69 void WebGraphicsContext3DImpl::name(t1 a1) { \
229 const GURL& active_url, 70 gl_->glname(a1); \
230 GpuChannelHost* host, 71 }
231 const Attributes& attributes, 72
232 bool lose_context_when_out_of_memory, 73 #define DELEGATE_TO_GL_1R(name, glname, t1, rt) \
233 const SharedMemoryLimits& limits, 74 rt WebGraphicsContext3DImpl::name(t1 a1) { \
234 WebGraphicsContext3DCommandBufferImpl* share_context) 75 return gl_->glname(a1); \
235 : initialize_failed_(false), 76 }
236 visible_(false), 77
237 host_(host), 78 #define DELEGATE_TO_GL_1RB(name, glname, t1, rt) \
238 surface_id_(surface_id), 79 rt WebGraphicsContext3DImpl::name(t1 a1) { \
239 active_url_(active_url), 80 return gl_->glname(a1) ? true : false; \
81 }
82
83 #define DELEGATE_TO_GL_2(name, glname, t1, t2) \
84 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
85 gl_->glname(a1, a2); \
86 }
87
88 #define DELEGATE_TO_GL_2R(name, glname, t1, t2, rt) \
89 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2) { \
90 return gl_->glname(a1, a2); \
91 }
92
93 #define DELEGATE_TO_GL_3(name, glname, t1, t2, t3) \
94 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
95 gl_->glname(a1, a2, a3); \
96 }
97
98 #define DELEGATE_TO_GL_3R(name, glname, t1, t2, t3, rt) \
99 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3) { \
100 return gl_->glname(a1, a2, a3); \
101 }
102
103 #define DELEGATE_TO_GL_4(name, glname, t1, t2, t3, t4) \
104 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
105 gl_->glname(a1, a2, a3, a4); \
106 }
107
108 #define DELEGATE_TO_GL_4R(name, glname, t1, t2, t3, t4, rt) \
109 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4) { \
110 return gl_->glname(a1, a2, a3, a4); \
111 }
112
113 #define DELEGATE_TO_GL_5(name, glname, t1, t2, t3, t4, t5) \
114 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5) {\
115 \
116 gl_->glname(a1, a2, a3, a4, a5); \
117 }
118
119 #define DELEGATE_TO_GL_6(name, glname, t1, t2, t3, t4, t5, t6) \
120 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
121 t6 a6) { \
122 gl_->glname(a1, a2, a3, a4, a5, a6); \
123 }
124
125 #define DELEGATE_TO_GL_7(name, glname, t1, t2, t3, t4, t5, t6, t7) \
126 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
127 t6 a6, t7 a7) { \
128 gl_->glname(a1, a2, a3, a4, a5, a6, a7); \
129 }
130
131 #define DELEGATE_TO_GL_8(name, glname, t1, t2, t3, t4, t5, t6, t7, t8) \
132 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
133 t6 a6, t7 a7, t8 a8) { \
134 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8); \
135 }
136
137 #define DELEGATE_TO_GL_9(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, t9) \
138 void WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
139 t6 a6, t7 a7, t8 a8, t9 a9) { \
140 gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
141 }
142
143 #define DELEGATE_TO_GL_9R(name, glname, t1, t2, t3, t4, t5, t6, t7, t8, \
144 t9, rt) \
145 rt WebGraphicsContext3DImpl::name(t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, \
146 t6 a6, t7 a7, t8 a8, t9 a9) { \
147 return gl_->glname(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
148 }
149
150 WebGraphicsContext3DImpl::WebGraphicsContext3DImpl(
151 const Attributes& attributes,
152 bool lose_context_when_out_of_memory)
153 : initialized_(false),
154 initialize_failed_(false),
240 context_lost_callback_(0), 155 context_lost_callback_(0),
241 context_lost_reason_(GL_NO_ERROR), 156 context_lost_reason_(GL_NO_ERROR),
242 error_message_callback_(0), 157 error_message_callback_(0),
243 attributes_(attributes), 158 attributes_(attributes),
244 gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu
245 : gfx::PreferIntegratedGpu),
246 weak_ptr_factory_(this),
247 initialized_(false),
248 gl_(NULL), 159 gl_(NULL),
249 lose_context_when_out_of_memory_(lose_context_when_out_of_memory), 160 lose_context_when_out_of_memory_(lose_context_when_out_of_memory),
250 mem_limits_(limits),
251 flush_id_(0) { 161 flush_id_(0) {
252 if (share_context) { 162 }
253 DCHECK(!attributes_.shareResources); 163
254 share_group_ = share_context->share_group_; 164 WebGraphicsContext3DImpl::~WebGraphicsContext3DImpl() {
255 } else { 165
256 share_group_ = attributes_.shareResources 166 }
257 ? GetDefaultShareGroupForHost(host) 167
258 : scoped_refptr<WebGraphicsContext3DCommandBufferImpl::ShareGroup>( 168 void WebGraphicsContext3DImpl::synthesizeGLError(WGC3Denum error) {
259 new ShareGroup()); 169 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
170 synthetic_errors_.end()) {
171 synthetic_errors_.push_back(error);
260 } 172 }
261 } 173 }
262 174
263 WebGraphicsContext3DCommandBufferImpl:: 175 uint32_t WebGraphicsContext3DImpl::lastFlushID() {
264 ~WebGraphicsContext3DCommandBufferImpl() {
265 if (real_gl_) {
266 real_gl_->SetErrorMessageCallback(NULL);
267 }
268
269 Destroy();
270 }
271
272 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL() {
273 if (initialized_)
274 return true;
275
276 if (initialize_failed_)
277 return false;
278
279 TRACE_EVENT0("gpu", "WebGfxCtx3DCmdBfrImpl::MaybeInitializeGL");
280
281 if (!CreateContext(surface_id_ != 0)) {
282 Destroy();
283 initialize_failed_ = true;
284 return false;
285 }
286
287 // TODO(twiz): This code is too fragile in that it assumes that only WebGL
288 // contexts will request noExtensions.
289 if (gl_ && attributes_.noExtensions)
290 gl_->EnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation");
291
292 command_buffer_->SetChannelErrorCallback(
293 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost,
294 weak_ptr_factory_.GetWeakPtr()));
295
296 command_buffer_->SetOnConsoleMessageCallback(
297 base::Bind(&WebGraphicsContext3DCommandBufferImpl::OnErrorMessage,
298 weak_ptr_factory_.GetWeakPtr()));
299
300 client_error_message_callback_.reset(
301 new WebGraphicsContext3DErrorMessageCallback(this));
302 real_gl_->SetErrorMessageCallback(client_error_message_callback_.get());
303
304 // Set attributes_ from created offscreen context.
305 {
306 static const int pcount = 4;
307 static const GLenum pnames[pcount] = {
308 GL_ALPHA_BITS,
309 GL_DEPTH_BITS,
310 GL_STENCIL_BITS,
311 GL_SAMPLE_BUFFERS,
312 };
313 GLint pvalues[pcount] = { 0, 0, 0, 0 };
314
315 gl_->GetMultipleIntegervCHROMIUM(pnames, pcount,
316 pvalues, sizeof(pvalues));
317
318 attributes_.alpha = pvalues[0] > 0;
319 attributes_.depth = pvalues[1] > 0;
320 attributes_.stencil = pvalues[2] > 0;
321 attributes_.antialias = pvalues[3] > 0;
322 }
323
324 visible_ = true;
325 initialized_ = true;
326 return true;
327 }
328
329 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer(
330 bool onscreen, WebGraphicsContext3DCommandBufferImpl* share_context) {
331 if (!host_.get())
332 return false;
333
334 CommandBufferProxyImpl* share_group_command_buffer = NULL;
335
336 if (share_context) {
337 share_group_command_buffer = share_context->command_buffer_.get();
338 }
339
340 std::vector<int32> attribs;
341 attribs.push_back(ALPHA_SIZE);
342 attribs.push_back(attributes_.alpha ? 8 : 0);
343 attribs.push_back(DEPTH_SIZE);
344 attribs.push_back(attributes_.depth ? 24 : 0);
345 attribs.push_back(STENCIL_SIZE);
346 attribs.push_back(attributes_.stencil ? 8 : 0);
347 attribs.push_back(SAMPLES);
348 attribs.push_back(attributes_.antialias ? 4 : 0);
349 attribs.push_back(SAMPLE_BUFFERS);
350 attribs.push_back(attributes_.antialias ? 1 : 0);
351 attribs.push_back(FAIL_IF_MAJOR_PERF_CAVEAT);
352 attribs.push_back(attributes_.failIfMajorPerformanceCaveat ? 1 : 0);
353 attribs.push_back(LOSE_CONTEXT_WHEN_OUT_OF_MEMORY);
354 attribs.push_back(lose_context_when_out_of_memory_ ? 1 : 0);
355 attribs.push_back(BIND_GENERATES_RESOURCES);
356 attribs.push_back(0);
357 attribs.push_back(NONE);
358
359 // Create a proxy to a command buffer in the GPU process.
360 if (onscreen) {
361 command_buffer_.reset(host_->CreateViewCommandBuffer(
362 surface_id_,
363 share_group_command_buffer,
364 attribs,
365 active_url_,
366 gpu_preference_));
367 } else {
368 command_buffer_.reset(host_->CreateOffscreenCommandBuffer(
369 gfx::Size(1, 1),
370 share_group_command_buffer,
371 attribs,
372 active_url_,
373 gpu_preference_));
374 }
375
376 if (!command_buffer_) {
377 DLOG(ERROR) << "GpuChannelHost failed to create command buffer.";
378 return false;
379 }
380
381 DVLOG_IF(1, gpu::error::IsError(command_buffer_->GetLastError()))
382 << "Context dead on arrival. Last error: "
383 << command_buffer_->GetLastError();
384 // Initialize the command buffer.
385 bool result = command_buffer_->Initialize();
386 LOG_IF(ERROR, !result) << "CommandBufferProxy::Initialize failed.";
387 return result;
388 }
389
390 bool WebGraphicsContext3DCommandBufferImpl::CreateContext(bool onscreen) {
391 // Ensure the gles2 library is initialized first in a thread safe way.
392 g_gles2_initializer.Get();
393
394 scoped_refptr<gpu::gles2::ShareGroup> gles2_share_group;
395
396 scoped_ptr<base::AutoLock> share_group_lock;
397 bool add_to_share_group = false;
398 if (!command_buffer_) {
399 WebGraphicsContext3DCommandBufferImpl* share_context = NULL;
400
401 share_group_lock.reset(new base::AutoLock(share_group_->lock()));
402 share_context = share_group_->GetAnyContextLocked();
403
404 if (!InitializeCommandBuffer(onscreen, share_context)) {
405 LOG(ERROR) << "Failed to initialize command buffer.";
406 return false;
407 }
408
409 if (share_context)
410 gles2_share_group = share_context->GetImplementation()->share_group();
411
412 add_to_share_group = true;
413 }
414
415 // Create the GLES2 helper, which writes the command buffer protocol.
416 gles2_helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get()));
417 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) {
418 LOG(ERROR) << "Failed to initialize GLES2CmdHelper.";
419 return false;
420 }
421
422 if (attributes_.noAutomaticFlushes)
423 gles2_helper_->SetAutomaticFlushes(false);
424 // Create a transfer buffer used to copy resources between the renderer
425 // process and the GPU process.
426 transfer_buffer_ .reset(new gpu::TransferBuffer(gles2_helper_.get()));
427
428 DCHECK(host_.get());
429
430 // Create the object exposing the OpenGL API.
431 bool bind_generates_resources = false;
432 real_gl_.reset(
433 new gpu::gles2::GLES2Implementation(gles2_helper_.get(),
434 gles2_share_group,
435 transfer_buffer_.get(),
436 bind_generates_resources,
437 lose_context_when_out_of_memory_,
438 command_buffer_.get()));
439 gl_ = real_gl_.get();
440
441 if (!real_gl_->Initialize(
442 mem_limits_.start_transfer_buffer_size,
443 mem_limits_.min_transfer_buffer_size,
444 mem_limits_.max_transfer_buffer_size,
445 mem_limits_.mapped_memory_reclaim_limit)) {
446 LOG(ERROR) << "Failed to initialize GLES2Implementation.";
447 return false;
448 }
449
450 if (add_to_share_group)
451 share_group_->AddContextLocked(this);
452
453 if (CommandLine::ForCurrentProcess()->HasSwitch(
454 switches::kEnableGpuClientTracing)) {
455 trace_gl_.reset(new gpu::gles2::GLES2TraceImplementation(gl_));
456 gl_ = trace_gl_.get();
457 }
458 return true;
459 }
460
461 bool WebGraphicsContext3DCommandBufferImpl::makeContextCurrent() {
462 if (!MaybeInitializeGL()) {
463 DLOG(ERROR) << "Failed to initialize context.";
464 return false;
465 }
466 gles2::SetGLContext(gl_);
467 if (gpu::error::IsError(command_buffer_->GetLastError())) {
468 LOG(ERROR) << "Context dead on arrival. Last error: "
469 << command_buffer_->GetLastError();
470 return false;
471 }
472
473 return true;
474 }
475
476 uint32_t WebGraphicsContext3DCommandBufferImpl::lastFlushID() {
477 return flush_id_; 176 return flush_id_;
478 } 177 }
479 178
480 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int) 179 DELEGATE_TO_GL_R(insertSyncPoint, InsertSyncPointCHROMIUM, unsigned int)
481 180
482 void WebGraphicsContext3DCommandBufferImpl::Destroy() {
483 share_group_->RemoveContext(this);
484
485 if (gl_) {
486 // First flush the context to ensure that any pending frees of resources
487 // are completed. Otherwise, if this context is part of a share group,
488 // those resources might leak. Also, any remaining side effects of commands
489 // issued on this context might not be visible to other contexts in the
490 // share group.
491 gl_->Flush();
492 gl_ = NULL;
493 }
494
495 trace_gl_.reset();
496 real_gl_.reset();
497 transfer_buffer_.reset();
498 gles2_helper_.reset();
499 real_gl_.reset();
500
501 if (command_buffer_) {
502 if (host_.get())
503 host_->DestroyCommandBuffer(command_buffer_.release());
504 command_buffer_.reset();
505 }
506
507 host_ = NULL;
508 }
509
510 gpu::ContextSupport*
511 WebGraphicsContext3DCommandBufferImpl::GetContextSupport() {
512 return real_gl_.get();
513 }
514
515 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() {
516 NOTREACHED();
517 }
518
519 void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM(
520 int x, int y, int width, int height) {
521 NOTREACHED();
522 }
523
524 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float) 181 DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float)
525 182
526 void WebGraphicsContext3DCommandBufferImpl::synthesizeGLError(
527 WGC3Denum error) {
528 if (std::find(synthetic_errors_.begin(), synthetic_errors_.end(), error) ==
529 synthetic_errors_.end()) {
530 synthetic_errors_.push_back(error);
531 }
532 }
533
534 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum, 183 DELEGATE_TO_GL_4R(mapBufferSubDataCHROMIUM, MapBufferSubDataCHROMIUM, WGC3Denum,
535 WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*) 184 WGC3Dintptr, WGC3Dsizeiptr, WGC3Denum, void*)
536 185
537 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM, 186 DELEGATE_TO_GL_1(unmapBufferSubDataCHROMIUM, UnmapBufferSubDataCHROMIUM,
538 const void*) 187 const void*)
539 188
540 void* WebGraphicsContext3DCommandBufferImpl::mapTexSubImage2DCHROMIUM( 189 DELEGATE_TO_GL_9R(mapTexSubImage2DCHROMIUM, MapTexSubImage2DCHROMIUM, WGC3Denum,
541 WGC3Denum target, 190 WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
542 WGC3Dint level, 191 WGC3Denum, WGC3Denum, WGC3Denum, void*)
543 WGC3Dint xoffset,
544 WGC3Dint yoffset,
545 WGC3Dsizei width,
546 WGC3Dsizei height,
547 WGC3Denum format,
548 WGC3Denum type,
549 WGC3Denum access) {
550 return gl_->MapTexSubImage2DCHROMIUM(
551 target, level, xoffset, yoffset, width, height, format, type, access);
552 }
553 192
554 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM, 193 DELEGATE_TO_GL_1(unmapTexSubImage2DCHROMIUM, UnmapTexSubImage2DCHROMIUM,
555 const void*) 194 const void*)
556 195
557 void WebGraphicsContext3DCommandBufferImpl::setVisibilityCHROMIUM(
558 bool visible) {
559 NOTREACHED();
560 }
561
562 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum, 196 DELEGATE_TO_GL_3(discardFramebufferEXT, DiscardFramebufferEXT, WGC3Denum,
563 WGC3Dsizei, const WGC3Denum*) 197 WGC3Dsizei, const WGC3Denum*)
564 198
565 void WebGraphicsContext3DCommandBufferImpl::copyTextureToParentTextureCHROMIUM( 199 blink::WebString WebGraphicsContext3DImpl::
566 WebGLId texture, WebGLId parentTexture) {
567 NOTIMPLEMENTED();
568 }
569
570 blink::WebString WebGraphicsContext3DCommandBufferImpl::
571 getRequestableExtensionsCHROMIUM() { 200 getRequestableExtensionsCHROMIUM() {
572 return blink::WebString::fromUTF8( 201 return blink::WebString::fromUTF8(
573 gl_->GetRequestableExtensionsCHROMIUM()); 202 gl_->GetRequestableExtensionsCHROMIUM());
574 } 203 }
575 204
576 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM, 205 DELEGATE_TO_GL_1(requestExtensionCHROMIUM, RequestExtensionCHROMIUM,
577 const char*) 206 const char*)
578 207
579 void WebGraphicsContext3DCommandBufferImpl::blitFramebufferCHROMIUM( 208 void WebGraphicsContext3DImpl::blitFramebufferCHROMIUM(
580 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, 209 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1,
581 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, 210 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1,
582 WGC3Dbitfield mask, WGC3Denum filter) { 211 WGC3Dbitfield mask, WGC3Denum filter) {
583 gl_->BlitFramebufferCHROMIUM( 212 gl_->BlitFramebufferCHROMIUM(
584 srcX0, srcY0, srcX1, srcY1, 213 srcX0, srcY0, srcX1, srcY1,
585 dstX0, dstY0, dstX1, dstY1, 214 dstX0, dstY0, dstX1, dstY1,
586 mask, filter); 215 mask, filter);
587 } 216 }
588 217
589 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM, 218 DELEGATE_TO_GL_5(renderbufferStorageMultisampleCHROMIUM,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 296
668 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId) 297 DELEGATE_TO_GL_2(detachShader, DetachShader, WebGLId, WebGLId)
669 298
670 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum) 299 DELEGATE_TO_GL_1(disable, Disable, WGC3Denum)
671 300
672 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray, 301 DELEGATE_TO_GL_1(disableVertexAttribArray, DisableVertexAttribArray,
673 WGC3Duint) 302 WGC3Duint)
674 303
675 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei) 304 DELEGATE_TO_GL_3(drawArrays, DrawArrays, WGC3Denum, WGC3Dint, WGC3Dsizei)
676 305
677 void WebGraphicsContext3DCommandBufferImpl::drawElements(WGC3Denum mode, 306 void WebGraphicsContext3DImpl::drawElements(WGC3Denum mode,
678 WGC3Dsizei count, 307 WGC3Dsizei count,
679 WGC3Denum type, 308 WGC3Denum type,
680 WGC3Dintptr offset) { 309 WGC3Dintptr offset) {
681 gl_->DrawElements( 310 gl_->DrawElements(
682 mode, count, type, 311 mode, count, type,
683 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 312 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
684 } 313 }
685 314
686 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum) 315 DELEGATE_TO_GL_1(enable, Enable, WGC3Denum)
687 316
688 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray, 317 DELEGATE_TO_GL_1(enableVertexAttribArray, EnableVertexAttribArray,
689 WGC3Duint) 318 WGC3Duint)
690 319
691 void WebGraphicsContext3DCommandBufferImpl::finish() { 320 void WebGraphicsContext3DImpl::finish() {
692 flush_id_ = GenFlushID(); 321 flush_id_ = GenFlushID();
693 gl_->Finish(); 322 gl_->Finish();
694 } 323 }
695 324
696 void WebGraphicsContext3DCommandBufferImpl::flush() { 325 void WebGraphicsContext3DImpl::flush() {
697 flush_id_ = GenFlushID(); 326 flush_id_ = GenFlushID();
698 gl_->Flush(); 327 gl_->Flush();
699 } 328 }
700 329
701 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer, 330 DELEGATE_TO_GL_4(framebufferRenderbuffer, FramebufferRenderbuffer,
702 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId) 331 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId)
703 332
704 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D, 333 DELEGATE_TO_GL_5(framebufferTexture2D, FramebufferTexture2D,
705 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint) 334 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint)
706 335
707 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum) 336 DELEGATE_TO_GL_1(frontFace, FrontFace, WGC3Denum)
708 337
709 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum) 338 DELEGATE_TO_GL_1(generateMipmap, GenerateMipmap, WGC3Denum)
710 339
711 bool WebGraphicsContext3DCommandBufferImpl::getActiveAttrib( 340 bool WebGraphicsContext3DImpl::getActiveAttrib(
712 WebGLId program, WGC3Duint index, ActiveInfo& info) { 341 WebGLId program, WGC3Duint index, ActiveInfo& info) {
713 if (!program) { 342 if (!program) {
714 synthesizeGLError(GL_INVALID_VALUE); 343 synthesizeGLError(GL_INVALID_VALUE);
715 return false; 344 return false;
716 } 345 }
717 GLint max_name_length = -1; 346 GLint max_name_length = -1;
718 gl_->GetProgramiv( 347 gl_->GetProgramiv(
719 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length); 348 program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max_name_length);
720 if (max_name_length < 0) 349 if (max_name_length < 0)
721 return false; 350 return false;
722 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); 351 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
723 if (!name) { 352 if (!name) {
724 synthesizeGLError(GL_OUT_OF_MEMORY); 353 synthesizeGLError(GL_OUT_OF_MEMORY);
725 return false; 354 return false;
726 } 355 }
727 GLsizei length = 0; 356 GLsizei length = 0;
728 GLint size = -1; 357 GLint size = -1;
729 GLenum type = 0; 358 GLenum type = 0;
730 gl_->GetActiveAttrib( 359 gl_->GetActiveAttrib(
731 program, index, max_name_length, &length, &size, &type, name.get()); 360 program, index, max_name_length, &length, &size, &type, name.get());
732 if (size < 0) { 361 if (size < 0) {
733 return false; 362 return false;
734 } 363 }
735 info.name = blink::WebString::fromUTF8(name.get(), length); 364 info.name = blink::WebString::fromUTF8(name.get(), length);
736 info.type = type; 365 info.type = type;
737 info.size = size; 366 info.size = size;
738 return true; 367 return true;
739 } 368 }
740 369
741 bool WebGraphicsContext3DCommandBufferImpl::getActiveUniform( 370 bool WebGraphicsContext3DImpl::getActiveUniform(
742 WebGLId program, WGC3Duint index, ActiveInfo& info) { 371 WebGLId program, WGC3Duint index, ActiveInfo& info) {
743 GLint max_name_length = -1; 372 GLint max_name_length = -1;
744 gl_->GetProgramiv( 373 gl_->GetProgramiv(
745 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length); 374 program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max_name_length);
746 if (max_name_length < 0) 375 if (max_name_length < 0)
747 return false; 376 return false;
748 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]); 377 scoped_ptr<GLchar[]> name(new GLchar[max_name_length]);
749 if (!name) { 378 if (!name) {
750 synthesizeGLError(GL_OUT_OF_MEMORY); 379 synthesizeGLError(GL_OUT_OF_MEMORY);
751 return false; 380 return false;
(...skipping 17 matching lines...) Expand all
769 398
770 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation, 399 DELEGATE_TO_GL_2R(getAttribLocation, GetAttribLocation,
771 WebGLId, const WGC3Dchar*, WGC3Dint) 400 WebGLId, const WGC3Dchar*, WGC3Dint)
772 401
773 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*) 402 DELEGATE_TO_GL_2(getBooleanv, GetBooleanv, WGC3Denum, WGC3Dboolean*)
774 403
775 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv, 404 DELEGATE_TO_GL_3(getBufferParameteriv, GetBufferParameteriv,
776 WGC3Denum, WGC3Denum, WGC3Dint*) 405 WGC3Denum, WGC3Denum, WGC3Dint*)
777 406
778 blink::WebGraphicsContext3D::Attributes 407 blink::WebGraphicsContext3D::Attributes
779 WebGraphicsContext3DCommandBufferImpl::getContextAttributes() { 408 WebGraphicsContext3DImpl::getContextAttributes() {
780 return attributes_; 409 return attributes_;
781 } 410 }
782 411
783 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getError() { 412 WGC3Denum WebGraphicsContext3DImpl::getError() {
784 if (!synthetic_errors_.empty()) { 413 if (!synthetic_errors_.empty()) {
785 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin(); 414 std::vector<WGC3Denum>::iterator iter = synthetic_errors_.begin();
786 WGC3Denum err = *iter; 415 WGC3Denum err = *iter;
787 synthetic_errors_.erase(iter); 416 synthetic_errors_.erase(iter);
788 return err; 417 return err;
789 } 418 }
790 419
791 return gl_->GetError(); 420 return gl_->GetError();
792 } 421 }
793 422
794 bool WebGraphicsContext3DCommandBufferImpl::isContextLost() {
795 return initialize_failed_ ||
796 (command_buffer_ && IsCommandBufferContextLost()) ||
797 context_lost_reason_ != GL_NO_ERROR;
798 }
799
800 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*) 423 DELEGATE_TO_GL_2(getFloatv, GetFloatv, WGC3Denum, WGC3Dfloat*)
801 424
802 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv, 425 DELEGATE_TO_GL_4(getFramebufferAttachmentParameteriv,
803 GetFramebufferAttachmentParameteriv, 426 GetFramebufferAttachmentParameteriv,
804 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*) 427 WGC3Denum, WGC3Denum, WGC3Denum, WGC3Dint*)
805 428
806 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*) 429 DELEGATE_TO_GL_2(getIntegerv, GetIntegerv, WGC3Denum, WGC3Dint*)
807 430
808 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*) 431 DELEGATE_TO_GL_3(getProgramiv, GetProgramiv, WebGLId, WGC3Denum, WGC3Dint*)
809 432
810 blink::WebString WebGraphicsContext3DCommandBufferImpl::getProgramInfoLog( 433 blink::WebString WebGraphicsContext3DImpl::getProgramInfoLog(
811 WebGLId program) { 434 WebGLId program) {
812 GLint logLength = 0; 435 GLint logLength = 0;
813 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); 436 gl_->GetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength);
814 if (!logLength) 437 if (!logLength)
815 return blink::WebString(); 438 return blink::WebString();
816 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 439 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
817 if (!log) 440 if (!log)
818 return blink::WebString(); 441 return blink::WebString();
819 GLsizei returnedLogLength = 0; 442 GLsizei returnedLogLength = 0;
820 gl_->GetProgramInfoLog( 443 gl_->GetProgramInfoLog(
821 program, logLength, &returnedLogLength, log.get()); 444 program, logLength, &returnedLogLength, log.get());
822 DCHECK_EQ(logLength, returnedLogLength + 1); 445 DCHECK_EQ(logLength, returnedLogLength + 1);
823 blink::WebString res = 446 blink::WebString res =
824 blink::WebString::fromUTF8(log.get(), returnedLogLength); 447 blink::WebString::fromUTF8(log.get(), returnedLogLength);
825 return res; 448 return res;
826 } 449 }
827 450
828 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv, 451 DELEGATE_TO_GL_3(getRenderbufferParameteriv, GetRenderbufferParameteriv,
829 WGC3Denum, WGC3Denum, WGC3Dint*) 452 WGC3Denum, WGC3Denum, WGC3Dint*)
830 453
831 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*) 454 DELEGATE_TO_GL_3(getShaderiv, GetShaderiv, WebGLId, WGC3Denum, WGC3Dint*)
832 455
833 blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderInfoLog( 456 blink::WebString WebGraphicsContext3DImpl::getShaderInfoLog(
834 WebGLId shader) { 457 WebGLId shader) {
835 GLint logLength = 0; 458 GLint logLength = 0;
836 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength); 459 gl_->GetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
837 if (!logLength) 460 if (!logLength)
838 return blink::WebString(); 461 return blink::WebString();
839 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 462 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
840 if (!log) 463 if (!log)
841 return blink::WebString(); 464 return blink::WebString();
842 GLsizei returnedLogLength = 0; 465 GLsizei returnedLogLength = 0;
843 gl_->GetShaderInfoLog( 466 gl_->GetShaderInfoLog(
844 shader, logLength, &returnedLogLength, log.get()); 467 shader, logLength, &returnedLogLength, log.get());
845 DCHECK_EQ(logLength, returnedLogLength + 1); 468 DCHECK_EQ(logLength, returnedLogLength + 1);
846 blink::WebString res = 469 blink::WebString res =
847 blink::WebString::fromUTF8(log.get(), returnedLogLength); 470 blink::WebString::fromUTF8(log.get(), returnedLogLength);
848 return res; 471 return res;
849 } 472 }
850 473
851 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat, 474 DELEGATE_TO_GL_4(getShaderPrecisionFormat, GetShaderPrecisionFormat,
852 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*) 475 WGC3Denum, WGC3Denum, WGC3Dint*, WGC3Dint*)
853 476
854 blink::WebString WebGraphicsContext3DCommandBufferImpl::getShaderSource( 477 blink::WebString WebGraphicsContext3DImpl::getShaderSource(
855 WebGLId shader) { 478 WebGLId shader) {
856 GLint logLength = 0; 479 GLint logLength = 0;
857 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength); 480 gl_->GetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &logLength);
858 if (!logLength) 481 if (!logLength)
859 return blink::WebString(); 482 return blink::WebString();
860 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 483 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
861 if (!log) 484 if (!log)
862 return blink::WebString(); 485 return blink::WebString();
863 GLsizei returnedLogLength = 0; 486 GLsizei returnedLogLength = 0;
864 gl_->GetShaderSource( 487 gl_->GetShaderSource(
865 shader, logLength, &returnedLogLength, log.get()); 488 shader, logLength, &returnedLogLength, log.get());
866 if (!returnedLogLength) 489 if (!returnedLogLength)
867 return blink::WebString(); 490 return blink::WebString();
868 DCHECK_EQ(logLength, returnedLogLength + 1); 491 DCHECK_EQ(logLength, returnedLogLength + 1);
869 blink::WebString res = 492 blink::WebString res =
870 blink::WebString::fromUTF8(log.get(), returnedLogLength); 493 blink::WebString::fromUTF8(log.get(), returnedLogLength);
871 return res; 494 return res;
872 } 495 }
873 496
874 blink::WebString WebGraphicsContext3DCommandBufferImpl:: 497 blink::WebString WebGraphicsContext3DImpl::
875 getTranslatedShaderSourceANGLE(WebGLId shader) { 498 getTranslatedShaderSourceANGLE(WebGLId shader) {
876 GLint logLength = 0; 499 GLint logLength = 0;
877 gl_->GetShaderiv( 500 gl_->GetShaderiv(
878 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength); 501 shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE, &logLength);
879 if (!logLength) 502 if (!logLength)
880 return blink::WebString(); 503 return blink::WebString();
881 scoped_ptr<GLchar[]> log(new GLchar[logLength]); 504 scoped_ptr<GLchar[]> log(new GLchar[logLength]);
882 if (!log) 505 if (!log)
883 return blink::WebString(); 506 return blink::WebString();
884 GLsizei returnedLogLength = 0; 507 GLsizei returnedLogLength = 0;
885 gl_->GetTranslatedShaderSourceANGLE( 508 gl_->GetTranslatedShaderSourceANGLE(
886 shader, logLength, &returnedLogLength, log.get()); 509 shader, logLength, &returnedLogLength, log.get());
887 if (!returnedLogLength) 510 if (!returnedLogLength)
888 return blink::WebString(); 511 return blink::WebString();
889 DCHECK_EQ(logLength, returnedLogLength + 1); 512 DCHECK_EQ(logLength, returnedLogLength + 1);
890 blink::WebString res = 513 blink::WebString res =
891 blink::WebString::fromUTF8(log.get(), returnedLogLength); 514 blink::WebString::fromUTF8(log.get(), returnedLogLength);
892 return res; 515 return res;
893 } 516 }
894 517
895 blink::WebString WebGraphicsContext3DCommandBufferImpl::getString( 518 blink::WebString WebGraphicsContext3DImpl::getString(
896 WGC3Denum name) { 519 WGC3Denum name) {
897 return blink::WebString::fromUTF8( 520 return blink::WebString::fromUTF8(
898 reinterpret_cast<const char*>(gl_->GetString(name))); 521 reinterpret_cast<const char*>(gl_->GetString(name)));
899 } 522 }
900 523
901 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv, 524 DELEGATE_TO_GL_3(getTexParameterfv, GetTexParameterfv,
902 WGC3Denum, WGC3Denum, WGC3Dfloat*) 525 WGC3Denum, WGC3Denum, WGC3Dfloat*)
903 526
904 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv, 527 DELEGATE_TO_GL_3(getTexParameteriv, GetTexParameteriv,
905 WGC3Denum, WGC3Denum, WGC3Dint*) 528 WGC3Denum, WGC3Denum, WGC3Dint*)
906 529
907 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*) 530 DELEGATE_TO_GL_3(getUniformfv, GetUniformfv, WebGLId, WGC3Dint, WGC3Dfloat*)
908 531
909 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*) 532 DELEGATE_TO_GL_3(getUniformiv, GetUniformiv, WebGLId, WGC3Dint, WGC3Dint*)
910 533
911 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation, 534 DELEGATE_TO_GL_2R(getUniformLocation, GetUniformLocation,
912 WebGLId, const WGC3Dchar*, WGC3Dint) 535 WebGLId, const WGC3Dchar*, WGC3Dint)
913 536
914 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv, 537 DELEGATE_TO_GL_3(getVertexAttribfv, GetVertexAttribfv,
915 WGC3Duint, WGC3Denum, WGC3Dfloat*) 538 WGC3Duint, WGC3Denum, WGC3Dfloat*)
916 539
917 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv, 540 DELEGATE_TO_GL_3(getVertexAttribiv, GetVertexAttribiv,
918 WGC3Duint, WGC3Denum, WGC3Dint*) 541 WGC3Duint, WGC3Denum, WGC3Dint*)
919 542
920 WGC3Dsizeiptr WebGraphicsContext3DCommandBufferImpl::getVertexAttribOffset( 543 WGC3Dsizeiptr WebGraphicsContext3DImpl::getVertexAttribOffset(
921 WGC3Duint index, WGC3Denum pname) { 544 WGC3Duint index, WGC3Denum pname) {
922 GLvoid* value = NULL; 545 GLvoid* value = NULL;
923 // NOTE: If pname is ever a value that returns more then 1 element 546 // NOTE: If pname is ever a value that returns more then 1 element
924 // this will corrupt memory. 547 // this will corrupt memory.
925 gl_->GetVertexAttribPointerv(index, pname, &value); 548 gl_->GetVertexAttribPointerv(index, pname, &value);
926 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value)); 549 return static_cast<WGC3Dsizeiptr>(reinterpret_cast<intptr_t>(value));
927 } 550 }
928 551
929 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum) 552 DELEGATE_TO_GL_2(hint, Hint, WGC3Denum, WGC3Denum)
930 553
(...skipping 16 matching lines...) Expand all
947 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId) 570 DELEGATE_TO_GL_1(linkProgram, LinkProgram, WebGLId)
948 571
949 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint) 572 DELEGATE_TO_GL_2(pixelStorei, PixelStorei, WGC3Denum, WGC3Dint)
950 573
951 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat) 574 DELEGATE_TO_GL_2(polygonOffset, PolygonOffset, WGC3Dfloat, WGC3Dfloat)
952 575
953 DELEGATE_TO_GL_7(readPixels, ReadPixels, 576 DELEGATE_TO_GL_7(readPixels, ReadPixels,
954 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum, 577 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, WGC3Denum,
955 WGC3Denum, void*) 578 WGC3Denum, void*)
956 579
957 void WebGraphicsContext3DCommandBufferImpl::releaseShaderCompiler() {
958 }
959
960 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage, 580 DELEGATE_TO_GL_4(renderbufferStorage, RenderbufferStorage,
961 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei) 581 WGC3Denum, WGC3Denum, WGC3Dsizei, WGC3Dsizei)
962 582
963 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean) 583 DELEGATE_TO_GL_2(sampleCoverage, SampleCoverage, WGC3Dfloat, WGC3Dboolean)
964 584
965 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) 585 DELEGATE_TO_GL_4(scissor, Scissor, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
966 586
967 void WebGraphicsContext3DCommandBufferImpl::shaderSource( 587 void WebGraphicsContext3DImpl::shaderSource(
968 WebGLId shader, const WGC3Dchar* string) { 588 WebGLId shader, const WGC3Dchar* string) {
969 GLint length = strlen(string); 589 GLint length = strlen(string);
970 gl_->ShaderSource(shader, 1, &string, &length); 590 gl_->ShaderSource(shader, 1, &string, &length);
971 } 591 }
972 592
973 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint) 593 DELEGATE_TO_GL_3(stencilFunc, StencilFunc, WGC3Denum, WGC3Dint, WGC3Duint)
974 594
975 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate, 595 DELEGATE_TO_GL_4(stencilFuncSeparate, StencilFuncSeparate,
976 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint) 596 WGC3Denum, WGC3Denum, WGC3Dint, WGC3Duint)
977 597
(...skipping 10 matching lines...) Expand all
988 608
989 DELEGATE_TO_GL_9(texImage2D, TexImage2D, 609 DELEGATE_TO_GL_9(texImage2D, TexImage2D,
990 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, 610 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei,
991 WGC3Dint, WGC3Denum, WGC3Denum, const void*) 611 WGC3Dint, WGC3Denum, WGC3Denum, const void*)
992 612
993 DELEGATE_TO_GL_3(texParameterf, TexParameterf, 613 DELEGATE_TO_GL_3(texParameterf, TexParameterf,
994 WGC3Denum, WGC3Denum, WGC3Dfloat); 614 WGC3Denum, WGC3Denum, WGC3Dfloat);
995 615
996 static const unsigned int kTextureWrapR = 0x8072; 616 static const unsigned int kTextureWrapR = 0x8072;
997 617
998 void WebGraphicsContext3DCommandBufferImpl::texParameteri( 618 void WebGraphicsContext3DImpl::texParameteri(
999 WGC3Denum target, WGC3Denum pname, WGC3Dint param) { 619 WGC3Denum target, WGC3Denum pname, WGC3Dint param) {
1000 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in 620 // TODO(kbr): figure out whether the setting of TEXTURE_WRAP_R in
1001 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the 621 // GraphicsContext3D.cpp is strictly necessary to avoid seams at the
1002 // edge of cube maps, and, if it is, push it into the GLES2 service 622 // edge of cube maps, and, if it is, push it into the GLES2 service
1003 // side code. 623 // side code.
1004 if (pname == kTextureWrapR) { 624 if (pname == kTextureWrapR) {
1005 return; 625 return;
1006 } 626 }
1007 gl_->TexParameteri(target, pname, param); 627 gl_->TexParameteri(target, pname, param);
1008 } 628 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 699
1080 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint, 700 DELEGATE_TO_GL_2(vertexAttrib3fv, VertexAttrib3fv, WGC3Duint,
1081 const WGC3Dfloat*) 701 const WGC3Dfloat*)
1082 702
1083 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint, 703 DELEGATE_TO_GL_5(vertexAttrib4f, VertexAttrib4f, WGC3Duint,
1084 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat) 704 WGC3Dfloat, WGC3Dfloat, WGC3Dfloat, WGC3Dfloat)
1085 705
1086 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint, 706 DELEGATE_TO_GL_2(vertexAttrib4fv, VertexAttrib4fv, WGC3Duint,
1087 const WGC3Dfloat*) 707 const WGC3Dfloat*)
1088 708
1089 void WebGraphicsContext3DCommandBufferImpl::vertexAttribPointer( 709 void WebGraphicsContext3DImpl::vertexAttribPointer(
1090 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized, 710 WGC3Duint index, WGC3Dint size, WGC3Denum type, WGC3Dboolean normalized,
1091 WGC3Dsizei stride, WGC3Dintptr offset) { 711 WGC3Dsizei stride, WGC3Dintptr offset) {
1092 gl_->VertexAttribPointer( 712 gl_->VertexAttribPointer(
1093 index, size, type, normalized, stride, 713 index, size, type, normalized, stride,
1094 reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 714 reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
1095 } 715 }
1096 716
1097 DELEGATE_TO_GL_4(viewport, Viewport, 717 DELEGATE_TO_GL_4(viewport, Viewport,
1098 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei) 718 WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei)
1099 719
1100 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*); 720 DELEGATE_TO_GL_2(genBuffers, GenBuffers, WGC3Dsizei, WebGLId*);
1101 721
1102 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*); 722 DELEGATE_TO_GL_2(genFramebuffers, GenFramebuffers, WGC3Dsizei, WebGLId*);
1103 723
1104 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*); 724 DELEGATE_TO_GL_2(genRenderbuffers, GenRenderbuffers, WGC3Dsizei, WebGLId*);
1105 725
1106 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*); 726 DELEGATE_TO_GL_2(genTextures, GenTextures, WGC3Dsizei, WebGLId*);
1107 727
1108 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*); 728 DELEGATE_TO_GL_2(deleteBuffers, DeleteBuffers, WGC3Dsizei, WebGLId*);
1109 729
1110 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*); 730 DELEGATE_TO_GL_2(deleteFramebuffers, DeleteFramebuffers, WGC3Dsizei, WebGLId*);
1111 731
1112 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei, 732 DELEGATE_TO_GL_2(deleteRenderbuffers, DeleteRenderbuffers, WGC3Dsizei,
1113 WebGLId*); 733 WebGLId*);
1114 734
1115 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*); 735 DELEGATE_TO_GL_2(deleteTextures, DeleteTextures, WGC3Dsizei, WebGLId*);
1116 736
1117 WebGLId WebGraphicsContext3DCommandBufferImpl::createBuffer() { 737 WebGLId WebGraphicsContext3DImpl::createBuffer() {
1118 GLuint o; 738 GLuint o;
1119 gl_->GenBuffers(1, &o); 739 gl_->GenBuffers(1, &o);
1120 return o; 740 return o;
1121 } 741 }
1122 742
1123 WebGLId WebGraphicsContext3DCommandBufferImpl::createFramebuffer() { 743 WebGLId WebGraphicsContext3DImpl::createFramebuffer() {
1124 GLuint o = 0; 744 GLuint o = 0;
1125 gl_->GenFramebuffers(1, &o); 745 gl_->GenFramebuffers(1, &o);
1126 return o; 746 return o;
1127 } 747 }
1128 748
1129 WebGLId WebGraphicsContext3DCommandBufferImpl::createRenderbuffer() { 749 WebGLId WebGraphicsContext3DImpl::createRenderbuffer() {
1130 GLuint o; 750 GLuint o;
1131 gl_->GenRenderbuffers(1, &o); 751 gl_->GenRenderbuffers(1, &o);
1132 return o; 752 return o;
1133 } 753 }
1134 754
1135 WebGLId WebGraphicsContext3DCommandBufferImpl::createTexture() { 755 WebGLId WebGraphicsContext3DImpl::createTexture() {
1136 GLuint o; 756 GLuint o;
1137 gl_->GenTextures(1, &o); 757 gl_->GenTextures(1, &o);
1138 return o; 758 return o;
1139 } 759 }
1140 760
1141 void WebGraphicsContext3DCommandBufferImpl::deleteBuffer(WebGLId buffer) { 761 void WebGraphicsContext3DImpl::deleteBuffer(WebGLId buffer) {
1142 gl_->DeleteBuffers(1, &buffer); 762 gl_->DeleteBuffers(1, &buffer);
1143 } 763 }
1144 764
1145 void WebGraphicsContext3DCommandBufferImpl::deleteFramebuffer( 765 void WebGraphicsContext3DImpl::deleteFramebuffer(
1146 WebGLId framebuffer) { 766 WebGLId framebuffer) {
1147 gl_->DeleteFramebuffers(1, &framebuffer); 767 gl_->DeleteFramebuffers(1, &framebuffer);
1148 } 768 }
1149 769
1150 void WebGraphicsContext3DCommandBufferImpl::deleteRenderbuffer( 770 void WebGraphicsContext3DImpl::deleteRenderbuffer(
1151 WebGLId renderbuffer) { 771 WebGLId renderbuffer) {
1152 gl_->DeleteRenderbuffers(1, &renderbuffer); 772 gl_->DeleteRenderbuffers(1, &renderbuffer);
1153 } 773 }
1154 774
1155 void WebGraphicsContext3DCommandBufferImpl::deleteTexture(WebGLId texture) { 775 void WebGraphicsContext3DImpl::deleteTexture(WebGLId texture) {
1156 gl_->DeleteTextures(1, &texture); 776 gl_->DeleteTextures(1, &texture);
1157 } 777 }
1158 778
1159 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId) 779 DELEGATE_TO_GL_R(createProgram, CreateProgram, WebGLId)
1160 780
1161 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId) 781 DELEGATE_TO_GL_1R(createShader, CreateShader, WGC3Denum, WebGLId)
1162 782
1163 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId) 783 DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId)
1164 784
1165 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId) 785 DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId)
1166 786
1167 void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback( 787 void WebGraphicsContext3DImpl::setErrorMessageCallback(
1168 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) { 788 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) {
1169 error_message_callback_ = cb; 789 error_message_callback_ = cb;
1170 } 790 }
1171 791
1172 void WebGraphicsContext3DCommandBufferImpl::setContextLostCallback( 792 void WebGraphicsContext3DImpl::setContextLostCallback(
1173 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { 793 WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) {
1174 context_lost_callback_ = cb; 794 context_lost_callback_ = cb;
1175 } 795 }
1176 796
1177 WGC3Denum WebGraphicsContext3DCommandBufferImpl::getGraphicsResetStatusARB() {
1178 if (IsCommandBufferContextLost() &&
1179 context_lost_reason_ == GL_NO_ERROR) {
1180 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1181 }
1182
1183 return context_lost_reason_;
1184 }
1185
1186 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() {
1187 // If the channel shut down unexpectedly, let that supersede the
1188 // command buffer's state.
1189 if (host_.get() && host_->IsLost())
1190 return true;
1191 gpu::CommandBuffer::State state = command_buffer_->GetLastState();
1192 return state.error == gpu::error::kLostContext;
1193 }
1194
1195 // static
1196 WebGraphicsContext3DCommandBufferImpl*
1197 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext(
1198 GpuChannelHost* host,
1199 const WebGraphicsContext3D::Attributes& attributes,
1200 bool lose_context_when_out_of_memory,
1201 const GURL& active_url,
1202 const SharedMemoryLimits& limits,
1203 WebGraphicsContext3DCommandBufferImpl* share_context) {
1204 if (!host)
1205 return NULL;
1206
1207 if (share_context && share_context->IsCommandBufferContextLost())
1208 return NULL;
1209
1210 return new WebGraphicsContext3DCommandBufferImpl(
1211 0,
1212 active_url,
1213 host,
1214 attributes,
1215 lose_context_when_out_of_memory,
1216 limits,
1217 share_context);
1218 }
1219
1220 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, 797 DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM,
1221 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) 798 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint)
1222 799
1223 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT, 800 DELEGATE_TO_GL_5(texStorage2DEXT, TexStorage2DEXT,
1224 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint) 801 WGC3Denum, WGC3Dint, WGC3Duint, WGC3Dint, WGC3Dint)
1225 802
1226 WebGLId WebGraphicsContext3DCommandBufferImpl::createQueryEXT() { 803 WebGLId WebGraphicsContext3DImpl::createQueryEXT() {
1227 GLuint o; 804 GLuint o;
1228 gl_->GenQueriesEXT(1, &o); 805 gl_->GenQueriesEXT(1, &o);
1229 return o; 806 return o;
1230 } 807 }
1231 808
1232 void WebGraphicsContext3DCommandBufferImpl::deleteQueryEXT( 809 void WebGraphicsContext3DImpl::deleteQueryEXT(
1233 WebGLId query) { 810 WebGLId query) {
1234 gl_->DeleteQueriesEXT(1, &query); 811 gl_->DeleteQueriesEXT(1, &query);
1235 } 812 }
1236 813
1237 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean) 814 DELEGATE_TO_GL_1R(isQueryEXT, IsQueryEXT, WebGLId, WGC3Dboolean)
1238 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId) 815 DELEGATE_TO_GL_2(beginQueryEXT, BeginQueryEXT, WGC3Denum, WebGLId)
1239 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum) 816 DELEGATE_TO_GL_1(endQueryEXT, EndQueryEXT, WGC3Denum)
1240 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*) 817 DELEGATE_TO_GL_3(getQueryivEXT, GetQueryivEXT, WGC3Denum, WGC3Denum, WGC3Dint*)
1241 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT, 818 DELEGATE_TO_GL_3(getQueryObjectuivEXT, GetQueryObjectuivEXT,
1242 WebGLId, WGC3Denum, WGC3Duint*) 819 WebGLId, WGC3Denum, WGC3Duint*)
1243 820
1244 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum, 821 DELEGATE_TO_GL_6(copyTextureCHROMIUM, CopyTextureCHROMIUM, WGC3Denum,
1245 WebGLId, WebGLId, WGC3Dint, WGC3Denum, WGC3Denum); 822 WebGLId, WebGLId, WGC3Dint, WGC3Denum, WGC3Denum);
1246 823
1247 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, 824 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1248 WebGLId, WGC3Dint, const WGC3Dchar*) 825 WebGLId, WGC3Dint, const WGC3Dchar*)
1249 826
1250 void WebGraphicsContext3DCommandBufferImpl::shallowFlushCHROMIUM() { 827 void WebGraphicsContext3DImpl::shallowFlushCHROMIUM() {
1251 flush_id_ = GenFlushID(); 828 flush_id_ = GenFlushID();
1252 gl_->ShallowFlushCHROMIUM(); 829 gl_->ShallowFlushCHROMIUM();
1253 } 830 }
1254 831
1255 void WebGraphicsContext3DCommandBufferImpl::shallowFinishCHROMIUM() { 832 void WebGraphicsContext3DImpl::shallowFinishCHROMIUM() {
1256 flush_id_ = GenFlushID(); 833 flush_id_ = GenFlushID();
1257 gl_->ShallowFinishCHROMIUM(); 834 gl_->ShallowFinishCHROMIUM();
1258 } 835 }
1259 836
1260 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint) 837 DELEGATE_TO_GL_1(waitSyncPoint, WaitSyncPointCHROMIUM, GLuint)
1261 838
1262 void WebGraphicsContext3DCommandBufferImpl::loseContextCHROMIUM( 839 void WebGraphicsContext3DImpl::loseContextCHROMIUM(
1263 WGC3Denum current, WGC3Denum other) { 840 WGC3Denum current, WGC3Denum other) {
1264 gl_->LoseContextCHROMIUM(current, other); 841 gl_->LoseContextCHROMIUM(current, other);
1265 gl_->Flush(); 842 gl_->Flush();
1266 } 843 }
1267 844
1268 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) 845 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1269 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, 846 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1270 WGC3Denum, const WGC3Dbyte*) 847 WGC3Denum, const WGC3Dbyte*)
1271 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, 848 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1272 WGC3Denum, const WGC3Dbyte*) 849 WGC3Denum, const WGC3Dbyte*)
1273 850
1274 void WebGraphicsContext3DCommandBufferImpl::insertEventMarkerEXT( 851 void WebGraphicsContext3DImpl::insertEventMarkerEXT(
1275 const WGC3Dchar* marker) { 852 const WGC3Dchar* marker) {
1276 gl_->InsertEventMarkerEXT(0, marker); 853 gl_->InsertEventMarkerEXT(0, marker);
1277 } 854 }
1278 855
1279 void WebGraphicsContext3DCommandBufferImpl::pushGroupMarkerEXT( 856 void WebGraphicsContext3DImpl::pushGroupMarkerEXT(
1280 const WGC3Dchar* marker) { 857 const WGC3Dchar* marker) {
1281 gl_->PushGroupMarkerEXT(0, marker); 858 gl_->PushGroupMarkerEXT(0, marker);
1282 } 859 }
1283 860
1284 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT); 861 DELEGATE_TO_GL(popGroupMarkerEXT, PopGroupMarkerEXT);
1285 862
1286 WebGLId WebGraphicsContext3DCommandBufferImpl::createVertexArrayOES() { 863 WebGLId WebGraphicsContext3DImpl::createVertexArrayOES() {
1287 GLuint array; 864 GLuint array;
1288 gl_->GenVertexArraysOES(1, &array); 865 gl_->GenVertexArraysOES(1, &array);
1289 return array; 866 return array;
1290 } 867 }
1291 868
1292 void WebGraphicsContext3DCommandBufferImpl::deleteVertexArrayOES( 869 void WebGraphicsContext3DImpl::deleteVertexArrayOES(
1293 WebGLId array) { 870 WebGLId array) {
1294 gl_->DeleteVertexArraysOES(1, &array); 871 gl_->DeleteVertexArraysOES(1, &array);
1295 } 872 }
1296 873
1297 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean) 874 DELEGATE_TO_GL_1R(isVertexArrayOES, IsVertexArrayOES, WebGLId, WGC3Dboolean)
1298 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId) 875 DELEGATE_TO_GL_1(bindVertexArrayOES, BindVertexArrayOES, WebGLId)
1299 876
1300 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM, 877 DELEGATE_TO_GL_2(bindTexImage2DCHROMIUM, BindTexImage2DCHROMIUM,
1301 WGC3Denum, WGC3Dint) 878 WGC3Denum, WGC3Dint)
1302 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM, 879 DELEGATE_TO_GL_2(releaseTexImage2DCHROMIUM, ReleaseTexImage2DCHROMIUM,
(...skipping 12 matching lines...) Expand all
1315 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*) 892 WGC3Dsizei, WGC3Denum, WGC3Denum, const void*)
1316 893
1317 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, 894 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1318 WGC3Denum) 895 WGC3Denum)
1319 896
1320 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*) 897 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, WGC3Dsizei, const WGC3Denum*)
1321 898
1322 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum, 899 DELEGATE_TO_GL_4(drawArraysInstancedANGLE, DrawArraysInstancedANGLE, WGC3Denum,
1323 WGC3Dint, WGC3Dsizei, WGC3Dsizei) 900 WGC3Dint, WGC3Dsizei, WGC3Dsizei)
1324 901
1325 void WebGraphicsContext3DCommandBufferImpl::drawElementsInstancedANGLE( 902 void WebGraphicsContext3DImpl::drawElementsInstancedANGLE(
1326 WGC3Denum mode, 903 WGC3Denum mode,
1327 WGC3Dsizei count, 904 WGC3Dsizei count,
1328 WGC3Denum type, 905 WGC3Denum type,
1329 WGC3Dintptr offset, 906 WGC3Dintptr offset,
1330 WGC3Dsizei primcount) { 907 WGC3Dsizei primcount) {
1331 gl_->DrawElementsInstancedANGLE( 908 gl_->DrawElementsInstancedANGLE(
1332 mode, count, type, 909 mode, count, type,
1333 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount); 910 reinterpret_cast<void*>(static_cast<intptr_t>(offset)), primcount);
1334 } 911 }
1335 912
(...skipping 18 matching lines...) Expand all
1354 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint); 931 DELEGATE_TO_GL_1(unmapImageCHROMIUM, UnmapImageCHROMIUM, WGC3Duint);
1355 932
1356 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT, 933 DELEGATE_TO_GL_6(framebufferTexture2DMultisampleEXT,
1357 FramebufferTexture2DMultisampleEXT, 934 FramebufferTexture2DMultisampleEXT,
1358 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei) 935 WGC3Denum, WGC3Denum, WGC3Denum, WebGLId, WGC3Dint, WGC3Dsizei)
1359 936
1360 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT, 937 DELEGATE_TO_GL_5(renderbufferStorageMultisampleEXT,
1361 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei, 938 RenderbufferStorageMultisampleEXT, WGC3Denum, WGC3Dsizei,
1362 WGC3Denum, WGC3Dsizei, WGC3Dsizei) 939 WGC3Denum, WGC3Dsizei, WGC3Dsizei)
1363 940
1364 GrGLInterface* WebGraphicsContext3DCommandBufferImpl::createGrGLInterface() { 941 GrGLInterface* WebGraphicsContext3DImpl::createGrGLInterface() {
1365 makeContextCurrent(); 942 makeContextCurrent();
1366 return skia_bindings::CreateCommandBufferSkiaGLBinding(); 943 return skia_bindings::CreateCommandBufferSkiaGLBinding();
1367 } 944 }
1368 945
1369 namespace { 946 gpu::gles2::GLES2ImplementationErrorMessageCallback*
1370 947 WebGraphicsContext3DImpl::getErrorMessageCallback() {
1371 WGC3Denum convertReason(gpu::error::ContextLostReason reason) { 948 if (!client_error_message_callback_) {
1372 switch (reason) { 949 client_error_message_callback_.reset(
1373 case gpu::error::kGuilty: 950 new WebGraphicsContext3DErrorMessageCallback(this));
1374 return GL_GUILTY_CONTEXT_RESET_ARB;
1375 case gpu::error::kInnocent:
1376 return GL_INNOCENT_CONTEXT_RESET_ARB;
1377 case gpu::error::kUnknown:
1378 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1379 } 951 }
1380 952 return client_error_message_callback_.get();
1381 NOTREACHED();
1382 return GL_UNKNOWN_CONTEXT_RESET_ARB;
1383 } 953 }
1384 954
1385 } // anonymous namespace 955 void WebGraphicsContext3DImpl::OnErrorMessage(
1386
1387 void WebGraphicsContext3DCommandBufferImpl::OnGpuChannelLost() {
1388 context_lost_reason_ = convertReason(
1389 command_buffer_->GetLastState().context_lost_reason);
1390 if (context_lost_callback_) {
1391 context_lost_callback_->onContextLost();
1392 }
1393
1394 share_group_->RemoveAllContexts();
1395
1396 DCHECK(host_.get());
1397 {
1398 base::AutoLock lock(g_default_share_groups_lock.Get());
1399 g_default_share_groups.Get().erase(host_.get());
1400 }
1401 }
1402
1403 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage(
1404 const std::string& message, int id) { 956 const std::string& message, int id) {
1405 if (error_message_callback_) { 957 if (error_message_callback_) {
1406 blink::WebString str = blink::WebString::fromUTF8(message.c_str()); 958 blink::WebString str = blink::WebString::fromUTF8(message.c_str());
1407 error_message_callback_->onErrorMessage(str, id); 959 error_message_callback_->onErrorMessage(str, id);
1408 } 960 }
1409 } 961 }
1410 962
963 // TODO(bajones): Look into removing these functions from the blink interface
964 void WebGraphicsContext3DImpl::prepareTexture() {
965 NOTREACHED();
966 }
967
968 void WebGraphicsContext3DImpl::postSubBufferCHROMIUM(
969 int x, int y, int width, int height) {
970 NOTREACHED();
971 }
972
973 void WebGraphicsContext3DImpl::setVisibilityCHROMIUM(
974 bool visible) {
975 NOTREACHED();
976 }
977
978 void WebGraphicsContext3DImpl::copyTextureToParentTextureCHROMIUM(
979 WebGLId texture, WebGLId parentTexture) {
980 NOTIMPLEMENTED();
981 }
982
983 void WebGraphicsContext3DImpl::releaseShaderCompiler() {
984 }
985
1411 } // namespace content 986 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698