| Index: cc/test/test_web_graphics_context_3d.cc
|
| diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
|
| index e315f65dd80fc9192f46fdff846714b78c9c6d09..3772a8e0fe6819e0d01963f6f6ab51a04627ef87 100644
|
| --- a/cc/test/test_web_graphics_context_3d.cc
|
| +++ b/cc/test/test_web_graphics_context_3d.cc
|
| @@ -7,7 +7,9 @@
|
| #include <algorithm>
|
| #include <string>
|
|
|
| +#include "base/bind.h"
|
| #include "base/logging.h"
|
| +#include "base/message_loop.h"
|
| #include "gpu/GLES2/gl2extchromium.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "third_party/khronos/GLES2/gl2ext.h"
|
| @@ -24,11 +26,10 @@ using WebKit::WebGraphicsContext3D;
|
|
|
| namespace cc {
|
|
|
| -static const WebGLId kBufferId = 1;
|
| -static const WebGLId kFramebufferId = 2;
|
| -static const WebGLId kProgramId = 3;
|
| -static const WebGLId kRenderbufferId = 4;
|
| -static const WebGLId kShaderId = 5;
|
| +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;
|
|
|
| @@ -37,6 +38,7 @@ const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337;
|
| TestWebGraphicsContext3D::TestWebGraphicsContext3D()
|
| : FakeWebGraphicsContext3D(),
|
| context_id_(s_context_id++),
|
| + next_buffer_id_(1),
|
| next_texture_id_(1),
|
| have_extension_io_surface_(false),
|
| have_extension_egl_image_(false),
|
| @@ -47,13 +49,15 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D()
|
| context_lost_callback_(NULL),
|
| max_texture_size_(1024),
|
| width_(0),
|
| - height_(0) {
|
| + height_(0),
|
| + bound_buffer_(0) {
|
| }
|
|
|
| TestWebGraphicsContext3D::TestWebGraphicsContext3D(
|
| const WebGraphicsContext3D::Attributes& attributes)
|
| : FakeWebGraphicsContext3D(),
|
| context_id_(s_context_id++),
|
| + next_buffer_id_(1),
|
| next_texture_id_(1),
|
| attributes_(attributes),
|
| have_extension_io_surface_(false),
|
| @@ -65,10 +69,15 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D(
|
| context_lost_callback_(NULL),
|
| max_texture_size_(1024),
|
| width_(0),
|
| - height_(0) {
|
| + height_(0),
|
| + bound_buffer_(0) {
|
| }
|
|
|
| TestWebGraphicsContext3D::~TestWebGraphicsContext3D() {
|
| + for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
|
| + if (sync_point_callbacks_[i] != NULL)
|
| + delete sync_point_callbacks_[i];
|
| + }
|
| }
|
|
|
| bool TestWebGraphicsContext3D::makeContextCurrent() {
|
| @@ -176,11 +185,14 @@ WGC3Dboolean TestWebGraphicsContext3D::isTexture(
|
| }
|
|
|
| WebGLId TestWebGraphicsContext3D::createBuffer() {
|
| - return kBufferId | context_id_ << 16;
|
| + return NextBufferId();
|
| }
|
|
|
| void TestWebGraphicsContext3D::deleteBuffer(WebGLId id) {
|
| - EXPECT_EQ(kBufferId | context_id_ << 16, id);
|
| + unsigned context_id = id >> 17;
|
| + unsigned buffer_id = id & 0x1ffff;
|
| + DCHECK(buffer_id && buffer_id < next_buffer_id_);
|
| + DCHECK_EQ(context_id, context_id_);
|
| }
|
|
|
| WebGLId TestWebGraphicsContext3D::createFramebuffer() {
|
| @@ -239,12 +251,6 @@ void TestWebGraphicsContext3D::useProgram(WebGLId program) {
|
| EXPECT_EQ(kProgramId | context_id_ << 16, program);
|
| }
|
|
|
| -void TestWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) {
|
| - if (!buffer)
|
| - return;
|
| - EXPECT_EQ(kBufferId | context_id_ << 16, buffer);
|
| -}
|
| -
|
| void TestWebGraphicsContext3D::bindFramebuffer(
|
| WGC3Denum target, WebGLId framebuffer) {
|
| if (!framebuffer)
|
| @@ -334,6 +340,84 @@ void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current,
|
| shared_contexts_.clear();
|
| }
|
|
|
| +void TestWebGraphicsContext3D::signalSyncPoint(
|
| + unsigned sync_point,
|
| + WebGraphicsSyncPointCallback* callback) {
|
| + sync_point_callbacks_.push_back(callback);
|
| +}
|
| +
|
| +void TestWebGraphicsContext3D::prepareTexture() {
|
| + CallAllSyncPointCallbacks();
|
| +}
|
| +
|
| +void TestWebGraphicsContext3D::finish() {
|
| + CallAllSyncPointCallbacks();
|
| +}
|
| +
|
| +void TestWebGraphicsContext3D::flush() {
|
| + CallAllSyncPointCallbacks();
|
| +}
|
| +
|
| +static void CallAndDestroy(
|
| + WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback* callback) {
|
| + if (!callback)
|
| + return;
|
| + callback->onSyncPointReached();
|
| + delete callback;
|
| +}
|
| +
|
| +void TestWebGraphicsContext3D::CallAllSyncPointCallbacks() {
|
| + for (size_t i = 0; i < sync_point_callbacks_.size(); ++i) {
|
| + base::MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&CallAndDestroy,
|
| + sync_point_callbacks_[i]));
|
| + }
|
| + sync_point_callbacks_.clear();
|
| +}
|
| +
|
| +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;
|
| + DCHECK(buffer_id && buffer_id < next_buffer_id_);
|
| + DCHECK_EQ(context_id, context_id_);
|
| +
|
| + 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) {
|
| + DCHECK_GT(buffers_.count(bound_buffer_), 0u);
|
| + DCHECK_EQ(target, buffers_.get(bound_buffer_)->target);
|
| + buffers_.get(bound_buffer_)->pixels.reset(new uint8[size]);
|
| + if (data != NULL)
|
| + memcpy(buffers_.get(bound_buffer_)->pixels.get(), data, size);
|
| +}
|
| +
|
| +void* TestWebGraphicsContext3D::mapBufferCHROMIUM(WebKit::WGC3Denum target,
|
| + WebKit::WGC3Denum access) {
|
| + DCHECK_GT(buffers_.count(bound_buffer_), 0u);
|
| + DCHECK_EQ(target, buffers_.get(bound_buffer_)->target);
|
| + return buffers_.get(bound_buffer_)->pixels.get();
|
| +}
|
| +
|
| +WebKit::WGC3Dboolean TestWebGraphicsContext3D::unmapBufferCHROMIUM(
|
| + WebKit::WGC3Denum target) {
|
| + DCHECK_GT(buffers_.count(bound_buffer_), 0u);
|
| + DCHECK_EQ(target, buffers_.get(bound_buffer_)->target);
|
| + buffers_.get(bound_buffer_)->pixels.reset();
|
| + return true;
|
| +}
|
| +
|
| WebGLId TestWebGraphicsContext3D::NextTextureId() {
|
| WebGLId texture_id = next_texture_id_++;
|
| DCHECK(texture_id < (1 << 16));
|
| @@ -341,4 +425,15 @@ WebGLId TestWebGraphicsContext3D::NextTextureId() {
|
| return texture_id;
|
| }
|
|
|
| +WebGLId TestWebGraphicsContext3D::NextBufferId() {
|
| + WebGLId buffer_id = next_buffer_id_++;
|
| + DCHECK(buffer_id < (1 << 17));
|
| + buffer_id |= context_id_ << 17;
|
| + return buffer_id;
|
| +}
|
| +
|
| +TestWebGraphicsContext3D::Buffer::Buffer() : target(0) {}
|
| +
|
| +TestWebGraphicsContext3D::Buffer::~Buffer() {}
|
| +
|
| } // namespace cc
|
|
|