summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/debug/fake_web_graphics_context_3d.cc2
-rw-r--r--cc/output/gl_renderer.cc43
-rw-r--r--cc/resources/image_raster_worker_pool.cc3
-rw-r--r--cc/resources/resource_provider.cc109
-rw-r--r--cc/resources/resource_provider.h37
-rw-r--r--cc/resources/resource_provider_unittest.cc38
-rw-r--r--cc/test/test_web_graphics_context_3d.cc2
-rw-r--r--cc/trees/layer_tree_host_impl_unittest.cc2
-rw-r--r--gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc21
-rw-r--r--ui/compositor/test_web_graphics_context_3d.cc2
-rw-r--r--ui/gl/gl_image_mock.h5
11 files changed, 173 insertions, 91 deletions
diff --git a/cc/debug/fake_web_graphics_context_3d.cc b/cc/debug/fake_web_graphics_context_3d.cc
index f49b86d..f493dc1 100644
--- a/cc/debug/fake_web_graphics_context_3d.cc
+++ b/cc/debug/fake_web_graphics_context_3d.cc
@@ -116,6 +116,8 @@ void FakeWebGraphicsContext3D::getIntegerv(
WebKit::WGC3Dint* value) {
if (pname == GL_MAX_TEXTURE_SIZE)
*value = 1024;
+ else if (pname == GL_ACTIVE_TEXTURE)
+ *value = GL_TEXTURE0;
}
void FakeWebGraphicsContext3D::getProgramiv(
diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc
index 71cfdcd..61d0eaa 100644
--- a/cc/output/gl_renderer.cc
+++ b/cc/output/gl_renderer.cc
@@ -843,6 +843,7 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
if (filter_bitmap.getTexture()) {
GrTexture* texture =
reinterpret_cast<GrTexture*>(filter_bitmap.getTexture());
+ DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context()));
Context()->bindTexture(GL_TEXTURE_2D, texture->getTextureHandle());
} else {
contents_resource_lock = make_scoped_ptr(
@@ -1026,10 +1027,10 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
tex_scale_x,
-tex_scale_y));
+ scoped_ptr<ResourceProvider::ScopedReadLockGL> shader_mask_sampler_lock;
if (shader_mask_sampler_location != -1) {
DCHECK_NE(shader_mask_tex_coord_scale_location, 1);
DCHECK_NE(shader_mask_tex_coord_offset_location, 1);
- GLC(Context(), Context()->activeTexture(GL_TEXTURE1));
GLC(Context(), Context()->uniform1i(shader_mask_sampler_location, 1));
float mask_tex_scale_x = quad->mask_uv_rect.width() / tex_scale_x;
@@ -1046,9 +1047,12 @@ void GLRenderer::DrawRenderPassQuad(DrawingFrame* frame,
Context()->uniform2f(shader_mask_tex_coord_scale_location,
mask_tex_scale_x,
-mask_tex_scale_y));
- resource_provider_->BindForSampling(
- quad->mask_resource_id, GL_TEXTURE_2D, GL_LINEAR);
- GLC(Context(), Context()->activeTexture(GL_TEXTURE0));
+ shader_mask_sampler_lock = make_scoped_ptr(
+ new ResourceProvider::ScopedSamplerGL(resource_provider_,
+ quad->mask_resource_id,
+ GL_TEXTURE_2D,
+ GL_TEXTURE1,
+ GL_LINEAR));
}
if (shader_edge_location != -1) {
@@ -1496,22 +1500,31 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
bool use_alpha_plane = quad->a_plane_resource_id != 0;
- GLC(Context(), Context()->activeTexture(GL_TEXTURE1));
ResourceProvider::ScopedSamplerGL y_plane_lock(
- resource_provider_, quad->y_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
- GLC(Context(), Context()->activeTexture(GL_TEXTURE2));
+ resource_provider_,
+ quad->y_plane_resource_id,
+ GL_TEXTURE_2D,
+ GL_TEXTURE1,
+ GL_LINEAR);
ResourceProvider::ScopedSamplerGL u_plane_lock(
- resource_provider_, quad->u_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
- GLC(Context(), Context()->activeTexture(GL_TEXTURE3));
+ resource_provider_,
+ quad->u_plane_resource_id,
+ GL_TEXTURE_2D,
+ GL_TEXTURE2,
+ GL_LINEAR);
ResourceProvider::ScopedSamplerGL v_plane_lock(
- resource_provider_, quad->v_plane_resource_id, GL_TEXTURE_2D, GL_LINEAR);
+ resource_provider_,
+ quad->v_plane_resource_id,
+ GL_TEXTURE_2D,
+ GL_TEXTURE3,
+ GL_LINEAR);
scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock;
if (use_alpha_plane) {
- GLC(Context(), Context()->activeTexture(GL_TEXTURE4));
a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
resource_provider_,
quad->a_plane_resource_id,
GL_TEXTURE_2D,
+ GL_TEXTURE4,
GL_LINEAR));
}
@@ -1584,9 +1597,6 @@ void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
SetShaderOpacity(quad->opacity(), alpha_location);
DrawQuadGeometry(frame, quad->quadTransform(), quad->rect, matrix_location);
-
- // Reset active texture back to texture 0.
- GLC(Context(), Context()->activeTexture(GL_TEXTURE0));
}
void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
@@ -1612,6 +1622,7 @@ void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame,
ResourceProvider::ScopedReadLockGL lock(resource_provider_,
quad->resource_id);
+ DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context()));
GLC(Context(),
Context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, lock.texture_id()));
@@ -1756,6 +1767,7 @@ void GLRenderer::FlushTextureQuadCache() {
// Assume the current active textures is 0.
ResourceProvider::ScopedReadLockGL locked_quad(resource_provider_,
draw_cache_.resource_id);
+ DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context()));
GLC(Context(),
Context()->bindTexture(GL_TEXTURE_2D, locked_quad.texture_id()));
@@ -1908,6 +1920,7 @@ void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame,
ResourceProvider::ScopedReadLockGL lock(resource_provider_,
quad->io_surface_resource_id);
+ DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context()));
GLC(Context(),
Context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB,
lock.texture_id()));
@@ -2060,7 +2073,7 @@ void GLRenderer::CopyTextureToFramebuffer(const DrawingFrame* frame,
}
SetShaderOpacity(1.f, program->fragment_shader().alpha_location());
-
+ DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(Context()));
GLC(Context(), Context()->bindTexture(GL_TEXTURE_2D, texture_id));
DrawQuadGeometry(
frame, draw_matrix, rect, program->vertex_shader().matrix_location());
diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc
index 62727aa..408459c 100644
--- a/cc/resources/image_raster_worker_pool.cc
+++ b/cc/resources/image_raster_worker_pool.cc
@@ -183,9 +183,6 @@ void ImageRasterWorkerPool::OnRasterTaskCompleted(
// Balanced with MapImage() call in ScheduleTasks().
resource_provider()->UnmapImage(task->resource()->id());
- // Bind image to resource.
- resource_provider()->BindImage(task->resource()->id());
-
task->DidRun(was_canceled);
task->WillComplete();
task->CompleteOnOriginThread();
diff --git a/cc/resources/resource_provider.cc b/cc/resources/resource_provider.cc
index 054e980..6d6ac9d 100644
--- a/cc/resources/resource_provider.cc
+++ b/cc/resources/resource_provider.cc
@@ -507,6 +507,8 @@ const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) {
// Uninitialized! Call SetPixels or LockForWrite first.
DCHECK(resource->allocated);
+ LazyCreate(resource);
+
if (resource->external) {
if (!resource->gl_id && resource->mailbox.IsTexture()) {
WebGraphicsContext3D* context3d = output_surface_->context3d();
@@ -599,8 +601,26 @@ ResourceProvider::ScopedSamplerGL::ScopedSamplerGL(
ResourceProvider::ResourceId resource_id,
GLenum target,
GLenum filter)
- : ScopedReadLockGL(resource_provider, resource_id) {
- resource_provider->BindForSampling(resource_id, target, filter);
+ : ScopedReadLockGL(resource_provider, resource_id),
+ target_(target),
+ unit_(GL_TEXTURE0) {
+ resource_provider->BindForSampling(resource_id, target, unit_, filter);
+}
+
+ResourceProvider::ScopedSamplerGL::ScopedSamplerGL(
+ ResourceProvider* resource_provider,
+ ResourceProvider::ResourceId resource_id,
+ GLenum target,
+ GLenum unit,
+ GLenum filter)
+ : ScopedReadLockGL(resource_provider, resource_id),
+ target_(target),
+ unit_(unit) {
+ resource_provider->BindForSampling(resource_id, target, unit, filter);
+}
+
+ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {
+ resource_provider_->UnbindForSampling(resource_id_, target_, unit_);
}
ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(
@@ -1073,7 +1093,9 @@ void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
}
void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id,
- GLenum target, GLenum filter) {
+ GLenum target,
+ GLenum unit,
+ GLenum filter) {
DCHECK(thread_checker_.CalledOnValidThread());
WebGraphicsContext3D* context3d = output_surface_->context3d();
ResourceMap::iterator it = resources_.find(resource_id);
@@ -1081,7 +1103,10 @@ void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id,
Resource* resource = &it->second;
DCHECK(resource->lock_for_read_count);
DCHECK(!resource->locked_for_write || resource->set_pixels_completion_forced);
+ DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d));
+ if (unit != GL_TEXTURE0)
+ GLC(context3d, context3d->activeTexture(unit));
GLC(context3d, context3d->bindTexture(target, resource->gl_id));
if (filter != resource->filter) {
GLC(context3d, context3d->texParameteri(target,
@@ -1092,6 +1117,33 @@ void ResourceProvider::BindForSampling(ResourceProvider::ResourceId resource_id,
filter));
resource->filter = filter;
}
+
+ if (resource->image_id)
+ context3d->bindTexImage2DCHROMIUM(target, resource->image_id);
+
+ // Active unit being GL_TEXTURE0 is effectively the ground state.
+ if (unit != GL_TEXTURE0)
+ GLC(context3d, context3d->activeTexture(GL_TEXTURE0));
+}
+
+void ResourceProvider::UnbindForSampling(
+ ResourceProvider::ResourceId resource_id, GLenum target, GLenum unit) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ ResourceMap::iterator it = resources_.find(resource_id);
+ DCHECK(it != resources_.end());
+ Resource* resource = &it->second;
+
+ if (!resource->image_id)
+ return;
+
+ WebGraphicsContext3D* context3d = output_surface_->context3d();
+ DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(context3d));
+ if (unit != GL_TEXTURE0)
+ GLC(context3d, context3d->activeTexture(unit));
+ context3d->releaseTexImage2DCHROMIUM(target, resource->image_id);
+ // Active unit being GL_TEXTURE0 is effectively the ground state.
+ if (unit != GL_TEXTURE0)
+ GLC(context3d, context3d->activeTexture(GL_TEXTURE0));
}
void ResourceProvider::BeginSetPixels(ResourceId id) {
@@ -1297,15 +1349,10 @@ void ResourceProvider::AcquireImage(ResourceId id) {
if (resource->type != GLTexture)
return;
- if (resource->image_id != 0) {
- // If we had previously allocated an image for this resource,
- // release it first, before acquiring the new image.
- // TODO(kaanb): This is a temporary workaround. We must return here
- // immediately. Platform specific code needs to deal with this
- // situation appropriately.
- ReleaseImage(id);
- }
+ if (resource->image_id)
+ return;
+ resource->allocated = true;
WebGraphicsContext3D* context3d = output_surface_->context3d();
DCHECK(context3d);
resource->image_id = context3d->createImageCHROMIUM(
@@ -1322,12 +1369,14 @@ void ResourceProvider::ReleaseImage(ResourceId id) {
DCHECK(!resource->external);
DCHECK(!resource->exported);
- if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
- DCHECK(context3d);
- context3d->destroyImageCHROMIUM(resource->image_id);
- resource->image_id = 0;
- }
+ if (!resource->image_id)
+ return;
+
+ WebGraphicsContext3D* context3d = output_surface_->context3d();
+ DCHECK(context3d);
+ context3d->destroyImageCHROMIUM(resource->image_id);
+ resource->image_id = 0;
+ resource->allocated = false;
}
uint8_t* ResourceProvider::MapImage(ResourceId id) {
@@ -1369,26 +1418,6 @@ void ResourceProvider::UnmapImage(ResourceId id) {
}
}
-void ResourceProvider::BindImage(ResourceId id) {
- DCHECK(thread_checker_.CalledOnValidThread());
- ResourceMap::iterator it = resources_.find(id);
- CHECK(it != resources_.end());
- Resource* resource = &it->second;
-
- DCHECK(!resource->external);
- DCHECK(!resource->exported);
-
- LazyCreate(resource);
- resource->allocated = true;
-
- if (resource->image_id) {
- WebGraphicsContext3D* context3d = output_surface_->context3d();
- DCHECK(context3d);
- context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
- context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id);
- }
-}
-
int ResourceProvider::GetImageStride(ResourceId id) {
DCHECK(thread_checker_.CalledOnValidThread());
ResourceMap::iterator it = resources_.find(id);
@@ -1410,4 +1439,10 @@ int ResourceProvider::GetImageStride(ResourceId id) {
return stride;
}
+GLint ResourceProvider::GetActiveTextureUnit(WebGraphicsContext3D* context) {
+ GLint active_unit = 0;
+ context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
+ return active_unit;
+}
+
} // namespace cc
diff --git a/cc/resources/resource_provider.h b/cc/resources/resource_provider.h
index 8e33aaf..4d1de6c 100644
--- a/cc/resources/resource_provider.h
+++ b/cc/resources/resource_provider.h
@@ -172,13 +172,6 @@ class CC_EXPORT ResourceProvider {
void ReceiveFromParent(
const TransferableResourceArray& transferable_resources);
- // Bind the given GL resource to a texture target for sampling using the
- // specified filter for both minification and magnification. The resource
- // must be locked for reading.
- void BindForSampling(ResourceProvider::ResourceId resource_id,
- GLenum target,
- GLenum filter);
-
// The following lock classes are part of the ResourceProvider API and are
// needed to read and write the resource contents. The user must ensure
// that they only use GL locks on GL resources, etc, and this is enforced
@@ -187,13 +180,15 @@ class CC_EXPORT ResourceProvider {
public:
ScopedReadLockGL(ResourceProvider* resource_provider,
ResourceProvider::ResourceId resource_id);
- ~ScopedReadLockGL();
+ virtual ~ScopedReadLockGL();
unsigned texture_id() const { return texture_id_; }
- private:
+ protected:
ResourceProvider* resource_provider_;
ResourceProvider::ResourceId resource_id_;
+
+ private:
unsigned texture_id_;
DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
@@ -205,8 +200,17 @@ class CC_EXPORT ResourceProvider {
ResourceProvider::ResourceId resource_id,
GLenum target,
GLenum filter);
+ ScopedSamplerGL(ResourceProvider* resource_provider,
+ ResourceProvider::ResourceId resource_id,
+ GLenum target,
+ GLenum unit,
+ GLenum filter);
+ virtual ~ScopedSamplerGL();
private:
+ GLenum target_;
+ GLenum unit_;
+
DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
};
@@ -296,9 +300,6 @@ class CC_EXPORT ResourceProvider {
uint8_t* MapImage(ResourceId id);
void UnmapImage(ResourceId id);
- // Binds the image to a texture.
- void BindImage(ResourceId id);
-
// Returns the stride for the image.
int GetImageStride(ResourceId id);
@@ -330,6 +331,7 @@ class CC_EXPORT ResourceProvider {
scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
offscreen_context_provider_ = offscreen_context_provider;
}
+ static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context);
private:
struct Resource {
@@ -408,6 +410,17 @@ class CC_EXPORT ResourceProvider {
void LazyCreate(Resource* resource);
void LazyAllocate(Resource* resource);
+ // Binds the given GL resource to a texture target for sampling using the
+ // specified filter for both minification and magnification. The resource
+ // must be locked for reading.
+ void BindForSampling(ResourceProvider::ResourceId resource_id,
+ GLenum target,
+ GLenum unit,
+ GLenum filter);
+ void UnbindForSampling(ResourceProvider::ResourceId resource_id,
+ GLenum target,
+ GLenum unit);
+
OutputSurface* output_surface_;
bool lost_output_surface_;
int highp_threshold_min_;
diff --git a/cc/resources/resource_provider_unittest.cc b/cc/resources/resource_provider_unittest.cc
index 804134a..a23af0b 100644
--- a/cc/resources/resource_provider_unittest.cc
+++ b/cc/resources/resource_provider_unittest.cc
@@ -1352,6 +1352,7 @@ class AllocationTrackingContext3D : public TestWebGraphicsContext3D {
GLint*));
MOCK_METHOD1(unmapImageCHROMIUM, void(WGC3Duint));
MOCK_METHOD2(bindTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
+ MOCK_METHOD2(releaseTexImage2DCHROMIUM, void(WGC3Denum, WGC3Dint));
};
TEST_P(ResourceProviderTest, TextureAllocation) {
@@ -1608,16 +1609,6 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
.RetiresOnSaturation();
resource_provider->AcquireImage(id);
- EXPECT_CALL(*context, createTexture())
- .WillOnce(Return(kTextureId))
- .RetiresOnSaturation();
- EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2)
- .RetiresOnSaturation();
- EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
- .Times(1)
- .RetiresOnSaturation();
- resource_provider->BindImage(id);
-
void* dummy_mapped_buffer_address = NULL;
EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE))
.WillOnce(Return(dummy_mapped_buffer_address))
@@ -1638,16 +1629,31 @@ TEST_P(ResourceProviderTest, Image_GLTexture) {
.RetiresOnSaturation();
resource_provider->UnmapImage(id);
- EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId))
+ EXPECT_CALL(*context, createTexture())
+ .WillOnce(Return(kTextureId))
+ .RetiresOnSaturation();
+ // Once in CreateTextureId and once in BindForSampling
+ EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
+ .Times(1)
+ .RetiresOnSaturation();
+ EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
.Times(1)
.RetiresOnSaturation();
- resource_provider->ReleaseImage(id);
-
- // Texture will be deleted when ResourceProvider destructor is
- // called when it goes out of scope when this method returns.
EXPECT_CALL(*context, deleteTexture(kTextureId))
.Times(1)
.RetiresOnSaturation();
+ {
+ ResourceProvider::ScopedSamplerGL lock_gl(
+ resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
+ EXPECT_EQ(kTextureId, lock_gl.texture_id());
+ }
+
+ EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId))
+ .Times(1)
+ .RetiresOnSaturation();
+ resource_provider->ReleaseImage(id);
}
TEST_P(ResourceProviderTest, Image_Bitmap) {
@@ -1678,8 +1684,6 @@ TEST_P(ResourceProviderTest, Image_Bitmap) {
memcpy(data, &kBadBeef, sizeof(kBadBeef));
resource_provider->UnmapImage(id);
- resource_provider->BindImage(id);
-
{
ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id);
const SkBitmap* sk_bitmap = lock.sk_bitmap();
diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc
index 44d43f9..7e82612 100644
--- a/cc/test/test_web_graphics_context_3d.cc
+++ b/cc/test/test_web_graphics_context_3d.cc
@@ -365,6 +365,8 @@ void TestWebGraphicsContext3D::getIntegerv(
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) {
diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc
index 5b92e61..cad1126 100644
--- a/cc/trees/layer_tree_host_impl_unittest.cc
+++ b/cc/trees/layer_tree_host_impl_unittest.cc
@@ -3461,6 +3461,8 @@ class PartialSwapContext : public TestWebGraphicsContext3D {
OVERRIDE {
if (pname == GL_MAX_TEXTURE_SIZE)
*value = 8192;
+ else if (pname == GL_ACTIVE_TEXTURE)
+ *value = GL_TEXTURE0;
}
};
diff --git a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
index 4647465..7e6372c 100644
--- a/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
+++ b/gpu/command_buffer/tests/gl_gpu_memory_buffer_unittests.cc
@@ -85,8 +85,8 @@ TEST_F(MockGpuMemoryBufferTest, Lifecycle) {
EXPECT_EQ(kImageId, image_id);
gfx::Size size(kImageWidth, kImageHeight);
- scoped_refptr<gfx::GLImageMock> gl_image(
- new gfx::GLImageMock(gpu_memory_buffer, size));
+ scoped_refptr<StrictMock<gfx::GLImageMock> > gl_image(
+ new StrictMock<gfx::GLImageMock>(gpu_memory_buffer, size));
image_manager_->AddImage(gl_image.get(), image_id);
EXPECT_CALL(*gpu_memory_buffer, IsMapped())
@@ -100,8 +100,7 @@ TEST_F(MockGpuMemoryBufferTest, Lifecycle) {
.Times(1)
.WillOnce(SetArgPointee<1>(buffer_pixels.get()))
.RetiresOnSaturation();
- void* mapped_buffer =
- glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
+ void* mapped_buffer = glMapImageCHROMIUM(image_id, GL_WRITE_ONLY);
EXPECT_EQ(buffer_pixels.get(), mapped_buffer);
EXPECT_CALL(*gpu_memory_buffer, IsMapped())
@@ -116,12 +115,22 @@ TEST_F(MockGpuMemoryBufferTest, Lifecycle) {
// Bind the texture and the image.
glBindTexture(GL_TEXTURE_2D, texture_id);
- EXPECT_CALL(*gl_image.get(), BindTexImage()).Times(1).WillOnce(Return(true))
+ EXPECT_CALL(*gl_image.get(), BindTexImage())
+ .Times(1)
+ .WillOnce(Return(true))
.RetiresOnSaturation();
- EXPECT_CALL(*gl_image.get(), GetSize()).Times(1).WillOnce(Return(size))
+ EXPECT_CALL(*gl_image.get(), GetSize())
+ .Times(1)
+ .WillOnce(Return(size))
.RetiresOnSaturation();
glBindTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
+ // Unbind the image.
+ EXPECT_CALL(*gl_image.get(), ReleaseTexImage())
+ .Times(1)
+ .RetiresOnSaturation();
+ glReleaseTexImage2DCHROMIUM(GL_TEXTURE_2D, image_id);
+
// Destroy the image.
EXPECT_CALL(*gpu_memory_buffer, Die())
.Times(1)
diff --git a/ui/compositor/test_web_graphics_context_3d.cc b/ui/compositor/test_web_graphics_context_3d.cc
index 37ea3bc..d8febc9 100644
--- a/ui/compositor/test_web_graphics_context_3d.cc
+++ b/ui/compositor/test_web_graphics_context_3d.cc
@@ -98,6 +98,8 @@ void TestWebGraphicsContext3D::getIntegerv(WebKit::WGC3Denum pname,
WebKit::WGC3Dint* value) {
if (pname == GL_MAX_TEXTURE_SIZE)
*value = 1024;
+ else if (pname == GL_ACTIVE_TEXTURE)
+ *value = GL_TEXTURE0;
}
void TestWebGraphicsContext3D::getProgramiv(WebKit::WebGLId program,
diff --git a/ui/gl/gl_image_mock.h b/ui/gl/gl_image_mock.h
index 25b7182..b903165 100644
--- a/ui/gl/gl_image_mock.h
+++ b/ui/gl/gl_image_mock.h
@@ -20,8 +20,11 @@ class GLImageMock : public GLImage {
MOCK_METHOD0(Destroy, void());
MOCK_METHOD0(GetSize, gfx::Size());
MOCK_METHOD0(ReleaseTexImage, void());
- private:
+
+ protected:
virtual ~GLImageMock();
+
+ private:
DISALLOW_COPY_AND_ASSIGN(GLImageMock);
};