Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / gpu / command_buffer / client / gles2_implementation.h
blobcfe8ed9f9c21150f22223b22d195f04ea7c88933
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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_
8 #include <GLES2/gl2.h>
10 #include <list>
11 #include <map>
12 #include <queue>
13 #include <set>
14 #include <string>
15 #include <utility>
16 #include <vector>
18 #include "base/compiler_specific.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "gpu/command_buffer/client/buffer_tracker.h"
22 #include "gpu/command_buffer/client/client_context_state.h"
23 #include "gpu/command_buffer/client/context_support.h"
24 #include "gpu/command_buffer/client/gles2_cmd_helper.h"
25 #include "gpu/command_buffer/client/gles2_impl_export.h"
26 #include "gpu/command_buffer/client/gles2_interface.h"
27 #include "gpu/command_buffer/client/mapped_memory.h"
28 #include "gpu/command_buffer/client/query_tracker.h"
29 #include "gpu/command_buffer/client/ref_counted.h"
30 #include "gpu/command_buffer/client/ring_buffer.h"
31 #include "gpu/command_buffer/client/share_group.h"
32 #include "gpu/command_buffer/common/capabilities.h"
33 #include "gpu/command_buffer/common/debug_marker_manager.h"
34 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
35 #include "gpu/command_buffer/common/id_allocator.h"
37 #if !defined(NDEBUG) && !defined(__native_client__) && !defined(GLES2_CONFORMANCE_TESTS) // NOLINT
38 #if defined(GLES2_INLINE_OPTIMIZATION)
39 // TODO(gman): Replace with macros that work with inline optmization.
40 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
41 #define GPU_CLIENT_LOG(args)
42 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
43 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
44 #else
45 #include "base/logging.h"
46 #define GPU_CLIENT_SINGLE_THREAD_CHECK() SingleThreadChecker checker(this);
47 #define GPU_CLIENT_LOG(args) DLOG_IF(INFO, debug_) << args;
48 #define GPU_CLIENT_LOG_CODE_BLOCK(code) code
49 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code) code
50 #define GPU_CLIENT_DEBUG
51 #endif
52 #else
53 #define GPU_CLIENT_SINGLE_THREAD_CHECK()
54 #define GPU_CLIENT_LOG(args)
55 #define GPU_CLIENT_LOG_CODE_BLOCK(code)
56 #define GPU_CLIENT_DCHECK_CODE_BLOCK(code)
57 #endif
59 #if defined(GPU_CLIENT_DEBUG)
60 // Set to 1 to have the client fail when a GL error is generated.
61 // This helps find bugs in the renderer since the debugger stops on the error.
62 # if 0
63 # define GL_CLIENT_FAIL_GL_ERRORS
64 # endif
65 #endif
67 // Check that destination pointers point to initialized memory.
68 // When the context is lost, calling GL function has no effect so if destination
69 // pointers point to initialized memory it can often lead to crash bugs. eg.
71 // GLsizei len;
72 // glGetShaderSource(shader, max_size, &len, buffer);
73 // std::string src(buffer, buffer + len); // len can be uninitialized here!!!
75 // Because this check is not official GL this check happens only on Chrome code,
76 // not Pepper.
78 // If it was up to us we'd just always write to the destination but the OpenGL
79 // spec defines the behavior of OpenGL functions, not us. :-(
80 #if defined(__native_client__) || defined(GLES2_CONFORMANCE_TESTS)
81 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v)
82 #define GPU_CLIENT_DCHECK(v)
83 #elif defined(GPU_DCHECK)
84 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) GPU_DCHECK(v)
85 #define GPU_CLIENT_DCHECK(v) GPU_DCHECK(v)
86 #elif defined(DCHECK)
87 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) DCHECK(v)
88 #define GPU_CLIENT_DCHECK(v) DCHECK(v)
89 #else
90 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(v) ASSERT(v)
91 #define GPU_CLIENT_DCHECK(v) ASSERT(v)
92 #endif
94 #define GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(type, ptr) \
95 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(ptr && \
96 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
98 #define GPU_CLIENT_VALIDATE_DESTINATION_OPTIONAL_INITALIZATION(type, ptr) \
99 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION_ASSERT(!ptr || \
100 (ptr[0] == static_cast<type>(0) || ptr[0] == static_cast<type>(-1)));
102 struct GLUniformDefinitionCHROMIUM;
104 namespace gpu {
106 class GpuControl;
107 class ScopedTransferBufferPtr;
108 class TransferBufferInterface;
110 namespace gles2 {
112 class ImageFactory;
113 class VertexArrayObjectManager;
115 class GLES2ImplementationErrorMessageCallback {
116 public:
117 virtual ~GLES2ImplementationErrorMessageCallback() { }
118 virtual void OnErrorMessage(const char* msg, int id) = 0;
121 // This class emulates GLES2 over command buffers. It can be used by a client
122 // program so that the program does not need deal with shared memory and command
123 // buffer management. See gl2_lib.h. Note that there is a performance gain to
124 // be had by changing your code to use command buffers directly by using the
125 // GLES2CmdHelper but that entails changing your code to use and deal with
126 // shared memory and synchronization issues.
127 class GLES2_IMPL_EXPORT GLES2Implementation
128 : NON_EXPORTED_BASE(public GLES2Interface),
129 NON_EXPORTED_BASE(public ContextSupport) {
130 public:
131 enum MappedMemoryLimit {
132 kNoLimit = MappedMemoryManager::kNoLimit,
135 // Stores GL state that never changes.
136 struct GLES2_IMPL_EXPORT GLStaticState {
137 GLStaticState();
138 ~GLStaticState();
140 typedef std::pair<GLenum, GLenum> ShaderPrecisionKey;
141 typedef std::map<ShaderPrecisionKey,
142 cmds::GetShaderPrecisionFormat::Result>
143 ShaderPrecisionMap;
144 ShaderPrecisionMap shader_precisions;
147 // The maxiumum result size from simple GL get commands.
148 static const size_t kMaxSizeOfSimpleResult = 16 * sizeof(uint32); // NOLINT.
150 // used for testing only. If more things are reseved add them here.
151 static const unsigned int kStartingOffset = kMaxSizeOfSimpleResult;
153 // Size in bytes to issue async flush for transfer buffer.
154 static const unsigned int kSizeToFlush = 256 * 1024;
156 // The bucket used for results. Public for testing only.
157 static const uint32 kResultBucketId = 1;
159 // Alignment of allocations.
160 static const unsigned int kAlignment = 4;
162 // GL names for the buffers used to emulate client side buffers.
163 static const GLuint kClientSideArrayId = 0xFEDCBA98u;
164 static const GLuint kClientSideElementArrayId = 0xFEDCBA99u;
166 // Number of swap buffers allowed before waiting.
167 static const size_t kMaxSwapBuffers = 2;
169 GLES2Implementation(GLES2CmdHelper* helper,
170 ShareGroup* share_group,
171 TransferBufferInterface* transfer_buffer,
172 bool bind_generates_resource,
173 bool lose_context_when_out_of_memory,
174 bool support_client_side_arrays,
175 GpuControl* gpu_control);
177 ~GLES2Implementation() override;
179 bool Initialize(
180 unsigned int starting_transfer_buffer_size,
181 unsigned int min_transfer_buffer_size,
182 unsigned int max_transfer_buffer_size,
183 unsigned int mapped_memory_limit);
185 // The GLES2CmdHelper being used by this GLES2Implementation. You can use
186 // this to issue cmds at a lower level for certain kinds of optimization.
187 GLES2CmdHelper* helper() const;
189 // Gets client side generated errors.
190 GLenum GetClientSideGLError();
192 // Include the auto-generated part of this class. We split this because
193 // it means we can easily edit the non-auto generated parts right here in
194 // this file instead of having to edit some template or the code generator.
195 #include "gpu/command_buffer/client/gles2_implementation_autogen.h"
197 void DisableVertexAttribArray(GLuint index) override;
198 void EnableVertexAttribArray(GLuint index) override;
199 void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params) override;
200 void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params) override;
202 // ContextSupport implementation.
203 void Swap() override;
204 void PartialSwapBuffers(const gfx::Rect& sub_buffer) override;
205 void ScheduleOverlayPlane(int plane_z_order,
206 gfx::OverlayTransform plane_transform,
207 unsigned overlay_texture_id,
208 const gfx::Rect& display_bounds,
209 const gfx::RectF& uv_rect) override;
210 GLuint InsertFutureSyncPointCHROMIUM() override;
211 void RetireSyncPointCHROMIUM(GLuint sync_point) override;
213 void GetProgramInfoCHROMIUMHelper(GLuint program, std::vector<int8>* result);
214 GLint GetAttribLocationHelper(GLuint program, const char* name);
215 GLint GetUniformLocationHelper(GLuint program, const char* name);
216 bool GetActiveAttribHelper(
217 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
218 GLint* size, GLenum* type, char* name);
219 bool GetActiveUniformHelper(
220 GLuint program, GLuint index, GLsizei bufsize, GLsizei* length,
221 GLint* size, GLenum* type, char* name);
223 void FreeUnusedSharedMemory();
224 void FreeEverything();
226 // ContextSupport implementation.
227 void SignalSyncPoint(uint32 sync_point,
228 const base::Closure& callback) override;
229 void SignalQuery(uint32 query, const base::Closure& callback) override;
230 void SetSurfaceVisible(bool visible) override;
232 void SetErrorMessageCallback(
233 GLES2ImplementationErrorMessageCallback* callback) {
234 error_message_callback_ = callback;
237 ShareGroup* share_group() const {
238 return share_group_.get();
241 const Capabilities& capabilities() const {
242 return capabilities_;
245 GpuControl* gpu_control() {
246 return gpu_control_;
249 ShareGroupContextData* share_group_context_data() {
250 return &share_group_context_data_;
253 private:
254 friend class GLES2ImplementationTest;
255 friend class VertexArrayObjectManager;
257 // Used to track whether an extension is available
258 enum ExtensionStatus {
259 kAvailableExtensionStatus,
260 kUnavailableExtensionStatus,
261 kUnknownExtensionStatus
264 // Base class for mapped resources.
265 struct MappedResource {
266 MappedResource(GLenum _access, int _shm_id, void* mem, unsigned int offset)
267 : access(_access),
268 shm_id(_shm_id),
269 shm_memory(mem),
270 shm_offset(offset) {
273 // access mode. Currently only GL_WRITE_ONLY is valid
274 GLenum access;
276 // Shared memory ID for buffer.
277 int shm_id;
279 // Address of shared memory
280 void* shm_memory;
282 // Offset of shared memory
283 unsigned int shm_offset;
286 // Used to track mapped textures.
287 struct MappedTexture : public MappedResource {
288 MappedTexture(
289 GLenum access,
290 int shm_id,
291 void* shm_mem,
292 unsigned int shm_offset,
293 GLenum _target,
294 GLint _level,
295 GLint _xoffset,
296 GLint _yoffset,
297 GLsizei _width,
298 GLsizei _height,
299 GLenum _format,
300 GLenum _type)
301 : MappedResource(access, shm_id, shm_mem, shm_offset),
302 target(_target),
303 level(_level),
304 xoffset(_xoffset),
305 yoffset(_yoffset),
306 width(_width),
307 height(_height),
308 format(_format),
309 type(_type) {
312 // These match the arguments to TexSubImage2D.
313 GLenum target;
314 GLint level;
315 GLint xoffset;
316 GLint yoffset;
317 GLsizei width;
318 GLsizei height;
319 GLenum format;
320 GLenum type;
323 // Used to track mapped buffers.
324 struct MappedBuffer : public MappedResource {
325 MappedBuffer(
326 GLenum access,
327 int shm_id,
328 void* shm_mem,
329 unsigned int shm_offset,
330 GLenum _target,
331 GLintptr _offset,
332 GLsizeiptr _size)
333 : MappedResource(access, shm_id, shm_mem, shm_offset),
334 target(_target),
335 offset(_offset),
336 size(_size) {
339 // These match the arguments to BufferSubData.
340 GLenum target;
341 GLintptr offset;
342 GLsizeiptr size;
345 struct TextureUnit {
346 TextureUnit()
347 : bound_texture_2d(0),
348 bound_texture_cube_map(0),
349 bound_texture_external_oes(0) {}
351 // texture currently bound to this unit's GL_TEXTURE_2D with glBindTexture
352 GLuint bound_texture_2d;
354 // texture currently bound to this unit's GL_TEXTURE_CUBE_MAP with
355 // glBindTexture
356 GLuint bound_texture_cube_map;
358 // texture currently bound to this unit's GL_TEXTURE_EXTERNAL_OES with
359 // glBindTexture
360 GLuint bound_texture_external_oes;
363 // Checks for single threaded access.
364 class SingleThreadChecker {
365 public:
366 explicit SingleThreadChecker(GLES2Implementation* gles2_implementation);
367 ~SingleThreadChecker();
369 private:
370 GLES2Implementation* gles2_implementation_;
373 // Gets the value of the result.
374 template <typename T>
375 T GetResultAs() {
376 return static_cast<T>(GetResultBuffer());
379 void* GetResultBuffer();
380 int32 GetResultShmId();
381 uint32 GetResultShmOffset();
383 // Lazily determines if GL_ANGLE_pack_reverse_row_order is available
384 bool IsAnglePackReverseRowOrderAvailable();
385 bool IsChromiumFramebufferMultisampleAvailable();
387 bool IsExtensionAvailableHelper(
388 const char* extension, ExtensionStatus* status);
390 // Gets the GLError through our wrapper.
391 GLenum GetGLError();
393 // Sets our wrapper for the GLError.
394 void SetGLError(GLenum error, const char* function_name, const char* msg);
395 void SetGLErrorInvalidEnum(
396 const char* function_name, GLenum value, const char* label);
398 // Returns the last error and clears it. Useful for debugging.
399 const std::string& GetLastError() {
400 return last_error_;
403 // Waits for all commands to execute.
404 void WaitForCmd();
406 // TODO(gman): These bucket functions really seem like they belong in
407 // CommandBufferHelper (or maybe BucketHelper?). Unfortunately they need
408 // a transfer buffer to function which is currently managed by this class.
410 // Gets the contents of a bucket.
411 bool GetBucketContents(uint32 bucket_id, std::vector<int8>* data);
413 // Sets the contents of a bucket.
414 void SetBucketContents(uint32 bucket_id, const void* data, size_t size);
416 // Sets the contents of a bucket as a string.
417 void SetBucketAsCString(uint32 bucket_id, const char* str);
419 // Gets the contents of a bucket as a string. Returns false if there is no
420 // string available which is a separate case from the empty string.
421 bool GetBucketAsString(uint32 bucket_id, std::string* str);
423 // Sets the contents of a bucket as a string.
424 void SetBucketAsString(uint32 bucket_id, const std::string& str);
426 // Returns true if id is reserved.
427 bool IsBufferReservedId(GLuint id);
428 bool IsFramebufferReservedId(GLuint id) { return false; }
429 bool IsRenderbufferReservedId(GLuint id) { return false; }
430 bool IsTextureReservedId(GLuint id) { return false; }
431 bool IsVertexArrayReservedId(GLuint id) { return false; }
432 bool IsProgramReservedId(GLuint id) { return false; }
433 bool IsValuebufferReservedId(GLuint id) { return false; }
435 bool BindBufferHelper(GLenum target, GLuint texture);
436 bool BindFramebufferHelper(GLenum target, GLuint texture);
437 bool BindRenderbufferHelper(GLenum target, GLuint texture);
438 bool BindTextureHelper(GLenum target, GLuint texture);
439 bool BindVertexArrayOESHelper(GLuint array);
440 bool BindValuebufferCHROMIUMHelper(GLenum target, GLuint valuebuffer);
441 bool UseProgramHelper(GLuint program);
443 void GenBuffersHelper(GLsizei n, const GLuint* buffers);
444 void GenFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
445 void GenRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
446 void GenTexturesHelper(GLsizei n, const GLuint* textures);
447 void GenVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
448 void GenQueriesEXTHelper(GLsizei n, const GLuint* queries);
449 void GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
451 void DeleteBuffersHelper(GLsizei n, const GLuint* buffers);
452 void DeleteFramebuffersHelper(GLsizei n, const GLuint* framebuffers);
453 void DeleteRenderbuffersHelper(GLsizei n, const GLuint* renderbuffers);
454 void DeleteTexturesHelper(GLsizei n, const GLuint* textures);
455 bool DeleteProgramHelper(GLuint program);
456 bool DeleteShaderHelper(GLuint shader);
457 void DeleteQueriesEXTHelper(GLsizei n, const GLuint* queries);
458 void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* arrays);
459 void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* valuebuffers);
461 void DeleteBuffersStub(GLsizei n, const GLuint* buffers);
462 void DeleteFramebuffersStub(GLsizei n, const GLuint* framebuffers);
463 void DeleteRenderbuffersStub(GLsizei n, const GLuint* renderbuffers);
464 void DeleteTexturesStub(GLsizei n, const GLuint* textures);
465 void DeleteProgramStub(GLsizei n, const GLuint* programs);
466 void DeleteShaderStub(GLsizei n, const GLuint* shaders);
467 void DeleteVertexArraysOESStub(GLsizei n, const GLuint* arrays);
468 void DeleteValuebuffersCHROMIUMStub(GLsizei n, const GLuint* valuebuffers);
470 void BufferDataHelper(
471 GLenum target, GLsizeiptr size, const void* data, GLenum usage);
472 void BufferSubDataHelper(
473 GLenum target, GLintptr offset, GLsizeiptr size, const void* data);
474 void BufferSubDataHelperImpl(
475 GLenum target, GLintptr offset, GLsizeiptr size, const void* data,
476 ScopedTransferBufferPtr* buffer);
478 GLuint CreateImageCHROMIUMHelper(ClientBuffer buffer,
479 GLsizei width,
480 GLsizei height,
481 GLenum internalformat);
482 void DestroyImageCHROMIUMHelper(GLuint image_id);
483 GLuint CreateGpuMemoryBufferImageCHROMIUMHelper(GLsizei width,
484 GLsizei height,
485 GLenum internalformat,
486 GLenum usage);
488 // Helper for GetVertexAttrib
489 bool GetVertexAttribHelper(GLuint index, GLenum pname, uint32* param);
491 GLuint GetMaxValueInBufferCHROMIUMHelper(
492 GLuint buffer_id, GLsizei count, GLenum type, GLuint offset);
494 void RestoreElementAndArrayBuffers(bool restore);
495 void RestoreArrayBuffer(bool restrore);
497 // The pixels pointer should already account for unpack skip rows and skip
498 // pixels.
499 void TexSubImage2DImpl(
500 GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
501 GLsizei height, GLenum format, GLenum type, uint32 unpadded_row_size,
502 const void* pixels, uint32 pixels_padded_row_size, GLboolean internal,
503 ScopedTransferBufferPtr* buffer, uint32 buffer_padded_row_size);
505 // Helpers for query functions.
506 bool GetHelper(GLenum pname, GLint* params);
507 bool GetBooleanvHelper(GLenum pname, GLboolean* params);
508 bool GetBufferParameterivHelper(GLenum target, GLenum pname, GLint* params);
509 bool GetFloatvHelper(GLenum pname, GLfloat* params);
510 bool GetFramebufferAttachmentParameterivHelper(
511 GLenum target, GLenum attachment, GLenum pname, GLint* params);
512 bool GetIntegervHelper(GLenum pname, GLint* params);
513 bool GetProgramivHelper(GLuint program, GLenum pname, GLint* params);
514 bool GetRenderbufferParameterivHelper(
515 GLenum target, GLenum pname, GLint* params);
516 bool GetShaderivHelper(GLuint shader, GLenum pname, GLint* params);
517 bool GetTexParameterfvHelper(GLenum target, GLenum pname, GLfloat* params);
518 bool GetTexParameterivHelper(GLenum target, GLenum pname, GLint* params);
519 const GLubyte* GetStringHelper(GLenum name);
521 bool IsExtensionAvailable(const char* ext);
523 // Caches certain capabilties state. Return true if cached.
524 bool SetCapabilityState(GLenum cap, bool enabled);
526 IdHandlerInterface* GetIdHandler(int id_namespace) const;
527 // IdAllocators for objects that can't be shared among contexts.
528 // For now, used only for Queries. TODO(hj.r.chung) Should be added for
529 // Framebuffer and Vertex array objects.
530 IdAllocator* GetIdAllocator(int id_namespace) const;
532 void FinishHelper();
534 void RunIfContextNotLost(const base::Closure& callback);
536 // Validate if an offset is valid, i.e., non-negative and fit into 32-bit.
537 // If not, generate an approriate error, and return false.
538 bool ValidateOffset(const char* func, GLintptr offset);
540 // Validate if a size is valid, i.e., non-negative and fit into 32-bit.
541 // If not, generate an approriate error, and return false.
542 bool ValidateSize(const char* func, GLsizeiptr offset);
544 // Remove the transfer buffer from the buffer tracker. For buffers used
545 // asynchronously the memory is free:ed if the upload has completed. For
546 // other buffers, the memory is either free:ed immediately or free:ed pending
547 // a token.
548 void RemoveTransferBuffer(BufferTracker::Buffer* buffer);
550 // Returns true if the async upload token has passed.
552 // NOTE: This will detect wrapped async tokens by checking if the most
553 // significant bit of async token to check is 1 but the last read is 0, i.e.
554 // the uint32 wrapped.
555 bool HasAsyncUploadTokenPassed(uint32 token) const {
556 return async_upload_sync_->HasAsyncUploadTokenPassed(token);
559 // Get the next async upload token.
560 uint32 NextAsyncUploadToken();
562 // Ensure that the shared memory used for synchronizing async upload tokens
563 // has been mapped.
565 // Returns false on error, true on success.
566 bool EnsureAsyncUploadSync();
568 // Checks the last read asynchronously upload token and frees any unmanaged
569 // transfer buffer that has its async token passed.
570 void PollAsyncUploads();
572 // Free every async upload buffer. If some async upload buffer is still in use
573 // wait for them to finish before freeing.
574 void FreeAllAsyncUploadBuffers();
576 bool GetBoundPixelTransferBuffer(
577 GLenum target, const char* function_name, GLuint* buffer_id);
578 BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid(
579 GLuint buffer_id,
580 const char* function_name, GLuint offset, GLsizei size);
582 const std::string& GetLogPrefix() const;
584 #if defined(GL_CLIENT_FAIL_GL_ERRORS)
585 void CheckGLError();
586 void FailGLError(GLenum error);
587 #else
588 void CheckGLError() { }
589 void FailGLError(GLenum /* error */) { }
590 #endif
592 GLES2Util util_;
593 GLES2CmdHelper* helper_;
594 TransferBufferInterface* transfer_buffer_;
595 std::string last_error_;
596 DebugMarkerManager debug_marker_manager_;
597 std::string this_in_hex_;
599 std::queue<int32> swap_buffers_tokens_;
600 std::queue<int32> rate_limit_tokens_;
602 ExtensionStatus angle_pack_reverse_row_order_status_;
603 ExtensionStatus chromium_framebuffer_multisample_;
605 GLStaticState static_state_;
606 ClientContextState state_;
608 // pack alignment as last set by glPixelStorei
609 GLint pack_alignment_;
611 // unpack alignment as last set by glPixelStorei
612 GLint unpack_alignment_;
614 // unpack yflip as last set by glPixelstorei
615 bool unpack_flip_y_;
617 // unpack row length as last set by glPixelStorei
618 GLint unpack_row_length_;
620 // unpack skip rows as last set by glPixelStorei
621 GLint unpack_skip_rows_;
623 // unpack skip pixels as last set by glPixelStorei
624 GLint unpack_skip_pixels_;
626 // pack reverse row order as last set by glPixelstorei
627 bool pack_reverse_row_order_;
629 scoped_ptr<TextureUnit[]> texture_units_;
631 // 0 to gl_state_.max_combined_texture_image_units.
632 GLuint active_texture_unit_;
634 GLuint bound_framebuffer_;
635 GLuint bound_read_framebuffer_;
636 GLuint bound_renderbuffer_;
637 GLuint bound_valuebuffer_;
639 // The program in use by glUseProgram
640 GLuint current_program_;
642 // The currently bound array buffer.
643 GLuint bound_array_buffer_id_;
645 // The currently bound pixel transfer buffers.
646 GLuint bound_pixel_pack_transfer_buffer_id_;
647 GLuint bound_pixel_unpack_transfer_buffer_id_;
649 // The current asynchronous pixel buffer upload token.
650 uint32 async_upload_token_;
652 // The shared memory used for synchronizing asynchronous upload tokens.
653 AsyncUploadSync* async_upload_sync_;
654 int32 async_upload_sync_shm_id_;
655 unsigned int async_upload_sync_shm_offset_;
657 // Unmanaged pixel transfer buffer memory pending asynchronous upload token.
658 typedef std::list<std::pair<void*, uint32> > DetachedAsyncUploadMemoryList;
659 DetachedAsyncUploadMemoryList detached_async_upload_memory_;
661 // Client side management for vertex array objects. Needed to correctly
662 // track client side arrays.
663 scoped_ptr<VertexArrayObjectManager> vertex_array_object_manager_;
665 GLuint reserved_ids_[2];
667 // Current GL error bits.
668 uint32 error_bits_;
670 // Whether or not to print debugging info.
671 bool debug_;
673 // When true, the context is lost when a GL_OUT_OF_MEMORY error occurs.
674 bool lose_context_when_out_of_memory_;
676 // Whether or not to support client side arrays.
677 bool support_client_side_arrays_;
679 // Used to check for single threaded access.
680 int use_count_;
682 // Map of GLenum to Strings for glGetString. We need to cache these because
683 // the pointer passed back to the client has to remain valid for eternity.
684 typedef std::map<uint32, std::set<std::string> > GLStringMap;
685 GLStringMap gl_strings_;
687 // Similar cache for glGetRequestableExtensionsCHROMIUM. We don't
688 // have an enum for this so handle it separately.
689 std::set<std::string> requestable_extensions_set_;
691 typedef std::map<const void*, MappedBuffer> MappedBufferMap;
692 MappedBufferMap mapped_buffers_;
694 typedef std::map<const void*, MappedTexture> MappedTextureMap;
695 MappedTextureMap mapped_textures_;
697 scoped_ptr<MappedMemoryManager> mapped_memory_;
699 scoped_refptr<ShareGroup> share_group_;
700 ShareGroupContextData share_group_context_data_;
702 scoped_ptr<QueryTracker> query_tracker_;
703 typedef std::map<GLuint, QueryTracker::Query*> QueryMap;
704 QueryMap current_queries_;
705 scoped_ptr<IdAllocator> query_id_allocator_;
707 scoped_ptr<BufferTracker> buffer_tracker_;
709 GLES2ImplementationErrorMessageCallback* error_message_callback_;
711 scoped_ptr<std::string> current_trace_name_;
713 GpuControl* gpu_control_;
715 Capabilities capabilities_;
717 base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_;
719 DISALLOW_COPY_AND_ASSIGN(GLES2Implementation);
722 inline bool GLES2Implementation::GetBufferParameterivHelper(
723 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
724 return false;
727 inline bool GLES2Implementation::GetFramebufferAttachmentParameterivHelper(
728 GLenum /* target */,
729 GLenum /* attachment */,
730 GLenum /* pname */,
731 GLint* /* params */) {
732 return false;
735 inline bool GLES2Implementation::GetRenderbufferParameterivHelper(
736 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
737 return false;
740 inline bool GLES2Implementation::GetShaderivHelper(
741 GLuint /* shader */, GLenum /* pname */, GLint* /* params */) {
742 return false;
745 inline bool GLES2Implementation::GetTexParameterfvHelper(
746 GLenum /* target */, GLenum /* pname */, GLfloat* /* params */) {
747 return false;
750 inline bool GLES2Implementation::GetTexParameterivHelper(
751 GLenum /* target */, GLenum /* pname */, GLint* /* params */) {
752 return false;
755 } // namespace gles2
756 } // namespace gpu
758 #endif // GPU_COMMAND_BUFFER_CLIENT_GLES2_IMPLEMENTATION_H_