summaryrefslogtreecommitdiffstats
path: root/cc/test
diff options
context:
space:
mode:
authorjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 06:54:59 +0000
committerjamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 06:54:59 +0000
commitc2610b9fb4b118315423456cc7e55eb9da40cb93 (patch)
tree86a4d6cd421b785f6b762c7d7084d9af0f425566 /cc/test
parent0249a653b7e5076f331848a11034059000b644da (diff)
downloadchromium_src-c2610b9fb4b118315423456cc7e55eb9da40cb93.zip
chromium_src-c2610b9fb4b118315423456cc7e55eb9da40cb93.tar.gz
chromium_src-c2610b9fb4b118315423456cc7e55eb9da40cb93.tar.bz2
Move test-only stuff from cc/debug/ to cc/test
This moves the test/fake context implementations from cc/debug/ to cc/test and stops linking them into production targets. Test targets elsewhere in the tree can link against cc_test_support to use these. R=danakj,piman Review URL: https://codereview.chromium.org/50303007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232025 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/test')
-rw-r--r--cc/test/fake_layer_tree_host_client.cc2
-rw-r--r--cc/test/fake_layer_tree_host_client.h2
-rw-r--r--cc/test/fake_output_surface.h4
-rw-r--r--cc/test/fake_web_graphics_context_3d.cc373
-rw-r--r--cc/test/fake_web_graphics_context_3d.h614
-rw-r--r--cc/test/fake_web_graphics_context_3d_unittest.cc2
-rw-r--r--cc/test/layer_tree_test.cc2
-rw-r--r--cc/test/ordered_texture_map.cc62
-rw-r--r--cc/test/ordered_texture_map.h45
-rw-r--r--cc/test/test_context_provider.cc228
-rw-r--r--cc/test/test_context_provider.h88
-rw-r--r--cc/test/test_context_support.cc36
-rw-r--r--cc/test/test_context_support.h37
-rw-r--r--cc/test/test_texture.cc29
-rw-r--r--cc/test/test_texture.h38
-rw-r--r--cc/test/test_web_graphics_context_3d.cc665
-rw-r--r--cc/test/test_web_graphics_context_3d.h322
17 files changed, 2543 insertions, 6 deletions
diff --git a/cc/test/fake_layer_tree_host_client.cc b/cc/test/fake_layer_tree_host_client.cc
index b74b094..1ee0bb8 100644
--- a/cc/test/fake_layer_tree_host_client.cc
+++ b/cc/test/fake_layer_tree_host_client.cc
@@ -4,9 +4,9 @@
#include "cc/test/fake_layer_tree_host_client.h"
-#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/output/context_provider.h"
#include "cc/test/fake_output_surface.h"
+#include "cc/test/test_web_graphics_context_3d.h"
namespace cc {
diff --git a/cc/test/fake_layer_tree_host_client.h b/cc/test/fake_layer_tree_host_client.h
index a1e1708..0bad7ad 100644
--- a/cc/test/fake_layer_tree_host_client.h
+++ b/cc/test/fake_layer_tree_host_client.h
@@ -6,8 +6,8 @@
#define CC_TEST_FAKE_LAYER_TREE_HOST_CLIENT_H_
#include "base/memory/scoped_ptr.h"
-#include "cc/debug/test_context_provider.h"
#include "cc/input/input_handler.h"
+#include "cc/test/test_context_provider.h"
#include "cc/trees/layer_tree_host.h"
namespace cc {
diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h
index 0540f13..0a85f4d 100644
--- a/cc/test/fake_output_surface.h
+++ b/cc/test/fake_output_surface.h
@@ -8,13 +8,13 @@
#include "base/callback.h"
#include "base/logging.h"
#include "base/time/time.h"
-#include "cc/debug/test_context_provider.h"
-#include "cc/debug/test_web_graphics_context_3d.h"
#include "cc/output/begin_frame_args.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/managed_memory_policy.h"
#include "cc/output/output_surface.h"
#include "cc/output/software_output_device.h"
+#include "cc/test/test_context_provider.h"
+#include "cc/test/test_web_graphics_context_3d.h"
namespace cc {
diff --git a/cc/test/fake_web_graphics_context_3d.cc b/cc/test/fake_web_graphics_context_3d.cc
new file mode 100644
index 0000000..d822cfe
--- /dev/null
+++ b/cc/test/fake_web_graphics_context_3d.cc
@@ -0,0 +1,373 @@
+// 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.
+
+#include "cc/test/fake_web_graphics_context_3d.h"
+
+#include "base/logging.h"
+#include "third_party/khronos/GLES2/gl2.h"
+
+using WebKit::WGC3Dboolean;
+using WebKit::WGC3Denum;
+using WebKit::WGC3Dsizei;
+using WebKit::WebGLId;
+using WebKit::WebGraphicsContext3D;
+
+namespace cc {
+
+FakeWebGraphicsContext3D::FakeWebGraphicsContext3D()
+ : WebKit::WebGraphicsContext3D() {
+}
+
+FakeWebGraphicsContext3D::~FakeWebGraphicsContext3D() {
+}
+
+bool FakeWebGraphicsContext3D::makeContextCurrent() {
+ return true;
+}
+
+bool FakeWebGraphicsContext3D::isGLES2Compliant() {
+ return false;
+}
+
+WebGLId FakeWebGraphicsContext3D::getPlatformTextureId() {
+ return 0;
+}
+
+bool FakeWebGraphicsContext3D::isContextLost() {
+ return false;
+}
+
+WGC3Denum FakeWebGraphicsContext3D::getGraphicsResetStatusARB() {
+ return GL_NO_ERROR;
+}
+
+void* FakeWebGraphicsContext3D::mapBufferSubDataCHROMIUM(
+ WGC3Denum target,
+ WebKit::WGC3Dintptr offset,
+ WebKit::WGC3Dsizeiptr size,
+ WGC3Denum access) {
+ return 0;
+}
+
+void* FakeWebGraphicsContext3D::mapTexSubImage2DCHROMIUM(
+ WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Dint xoffset,
+ WebKit::WGC3Dint yoffset,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WGC3Denum format,
+ WGC3Denum type,
+ WGC3Denum access) {
+ return 0;
+}
+
+WebKit::WebString FakeWebGraphicsContext3D::getRequestableExtensionsCHROMIUM() {
+ return WebKit::WebString();
+}
+
+WGC3Denum FakeWebGraphicsContext3D::checkFramebufferStatus(
+ WGC3Denum target) {
+ return GL_FRAMEBUFFER_COMPLETE;
+}
+
+bool FakeWebGraphicsContext3D::getActiveAttrib(
+ WebGLId program,
+ WebKit::WGC3Duint index,
+ ActiveInfo&) {
+ return false;
+}
+
+bool FakeWebGraphicsContext3D::getActiveUniform(
+ WebGLId program,
+ WebKit::WGC3Duint index,
+ ActiveInfo&) {
+ return false;
+}
+
+WebKit::WGC3Dint FakeWebGraphicsContext3D::getAttribLocation(
+ WebGLId program,
+ const WebKit::WGC3Dchar* name) {
+ return 0;
+}
+
+WebGraphicsContext3D::Attributes
+ FakeWebGraphicsContext3D::getContextAttributes() {
+ return WebGraphicsContext3D::Attributes();
+}
+
+WGC3Denum FakeWebGraphicsContext3D::getError() {
+ return 0;
+}
+
+void FakeWebGraphicsContext3D::getIntegerv(
+ WGC3Denum pname,
+ WebKit::WGC3Dint* value) {
+ if (pname == GL_MAX_TEXTURE_SIZE)
+ *value = 1024;
+ else if (pname == GL_ACTIVE_TEXTURE)
+ *value = GL_TEXTURE0;
+}
+
+void FakeWebGraphicsContext3D::getProgramiv(
+ WebGLId program,
+ WGC3Denum pname,
+ WebKit::WGC3Dint* value) {
+ if (pname == GL_LINK_STATUS)
+ *value = 1;
+}
+
+WebKit::WebString FakeWebGraphicsContext3D::getProgramInfoLog(
+ WebGLId program) {
+ return WebKit::WebString();
+}
+
+void FakeWebGraphicsContext3D::getShaderiv(
+ WebGLId shader,
+ WGC3Denum pname,
+ WebKit::WGC3Dint* value) {
+ if (pname == GL_COMPILE_STATUS)
+ *value = 1;
+}
+
+WebKit::WebString FakeWebGraphicsContext3D::getShaderInfoLog(
+ WebGLId shader) {
+ return WebKit::WebString();
+}
+
+void FakeWebGraphicsContext3D::getShaderPrecisionFormat(
+ WebKit::WGC3Denum shadertype,
+ WebKit::WGC3Denum precisiontype,
+ WebKit::WGC3Dint* range,
+ WebKit::WGC3Dint* precision) {
+ // Return the minimum precision requirements of the GLES specificatin.
+ switch (precisiontype) {
+ case GL_LOW_INT:
+ range[0] = 8;
+ range[1] = 8;
+ *precision = 0;
+ break;
+ case GL_MEDIUM_INT:
+ range[0] = 10;
+ range[1] = 10;
+ *precision = 0;
+ break;
+ case GL_HIGH_INT:
+ range[0] = 16;
+ range[1] = 16;
+ *precision = 0;
+ break;
+ case GL_LOW_FLOAT:
+ range[0] = 8;
+ range[1] = 8;
+ *precision = 8;
+ break;
+ case GL_MEDIUM_FLOAT:
+ range[0] = 14;
+ range[1] = 14;
+ *precision = 10;
+ break;
+ case GL_HIGH_FLOAT:
+ range[0] = 62;
+ range[1] = 62;
+ *precision = 16;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+WebKit::WebString FakeWebGraphicsContext3D::getShaderSource(
+ WebGLId shader) {
+ return WebKit::WebString();
+}
+
+WebKit::WebString FakeWebGraphicsContext3D::getString(WGC3Denum name) {
+ return WebKit::WebString();
+}
+
+WebKit::WGC3Dint FakeWebGraphicsContext3D::getUniformLocation(
+ WebGLId program,
+ const WebKit::WGC3Dchar* name) {
+ return 0;
+}
+
+WebKit::WGC3Dsizeiptr FakeWebGraphicsContext3D::getVertexAttribOffset(
+ WebKit::WGC3Duint index,
+ WGC3Denum pname) {
+ return 0;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isBuffer(
+ WebGLId buffer) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isEnabled(
+ WGC3Denum cap) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isFramebuffer(
+ WebGLId framebuffer) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isProgram(
+ WebGLId program) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isRenderbuffer(
+ WebGLId renderbuffer) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isShader(
+ WebGLId shader) {
+ return false;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isTexture(
+ WebGLId texture) {
+ return false;
+}
+
+void FakeWebGraphicsContext3D::genBuffers(WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = 1;
+}
+
+void FakeWebGraphicsContext3D::genFramebuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = 1;
+}
+
+void FakeWebGraphicsContext3D::genRenderbuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = 1;
+}
+
+void FakeWebGraphicsContext3D::genTextures(WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = 1;
+}
+
+void FakeWebGraphicsContext3D::deleteBuffers(WGC3Dsizei count, WebGLId* ids) {
+}
+
+void FakeWebGraphicsContext3D::deleteFramebuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+}
+
+void FakeWebGraphicsContext3D::deleteRenderbuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+}
+
+void FakeWebGraphicsContext3D::deleteTextures(WGC3Dsizei count, WebGLId* ids) {
+}
+
+WebGLId FakeWebGraphicsContext3D::createBuffer() {
+ return 1;
+}
+
+WebGLId FakeWebGraphicsContext3D::createFramebuffer() {
+ return 1;
+}
+
+WebGLId FakeWebGraphicsContext3D::createRenderbuffer() {
+ return 1;
+}
+
+WebGLId FakeWebGraphicsContext3D::createTexture() {
+ return 1;
+}
+
+void FakeWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) {
+}
+
+void FakeWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) {
+}
+
+void FakeWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) {
+}
+
+void FakeWebGraphicsContext3D::deleteTexture(WebGLId texture_id) {
+}
+
+WebGLId FakeWebGraphicsContext3D::createProgram() {
+ return 1;
+}
+
+WebGLId FakeWebGraphicsContext3D::createShader(WGC3Denum) {
+ return 1;
+}
+
+void FakeWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) {
+}
+
+void FakeWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) {
+}
+
+void FakeWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) {
+}
+
+void FakeWebGraphicsContext3D::useProgram(WebGLId program) {
+}
+
+void FakeWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) {
+}
+
+void FakeWebGraphicsContext3D::bindFramebuffer(
+ WGC3Denum target, WebGLId framebuffer) {
+}
+
+void FakeWebGraphicsContext3D::bindRenderbuffer(
+ WGC3Denum target, WebGLId renderbuffer) {
+}
+
+void FakeWebGraphicsContext3D::bindTexture(
+ WGC3Denum target, WebGLId texture_id) {
+}
+
+WebGLId FakeWebGraphicsContext3D::createQueryEXT() {
+ return 1;
+}
+
+WGC3Dboolean FakeWebGraphicsContext3D::isQueryEXT(WebGLId query) {
+ return true;
+}
+
+void FakeWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) {
+}
+
+void FakeWebGraphicsContext3D::getQueryObjectuivEXT(
+ WebKit::WebGLId query,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Duint* params) {
+}
+
+void FakeWebGraphicsContext3D::setContextLostCallback(
+ WebGraphicsContextLostCallback* callback) {
+}
+
+void FakeWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
+ WGC3Denum other) {
+}
+
+WebKit::WGC3Duint FakeWebGraphicsContext3D::createImageCHROMIUM(
+ WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum internalformat) {
+ return 0;
+}
+
+void* FakeWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum access) {
+ return 0;
+}
+
+} // namespace cc
diff --git a/cc/test/fake_web_graphics_context_3d.h b/cc/test/fake_web_graphics_context_3d.h
new file mode 100644
index 0000000..35f55c6
--- /dev/null
+++ b/cc/test/fake_web_graphics_context_3d.h
@@ -0,0 +1,614 @@
+// 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_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_
+#define CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_
+
+#include <string>
+
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+
+namespace cc {
+
+// WebGraphicsContext3D base class for use in unit tests.
+// All operations are no-ops (returning 0 if necessary).
+class FakeWebGraphicsContext3D : public WebKit::WebGraphicsContext3D {
+ public:
+ FakeWebGraphicsContext3D();
+ virtual ~FakeWebGraphicsContext3D();
+
+ virtual bool makeContextCurrent();
+
+ virtual bool isGLES2Compliant();
+
+ virtual WebKit::WebGLId getPlatformTextureId();
+
+ virtual void prepareTexture() {}
+
+ virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) {}
+
+ virtual void synthesizeGLError(WebKit::WGC3Denum) {}
+
+ virtual bool isContextLost();
+ virtual WebKit::WGC3Denum getGraphicsResetStatusARB();
+
+ virtual void* mapBufferSubDataCHROMIUM(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dintptr offset,
+ WebKit::WGC3Dsizeiptr size,
+ WebKit::WGC3Denum access);
+
+ virtual void unmapBufferSubDataCHROMIUM(const void*) {}
+ virtual void* mapTexSubImage2DCHROMIUM(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Dint xoffset,
+ WebKit::WGC3Dint yoffset,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum format,
+ WebKit::WGC3Denum type,
+ WebKit::WGC3Denum access);
+ virtual void unmapTexSubImage2DCHROMIUM(const void*) {}
+
+ virtual void setVisibilityCHROMIUM(bool visible) {}
+
+ virtual void discardFramebufferEXT(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dsizei num_attachments,
+ const WebKit::WGC3Denum* attachments) {}
+
+ virtual WebKit::WebString getRequestableExtensionsCHROMIUM();
+ virtual void requestExtensionCHROMIUM(const char*) {}
+
+ virtual void blitFramebufferCHROMIUM(
+ WebKit::WGC3Dint src_x0,
+ WebKit::WGC3Dint src_y0,
+ WebKit::WGC3Dint src_x1,
+ WebKit::WGC3Dint src_y1,
+ WebKit::WGC3Dint dst_x0,
+ WebKit::WGC3Dint dst_y0,
+ WebKit::WGC3Dint dst_x1,
+ WebKit::WGC3Dint dst_y1,
+ WebKit::WGC3Dbitfield mask,
+ WebKit::WGC3Denum filter) {}
+ virtual void renderbufferStorageMultisampleCHROMIUM(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dsizei samples,
+ WebKit::WGC3Denum internalformat,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height) {}
+
+ virtual void activeTexture(WebKit::WGC3Denum texture) {}
+ virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
+ virtual void bindAttribLocation(
+ WebKit::WebGLId program,
+ WebKit::WGC3Duint index,
+ const WebKit::WGC3Dchar* name) {}
+ virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer);
+ virtual void bindFramebuffer(
+ WebKit::WGC3Denum target, WebKit::WebGLId framebuffer);
+ virtual void bindRenderbuffer(
+ WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer);
+ virtual void bindTexture(
+ WebKit::WGC3Denum target,
+ WebKit::WebGLId texture_id);
+ virtual void blendColor(
+ WebKit::WGC3Dclampf red,
+ WebKit::WGC3Dclampf green,
+ WebKit::WGC3Dclampf blue,
+ WebKit::WGC3Dclampf alpha) {}
+ virtual void blendEquation(WebKit::WGC3Denum mode) {}
+ virtual void blendEquationSeparate(
+ WebKit::WGC3Denum mode_rgb,
+ WebKit::WGC3Denum mode_alpha) {}
+ virtual void blendFunc(
+ WebKit::WGC3Denum sfactor,
+ WebKit::WGC3Denum dfactor) {}
+ virtual void blendFuncSeparate(
+ WebKit::WGC3Denum src_rgb,
+ WebKit::WGC3Denum dst_rgb,
+ WebKit::WGC3Denum src_alpha,
+ WebKit::WGC3Denum dst_alpha) {}
+
+ virtual void bufferData(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dsizeiptr size,
+ const void* data,
+ WebKit::WGC3Denum usage) {}
+ virtual void bufferSubData(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dintptr offset,
+ WebKit::WGC3Dsizeiptr size,
+ const void* data) {}
+
+ virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target);
+
+ virtual void clear(WebKit::WGC3Dbitfield mask) {}
+ virtual void clearColor(
+ WebKit::WGC3Dclampf red,
+ WebKit::WGC3Dclampf green,
+ WebKit::WGC3Dclampf blue,
+ WebKit::WGC3Dclampf alpha) {}
+ virtual void clearDepth(WebKit::WGC3Dclampf depth) {}
+ virtual void clearStencil(WebKit::WGC3Dint s) {}
+ virtual void colorMask(
+ WebKit::WGC3Dboolean red,
+ WebKit::WGC3Dboolean green,
+ WebKit::WGC3Dboolean blue,
+ WebKit::WGC3Dboolean alpha) {}
+ virtual void compileShader(WebKit::WebGLId shader) {}
+
+ virtual void compressedTexImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Denum internal_format,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Dint border,
+ WebKit::WGC3Dsizei image_size,
+ const void* data) {}
+ virtual void compressedTexSubImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Dint xoffset,
+ WebKit::WGC3Dint yoffset,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum format,
+ WebKit::WGC3Dsizei image_size,
+ const void* data) {}
+ virtual void copyTexImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Denum internalformat,
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Dint border) {}
+ virtual void copyTexSubImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Dint xoffset,
+ WebKit::WGC3Dint yoffset,
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height) {}
+ virtual void cullFace(WebKit::WGC3Denum mode) {}
+ virtual void depthFunc(WebKit::WGC3Denum func) {}
+ virtual void depthMask(WebKit::WGC3Dboolean flag) {}
+ virtual void depthRange(
+ WebKit::WGC3Dclampf z_near,
+ WebKit::WGC3Dclampf z_far) {}
+ virtual void detachShader(WebKit::WebGLId program, WebKit::WebGLId shader) {}
+ virtual void disable(WebKit::WGC3Denum cap) {}
+ virtual void disableVertexAttribArray(WebKit::WGC3Duint index) {}
+ virtual void drawArrays(
+ WebKit::WGC3Denum mode,
+ WebKit::WGC3Dint first,
+ WebKit::WGC3Dsizei count) {}
+ virtual void drawElements(
+ WebKit::WGC3Denum mode,
+ WebKit::WGC3Dsizei count,
+ WebKit::WGC3Denum type,
+ WebKit::WGC3Dintptr offset) {}
+
+ virtual void enable(WebKit::WGC3Denum cap) {}
+ virtual void enableVertexAttribArray(WebKit::WGC3Duint index) {}
+ virtual void finish() {}
+ virtual void flush() {}
+ virtual void framebufferRenderbuffer(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum attachment,
+ WebKit::WGC3Denum renderbuffertarget,
+ WebKit::WebGLId renderbuffer) {}
+ virtual void framebufferTexture2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum attachment,
+ WebKit::WGC3Denum textarget,
+ WebKit::WebGLId texture,
+ WebKit::WGC3Dint level) {}
+ virtual void frontFace(WebKit::WGC3Denum mode) {}
+ virtual void generateMipmap(WebKit::WGC3Denum target) {}
+
+ virtual bool getActiveAttrib(
+ WebKit::WebGLId program,
+ WebKit::WGC3Duint index, ActiveInfo&);
+ virtual bool getActiveUniform(
+ WebKit::WebGLId program,
+ WebKit::WGC3Duint index,
+ ActiveInfo&);
+ virtual void getAttachedShaders(
+ WebKit::WebGLId program,
+ WebKit::WGC3Dsizei max_count,
+ WebKit::WGC3Dsizei* count,
+ WebKit::WebGLId* shaders) {}
+ virtual WebKit::WGC3Dint getAttribLocation(
+ WebKit::WebGLId program,
+ const WebKit::WGC3Dchar* name);
+ virtual void getBooleanv(
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dboolean* value) {}
+ virtual void getBufferParameteriv(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value) {}
+ virtual Attributes getContextAttributes();
+ virtual WebKit::WGC3Denum getError();
+ virtual void getFloatv(
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dfloat* value) {}
+ virtual void getFramebufferAttachmentParameteriv(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum attachment,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value) {}
+
+ virtual void getIntegerv(
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value);
+
+ virtual void getProgramiv(
+ WebKit::WebGLId program,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value);
+
+ virtual WebKit::WebString getProgramInfoLog(WebKit::WebGLId program);
+ virtual void getRenderbufferParameteriv(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value) {}
+
+ virtual void getShaderiv(
+ WebKit::WebGLId shader,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value);
+
+ virtual WebKit::WebString getShaderInfoLog(WebKit::WebGLId shader);
+ virtual void getShaderPrecisionFormat(
+ WebKit::WGC3Denum shadertype,
+ WebKit::WGC3Denum precisiontype,
+ WebKit::WGC3Dint* range,
+ WebKit::WGC3Dint* precision);
+ virtual WebKit::WebString getShaderSource(WebKit::WebGLId shader);
+ virtual WebKit::WebString getString(WebKit::WGC3Denum name);
+ virtual void getTexParameterfv(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dfloat* value) {}
+ virtual void getTexParameteriv(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value) {}
+ virtual void getUniformfv(
+ WebKit::WebGLId program,
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dfloat* value) {}
+ virtual void getUniformiv(
+ WebKit::WebGLId program,
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dint* value) {}
+ virtual WebKit::WGC3Dint getUniformLocation(
+ WebKit::WebGLId program,
+ const WebKit::WGC3Dchar* name);
+ virtual void getVertexAttribfv(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dfloat* value) {}
+ virtual void getVertexAttribiv(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value) {}
+ virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Denum pname);
+
+ virtual void hint(WebKit::WGC3Denum target, WebKit::WGC3Denum mode) {}
+ virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer);
+ virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap);
+ virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer);
+ virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program);
+ virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer);
+ virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader);
+ virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture);
+ virtual void lineWidth(WebKit::WGC3Dfloat) {}
+ virtual void linkProgram(WebKit::WebGLId program) {}
+ virtual void pixelStorei(WebKit::WGC3Denum pname, WebKit::WGC3Dint param) {}
+ virtual void polygonOffset(
+ WebKit::WGC3Dfloat factor,
+ WebKit::WGC3Dfloat units) {}
+
+ virtual void readPixels(
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum format,
+ WebKit::WGC3Denum type,
+ void* pixels) {}
+
+ virtual void releaseShaderCompiler() {}
+
+ virtual void renderbufferStorage(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum internalformat,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height) {}
+ virtual void sampleCoverage(
+ WebKit::WGC3Dclampf value,
+ WebKit::WGC3Dboolean invert) {}
+ virtual void scissor(
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height) {}
+ virtual void shaderSource(
+ WebKit::WebGLId shader,
+ const WebKit::WGC3Dchar* string) {}
+ virtual void stencilFunc(
+ WebKit::WGC3Denum func,
+ WebKit::WGC3Dint ref,
+ WebKit::WGC3Duint mask) {}
+ virtual void stencilFuncSeparate(
+ WebKit::WGC3Denum face,
+ WebKit::WGC3Denum func,
+ WebKit::WGC3Dint ref,
+ WebKit::WGC3Duint mask) {}
+ virtual void stencilMask(WebKit::WGC3Duint mask) {}
+ virtual void stencilMaskSeparate(
+ WebKit::WGC3Denum face,
+ WebKit::WGC3Duint mask) {}
+ virtual void stencilOp(
+ WebKit::WGC3Denum fail,
+ WebKit::WGC3Denum zfail,
+ WebKit::WGC3Denum zpass) {}
+ virtual void stencilOpSeparate(
+ WebKit::WGC3Denum face,
+ WebKit::WGC3Denum fail,
+ WebKit::WGC3Denum zfail,
+ WebKit::WGC3Denum zpass) {}
+
+ virtual void texImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Denum internalformat,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Dint border,
+ WebKit::WGC3Denum format,
+ WebKit::WGC3Denum type,
+ const void* pixels) {}
+
+ virtual void texParameterf(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dfloat param) {}
+ virtual void texParameteri(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint param) {}
+
+ virtual void texSubImage2D(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint level,
+ WebKit::WGC3Dint xoffset,
+ WebKit::WGC3Dint yoffset,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum format,
+ WebKit::WGC3Denum type,
+ const void* pixels) {}
+
+ virtual void uniform1f(WebKit::WGC3Dint location, WebKit::WGC3Dfloat x) {}
+ virtual void uniform1fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dfloat* v) {}
+ virtual void uniform1i(WebKit::WGC3Dint location, WebKit::WGC3Dint x) {}
+ virtual void uniform1iv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dint* v) {}
+ virtual void uniform2f(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y) {}
+ virtual void uniform2fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dfloat* v) {}
+ virtual void uniform2i(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y) {}
+ virtual void uniform2iv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dint* v) {}
+ virtual void uniform3f(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y,
+ WebKit::WGC3Dfloat z) {}
+ virtual void uniform3fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dfloat* v) {}
+ virtual void uniform3i(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dint z) {}
+ virtual void uniform3iv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dint* v) {}
+ virtual void uniform4f(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y,
+ WebKit::WGC3Dfloat z,
+ WebKit::WGC3Dfloat w) {}
+ virtual void uniform4fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dfloat* v) {}
+ virtual void uniform4i(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dint z,
+ WebKit::WGC3Dint w) {}
+ virtual void uniform4iv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ const WebKit::WGC3Dint* v) {}
+ virtual void uniformMatrix2fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ WebKit::WGC3Dboolean transpose,
+ const WebKit::WGC3Dfloat* value) {}
+ virtual void uniformMatrix3fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ WebKit::WGC3Dboolean transpose,
+ const WebKit::WGC3Dfloat* value) {}
+ virtual void uniformMatrix4fv(
+ WebKit::WGC3Dint location,
+ WebKit::WGC3Dsizei count,
+ WebKit::WGC3Dboolean transpose,
+ const WebKit::WGC3Dfloat* value) {}
+
+ virtual void useProgram(WebKit::WebGLId program);
+ virtual void validateProgram(WebKit::WebGLId program) {}
+
+ virtual void vertexAttrib1f(WebKit::WGC3Duint index, WebKit::WGC3Dfloat x) {}
+ virtual void vertexAttrib1fv(
+ WebKit::WGC3Duint index,
+ const WebKit::WGC3Dfloat* values) {}
+ virtual void vertexAttrib2f(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y) {}
+ virtual void vertexAttrib2fv(
+ WebKit::WGC3Duint index,
+ const WebKit::WGC3Dfloat* values) {}
+ virtual void vertexAttrib3f(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y,
+ WebKit::WGC3Dfloat z) {}
+ virtual void vertexAttrib3fv(
+ WebKit::WGC3Duint index,
+ const WebKit::WGC3Dfloat* values) {}
+ virtual void vertexAttrib4f(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Dfloat x,
+ WebKit::WGC3Dfloat y,
+ WebKit::WGC3Dfloat z,
+ WebKit::WGC3Dfloat w) {}
+ virtual void vertexAttrib4fv(
+ WebKit::WGC3Duint index,
+ const WebKit::WGC3Dfloat* values) {}
+ virtual void vertexAttribPointer(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Dint size,
+ WebKit::WGC3Denum type,
+ WebKit::WGC3Dboolean normalized,
+ WebKit::WGC3Dsizei stride,
+ WebKit::WGC3Dintptr offset) {}
+
+ virtual void viewport(
+ WebKit::WGC3Dint x,
+ WebKit::WGC3Dint y,
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height) {}
+
+ virtual void genBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genFramebuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genRenderbuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+
+ virtual void deleteBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteFramebuffers(
+ WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteRenderbuffers(
+ WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+
+ virtual WebKit::WebGLId createBuffer();
+ virtual WebKit::WebGLId createFramebuffer();
+ virtual WebKit::WebGLId createRenderbuffer();
+ virtual WebKit::WebGLId createTexture();
+
+ virtual void deleteBuffer(WebKit::WebGLId id);
+ virtual void deleteFramebuffer(WebKit::WebGLId id);
+ virtual void deleteRenderbuffer(WebKit::WebGLId id);
+ virtual void deleteTexture(WebKit::WebGLId id);
+
+ virtual WebKit::WebGLId createProgram();
+ virtual WebKit::WebGLId createShader(WebKit::WGC3Denum);
+
+ virtual void deleteProgram(WebKit::WebGLId id);
+ virtual void deleteShader(WebKit::WebGLId id);
+
+ virtual void texStorage2DEXT(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Dint levels,
+ WebKit::WGC3Duint internalformat,
+ WebKit::WGC3Dint width,
+ WebKit::WGC3Dint height) {}
+
+ virtual WebKit::WebGLId createQueryEXT();
+ virtual void deleteQueryEXT(WebKit::WebGLId query) {}
+ virtual WebKit::WGC3Dboolean isQueryEXT(WebKit::WebGLId query);
+ virtual void beginQueryEXT(
+ WebKit::WGC3Denum target,
+ WebKit::WebGLId query) {}
+ virtual void endQueryEXT(WebKit::WGC3Denum target);
+ virtual void getQueryivEXT(
+ WebKit::WGC3Denum target,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* params) {}
+ virtual void getQueryObjectuivEXT(
+ WebKit::WebGLId query,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Duint* params);
+
+ virtual void setContextLostCallback(
+ WebGraphicsContextLostCallback* callback);
+
+ virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
+ WebKit::WGC3Denum other);
+
+ virtual void drawBuffersEXT(WebKit::WGC3Dsizei m,
+ const WebKit::WGC3Denum* bufs) {}
+
+ virtual void bindTexImage2DCHROMIUM(WebKit::WGC3Denum target,
+ WebKit::WGC3Dint image_id) {}
+
+ // GL_CHROMIUM_gpu_memory_buffer
+ virtual WebKit::WGC3Duint createImageCHROMIUM(
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum internalformat);
+ virtual void destroyImageCHROMIUM(WebKit::WGC3Duint image_id) {}
+ virtual void getImageParameterivCHROMIUM(
+ WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* params) {}
+ virtual void* mapImageCHROMIUM(
+ WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum access);
+ virtual void unmapImageCHROMIUM(WebKit::WGC3Duint image_id) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FakeWebGraphicsContext3D);
+};
+
+} // namespace cc
+
+#endif // CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_
diff --git a/cc/test/fake_web_graphics_context_3d_unittest.cc b/cc/test/fake_web_graphics_context_3d_unittest.cc
index ef0f143f..3d119ee 100644
--- a/cc/test/fake_web_graphics_context_3d_unittest.cc
+++ b/cc/test/fake_web_graphics_context_3d_unittest.cc
@@ -4,7 +4,7 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
-#include "cc/debug/test_web_graphics_context_3d.h"
+#include "cc/test/test_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc
index 9ca0bbd..7ad2966 100644
--- a/cc/test/layer_tree_test.cc
+++ b/cc/test/layer_tree_test.cc
@@ -10,7 +10,6 @@
#include "cc/animation/layer_animation_controller.h"
#include "cc/animation/timing_function.h"
#include "cc/base/switches.h"
-#include "cc/debug/test_context_provider.h"
#include "cc/input/input_handler.h"
#include "cc/layers/content_layer.h"
#include "cc/layers/layer.h"
@@ -19,6 +18,7 @@
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/occlusion_tracker_test_common.h"
+#include "cc/test/test_context_provider.h"
#include "cc/test/tiled_layer_test_common.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/single_thread_proxy.h"
diff --git a/cc/test/ordered_texture_map.cc b/cc/test/ordered_texture_map.cc
new file mode 100644
index 0000000..71b20a4
--- /dev/null
+++ b/cc/test/ordered_texture_map.cc
@@ -0,0 +1,62 @@
+// 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.
+
+#include "cc/test/ordered_texture_map.h"
+
+#include "base/logging.h"
+#include "cc/test/test_texture.h"
+
+namespace cc {
+
+OrderedTextureMap::OrderedTextureMap() {}
+
+OrderedTextureMap::~OrderedTextureMap() {}
+
+void OrderedTextureMap::Append(WebKit::WebGLId id,
+ scoped_refptr<TestTexture> texture) {
+ DCHECK(texture.get());
+ DCHECK(!ContainsId(id));
+
+ textures_[id] = texture;
+ ordered_textures_.push_back(id);
+}
+
+void OrderedTextureMap::Replace(WebKit::WebGLId id,
+ scoped_refptr<TestTexture> texture) {
+ DCHECK(texture.get());
+ DCHECK(ContainsId(id));
+
+ textures_[id] = texture;
+}
+
+void OrderedTextureMap::Remove(WebKit::WebGLId id) {
+ TextureMap::iterator map_it = textures_.find(id);
+ DCHECK(map_it != textures_.end());
+ textures_.erase(map_it);
+
+ TextureList::iterator list_it =
+ std::find(ordered_textures_.begin(), ordered_textures_.end(), id);
+ DCHECK(list_it != ordered_textures_.end());
+ ordered_textures_.erase(list_it);
+}
+
+size_t OrderedTextureMap::Size() { return ordered_textures_.size(); }
+
+bool OrderedTextureMap::ContainsId(WebKit::WebGLId id) {
+ return textures_.find(id) != textures_.end();
+}
+
+scoped_refptr<TestTexture> OrderedTextureMap::TextureForId(WebKit::WebGLId id) {
+ DCHECK(ContainsId(id));
+ scoped_refptr<TestTexture> texture = textures_[id];
+ DCHECK(texture.get());
+ return texture;
+}
+
+WebKit::WebGLId OrderedTextureMap::IdAt(size_t index) {
+ DCHECK(index < Size());
+ return ordered_textures_[index];
+}
+
+} // namespace cc
diff --git a/cc/test/ordered_texture_map.h b/cc/test/ordered_texture_map.h
new file mode 100644
index 0000000..852e86b
--- /dev/null
+++ b/cc/test/ordered_texture_map.h
@@ -0,0 +1,45 @@
+// 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_ORDERED_TEXTURE_MAP_H_
+#define CC_TEST_ORDERED_TEXTURE_MAP_H_
+
+#include <vector>
+
+#include "base/containers/hash_tables.h"
+#include "base/memory/ref_counted.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+
+namespace cc {
+
+struct TestTexture;
+
+class OrderedTextureMap {
+ public:
+ OrderedTextureMap();
+ ~OrderedTextureMap();
+
+ void Append(WebKit::WebGLId id, scoped_refptr<TestTexture> texture);
+ void Replace(WebKit::WebGLId id, scoped_refptr<TestTexture> texture);
+ void Remove(WebKit::WebGLId id);
+
+ size_t Size();
+
+ bool ContainsId(WebKit::WebGLId id);
+
+ scoped_refptr<TestTexture> TextureForId(WebKit::WebGLId id);
+ WebKit::WebGLId IdAt(size_t index);
+
+ private:
+ typedef base::hash_map<WebKit::WebGLId, scoped_refptr<TestTexture> >
+ TextureMap;
+ typedef std::vector<WebKit::WebGLId> TextureList;
+
+ TextureMap textures_;
+ TextureList ordered_textures_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_ORDERED_TEXTURE_MAP_H_
diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc
new file mode 100644
index 0000000..fbe6ea2
--- /dev/null
+++ b/cc/test/test_context_provider.cc
@@ -0,0 +1,228 @@
+// 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.
+
+#include "cc/test/test_context_provider.h"
+
+#include <set>
+#include <vector>
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/logging.h"
+#include "base/strings/string_split.h"
+#include "cc/test/test_web_graphics_context_3d.h"
+
+namespace cc {
+
+class TestContextProvider::LostContextCallbackProxy
+ : public WebKit::WebGraphicsContext3D::WebGraphicsContextLostCallback {
+ public:
+ explicit LostContextCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setContextLostCallback(this);
+ }
+
+ virtual ~LostContextCallbackProxy() {
+ provider_->context3d_->setContextLostCallback(NULL);
+ }
+
+ virtual void onContextLost() {
+ provider_->OnLostContext();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
+class TestContextProvider::SwapBuffersCompleteCallbackProxy
+ : public WebKit::WebGraphicsContext3D::
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM {
+ public:
+ explicit SwapBuffersCompleteCallbackProxy(TestContextProvider* provider)
+ : provider_(provider) {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this);
+ }
+
+ virtual ~SwapBuffersCompleteCallbackProxy() {
+ provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL);
+ }
+
+ virtual void onSwapBuffersComplete() {
+ provider_->OnSwapBuffersComplete();
+ }
+
+ private:
+ TestContextProvider* provider_;
+};
+
+// static
+scoped_refptr<TestContextProvider> TestContextProvider::Create() {
+ return Create(TestWebGraphicsContext3D::Create().Pass());
+}
+
+// static
+scoped_refptr<TestContextProvider> TestContextProvider::Create(
+ scoped_ptr<TestWebGraphicsContext3D> context) {
+ if (!context)
+ return NULL;
+ return new TestContextProvider(context.Pass());
+}
+
+TestContextProvider::TestContextProvider(
+ scoped_ptr<TestWebGraphicsContext3D> context)
+ : context3d_(context.Pass()), bound_(false), destroyed_(false) {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+ DCHECK(context3d_);
+ context_thread_checker_.DetachFromThread();
+ context3d_->set_test_support(&support_);
+}
+
+TestContextProvider::~TestContextProvider() {
+ DCHECK(main_thread_checker_.CalledOnValidThread() ||
+ context_thread_checker_.CalledOnValidThread());
+}
+
+bool TestContextProvider::BindToCurrentThread() {
+ DCHECK(context3d_);
+
+ // This is called on the thread the context will be used.
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (bound_)
+ return true;
+
+ bound_ = true;
+ if (!context3d_->makeContextCurrent()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ return false;
+ }
+
+ lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this));
+ swap_buffers_complete_callback_proxy_.reset(
+ new SwapBuffersCompleteCallbackProxy(this));
+
+ return true;
+}
+
+ContextProvider::Capabilities TestContextProvider::ContextCapabilities() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return context3d_->test_capabilities();
+}
+
+WebKit::WebGraphicsContext3D* TestContextProvider::Context3d() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return context3d_.get();
+}
+
+gpu::ContextSupport* TestContextProvider::ContextSupport() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return &support_;
+}
+
+class GrContext* TestContextProvider::GrContext() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ // TODO(danakj): Make a test GrContext that works with a test Context3d.
+ return NULL;
+}
+
+void TestContextProvider::VerifyContexts() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ if (context3d_->isContextLost()) {
+ base::AutoLock lock(destroyed_lock_);
+ destroyed_ = true;
+ }
+}
+
+bool TestContextProvider::DestroyedOnMainThread() {
+ DCHECK(main_thread_checker_.CalledOnValidThread());
+
+ base::AutoLock lock(destroyed_lock_);
+ return destroyed_;
+}
+
+void TestContextProvider::OnLostContext() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ {
+ base::AutoLock lock(destroyed_lock_);
+ if (destroyed_)
+ return;
+ destroyed_ = true;
+ }
+ if (!lost_context_callback_.is_null())
+ base::ResetAndReturn(&lost_context_callback_).Run();
+}
+
+void TestContextProvider::OnSwapBuffersComplete() {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ if (!swap_buffers_complete_callback_.is_null())
+ swap_buffers_complete_callback_.Run();
+}
+
+TestWebGraphicsContext3D* TestContextProvider::TestContext3d() {
+ DCHECK(context3d_);
+ DCHECK(bound_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return context3d_.get();
+}
+
+TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
+ DCHECK(context3d_);
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+
+ return context3d_.get();
+}
+
+void TestContextProvider::SetMemoryAllocation(
+ const ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible) {
+ if (memory_policy_changed_callback_.is_null())
+ return;
+ memory_policy_changed_callback_.Run(
+ policy, discard_backbuffer_when_not_visible);
+}
+
+void TestContextProvider::SetLostContextCallback(
+ const LostContextCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(lost_context_callback_.is_null() || cb.is_null());
+ lost_context_callback_ = cb;
+}
+
+void TestContextProvider::SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(swap_buffers_complete_callback_.is_null() || cb.is_null());
+ swap_buffers_complete_callback_ = cb;
+}
+
+void TestContextProvider::SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& cb) {
+ DCHECK(context_thread_checker_.CalledOnValidThread());
+ DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null());
+ memory_policy_changed_callback_ = cb;
+}
+
+void TestContextProvider::SetMaxTransferBufferUsageBytes(
+ size_t max_transfer_buffer_usage_bytes) {
+ context3d_->SetMaxTransferBufferUsageBytes(max_transfer_buffer_usage_bytes);
+}
+
+} // namespace cc
diff --git a/cc/test/test_context_provider.h b/cc/test/test_context_provider.h
new file mode 100644
index 0000000..2c64fe5
--- /dev/null
+++ b/cc/test/test_context_provider.h
@@ -0,0 +1,88 @@
+// 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_CONTEXT_PROVIDER_H_
+#define CC_TEST_TEST_CONTEXT_PROVIDER_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "cc/output/context_provider.h"
+#include "cc/test/test_context_support.h"
+
+namespace WebKit { class WebGraphicsContext3D; }
+
+namespace cc {
+class TestWebGraphicsContext3D;
+
+class TestContextProvider : public cc::ContextProvider {
+ public:
+ typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)>
+ CreateCallback;
+
+ static scoped_refptr<TestContextProvider> Create();
+ static scoped_refptr<TestContextProvider> Create(
+ scoped_ptr<TestWebGraphicsContext3D> context);
+
+ virtual bool BindToCurrentThread() OVERRIDE;
+ virtual Capabilities ContextCapabilities() OVERRIDE;
+ virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
+ virtual gpu::ContextSupport* ContextSupport() OVERRIDE;
+ virtual class GrContext* GrContext() OVERRIDE;
+ virtual void VerifyContexts() OVERRIDE;
+ virtual bool DestroyedOnMainThread() OVERRIDE;
+ virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE;
+ virtual void SetSwapBuffersCompleteCallback(
+ const SwapBuffersCompleteCallback& cb) OVERRIDE;
+ virtual void SetMemoryPolicyChangedCallback(
+ const MemoryPolicyChangedCallback& cb) OVERRIDE;
+
+ TestWebGraphicsContext3D* TestContext3d();
+
+ // This returns the TestWebGraphicsContext3D but is valid to call
+ // before the context is bound to a thread. This is needed to set up
+ // state on the test context before binding. Don't call
+ // makeContextCurrent on the context returned from this method.
+ TestWebGraphicsContext3D* UnboundTestContext3d();
+
+ void SetMemoryAllocation(const ManagedMemoryPolicy& policy,
+ bool discard_backbuffer_when_not_visible);
+
+ void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
+
+ protected:
+ explicit TestContextProvider(scoped_ptr<TestWebGraphicsContext3D> context);
+ virtual ~TestContextProvider();
+
+ void OnLostContext();
+ void OnSwapBuffersComplete();
+
+ TestContextSupport support_;
+
+ scoped_ptr<TestWebGraphicsContext3D> context3d_;
+ bool bound_;
+
+ base::ThreadChecker main_thread_checker_;
+ base::ThreadChecker context_thread_checker_;
+
+ base::Lock destroyed_lock_;
+ bool destroyed_;
+
+ LostContextCallback lost_context_callback_;
+ SwapBuffersCompleteCallback swap_buffers_complete_callback_;
+ MemoryPolicyChangedCallback memory_policy_changed_callback_;
+
+ class LostContextCallbackProxy;
+ scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
+
+ class SwapBuffersCompleteCallbackProxy;
+ scoped_ptr<SwapBuffersCompleteCallbackProxy>
+ swap_buffers_complete_callback_proxy_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_
+
diff --git a/cc/test/test_context_support.cc b/cc/test/test_context_support.cc
new file mode 100644
index 0000000..d71f74d
--- /dev/null
+++ b/cc/test/test_context_support.cc
@@ -0,0 +1,36 @@
+// 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.
+
+#include "cc/test/test_context_support.h"
+
+#include "base/message_loop/message_loop.h"
+
+namespace cc {
+
+TestContextSupport::TestContextSupport() {}
+TestContextSupport::~TestContextSupport() {}
+
+void TestContextSupport::SignalSyncPoint(uint32 sync_point,
+ const base::Closure& callback) {
+ sync_point_callbacks_.push_back(callback);
+}
+
+void TestContextSupport::SignalQuery(uint32 query,
+ const base::Closure& callback) {
+ sync_point_callbacks_.push_back(callback);
+}
+
+void TestContextSupport::SendManagedMemoryStats(
+ const gpu::ManagedMemoryStats& stats) {
+}
+
+void TestContextSupport::CallAllSyncPointCallbacks() {
+ for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, sync_point_callbacks_[i]);
+ }
+ sync_point_callbacks_.clear();
+}
+
+} // namespace cc
diff --git a/cc/test/test_context_support.h b/cc/test/test_context_support.h
new file mode 100644
index 0000000..6c2258e
--- /dev/null
+++ b/cc/test/test_context_support.h
@@ -0,0 +1,37 @@
+// 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_CONTEXT_SUPPORT_H_
+#define CC_TEST_TEST_CONTEXT_SUPPORT_H_
+
+#include <vector>
+
+#include "gpu/command_buffer/client/context_support.h"
+
+namespace cc {
+
+class TestContextSupport : public gpu::ContextSupport {
+ public:
+ TestContextSupport();
+ virtual ~TestContextSupport();
+
+ // gpu::ContextSupport implementation.
+ virtual void SignalSyncPoint(uint32 sync_point,
+ const base::Closure& callback) OVERRIDE;
+ virtual void SignalQuery(uint32 query,
+ const base::Closure& callback) OVERRIDE;
+ virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats)
+ OVERRIDE;
+
+ void CallAllSyncPointCallbacks();
+
+ private:
+ std::vector<base::Closure> sync_point_callbacks_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestContextSupport);
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_CONTEXT_SUPPORT_H_
diff --git a/cc/test/test_texture.cc b/cc/test/test_texture.cc
new file mode 100644
index 0000000..f68f5a6
--- /dev/null
+++ b/cc/test/test_texture.cc
@@ -0,0 +1,29 @@
+// 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.
+
+#include "cc/test/test_texture.h"
+
+#include "third_party/khronos/GLES2/gl2.h"
+
+namespace cc {
+
+size_t TextureSizeBytes(gfx::Size size, ResourceFormat format) {
+ unsigned int components_per_pixel = 4;
+ unsigned int bytes_per_component = 1;
+ return size.width() * size.height() * components_per_pixel *
+ bytes_per_component;
+}
+
+TestTexture::TestTexture()
+ : format(RGBA_8888), filter(GL_NEAREST_MIPMAP_LINEAR) {}
+
+TestTexture::~TestTexture() {}
+
+void TestTexture::Reallocate(gfx::Size size, ResourceFormat format) {
+ this->size = size;
+ this->format = format;
+ this->data.reset(new uint8_t[TextureSizeBytes(size, format)]);
+}
+
+} // namespace cc
diff --git a/cc/test/test_texture.h b/cc/test/test_texture.h
new file mode 100644
index 0000000..a286468
--- /dev/null
+++ b/cc/test/test_texture.h
@@ -0,0 +1,38 @@
+// 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_TEXTURE_H_
+#define CC_TEST_TEST_TEXTURE_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "cc/resources/resource_format.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+#include "ui/gfx/size.h"
+
+namespace cc {
+
+size_t TextureSizeBytes(gfx::Size size, ResourceFormat format);
+
+struct TestTexture : public base::RefCounted<TestTexture> {
+ TestTexture();
+
+ void Reallocate(gfx::Size size, ResourceFormat format);
+
+ gfx::Size size;
+ ResourceFormat format;
+ scoped_ptr<uint8_t[]> data;
+
+ // TODO(mvujovic): Replace this with a hash map of texture parameter names
+ // and values, which can hold this filter parameter value and more.
+ WebKit::WGC3Denum filter;
+
+ private:
+ friend class base::RefCounted<TestTexture>;
+ ~TestTexture();
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_TEXTURE_H_
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
new file mode 100644
index 0000000..0c15f20
--- /dev/null
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -0,0 +1,665 @@
+// 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.
+
+#include "cc/test/test_web_graphics_context_3d.h"
+
+#include <algorithm>
+#include <string>
+
+#include "base/bind.h"
+#include "base/lazy_instance.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "cc/test/test_context_support.h"
+#include "gpu/GLES2/gl2extchromium.h"
+#include "third_party/khronos/GLES2/gl2ext.h"
+
+using WebKit::WGC3Dboolean;
+using WebKit::WGC3Dchar;
+using WebKit::WGC3Denum;
+using WebKit::WGC3Dint;
+using WebKit::WGC3Dsizei;
+using WebKit::WGC3Dsizeiptr;
+using WebKit::WGC3Duint;
+using WebKit::WebGLId;
+using WebKit::WebGraphicsContext3D;
+
+namespace cc {
+
+static const WebGLId kFramebufferId = 1;
+static const WebGLId kProgramId = 2;
+static const WebGLId kRenderbufferId = 3;
+static const WebGLId kShaderId = 4;
+
+static unsigned s_context_id = 1;
+
+const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337;
+
+static base::LazyInstance<base::Lock>::Leaky
+ g_shared_namespace_lock = LAZY_INSTANCE_INITIALIZER;
+
+TestWebGraphicsContext3D::Namespace*
+ TestWebGraphicsContext3D::shared_namespace_ = NULL;
+
+TestWebGraphicsContext3D::Namespace::Namespace()
+ : next_buffer_id(1),
+ next_image_id(1),
+ next_texture_id(1) {
+}
+
+TestWebGraphicsContext3D::Namespace::~Namespace() {
+ g_shared_namespace_lock.Get().AssertAcquired();
+ if (shared_namespace_ == this)
+ shared_namespace_ = NULL;
+}
+
+// static
+scoped_ptr<TestWebGraphicsContext3D> TestWebGraphicsContext3D::Create() {
+ return make_scoped_ptr(new TestWebGraphicsContext3D());
+}
+
+TestWebGraphicsContext3D::TestWebGraphicsContext3D()
+ : FakeWebGraphicsContext3D(),
+ context_id_(s_context_id++),
+ times_make_current_succeeds_(-1),
+ times_bind_texture_succeeds_(-1),
+ times_end_query_succeeds_(-1),
+ times_gen_mailbox_succeeds_(-1),
+ context_lost_(false),
+ times_map_image_chromium_succeeds_(-1),
+ times_map_buffer_chromium_succeeds_(-1),
+ context_lost_callback_(NULL),
+ swap_buffers_callback_(NULL),
+ max_texture_size_(2048),
+ width_(0),
+ height_(0),
+ test_support_(NULL),
+ bound_buffer_(0),
+ weak_ptr_factory_(this) {
+ CreateNamespace();
+ test_capabilities_.swapbuffers_complete_callback = true;
+}
+
+TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
+ base::AutoLock lock(g_shared_namespace_lock.Get());
+ namespace_ = NULL;
+}
+
+void TestWebGraphicsContext3D::CreateNamespace() {
+ if (attributes_.shareResources) {
+ base::AutoLock lock(g_shared_namespace_lock.Get());
+ if (shared_namespace_) {
+ namespace_ = shared_namespace_;
+ } else {
+ namespace_ = new Namespace;
+ shared_namespace_ = namespace_.get();
+ }
+ } else {
+ namespace_ = new Namespace;
+ }
+}
+
+bool TestWebGraphicsContext3D::makeContextCurrent() {
+ if (times_make_current_succeeds_ >= 0) {
+ if (!times_make_current_succeeds_) {
+ loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
+ GL_INNOCENT_CONTEXT_RESET_ARB);
+ }
+ --times_make_current_succeeds_;
+ }
+ return !context_lost_;
+}
+
+void TestWebGraphicsContext3D::reshapeWithScaleFactor(
+ int width, int height, float scale_factor) {
+ width_ = width;
+ height_ = height;
+}
+
+bool TestWebGraphicsContext3D::isContextLost() {
+ return context_lost_;
+}
+
+WGC3Denum TestWebGraphicsContext3D::getGraphicsResetStatusARB() {
+ return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR;
+}
+
+WGC3Denum TestWebGraphicsContext3D::checkFramebufferStatus(
+ WGC3Denum target) {
+ if (context_lost_)
+ return GL_FRAMEBUFFER_UNDEFINED_OES;
+ return GL_FRAMEBUFFER_COMPLETE;
+}
+
+WebGraphicsContext3D::Attributes
+ TestWebGraphicsContext3D::getContextAttributes() {
+ return attributes_;
+}
+
+WebKit::WebString TestWebGraphicsContext3D::getString(WGC3Denum name) {
+ return WebKit::WebString();
+}
+
+WGC3Dint TestWebGraphicsContext3D::getUniformLocation(
+ WebGLId program,
+ const WGC3Dchar* name) {
+ return 0;
+}
+
+WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset(
+ WGC3Duint index,
+ WGC3Denum pname) {
+ return 0;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isBuffer(
+ WebGLId buffer) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isEnabled(
+ WGC3Denum cap) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isFramebuffer(
+ WebGLId framebuffer) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isProgram(
+ WebGLId program) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isRenderbuffer(
+ WebGLId renderbuffer) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isShader(
+ WebGLId shader) {
+ return false;
+}
+
+WGC3Dboolean TestWebGraphicsContext3D::isTexture(
+ WebGLId texture) {
+ return false;
+}
+
+void TestWebGraphicsContext3D::genBuffers(WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = NextBufferId();
+}
+
+void TestWebGraphicsContext3D::genFramebuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = kFramebufferId | context_id_ << 16;
+}
+
+void TestWebGraphicsContext3D::genRenderbuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ ids[i] = kRenderbufferId | context_id_ << 16;
+}
+
+void TestWebGraphicsContext3D::genTextures(WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i) {
+ ids[i] = NextTextureId();
+ DCHECK_NE(ids[i], kExternalTextureId);
+ }
+ base::AutoLock lock(namespace_->lock);
+ for (int i = 0; i < count; ++i)
+ namespace_->textures.Append(ids[i], new TestTexture());
+}
+
+void TestWebGraphicsContext3D::deleteBuffers(WGC3Dsizei count, WebGLId* ids) {
+ base::AutoLock lock(namespace_->lock);
+ for (int i = 0; i < count; ++i) {
+ unsigned context_id = ids[i] >> 17;
+ unsigned buffer_id = ids[i] & 0x1ffff;
+ DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
+ DCHECK_EQ(context_id, context_id_);
+ }
+}
+
+void TestWebGraphicsContext3D::deleteFramebuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ DCHECK_EQ(kFramebufferId | context_id_ << 16, ids[i]);
+}
+
+void TestWebGraphicsContext3D::deleteRenderbuffers(
+ WGC3Dsizei count, WebGLId* ids) {
+ for (int i = 0; i < count; ++i)
+ DCHECK_EQ(kRenderbufferId | context_id_ << 16, ids[i]);
+}
+
+void TestWebGraphicsContext3D::deleteTextures(WGC3Dsizei count, WebGLId* ids) {
+ base::AutoLock lock(namespace_->lock);
+ for (int i = 0; i < count; ++i) {
+ namespace_->textures.Remove(ids[i]);
+ texture_targets_.UnbindTexture(ids[i]);
+ }
+}
+
+WebGLId TestWebGraphicsContext3D::createBuffer() {
+ WebGLId id;
+ genBuffers(1, &id);
+ return id;
+}
+
+WebGLId TestWebGraphicsContext3D::createFramebuffer() {
+ WebGLId id;
+ genFramebuffers(1, &id);
+ return id;
+}
+
+WebGLId TestWebGraphicsContext3D::createRenderbuffer() {
+ WebGLId id;
+ genRenderbuffers(1, &id);
+ return id;
+}
+
+WebGLId TestWebGraphicsContext3D::createTexture() {
+ WebGLId id;
+ genTextures(1, &id);
+ return id;
+}
+
+void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) {
+ deleteBuffers(1, &id);
+}
+
+void TestWebGraphicsContext3D::deleteFramebuffer(WebGLId id) {
+ deleteFramebuffers(1, &id);
+}
+
+void TestWebGraphicsContext3D::deleteRenderbuffer(WebGLId id) {
+ deleteRenderbuffers(1, &id);
+}
+
+void TestWebGraphicsContext3D::deleteTexture(WebGLId id) {
+ deleteTextures(1, &id);
+}
+
+WebGLId TestWebGraphicsContext3D::createProgram() {
+ return kProgramId | context_id_ << 16;
+}
+
+WebGLId TestWebGraphicsContext3D::createShader(WGC3Denum) {
+ return kShaderId | context_id_ << 16;
+}
+
+WebGLId TestWebGraphicsContext3D::createExternalTexture() {
+ base::AutoLock lock(namespace_->lock);
+ namespace_->textures.Append(kExternalTextureId, new TestTexture());
+ return kExternalTextureId;
+}
+
+void TestWebGraphicsContext3D::deleteProgram(WebGLId id) {
+ DCHECK_EQ(kProgramId | context_id_ << 16, id);
+}
+
+void TestWebGraphicsContext3D::deleteShader(WebGLId id) {
+ DCHECK_EQ(kShaderId | context_id_ << 16, id);
+}
+
+void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) {
+ DCHECK_EQ(kProgramId | context_id_ << 16, program);
+ DCHECK_EQ(kShaderId | context_id_ << 16, shader);
+}
+
+void TestWebGraphicsContext3D::useProgram(WebGLId program) {
+ if (!program)
+ return;
+ DCHECK_EQ(kProgramId | context_id_ << 16, program);
+}
+
+void TestWebGraphicsContext3D::bindFramebuffer(
+ WGC3Denum target, WebGLId framebuffer) {
+ if (!framebuffer)
+ return;
+ DCHECK_EQ(kFramebufferId | context_id_ << 16, framebuffer);
+}
+
+void TestWebGraphicsContext3D::bindRenderbuffer(
+ WGC3Denum target, WebGLId renderbuffer) {
+ if (!renderbuffer)
+ return;
+ DCHECK_EQ(kRenderbufferId | context_id_ << 16, renderbuffer);
+}
+
+void TestWebGraphicsContext3D::bindTexture(
+ WGC3Denum target, WebGLId texture_id) {
+ if (times_bind_texture_succeeds_ >= 0) {
+ if (!times_bind_texture_succeeds_) {
+ loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
+ GL_INNOCENT_CONTEXT_RESET_ARB);
+ }
+ --times_bind_texture_succeeds_;
+ }
+
+ if (!texture_id)
+ return;
+ base::AutoLock lock(namespace_->lock);
+ DCHECK(namespace_->textures.ContainsId(texture_id));
+ texture_targets_.BindTexture(target, texture_id);
+ used_textures_.insert(texture_id);
+}
+
+WebKit::WebGLId TestWebGraphicsContext3D::BoundTextureId(
+ WebKit::WGC3Denum target) {
+ return texture_targets_.BoundTexture(target);
+}
+
+void TestWebGraphicsContext3D::endQueryEXT(WGC3Denum target) {
+ if (times_end_query_succeeds_ >= 0) {
+ if (!times_end_query_succeeds_) {
+ loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
+ GL_INNOCENT_CONTEXT_RESET_ARB);
+ }
+ --times_end_query_succeeds_;
+ }
+}
+
+void TestWebGraphicsContext3D::getQueryObjectuivEXT(
+ WebGLId query,
+ WGC3Denum pname,
+ WGC3Duint* params) {
+ // If the context is lost, behave as if result is available.
+ if (pname == GL_QUERY_RESULT_AVAILABLE_EXT)
+ *params = 1;
+}
+
+void TestWebGraphicsContext3D::getIntegerv(
+ WGC3Denum pname,
+ WebKit::WGC3Dint* value) {
+ if (pname == GL_MAX_TEXTURE_SIZE)
+ *value = max_texture_size_;
+ else if (pname == GL_ACTIVE_TEXTURE)
+ *value = GL_TEXTURE0;
+}
+
+void TestWebGraphicsContext3D::genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox) {
+ if (times_gen_mailbox_succeeds_ >= 0) {
+ if (!times_gen_mailbox_succeeds_) {
+ loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
+ GL_INNOCENT_CONTEXT_RESET_ARB);
+ }
+ --times_gen_mailbox_succeeds_;
+ }
+ if (context_lost_) {
+ memset(mailbox, 0, 64);
+ return;
+ }
+
+ static char mailbox_name1 = '1';
+ static char mailbox_name2 = '1';
+ mailbox[0] = mailbox_name1;
+ mailbox[1] = mailbox_name2;
+ mailbox[2] = '\0';
+ if (++mailbox_name1 == 0) {
+ mailbox_name1 = '1';
+ ++mailbox_name2;
+ }
+}
+
+void TestWebGraphicsContext3D::setContextLostCallback(
+ WebGraphicsContextLostCallback* callback) {
+ context_lost_callback_ = callback;
+}
+
+void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
+ WGC3Denum other) {
+ if (context_lost_)
+ return;
+ context_lost_ = true;
+ if (context_lost_callback_)
+ context_lost_callback_->onContextLost();
+
+ for (size_t i = 0; i < shared_contexts_.size(); ++i)
+ shared_contexts_[i]->loseContextCHROMIUM(current, other);
+ shared_contexts_.clear();
+}
+
+void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM(
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback) {
+ if (test_capabilities_.swapbuffers_complete_callback)
+ swap_buffers_callback_ = callback;
+}
+
+void TestWebGraphicsContext3D::prepareTexture() {
+ // TODO(jamesr): This should implemented as ContextSupport::SwapBuffers().
+ if (swap_buffers_callback_) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&TestWebGraphicsContext3D::SwapBuffersComplete,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+ test_support_->CallAllSyncPointCallbacks();
+}
+
+void TestWebGraphicsContext3D::finish() {
+ test_support_->CallAllSyncPointCallbacks();
+}
+
+void TestWebGraphicsContext3D::flush() {
+ test_support_->CallAllSyncPointCallbacks();
+}
+
+void TestWebGraphicsContext3D::SwapBuffersComplete() {
+ if (swap_buffers_callback_)
+ swap_buffers_callback_->onSwapBuffersComplete();
+}
+
+void TestWebGraphicsContext3D::bindBuffer(WebKit::WGC3Denum target,
+ WebKit::WebGLId buffer) {
+ bound_buffer_ = buffer;
+ if (!bound_buffer_)
+ return;
+ unsigned context_id = buffer >> 17;
+ unsigned buffer_id = buffer & 0x1ffff;
+ base::AutoLock lock(namespace_->lock);
+ DCHECK(buffer_id && buffer_id < namespace_->next_buffer_id);
+ DCHECK_EQ(context_id, context_id_);
+
+ base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
+ if (buffers.count(bound_buffer_) == 0)
+ buffers.set(bound_buffer_, make_scoped_ptr(new Buffer).Pass());
+
+ buffers.get(bound_buffer_)->target = target;
+}
+
+void TestWebGraphicsContext3D::bufferData(WebKit::WGC3Denum target,
+ WebKit::WGC3Dsizeiptr size,
+ const void* data,
+ WebKit::WGC3Denum usage) {
+ base::AutoLock lock(namespace_->lock);
+ base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
+ DCHECK_GT(buffers.count(bound_buffer_), 0u);
+ DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
+ Buffer* buffer = buffers.get(bound_buffer_);
+ if (context_lost_) {
+ buffer->pixels.reset();
+ return;
+ }
+
+ buffer->pixels.reset(new uint8[size]);
+ buffer->size = size;
+ if (data != NULL)
+ memcpy(buffer->pixels.get(), data, size);
+}
+
+void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target,
+ WebKit::WGC3Denum access) {
+ base::AutoLock lock(namespace_->lock);
+ base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
+ DCHECK_GT(buffers.count(bound_buffer_), 0u);
+ DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
+ if (times_map_buffer_chromium_succeeds_ >= 0) {
+ if (!times_map_buffer_chromium_succeeds_) {
+ return NULL;
+ }
+ --times_map_buffer_chromium_succeeds_;
+ }
+ return buffers.get(bound_buffer_)->pixels.get();
+}
+
+WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM(
+ WebKit::WGC3Denum target) {
+ base::AutoLock lock(namespace_->lock);
+ base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
+ DCHECK_GT(buffers.count(bound_buffer_), 0u);
+ DCHECK_EQ(target, buffers.get(bound_buffer_)->target);
+ buffers.get(bound_buffer_)->pixels.reset();
+ return true;
+}
+
+WebKit::WGC3Duint TestWebGraphicsContext3D::createImageCHROMIUM(
+ WebKit::WGC3Dsizei width, WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum internalformat) {
+ DCHECK_EQ(GL_RGBA8_OES, static_cast<int>(internalformat));
+ WebKit::WGC3Duint image_id = NextImageId();
+ base::AutoLock lock(namespace_->lock);
+ base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images;
+ images.set(image_id, make_scoped_ptr(new Image).Pass());
+ images.get(image_id)->pixels.reset(new uint8[width * height * 4]);
+ return image_id;
+}
+
+void TestWebGraphicsContext3D::destroyImageCHROMIUM(
+ WebKit::WGC3Duint id) {
+ base::AutoLock lock(namespace_->lock);
+ unsigned context_id = id >> 17;
+ unsigned image_id = id & 0x1ffff;
+ DCHECK(image_id && image_id < namespace_->next_image_id);
+ DCHECK_EQ(context_id, context_id_);
+}
+
+void TestWebGraphicsContext3D::getImageParameterivCHROMIUM(
+ WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* params) {
+ base::AutoLock lock(namespace_->lock);
+ DCHECK_GT(namespace_->images.count(image_id), 0u);
+ DCHECK_EQ(GL_IMAGE_ROWBYTES_CHROMIUM, static_cast<int>(pname));
+ *params = 0;
+}
+
+void* TestWebGraphicsContext3D::mapImageCHROMIUM(WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum access) {
+ base::AutoLock lock(namespace_->lock);
+ base::ScopedPtrHashMap<unsigned, Image>& images = namespace_->images;
+ DCHECK_GT(images.count(image_id), 0u);
+ if (times_map_image_chromium_succeeds_ >= 0) {
+ if (!times_map_image_chromium_succeeds_) {
+ return NULL;
+ }
+ --times_map_image_chromium_succeeds_;
+ }
+ return images.get(image_id)->pixels.get();
+}
+
+void TestWebGraphicsContext3D::unmapImageCHROMIUM(
+ WebKit::WGC3Duint image_id) {
+ base::AutoLock lock(namespace_->lock);
+ DCHECK_GT(namespace_->images.count(image_id), 0u);
+}
+
+size_t TestWebGraphicsContext3D::NumTextures() const {
+ base::AutoLock lock(namespace_->lock);
+ return namespace_->textures.Size();
+}
+
+WebKit::WebGLId TestWebGraphicsContext3D::TextureAt(int i) const {
+ base::AutoLock lock(namespace_->lock);
+ return namespace_->textures.IdAt(i);
+}
+
+WebGLId TestWebGraphicsContext3D::NextTextureId() {
+ base::AutoLock lock(namespace_->lock);
+ WebGLId texture_id = namespace_->next_texture_id++;
+ DCHECK(texture_id < (1 << 16));
+ texture_id |= context_id_ << 16;
+ return texture_id;
+}
+
+WebGLId TestWebGraphicsContext3D::NextBufferId() {
+ base::AutoLock lock(namespace_->lock);
+ WebGLId buffer_id = namespace_->next_buffer_id++;
+ DCHECK(buffer_id < (1 << 17));
+ buffer_id |= context_id_ << 17;
+ return buffer_id;
+}
+
+WebKit::WGC3Duint TestWebGraphicsContext3D::NextImageId() {
+ base::AutoLock lock(namespace_->lock);
+ WGC3Duint image_id = namespace_->next_image_id++;
+ DCHECK(image_id < (1 << 17));
+ image_id |= context_id_ << 17;
+ return image_id;
+}
+
+size_t TestWebGraphicsContext3D::GetTransferBufferMemoryUsedBytes() const {
+ size_t total_bytes = 0;
+ base::ScopedPtrHashMap<unsigned, Buffer>& buffers = namespace_->buffers;
+ base::ScopedPtrHashMap<unsigned, Buffer>::iterator it = buffers.begin();
+ for (; it != buffers.end(); ++it) {
+ Buffer* buffer = it->second;
+ if (buffer->target == GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM)
+ total_bytes += buffer->size;
+ }
+ return total_bytes;
+}
+
+void TestWebGraphicsContext3D::SetMaxTransferBufferUsageBytes(
+ size_t max_transfer_buffer_usage_bytes) {
+ test_capabilities_.max_transfer_buffer_usage_bytes =
+ max_transfer_buffer_usage_bytes;
+}
+
+TestWebGraphicsContext3D::TextureTargets::TextureTargets() {
+ // Initialize default bindings.
+ bound_textures_[GL_TEXTURE_2D] = 0;
+ bound_textures_[GL_TEXTURE_EXTERNAL_OES] = 0;
+ bound_textures_[GL_TEXTURE_RECTANGLE_ARB] = 0;
+}
+
+TestWebGraphicsContext3D::TextureTargets::~TextureTargets() {}
+
+void TestWebGraphicsContext3D::TextureTargets::BindTexture(
+ WebKit::WGC3Denum target,
+ WebKit::WebGLId id) {
+ // Make sure this is a supported target by seeing if it was bound to before.
+ DCHECK(bound_textures_.find(target) != bound_textures_.end());
+ bound_textures_[target] = id;
+}
+
+void TestWebGraphicsContext3D::TextureTargets::UnbindTexture(
+ WebKit::WebGLId id) {
+ // Bind zero to any targets that the id is bound to.
+ for (TargetTextureMap::iterator it = bound_textures_.begin();
+ it != bound_textures_.end();
+ it++) {
+ if (it->second == id)
+ it->second = 0;
+ }
+}
+
+WebKit::WebGLId TestWebGraphicsContext3D::TextureTargets::BoundTexture(
+ WebKit::WGC3Denum target) {
+ DCHECK(bound_textures_.find(target) != bound_textures_.end());
+ return bound_textures_[target];
+}
+
+TestWebGraphicsContext3D::Buffer::Buffer() : target(0), size(0) {}
+
+TestWebGraphicsContext3D::Buffer::~Buffer() {}
+
+TestWebGraphicsContext3D::Image::Image() {}
+
+TestWebGraphicsContext3D::Image::~Image() {}
+
+} // namespace cc
diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h
new file mode 100644
index 0000000..796e34d
--- /dev/null
+++ b/cc/test/test_web_graphics_context_3d.h
@@ -0,0 +1,322 @@
+// 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_WEB_GRAPHICS_CONTEXT_3D_H_
+#define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_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/fake_web_graphics_context_3d.h"
+#include "cc/test/ordered_texture_map.h"
+#include "cc/test/test_texture.h"
+#include "third_party/khronos/GLES2/gl2.h"
+
+namespace cc {
+class TestContextSupport;
+
+class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D {
+ public:
+ static scoped_ptr<TestWebGraphicsContext3D> Create();
+
+ virtual ~TestWebGraphicsContext3D();
+
+ virtual bool makeContextCurrent();
+
+ virtual void reshapeWithScaleFactor(
+ int width, int height, float scale_factor);
+
+ virtual bool isContextLost();
+ virtual WebKit::WGC3Denum getGraphicsResetStatusARB();
+
+ virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader);
+ virtual void bindFramebuffer(
+ WebKit::WGC3Denum target, WebKit::WebGLId framebuffer);
+ virtual void bindRenderbuffer(
+ WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer);
+ virtual void bindTexture(
+ WebKit::WGC3Denum target,
+ WebKit::WebGLId texture_id);
+
+ virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target);
+
+ virtual Attributes getContextAttributes();
+
+ virtual WebKit::WebString getString(WebKit::WGC3Denum name);
+ virtual WebKit::WGC3Dint getUniformLocation(
+ WebKit::WebGLId program,
+ const WebKit::WGC3Dchar* name);
+ virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset(
+ WebKit::WGC3Duint index,
+ WebKit::WGC3Denum pname);
+
+ virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer);
+ virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap);
+ virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer);
+ virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program);
+ virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer);
+ virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader);
+ virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture);
+
+ virtual void useProgram(WebKit::WebGLId program);
+
+ virtual void genBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genFramebuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genRenderbuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void genTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+
+ virtual void deleteBuffers(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteFramebuffers(
+ WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteRenderbuffers(
+ WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+ virtual void deleteTextures(WebKit::WGC3Dsizei count, WebKit::WebGLId* ids);
+
+ virtual WebKit::WebGLId createBuffer();
+ virtual WebKit::WebGLId createFramebuffer();
+ virtual WebKit::WebGLId createRenderbuffer();
+ virtual WebKit::WebGLId createTexture();
+
+ virtual void deleteBuffer(WebKit::WebGLId id);
+ virtual void deleteFramebuffer(WebKit::WebGLId id);
+ virtual void deleteRenderbuffer(WebKit::WebGLId id);
+ virtual void deleteTexture(WebKit::WebGLId id);
+
+ virtual WebKit::WebGLId createProgram();
+ virtual WebKit::WebGLId createShader(WebKit::WGC3Denum);
+ virtual WebKit::WebGLId createExternalTexture();
+
+ virtual void deleteProgram(WebKit::WebGLId id);
+ virtual void deleteShader(WebKit::WebGLId id);
+
+ virtual void endQueryEXT(WebKit::WGC3Denum target);
+ virtual void getQueryObjectuivEXT(
+ WebKit::WebGLId query,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Duint* params);
+
+ virtual void getIntegerv(
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* value);
+
+ virtual void genMailboxCHROMIUM(WebKit::WGC3Dbyte* mailbox);
+ virtual void produceTextureCHROMIUM(WebKit::WGC3Denum target,
+ const WebKit::WGC3Dbyte* mailbox) { }
+ virtual void consumeTextureCHROMIUM(WebKit::WGC3Denum target,
+ const WebKit::WGC3Dbyte* mailbox) { }
+
+ virtual void setContextLostCallback(
+ WebGraphicsContextLostCallback* callback);
+
+ virtual void loseContextCHROMIUM(WebKit::WGC3Denum current,
+ WebKit::WGC3Denum other);
+
+ virtual void setSwapBuffersCompleteCallbackCHROMIUM(
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback);
+
+ virtual void prepareTexture();
+ virtual void finish();
+ virtual void flush();
+
+ virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer);
+ virtual void bufferData(WebKit::WGC3Denum target,
+ WebKit::WGC3Dsizeiptr size,
+ const void* data,
+ WebKit::WGC3Denum usage);
+ virtual void* mapBufferCHROMIUM(WebKit::WGC3Denum target,
+ WebKit::WGC3Denum access);
+ virtual WebKit::WGC3Dboolean unmapBufferCHROMIUM(WebKit::WGC3Denum target);
+
+ virtual WebKit::WGC3Duint createImageCHROMIUM(
+ WebKit::WGC3Dsizei width,
+ WebKit::WGC3Dsizei height,
+ WebKit::WGC3Denum internalformat);
+ virtual void destroyImageCHROMIUM(WebKit::WGC3Duint image_id);
+ virtual void getImageParameterivCHROMIUM(
+ WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum pname,
+ WebKit::WGC3Dint* params);
+ virtual void* mapImageCHROMIUM(
+ WebKit::WGC3Duint image_id,
+ WebKit::WGC3Denum access);
+ virtual void unmapImageCHROMIUM(WebKit::WGC3Duint image_id);
+
+ 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;
+ WebKit::WebGLId 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(WebKit::WebGraphicsContext3D* context3d) {
+ shared_contexts_.push_back(context3d);
+ }
+
+ void set_max_texture_size(int size) { max_texture_size_ = size; }
+
+ static const WebKit::WebGLId kExternalTextureId;
+ virtual WebKit::WebGLId NextTextureId();
+
+ virtual WebKit::WebGLId NextBufferId();
+
+ virtual WebKit::WebGLId NextImageId();
+
+ 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(WebKit::WGC3Denum target, WebKit::WebGLId id);
+ void UnbindTexture(WebKit::WebGLId id);
+
+ WebKit::WebGLId BoundTexture(WebKit::WGC3Denum target);
+
+ private:
+ typedef base::hash_map<WebKit::WGC3Denum, WebKit::WebGLId> TargetTextureMap;
+ TargetTextureMap bound_textures_;
+ };
+
+ struct Buffer {
+ Buffer();
+ ~Buffer();
+
+ WebKit::WGC3Denum 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;
+ unsigned next_buffer_id;
+ unsigned next_image_id;
+ unsigned next_texture_id;
+ base::ScopedPtrHashMap<unsigned, Buffer> buffers;
+ base::ScopedPtrHashMap<unsigned, Image> images;
+ OrderedTextureMap textures;
+
+ private:
+ friend class base::RefCountedThreadSafe<Namespace>;
+ ~Namespace();
+ DISALLOW_COPY_AND_ASSIGN(Namespace);
+ };
+
+ TestWebGraphicsContext3D();
+
+ void CallAllSyncPointCallbacks();
+ void SwapBuffersComplete();
+ void CreateNamespace();
+ WebKit::WebGLId BoundTextureId(WebKit::WGC3Denum target);
+
+ unsigned context_id_;
+ Attributes attributes_;
+ 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_;
+ WebGraphicsContextLostCallback* context_lost_callback_;
+ WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_;
+ base::hash_set<WebKit::WebGLId> used_textures_;
+ std::vector<WebKit::WebGraphicsContext3D*> shared_contexts_;
+ int max_texture_size_;
+ int width_;
+ int height_;
+ TestContextSupport* test_support_;
+
+ unsigned bound_buffer_;
+ TextureTargets texture_targets_;
+
+ scoped_refptr<Namespace> namespace_;
+ static Namespace* shared_namespace_;
+
+ base::WeakPtrFactory<TestWebGraphicsContext3D> weak_ptr_factory_;
+};
+
+} // namespace cc
+
+#endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_