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

Unified Diff: cc/test/test_gles2_interface.h

Issue 93283002: Add GLES2Interface version of TWGC3D Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/test/test_gles2_interface.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/test/test_gles2_interface.h
diff --git a/cc/test/test_gles2_interface.h b/cc/test/test_gles2_interface.h
new file mode 100644
index 0000000000000000000000000000000000000000..d65ff64d835901ab2e9f1a4dc68857f76ecf2b54
--- /dev/null
+++ b/cc/test/test_gles2_interface.h
@@ -0,0 +1,296 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_TEST_TEST_GLES2_INTERFACE_H_
+#define CC_TEST_TEST_GLES2_INTERFACE_H_
+
+#include <vector>
+
+#include "base/compiler_specific.h"
+#include "base/containers/hash_tables.h"
+#include "base/containers/scoped_ptr_hash_map.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/stl_util.h"
+#include "base/synchronization/lock.h"
+#include "cc/output/context_provider.h"
+#include "cc/test/ordered_texture_map.h"
+#include "cc/test/test_texture.h"
+#include "gpu/command_buffer/client/gles2_interface_stub.h"
+#include "third_party/khronos/GLES2/gl2.h"
+
+namespace cc {
+class TestContextSupport;
+
+class TestGLES2Interface : public gpu::gles2::GLES2InterfaceStub {
+ public:
+ static scoped_ptr<TestGLES2Interface> Create();
+
+ virtual ~TestGLES2Interface();
+
+ virtual bool makeContextCurrent();
+
+ virtual void reshapeWithScaleFactor(
+ int width, int height, float scale_factor);
+
+ virtual bool isContextLost();
+
+ GLuint CreateExternalTexture();
+
+ virtual void AttachShader(GLuint program, GLuint shader) OVERRIDE;
+ virtual void BindFramebuffer(
+ GLenum target, GLuint framebuffer) OVERRIDE;
+ virtual void BindRenderbuffer(
+ GLenum target, GLuint renderbuffer) OVERRIDE;
+ virtual void BindTexture(
+ GLenum target,
+ GLuint texture_id) OVERRIDE;
+
+ virtual GLenum CheckFramebufferStatus(GLenum target) OVERRIDE;
+
+ virtual const GLubyte* GetString(GLenum name) OVERRIDE;
+ virtual GLint GetUniformLocation(
+ GLuint program,
+ const GLchar* name) OVERRIDE;
+ virtual void GetVertexAttribPointerv(
+ GLuint index,
+ GLenum pname,
+ void** pointer) OVERRIDE;
+
+ virtual void UseProgram(GLuint program) OVERRIDE;
+
+ virtual void GenBuffers(GLsizei count, GLuint* ids) OVERRIDE;
+ virtual void GenFramebuffers(GLsizei count, GLuint* ids) OVERRIDE;
+ virtual void GenRenderbuffers(GLsizei count, GLuint* ids) OVERRIDE;
+ virtual void GenTextures(GLsizei count, GLuint* ids) OVERRIDE;
+
+ virtual void DeleteBuffers(GLsizei count, const GLuint* ids) OVERRIDE;
+ virtual void DeleteFramebuffers(
+ GLsizei count, const GLuint* ids) OVERRIDE;
+ virtual void DeleteRenderbuffers(
+ GLsizei count, const GLuint* ids) OVERRIDE;
+ virtual void DeleteTextures(GLsizei count, const GLuint* ids) OVERRIDE;
+
+ virtual GLuint CreateProgram() OVERRIDE;
+ virtual GLuint CreateShader(GLenum) OVERRIDE;
+
+ virtual void DeleteProgram(GLuint id) OVERRIDE;
+ virtual void DeleteShader(GLuint id) OVERRIDE;
+
+ virtual void EndQueryEXT(GLenum target) OVERRIDE;
+ virtual void GetQueryObjectuivEXT(
+ GLuint query,
+ GLenum pname,
+ GLuint* params) OVERRIDE;
+
+ virtual void GetIntegerv(
+ GLenum pname,
+ GLint* value) OVERRIDE;
+
+ virtual void GenMailboxCHROMIUM(GLbyte* mailbox) OVERRIDE;
+
+ virtual void LoseContextCHROMIUM(GLenum current,
+ GLenum other) OVERRIDE;
+
+ virtual void Finish() OVERRIDE;
+ virtual void Flush() OVERRIDE;
+
+ virtual void BindBuffer(GLenum target, GLuint buffer) OVERRIDE;
+ virtual void BufferData(GLenum target,
+ GLsizeiptr size,
+ const void* data,
+ GLenum usage) OVERRIDE;
+ virtual void* MapBufferCHROMIUM(GLenum target,
+ GLenum access) OVERRIDE;
+ virtual GLboolean UnmapBufferCHROMIUM(GLenum target) OVERRIDE;
+
+ virtual GLuint CreateImageCHROMIUM(
+ GLsizei width,
+ GLsizei height,
+ GLenum internalformat) OVERRIDE;
+ virtual void DestroyImageCHROMIUM(GLuint image_id) OVERRIDE;
+ virtual void GetImageParameterivCHROMIUM(
+ GLuint image_id,
+ GLenum pname,
+ GLint* params) OVERRIDE;
+ virtual void* MapImageCHROMIUM(
+ GLuint image_id,
+ GLenum access) OVERRIDE;
+ virtual void UnmapImageCHROMIUM(GLuint image_id) OVERRIDE;
+
+ const ContextProvider::Capabilities& test_capabilities() const {
+ return test_capabilities_;
+ }
+
+ // When set, MakeCurrent() will fail after this many times.
+ void set_times_make_current_succeeds(int times) {
+ times_make_current_succeeds_ = times;
+ }
+ void set_times_bind_texture_succeeds(int times) {
+ times_bind_texture_succeeds_ = times;
+ }
+ void set_times_end_query_succeeds(int times) {
+ times_end_query_succeeds_ = times;
+ }
+ void set_times_gen_mailbox_succeeds(int times) {
+ times_gen_mailbox_succeeds_ = times;
+ }
+
+ // When set, mapImageCHROMIUM and mapBufferCHROMIUM will return NULL after
+ // this many times.
+ void set_times_map_image_chromium_succeeds(int times) {
+ times_map_image_chromium_succeeds_ = times;
+ }
+ void set_times_map_buffer_chromium_succeeds(int times) {
+ times_map_buffer_chromium_succeeds_ = times;
+ }
+
+ size_t NumTextures() const;
+ GLuint TextureAt(int i) const;
+
+ size_t NumUsedTextures() const { return used_textures_.size(); }
+ bool UsedTexture(int texture) const {
+ return ContainsKey(used_textures_, texture);
+ }
+ void ResetUsedTextures() { used_textures_.clear(); }
+
+ void set_support_swapbuffers_complete_callback(bool support) {
+ test_capabilities_.swapbuffers_complete_callback = support;
+ }
+ void set_have_extension_io_surface(bool have) {
+ test_capabilities_.iosurface = have;
+ test_capabilities_.texture_rectangle = have;
+ }
+ void set_have_extension_egl_image(bool have) {
+ test_capabilities_.egl_image_external = have;
+ }
+ void set_have_post_sub_buffer(bool have) {
+ test_capabilities_.post_sub_buffer = have;
+ }
+ void set_have_discard_framebuffer(bool have) {
+ test_capabilities_.discard_framebuffer = have;
+ }
+ void set_support_compressed_texture_etc1(bool support) {
+ test_capabilities_.texture_format_etc1 = support;
+ }
+
+ // When this context is lost, all contexts in its share group are also lost.
+ void add_share_group_context(gpu::gles2::GLES2Interface* context3d) {
+ shared_contexts_.push_back(context3d);
+ }
+
+ void set_max_texture_size(int size) { max_texture_size_ = size; }
+
+ static const GLuint kExternalTextureId;
+ virtual GLuint NextTextureId();
+ virtual void RetireTextureId(GLuint id);
+
+ virtual GLuint NextBufferId();
+ virtual void RetireBufferId(GLuint id);
+
+ virtual GLuint NextImageId();
+ virtual void RetireImageId(GLuint id);
+
+ size_t GetTransferBufferMemoryUsedBytes() const;
+ void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
+
+ void set_test_support(TestContextSupport* test_support) {
+ test_support_ = test_support;
+ }
+
+ protected:
+ struct TextureTargets {
+ TextureTargets();
+ ~TextureTargets();
+
+ void BindTexture(GLenum target, GLuint id);
+ void UnbindTexture(GLuint id);
+
+ GLuint BoundTexture(GLenum target);
+
+ private:
+ typedef base::hash_map<GLenum, GLuint> TargetTextureMap;
+ TargetTextureMap bound_textures_;
+ };
+
+ struct Buffer {
+ Buffer();
+ ~Buffer();
+
+ GLenum target;
+ scoped_ptr<uint8[]> pixels;
+ size_t size;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Buffer);
+ };
+
+ struct Image {
+ Image();
+ ~Image();
+
+ scoped_ptr<uint8[]> pixels;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(Image);
+ };
+
+ struct Namespace : public base::RefCountedThreadSafe<Namespace> {
+ Namespace();
+
+ // Protects all fields.
+ base::Lock lock;
+ uint8 next_buffer_id;
+ uint8 next_image_id;
+ uint8 next_texture_id;
+ base::ScopedPtrHashMap<uint8, Buffer> buffers;
+ base::ScopedPtrHashMap<uint8, Image> images;
+ OrderedTextureMap textures;
+
+ private:
+ friend class base::RefCountedThreadSafe<Namespace>;
+ ~Namespace();
+ DISALLOW_COPY_AND_ASSIGN(Namespace);
+ };
+
+ TestGLES2Interface();
+
+ void CallAllSyncPointCallbacks();
+ void SwapBuffersComplete();
+ void CreateNamespace();
+ GLuint BoundTextureId(GLenum target);
+
+ uint8 context_id_;
+ ContextProvider::Capabilities test_capabilities_;
+ int times_make_current_succeeds_;
+ int times_bind_texture_succeeds_;
+ int times_end_query_succeeds_;
+ int times_gen_mailbox_succeeds_;
+ bool context_lost_;
+ int times_map_image_chromium_succeeds_;
+ int times_map_buffer_chromium_succeeds_;
+ base::hash_set<GLuint> used_textures_;
+ GLuint next_program_id_;
+ base::hash_set<GLuint> program_set_;
+ GLuint next_shader_id_;
+ base::hash_set<GLuint> shader_set_;
+ std::vector<gpu::gles2::GLES2Interface*> shared_contexts_;
+ int max_texture_size_;
+ int width_;
+ int height_;
+ TestContextSupport* test_support_;
+
+ uint8 bound_buffer_;
+ TextureTargets texture_targets_;
+
+ scoped_refptr<Namespace> namespace_;
+ static Namespace* shared_namespace_;
+
+ base::WeakPtrFactory<TestGLES2Interface> weak_ptr_factory_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_GLES2_INTERFACE_H_
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/test/test_gles2_interface.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698