Implement {Bind,Release}TexImage2DCHROMIUM
Pretty much a copy-and-paste from gles2_cmd_decoder.cc w/ unittest. Bug: 789238 Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel Change-Id: Ie1198944994239bbf581df3120bbe655f27f1788 Reviewed-on: https://chromium-review.googlesource.com/981091 Reviewed-by: Zhenyao Mo <zmo@chromium.org> Commit-Queue: Jonathan Backer <backer@chromium.org> Cr-Commit-Position: refs/heads/master@{#546265}
This commit is contained in:

committed by
Commit Bot

parent
6cec6359dc
commit
ac62dde1c3
@@ -30,6 +30,7 @@
|
||||
#include "gpu/command_buffer/service/error_state.h"
|
||||
#include "gpu/command_buffer/service/feature_info.h"
|
||||
#include "gpu/command_buffer/service/framebuffer_manager.h"
|
||||
#include "gpu/command_buffer/service/image_manager.h"
|
||||
#include "gpu/command_buffer/service/logger.h"
|
||||
#include "gpu/command_buffer/service/mailbox_manager.h"
|
||||
#include "gpu/command_buffer/service/query_manager.h"
|
||||
@@ -275,6 +276,7 @@ class RasterDecoderImpl : public RasterDecoder, public gles2::ErrorStateClient {
|
||||
Logger* GetLogger() override;
|
||||
|
||||
void SetIgnoreCachedStateForTest(bool ignore) override;
|
||||
ImageManager* GetImageManagerForTest() override;
|
||||
|
||||
private:
|
||||
std::unordered_map<GLuint, TextureMetadata> texture_metadata_;
|
||||
@@ -316,6 +318,8 @@ class RasterDecoderImpl : public RasterDecoder, public gles2::ErrorStateClient {
|
||||
|
||||
TextureManager* texture_manager() { return group_->texture_manager(); }
|
||||
|
||||
ImageManager* image_manager() { return group_->image_manager(); }
|
||||
|
||||
// Creates a Texture for the given texture.
|
||||
TextureRef* CreateTexture(GLuint client_id, GLuint service_id) {
|
||||
return texture_manager()->CreateTexture(client_id, service_id);
|
||||
@@ -380,13 +384,9 @@ class RasterDecoderImpl : public RasterDecoder, public gles2::ErrorStateClient {
|
||||
void DoFlush();
|
||||
void DoGetIntegerv(GLenum pname, GLint* params, GLsizei params_size);
|
||||
void DoTexParameteri(GLuint texture_id, GLenum pname, GLint param);
|
||||
void DoBindTexImage2DCHROMIUM(GLuint texture_id, GLint image_id) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
void DoBindTexImage2DCHROMIUM(GLuint texture_id, GLint image_id);
|
||||
void DoProduceTextureDirect(GLuint texture, const volatile GLbyte* key);
|
||||
void DoReleaseTexImage2DCHROMIUM(GLuint texture_id, GLint image_id) {
|
||||
NOTIMPLEMENTED();
|
||||
}
|
||||
void DoReleaseTexImage2DCHROMIUM(GLuint texture_id, GLint image_id);
|
||||
void TexStorage2DImage(TextureRef* texture_ref,
|
||||
const TextureMetadata& texture_metadata,
|
||||
GLsizei width,
|
||||
@@ -957,6 +957,10 @@ void RasterDecoderImpl::SetIgnoreCachedStateForTest(bool ignore) {
|
||||
state_.SetIgnoreCachedStateForTest(ignore);
|
||||
}
|
||||
|
||||
ImageManager* RasterDecoderImpl::GetImageManagerForTest() {
|
||||
return group_->image_manager();
|
||||
}
|
||||
|
||||
void RasterDecoderImpl::BeginDecoding() {
|
||||
gpu_debug_commands_ = log_commands() || debug();
|
||||
}
|
||||
@@ -1466,6 +1470,101 @@ void RasterDecoderImpl::DoTexParameteri(GLuint client_id,
|
||||
pname, param);
|
||||
}
|
||||
|
||||
void RasterDecoderImpl::DoBindTexImage2DCHROMIUM(GLuint client_id,
|
||||
GLint image_id) {
|
||||
TextureRef* texture_ref = GetTexture(client_id);
|
||||
if (!texture_ref) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "BindTexImage2DCHROMIUM",
|
||||
"unknown texture");
|
||||
return;
|
||||
}
|
||||
|
||||
TextureMetadata* texture_metadata = GetTextureMetadata(client_id);
|
||||
if (!texture_metadata) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "BindTexImage2DCHROMIUM",
|
||||
"unknown texture");
|
||||
return;
|
||||
}
|
||||
|
||||
gl::GLImage* image = image_manager()->LookupImage(image_id);
|
||||
if (!image) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "BindTexImage2DCHROMIUM",
|
||||
"no image found with the given ID");
|
||||
return;
|
||||
}
|
||||
|
||||
Texture* texture = texture_ref->texture();
|
||||
if (texture->IsImmutable()) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "BindTexImage2DCHROMIUM",
|
||||
"texture is immutable");
|
||||
return;
|
||||
}
|
||||
|
||||
Texture::ImageState image_state = Texture::UNBOUND;
|
||||
|
||||
{
|
||||
ScopedTextureBinder binder(&state_, texture_manager(), texture_ref,
|
||||
texture_metadata->target());
|
||||
|
||||
if (image->BindTexImage(texture_metadata->target()))
|
||||
image_state = Texture::BOUND;
|
||||
}
|
||||
|
||||
gfx::Size size = image->GetSize();
|
||||
texture_manager()->SetLevelInfo(
|
||||
texture_ref, texture_metadata->target(), 0, image->GetInternalFormat(),
|
||||
size.width(), size.height(), 1, 0, image->GetInternalFormat(),
|
||||
GL_UNSIGNED_BYTE, gfx::Rect(size));
|
||||
texture_manager()->SetLevelImage(texture_ref, texture_metadata->target(), 0,
|
||||
image, image_state);
|
||||
}
|
||||
|
||||
void RasterDecoderImpl::DoReleaseTexImage2DCHROMIUM(GLuint client_id,
|
||||
GLint image_id) {
|
||||
TRACE_EVENT0("gpu", "RasterDecoderImpl::DoReleaseTexImage2DCHROMIUM");
|
||||
|
||||
TextureRef* texture_ref = GetTexture(client_id);
|
||||
if (!texture_ref) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "ReleaseTexImage2DCHROMIUM",
|
||||
"unknown texture");
|
||||
return;
|
||||
}
|
||||
|
||||
TextureMetadata* texture_metadata = GetTextureMetadata(client_id);
|
||||
if (!texture_metadata) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "ReleaseTexImage2DCHROMIUM",
|
||||
"unknown texture");
|
||||
return;
|
||||
}
|
||||
|
||||
gl::GLImage* image = image_manager()->LookupImage(image_id);
|
||||
if (!image) {
|
||||
LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "ReleaseTexImage2DCHROMIUM",
|
||||
"no image found with the given ID");
|
||||
return;
|
||||
}
|
||||
|
||||
Texture::ImageState image_state;
|
||||
|
||||
// Do nothing when image is not currently bound.
|
||||
if (texture_ref->texture()->GetLevelImage(texture_metadata->target(), 0,
|
||||
&image_state) != image)
|
||||
return;
|
||||
|
||||
if (image_state == Texture::BOUND) {
|
||||
ScopedTextureBinder binder(&state_, texture_manager(), texture_ref,
|
||||
texture_metadata->target());
|
||||
|
||||
image->ReleaseTexImage(texture_metadata->target());
|
||||
texture_manager()->SetLevelInfo(texture_ref, texture_metadata->target(), 0,
|
||||
GL_RGBA, 0, 0, 1, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, gfx::Rect());
|
||||
}
|
||||
|
||||
texture_manager()->SetLevelImage(texture_ref, texture_metadata->target(), 0,
|
||||
nullptr, Texture::UNBOUND);
|
||||
}
|
||||
|
||||
void RasterDecoderImpl::DoProduceTextureDirect(GLuint client_id,
|
||||
const volatile GLbyte* key) {
|
||||
TRACE_EVENT2("gpu", "RasterDecoderImpl::DoProduceTextureDirect", "context",
|
||||
|
@@ -16,6 +16,7 @@ class DecoderClient;
|
||||
|
||||
namespace gles2 {
|
||||
class GLES2Util;
|
||||
class ImageManager;
|
||||
class Logger;
|
||||
class Outputter;
|
||||
} // namespace gles2
|
||||
@@ -54,6 +55,9 @@ class GPU_GLES2_EXPORT RasterDecoder : public DecoderContext,
|
||||
virtual gles2::Logger* GetLogger() = 0;
|
||||
virtual void SetIgnoreCachedStateForTest(bool ignore) = 0;
|
||||
|
||||
// Gets the ImageManager for this context.
|
||||
virtual gles2::ImageManager* GetImageManagerForTest() = 0;
|
||||
|
||||
void set_initialized() { initialized_ = true; }
|
||||
|
||||
// Set to true to call glGetError after every command.
|
||||
|
@@ -33,6 +33,7 @@ class ContextGroup;
|
||||
class ErrorState;
|
||||
class GpuFenceManager;
|
||||
class GLES2Util;
|
||||
class ImageManager;
|
||||
struct ContextState;
|
||||
class FeatureInfo;
|
||||
class Logger;
|
||||
@@ -92,6 +93,7 @@ class MockRasterDecoder : public RasterDecoder {
|
||||
MOCK_METHOD0(GetQueryManager, QueryManager*());
|
||||
MOCK_METHOD0(GetGpuFenceManager, gpu::gles2::GpuFenceManager*());
|
||||
MOCK_METHOD1(SetIgnoreCachedStateForTest, void(bool ignore));
|
||||
MOCK_METHOD0(GetImageManagerForTest, gles2::ImageManager*());
|
||||
MOCK_METHOD4(DoCommands,
|
||||
error::Error(unsigned int num_commands,
|
||||
const volatile void* buffer,
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "gpu/command_buffer/service/raster_decoder_unittest_base.h"
|
||||
#include "gpu/command_buffer/service/test_helper.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/gl/gl_image_stub.h"
|
||||
#include "ui/gl/gl_mock.h"
|
||||
|
||||
using ::testing::_;
|
||||
@@ -355,5 +356,49 @@ TEST_P(RasterDecoderTest, ProduceAndConsumeTexture) {
|
||||
EXPECT_EQ(kServiceTextureId, texture->service_id());
|
||||
}
|
||||
|
||||
TEST_P(RasterDecoderTest, ReleaseTexImage2DCHROMIUM) {
|
||||
const GLint kImageId = 1;
|
||||
scoped_refptr<gl::GLImage> image(new gl::GLImageStub);
|
||||
GetImageManagerForTest()->AddImage(image.get(), kImageId);
|
||||
EXPECT_FALSE(GetImageManagerForTest()->LookupImage(kImageId) == nullptr);
|
||||
|
||||
// Bind image to texture.
|
||||
SetScopedTextureBinderExpectations(GL_TEXTURE_2D);
|
||||
cmds::BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
|
||||
bind_tex_image_2d_cmd.Init(client_texture_id_, kImageId);
|
||||
EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
|
||||
EXPECT_EQ(GL_NO_ERROR, GetGLError());
|
||||
|
||||
gles2::TextureRef* texture_ref =
|
||||
group().texture_manager()->GetTexture(client_texture_id_);
|
||||
ASSERT_TRUE(texture_ref != nullptr);
|
||||
gles2::Texture* texture = texture_ref->texture();
|
||||
GLsizei width;
|
||||
GLsizei height;
|
||||
EXPECT_TRUE(
|
||||
texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
|
||||
// Dimensions from |image| above.
|
||||
EXPECT_EQ(1, width);
|
||||
EXPECT_EQ(1, height);
|
||||
|
||||
// Image should now be set.
|
||||
EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == nullptr);
|
||||
|
||||
// Release image from texture.
|
||||
SetScopedTextureBinderExpectations(GL_TEXTURE_2D);
|
||||
cmds::ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
|
||||
release_tex_image_2d_cmd.Init(client_texture_id_, kImageId);
|
||||
EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
|
||||
|
||||
EXPECT_TRUE(
|
||||
texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
|
||||
// Size reset.
|
||||
EXPECT_EQ(0, width);
|
||||
EXPECT_EQ(0, height);
|
||||
|
||||
// Image should no longer be set.
|
||||
EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == nullptr);
|
||||
}
|
||||
|
||||
} // namespace raster
|
||||
} // namespace gpu
|
||||
|
@@ -41,6 +41,7 @@
|
||||
namespace gpu {
|
||||
|
||||
namespace gles2 {
|
||||
class ImageManager;
|
||||
class MemoryTracker;
|
||||
} // namespace gles2
|
||||
|
||||
@@ -153,6 +154,9 @@ class RasterDecoderTestBase : public ::testing::TestWithParam<bool>,
|
||||
}
|
||||
|
||||
RasterDecoder* GetDecoder() const { return decoder_.get(); }
|
||||
gles2::ImageManager* GetImageManagerForTest() {
|
||||
return decoder_->GetImageManagerForTest();
|
||||
}
|
||||
|
||||
typedef gles2::TestHelper::AttribInfo AttribInfo;
|
||||
typedef gles2::TestHelper::UniformInfo UniformInfo;
|
||||
|
Reference in New Issue
Block a user