diff options
author | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 13:04:11 +0000 |
---|---|---|
committer | skyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 13:04:11 +0000 |
commit | 50bcb3cb9d02bd24ad21cb95a6375a37e38aeec1 (patch) | |
tree | e33e32d293f984d7c940a22fefc96739c0314429 /gpu | |
parent | 96946824b34885701dfe7fb36e035385fd859c0b (diff) | |
download | chromium_src-50bcb3cb9d02bd24ad21cb95a6375a37e38aeec1.zip chromium_src-50bcb3cb9d02bd24ad21cb95a6375a37e38aeec1.tar.gz chromium_src-50bcb3cb9d02bd24ad21cb95a6375a37e38aeec1.tar.bz2 |
gpu: Upgrade DEPTH_COMPONENT16 to DEPTH_COMPONENT24 if possible
Upgrade the DEPTH_COMPONENT16 render buffer storage format to
DEPTH_COMPONENT24 if the GLES implementation supports the OES_depth24
extension. This is done to improve content portability between desktop
and mobile, since we already do a similar mapping from DEPTH_COMPONENT16
to the unsized DEPTH_COMPONENT on desktop GL. This means that for
example WebGL content can end up relying on a higher precision depth
buffer even though it only requested DEPTH_COMPONENT16.
BUG=285400
TEST=http://www.khronos.org/registry/webgl/conformance-suites/1.0.1/webgl-conformance-tests.html on Nexus 4
Review URL: https://chromiumcodereview.appspot.com/24079010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224117 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/context_group.cc | 5 | ||||
-rw-r--r-- | gpu/command_buffer/service/feature_info.cc | 2 | ||||
-rw-r--r-- | gpu/command_buffer/service/feature_info.h | 1 | ||||
-rw-r--r-- | gpu/command_buffer/service/framebuffer_manager_unittest.cc | 35 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 25 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager.cc | 19 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager.h | 13 | ||||
-rw-r--r-- | gpu/command_buffer/service/renderbuffer_manager_unittest.cc | 37 |
8 files changed, 88 insertions, 49 deletions
diff --git a/gpu/command_buffer/service/context_group.cc b/gpu/command_buffer/service/context_group.cc index bb6ad71..0cb6e51 100644 --- a/gpu/command_buffer/service/context_group.cc +++ b/gpu/command_buffer/service/context_group.cc @@ -120,12 +120,15 @@ bool ContextGroup::Initialize( draw_buffer_ = GL_BACK; } + const bool depth24_supported = feature_info_->feature_flags().oes_depth24; + buffer_manager_.reset( new BufferManager(memory_tracker_.get(), feature_info_.get())); framebuffer_manager_.reset( new FramebufferManager(max_draw_buffers_, max_color_attachments_)); renderbuffer_manager_.reset(new RenderbufferManager( - memory_tracker_.get(), max_renderbuffer_size, max_samples)); + memory_tracker_.get(), max_renderbuffer_size, max_samples, + depth24_supported)); shader_manager_.reset(new ShaderManager()); // Lookup GL things we need to know. diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc index b9fd20e..cddf0a5 100644 --- a/gpu/command_buffer/service/feature_info.cc +++ b/gpu/command_buffer/service/feature_info.cc @@ -104,6 +104,7 @@ FeatureInfo::FeatureFlags::FeatureFlags() use_img_for_multisampled_render_to_texture(false), oes_standard_derivatives(false), oes_egl_image_external(false), + oes_depth24(false), npot_ok(false), enable_texture_float_linear(false), enable_texture_half_float_linear(false), @@ -497,6 +498,7 @@ void FeatureInfo::InitializeFeatures() { if (extensions.Contains("GL_OES_depth24") || gfx::HasDesktopGLFeatures()) { AddExtensionString("GL_OES_depth24"); + feature_flags_.oes_depth24 = true; validators_.render_buffer_format.AddValue(GL_DEPTH_COMPONENT24); } diff --git a/gpu/command_buffer/service/feature_info.h b/gpu/command_buffer/service/feature_info.h index 782b3a8..7d5041f 100644 --- a/gpu/command_buffer/service/feature_info.h +++ b/gpu/command_buffer/service/feature_info.h @@ -32,6 +32,7 @@ class GPU_EXPORT FeatureInfo : public base::RefCounted<FeatureInfo> { bool use_img_for_multisampled_render_to_texture; bool oes_standard_derivatives; bool oes_egl_image_external; + bool oes_depth24; bool npot_ok; bool enable_texture_float_linear; bool enable_texture_half_float_linear; diff --git a/gpu/command_buffer/service/framebuffer_manager_unittest.cc b/gpu/command_buffer/service/framebuffer_manager_unittest.cc index a2c8aeb..0793258 100644 --- a/gpu/command_buffer/service/framebuffer_manager_unittest.cc +++ b/gpu/command_buffer/service/framebuffer_manager_unittest.cc @@ -15,19 +15,24 @@ using ::testing::Return; namespace gpu { namespace gles2 { +namespace { -class FramebufferManagerTest : public testing::Test { - static const GLint kMaxTextureSize = 64; - static const GLint kMaxCubemapSize = 64; - static const GLint kMaxRenderbufferSize = 64; - static const GLint kMaxSamples = 4; +const GLint kMaxTextureSize = 64; +const GLint kMaxCubemapSize = 64; +const GLint kMaxRenderbufferSize = 64; +const GLint kMaxSamples = 4; +const bool kDepth24Supported = false; + +} // namespace +class FramebufferManagerTest : public testing::Test { public: FramebufferManagerTest() : manager_(1, 1), texture_manager_( NULL, new FeatureInfo(), kMaxTextureSize, kMaxCubemapSize), - renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples) { + renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples, + kDepth24Supported) { } virtual ~FramebufferManagerTest() { @@ -54,13 +59,6 @@ class FramebufferManagerTest : public testing::Test { RenderbufferManager renderbuffer_manager_; }; -// GCC requires these declarations, but MSVC requires they not be present -#ifndef COMPILER_MSVC -const GLint FramebufferManagerTest::kMaxTextureSize; -const GLint FramebufferManagerTest::kMaxCubemapSize; -const GLint FramebufferManagerTest::kMaxRenderbufferSize; -#endif - TEST_F(FramebufferManagerTest, Basic) { const GLuint kClient1Id = 1; const GLuint kService1Id = 11; @@ -110,16 +108,12 @@ class FramebufferInfoTest : public testing::Test { static const GLuint kClient1Id = 1; static const GLuint kService1Id = 11; - static const GLint kMaxTextureSize = 64; - static const GLint kMaxCubemapSize = 64; - static const GLint kMaxRenderbufferSize = 64; - static const GLint kMaxSamples = 4; - FramebufferInfoTest() : manager_(1, 1), texture_manager_( NULL, new FeatureInfo(), kMaxTextureSize, kMaxCubemapSize), - renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples) { + renderbuffer_manager_(NULL, kMaxRenderbufferSize, kMaxSamples, + kDepth24Supported) { } virtual ~FramebufferInfoTest() { manager_.Destroy(false); @@ -155,9 +149,6 @@ class FramebufferInfoTest : public testing::Test { #ifndef COMPILER_MSVC const GLuint FramebufferInfoTest::kClient1Id; const GLuint FramebufferInfoTest::kService1Id; -const GLint FramebufferInfoTest::kMaxTextureSize; -const GLint FramebufferInfoTest::kMaxCubemapSize; -const GLint FramebufferInfoTest::kMaxRenderbufferSize; #endif TEST_F(FramebufferInfoTest, Basic) { diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 016fa4b..de95071 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -1941,8 +1941,8 @@ bool BackRenderbuffer::AllocateStorage(const gfx::Size& size, GLenum format, ScopedRenderBufferBinder binder(decoder_, id_); uint32 estimated_size = 0; - if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( - size.width(), size.height(), samples, format, &estimated_size)) { + if (!decoder_->renderbuffer_manager()->ComputeEstimatedRenderbufferSize( + size.width(), size.height(), samples, format, &estimated_size)) { return false; } @@ -5022,8 +5022,8 @@ void GLES2DecoderImpl::DoRenderbufferStorageMultisample( } uint32 estimated_size = 0; - if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( - width, height, samples, internalformat, &estimated_size)) { + if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( + width, height, samples, internalformat, &estimated_size)) { LOCAL_SET_GL_ERROR( GL_OUT_OF_MEMORY, "glRenderbufferStorageMultsample", "dimensions too large"); @@ -5037,8 +5037,9 @@ void GLES2DecoderImpl::DoRenderbufferStorageMultisample( return; } - GLenum impl_format = RenderbufferManager:: - InternalRenderbufferFormatToImplFormat(internalformat); + GLenum impl_format = + renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( + internalformat); LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisample"); if (IsAngle()) { glRenderbufferStorageMultisampleANGLE( @@ -5190,8 +5191,8 @@ void GLES2DecoderImpl::DoRenderbufferStorage( } uint32 estimated_size = 0; - if (!RenderbufferManager::ComputeEstimatedRenderbufferSize( - width, height, 1, internalformat, &estimated_size)) { + if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( + width, height, 1, internalformat, &estimated_size)) { LOCAL_SET_GL_ERROR( GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); return; @@ -5205,9 +5206,11 @@ void GLES2DecoderImpl::DoRenderbufferStorage( LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); glRenderbufferStorageEXT( - target, RenderbufferManager:: - InternalRenderbufferFormatToImplFormat(internalformat), - width, height); + target, + renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( + internalformat), + width, + height); GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); if (error == GL_NO_ERROR) { // TODO(gman): If tetxures tracked which framebuffers they were attached to diff --git a/gpu/command_buffer/service/renderbuffer_manager.cc b/gpu/command_buffer/service/renderbuffer_manager.cc index 0190c44..03c37cb 100644 --- a/gpu/command_buffer/service/renderbuffer_manager.cc +++ b/gpu/command_buffer/service/renderbuffer_manager.cc @@ -17,11 +17,13 @@ namespace gles2 { RenderbufferManager::RenderbufferManager( MemoryTracker* memory_tracker, GLint max_renderbuffer_size, - GLint max_samples) + GLint max_samples, + bool depth24_supported) : memory_tracker_( new MemoryTypeTracker(memory_tracker, MemoryTracker::kUnmanaged)), max_renderbuffer_size_(max_renderbuffer_size), max_samples_(max_samples), + depth24_supported_(depth24_supported), num_uncleared_renderbuffers_(0), renderbuffer_count_(0), have_context_(true) { @@ -38,7 +40,7 @@ RenderbufferManager::~RenderbufferManager() { size_t Renderbuffer::EstimatedSize() { uint32 size = 0; - RenderbufferManager::ComputeEstimatedRenderbufferSize( + manager_->ComputeEstimatedRenderbufferSize( width_, height_, samples_, internal_format_, &size); return size; } @@ -149,8 +151,11 @@ void RenderbufferManager::RemoveRenderbuffer(GLuint client_id) { } } -bool RenderbufferManager::ComputeEstimatedRenderbufferSize( - int width, int height, int samples, int internal_format, uint32* size) { +bool RenderbufferManager::ComputeEstimatedRenderbufferSize(int width, + int height, + int samples, + int internal_format, + uint32* size) const { DCHECK(size); uint32 temp = 0; @@ -170,7 +175,7 @@ bool RenderbufferManager::ComputeEstimatedRenderbufferSize( } GLenum RenderbufferManager::InternalRenderbufferFormatToImplFormat( - GLenum impl_format) { + GLenum impl_format) const { if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { switch (impl_format) { case GL_DEPTH_COMPONENT16: @@ -181,6 +186,10 @@ GLenum RenderbufferManager::InternalRenderbufferFormatToImplFormat( case GL_RGB565: return GL_RGB; } + } else { + // Upgrade 16-bit depth to 24-bit if possible. + if (impl_format == GL_DEPTH_COMPONENT16 && depth24_supported_) + return GL_DEPTH_COMPONENT24; } return impl_format; } diff --git a/gpu/command_buffer/service/renderbuffer_manager.h b/gpu/command_buffer/service/renderbuffer_manager.h index 73fc2cb..707d263 100644 --- a/gpu/command_buffer/service/renderbuffer_manager.h +++ b/gpu/command_buffer/service/renderbuffer_manager.h @@ -126,7 +126,8 @@ class GPU_EXPORT RenderbufferManager { public: RenderbufferManager(MemoryTracker* memory_tracker, GLint max_renderbuffer_size, - GLint max_samples); + GLint max_samples, + bool depth24_supported); ~RenderbufferManager(); GLint max_renderbuffer_size() const { @@ -163,9 +164,12 @@ class GPU_EXPORT RenderbufferManager { return memory_tracker_->GetMemRepresented(); } - static bool ComputeEstimatedRenderbufferSize( - int width, int height, int samples, int internal_format, uint32* size); - static GLenum InternalRenderbufferFormatToImplFormat(GLenum impl_format); + bool ComputeEstimatedRenderbufferSize(int width, + int height, + int samples, + int internal_format, + uint32* size) const; + GLenum InternalRenderbufferFormatToImplFormat(GLenum impl_format) const; private: friend class Renderbuffer; @@ -177,6 +181,7 @@ class GPU_EXPORT RenderbufferManager { GLint max_renderbuffer_size_; GLint max_samples_; + bool depth24_supported_; int num_uncleared_renderbuffers_; diff --git a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc index 20e18c1..c43e94a 100644 --- a/gpu/command_buffer/service/renderbuffer_manager_unittest.cc +++ b/gpu/command_buffer/service/renderbuffer_manager_unittest.cc @@ -8,6 +8,7 @@ #include "gpu/command_buffer/common/gles2_cmd_utils.h" #include "gpu/command_buffer/service/mocks.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_mock.h" using ::testing::StrictMock; @@ -21,11 +22,11 @@ class RenderbufferManagerTestBase : public testing::Test { static const GLint kMaxSamples = 4; protected: - void SetUpBase(MemoryTracker* memory_tracker) { + void SetUpBase(MemoryTracker* memory_tracker, bool depth24_supported) { gl_.reset(new ::testing::StrictMock<gfx::MockGLInterface>()); ::gfx::GLInterface::SetGLInterface(gl_.get()); manager_.reset(new RenderbufferManager( - memory_tracker, kMaxSize, kMaxSamples)); + memory_tracker, kMaxSize, kMaxSamples, depth24_supported)); } virtual void TearDown() { @@ -43,7 +44,8 @@ class RenderbufferManagerTestBase : public testing::Test { class RenderbufferManagerTest : public RenderbufferManagerTestBase { protected: virtual void SetUp() { - SetUpBase(NULL); + bool depth24_supported = false; + SetUpBase(NULL, depth24_supported); } }; @@ -52,7 +54,8 @@ class RenderbufferManagerMemoryTrackerTest protected: virtual void SetUp() { mock_memory_tracker_ = new StrictMock<MockMemoryTracker>(); - SetUpBase(mock_memory_tracker_.get()); + bool depth24_supported = false; + SetUpBase(mock_memory_tracker_.get(), depth24_supported); } scoped_refptr<MockMemoryTracker> mock_memory_tracker_; @@ -179,9 +182,9 @@ TEST_F(RenderbufferManagerMemoryTrackerTest, Basic) { const GLsizei kHeight2 = 32; uint32 expected_size_1 = 0; uint32 expected_size_2 = 0; - RenderbufferManager::ComputeEstimatedRenderbufferSize( + manager_->ComputeEstimatedRenderbufferSize( kWidth, kHeight1, kSamples, kFormat, &expected_size_1); - RenderbufferManager::ComputeEstimatedRenderbufferSize( + manager_->ComputeEstimatedRenderbufferSize( kWidth, kHeight2, kSamples, kFormat, &expected_size_2); EXPECT_MEMORY_ALLOCATION_CHANGE( 0, expected_size_1, MemoryTracker::kUnmanaged); @@ -291,6 +294,28 @@ TEST_F(RenderbufferManagerTest, AddToSignature) { .RetiresOnSaturation(); } +class RenderbufferManagerFormatTest : public RenderbufferManagerTestBase { + protected: + virtual void SetUp() { + bool depth24_supported = true; + SetUpBase(NULL, depth24_supported); + } +}; + +TEST_F(RenderbufferManagerFormatTest, UpgradeDepthFormatOnGLES) { + gfx::SetGLImplementation(gfx::kGLImplementationEGLGLES2); + GLenum impl_format = + manager_->InternalRenderbufferFormatToImplFormat(GL_DEPTH_COMPONENT16); + EXPECT_EQ(static_cast<GLenum>(GL_DEPTH_COMPONENT24), impl_format); +} + +TEST_F(RenderbufferManagerFormatTest, UseUnsizedDepthFormatOnNonGLES) { + gfx::SetGLImplementation(gfx::kGLImplementationDesktopGL); + GLenum impl_format = + manager_->InternalRenderbufferFormatToImplFormat(GL_DEPTH_COMPONENT16); + EXPECT_EQ(static_cast<GLenum>(GL_DEPTH_COMPONENT), impl_format); +} + } // namespace gles2 } // namespace gpu |