Commit 9b0c4393 authored by piman's avatar piman Committed by Commit bot

Use GLVersionInfo instead of gl::GetGLImplementation() to decide GL paths

This is more consistent overall, GetGLImplementation() doesn't tell exactly
whether we're using the core profile, or which version of ES etc.
It also helps testing & fuzzing, because mocks/stubs may implement ES2 but don't
report kGLImplementationEGLGLES2, causing inconsistencies.

BUG=None
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel

Review-Url: https://codereview.chromium.org/2170293002
Cr-Commit-Position: refs/heads/master@{#407276}
parent d5167302
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "gpu/command_buffer/service/memory_tracking.h" #include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/transform_feedback_manager.h" #include "gpu/command_buffer/service/transform_feedback_manager.h"
#include "ui/gl/gl_bindings.h" #include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_version_info.h" #include "ui/gl/gl_version_info.h"
#include "ui/gl/trace_util.h" #include "ui/gl/trace_util.h"
...@@ -359,8 +358,9 @@ bool BufferManager::UseNonZeroSizeForClientSideArrayBuffer() { ...@@ -359,8 +358,9 @@ bool BufferManager::UseNonZeroSizeForClientSideArrayBuffer() {
bool BufferManager::UseShadowBuffer(GLenum target, GLenum usage) { bool BufferManager::UseShadowBuffer(GLenum target, GLenum usage) {
const bool is_client_side_array = IsUsageClientSideArray(usage); const bool is_client_side_array = IsUsageClientSideArray(usage);
// feature_info_ can be null in some unit tests.
const bool support_fixed_attribs = const bool support_fixed_attribs =
gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2; !feature_info_ || feature_info_->gl_version_info().is_es;
// TODO(zmo): Don't shadow buffer data on ES3. crbug.com/491002. // TODO(zmo): Don't shadow buffer data on ES3. crbug.com/491002.
return ( return (
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "gpu/command_buffer/service/gl_utils.h" #include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h" #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_version_info.h"
namespace { namespace {
...@@ -94,11 +94,11 @@ const char* kShaderPrecisionPreamble = "\ ...@@ -94,11 +94,11 @@ const char* kShaderPrecisionPreamble = "\
#define TexCoordPrecision\n\ #define TexCoordPrecision\n\
#endif\n"; #endif\n";
std::string GetVertexShaderSource() { std::string GetVertexShaderSource(const gl::GLVersionInfo& gl_version_info) {
std::string source; std::string source;
// Preamble for core and compatibility mode. // Preamble for core and compatibility mode.
if (gl::GetGLImplementation() == gl::kGLImplementationDesktopGLCoreProfile) { if (gl_version_info.is_desktop_core_profile) {
source += std::string("\ source += std::string("\
#version 150\n\ #version 150\n\
#define ATTRIBUTE in\n\ #define ATTRIBUTE in\n\
...@@ -130,13 +130,14 @@ std::string GetVertexShaderSource() { ...@@ -130,13 +130,14 @@ std::string GetVertexShaderSource() {
return source; return source;
} }
std::string GetFragmentShaderSource(bool premultiply_alpha, std::string GetFragmentShaderSource(const gl::GLVersionInfo& gl_version_info,
bool premultiply_alpha,
bool unpremultiply_alpha, bool unpremultiply_alpha,
GLenum target) { GLenum target) {
std::string source; std::string source;
// Preamble for core and compatibility mode. // Preamble for core and compatibility mode.
if (gl::GetGLImplementation() == gl::kGLImplementationDesktopGLCoreProfile) { if (gl_version_info.is_desktop_core_profile) {
source += std::string("\ source += std::string("\
#version 150\n\ #version 150\n\
out vec4 frag_color;\n\ out vec4 frag_color;\n\
...@@ -574,12 +575,13 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( ...@@ -574,12 +575,13 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal(
DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager."; DLOG(ERROR) << "CopyTextureCHROMIUM: Uninitialized manager.";
return; return;
} }
const gl::GLVersionInfo& gl_version_info =
decoder->GetFeatureInfo()->gl_version_info();
if (vertex_array_object_id_) { if (vertex_array_object_id_) {
glBindVertexArrayOES(vertex_array_object_id_); glBindVertexArrayOES(vertex_array_object_id_);
} else { } else {
if (gl::GetGLImplementation() != if (!gl_version_info.is_desktop_core_profile) {
gl::kGLImplementationDesktopGLCoreProfile) {
decoder->ClearAllAttributes(); decoder->ClearAllAttributes();
} }
glEnableVertexAttribArray(kVertexPositionAttrib); glEnableVertexAttribArray(kVertexPositionAttrib);
...@@ -598,15 +600,16 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal( ...@@ -598,15 +600,16 @@ void CopyTextureCHROMIUMResourceManager::DoCopyTextureInternal(
info->program = glCreateProgram(); info->program = glCreateProgram();
if (!vertex_shader_) { if (!vertex_shader_) {
vertex_shader_ = glCreateShader(GL_VERTEX_SHADER); vertex_shader_ = glCreateShader(GL_VERTEX_SHADER);
std::string source = GetVertexShaderSource(); std::string source = GetVertexShaderSource(gl_version_info);
CompileShader(vertex_shader_, source.c_str()); CompileShader(vertex_shader_, source.c_str());
} }
glAttachShader(info->program, vertex_shader_); glAttachShader(info->program, vertex_shader_);
GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id]; GLuint* fragment_shader = &fragment_shaders_[fragment_shader_id];
if (!*fragment_shader) { if (!*fragment_shader) {
*fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); *fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
std::string source = GetFragmentShaderSource( std::string source =
premultiply_alpha, unpremultiply_alpha, source_target); GetFragmentShaderSource(gl_version_info, premultiply_alpha,
unpremultiply_alpha, source_target);
CompileShader(*fragment_shader, source.c_str()); CompileShader(*fragment_shader, source.c_str());
} }
glAttachShader(info->program, *fragment_shader); glAttachShader(info->program, *fragment_shader);
......
...@@ -41,6 +41,7 @@ namespace gles2 { ...@@ -41,6 +41,7 @@ namespace gles2 {
class ContextGroup; class ContextGroup;
class ErrorState; class ErrorState;
class FeatureInfo;
class GLES2Util; class GLES2Util;
class ImageManager; class ImageManager;
class Logger; class Logger;
...@@ -184,6 +185,7 @@ class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>, ...@@ -184,6 +185,7 @@ class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
// Gets the associated ContextGroup // Gets the associated ContextGroup
virtual ContextGroup* GetContextGroup() = 0; virtual ContextGroup* GetContextGroup() = 0;
virtual const FeatureInfo* GetFeatureInfo() const = 0;
virtual Capabilities GetCapabilities() = 0; virtual Capabilities GetCapabilities() = 0;
......
...@@ -65,6 +65,7 @@ class MockGLES2Decoder : public GLES2Decoder { ...@@ -65,6 +65,7 @@ class MockGLES2Decoder : public GLES2Decoder {
MOCK_METHOD0(GetGLSurface, gl::GLSurface*()); MOCK_METHOD0(GetGLSurface, gl::GLSurface*());
MOCK_METHOD0(GetGLContext, gl::GLContext*()); MOCK_METHOD0(GetGLContext, gl::GLContext*());
MOCK_METHOD0(GetContextGroup, ContextGroup*()); MOCK_METHOD0(GetContextGroup, ContextGroup*());
MOCK_CONST_METHOD0(GetFeatureInfo, const FeatureInfo*());
MOCK_METHOD0(GetContextState, const ContextState*()); MOCK_METHOD0(GetContextState, const ContextState*());
MOCK_METHOD1(GetTranslator, MOCK_METHOD1(GetTranslator,
scoped_refptr<ShaderTranslatorInterface>(unsigned int type)); scoped_refptr<ShaderTranslatorInterface>(unsigned int type));
......
...@@ -174,6 +174,10 @@ gpu::gles2::ContextGroup* GLES2DecoderPassthroughImpl::GetContextGroup() { ...@@ -174,6 +174,10 @@ gpu::gles2::ContextGroup* GLES2DecoderPassthroughImpl::GetContextGroup() {
return nullptr; return nullptr;
} }
const FeatureInfo* GLES2DecoderPassthroughImpl::GetFeatureInfo() const {
return nullptr;
}
gpu::Capabilities GLES2DecoderPassthroughImpl::GetCapabilities() { gpu::Capabilities GLES2DecoderPassthroughImpl::GetCapabilities() {
DCHECK(initialized()); DCHECK(initialized());
Capabilities caps; Capabilities caps;
......
...@@ -73,6 +73,8 @@ class GLES2DecoderPassthroughImpl : public GLES2Decoder { ...@@ -73,6 +73,8 @@ class GLES2DecoderPassthroughImpl : public GLES2Decoder {
// Gets the associated ContextGroup // Gets the associated ContextGroup
ContextGroup* GetContextGroup() override; ContextGroup* GetContextGroup() override;
const FeatureInfo* GetFeatureInfo() const override;
Capabilities GetCapabilities() override; Capabilities GetCapabilities() override;
// Restores all of the decoder GL state. // Restores all of the decoder GL state.
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "gpu/command_buffer/service/test_helper.h" #include "gpu/command_buffer/service/test_helper.h"
#include "gpu/command_buffer/service/vertex_attrib_manager.h" #include "gpu/command_buffer/service/vertex_attrib_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h" #include "ui/gl/gl_mock.h"
#include "ui/gl/init/gl_factory.h" #include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_surface_test_support.h" #include "ui/gl/test/gl_surface_test_support.h"
...@@ -394,6 +393,12 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine( ...@@ -394,6 +393,12 @@ void GLES2DecoderTestBase::InitDecoderWithCommandLine(
.RetiresOnSaturation(); .RetiresOnSaturation();
} }
if (group_->feature_info()->gl_version_info().is_es) {
EXPECT_CALL(
*gl_, GetShaderPrecisionFormat(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, _, _))
.RetiresOnSaturation();
}
static GLint max_viewport_dims[] = { static GLint max_viewport_dims[] = {
kMaxViewportWidth, kMaxViewportWidth,
kMaxViewportHeight kMaxViewportHeight
...@@ -1486,8 +1491,7 @@ void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) { ...@@ -1486,8 +1491,7 @@ void GLES2DecoderTestBase::AddExpectationsForRestoreAttribState(GLuint attrib) {
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
if (attrib != 0 || if (attrib != 0 || group_->feature_info()->gl_version_info().is_es) {
gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2) {
// TODO(bajones): Not sure if I can tell which of these will be called // TODO(bajones): Not sure if I can tell which of these will be called
EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib)) EXPECT_CALL(*gl_, EnableVertexAttribArray(attrib))
.Times(testing::AtMost(1)) .Times(testing::AtMost(1))
......
...@@ -607,8 +607,14 @@ TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) { ...@@ -607,8 +607,14 @@ TEST_P(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) {
EXPECT_NE(error::kNoError, ExecuteCmd(cmd)); EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
} }
TEST_P(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatSucceeds) { TEST_P(GLES2DecoderManualInitTest, GetShaderPrecisionFormatSucceeds) {
ScopedGLImplementationSetter gl_impl(::gl::kGLImplementationEGLGLES2); // Force ES underlying implementation to ensure we check the shader precision
// format.
InitState init;
init.gl_version = "opengl es 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
GetShaderPrecisionFormat cmd; GetShaderPrecisionFormat cmd;
typedef GetShaderPrecisionFormat::Result Result; typedef GetShaderPrecisionFormat::Result Result;
Result* result = static_cast<Result*>(shared_memory_address_); Result* result = static_cast<Result*>(shared_memory_address_);
......
...@@ -1184,16 +1184,6 @@ sh::OutputVariable TestHelper::ConstructOutputVariable( ...@@ -1184,16 +1184,6 @@ sh::OutputVariable TestHelper::ConstructOutputVariable(
type, array_size, precision, static_use, name); type, array_size, precision, static_use, name);
} }
ScopedGLImplementationSetter::ScopedGLImplementationSetter(
gl::GLImplementation implementation)
: old_implementation_(gl::GetGLImplementation()) {
gl::SetGLImplementation(implementation);
}
ScopedGLImplementationSetter::~ScopedGLImplementationSetter() {
gl::SetGLImplementation(old_implementation_);
}
} // namespace gles2 } // namespace gles2
} // namespace gpu } // namespace gpu
...@@ -227,18 +227,6 @@ class TestHelper { ...@@ -227,18 +227,6 @@ class TestHelper {
static std::vector<std::string> split_extensions_; static std::vector<std::string> split_extensions_;
}; };
// This object temporaritly Sets what gl::GetGLImplementation returns. During
// testing the GLImplementation is set to kGLImplemenationMockGL but lots of
// code branches based on what gl::GetGLImplementation returns.
class ScopedGLImplementationSetter {
public:
explicit ScopedGLImplementationSetter(gl::GLImplementation implementation);
~ScopedGLImplementationSetter();
private:
gl::GLImplementation old_implementation_;
};
} // namespace gles2 } // namespace gles2
} // namespace gpu } // namespace gpu
......
...@@ -222,7 +222,7 @@ class TextureUploadPerfTest : public testing::Test { ...@@ -222,7 +222,7 @@ class TextureUploadPerfTest : public testing::Test {
// used to draw a quad on the offscreen surface. // used to draw a quad on the offscreen surface.
vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader); vertex_shader_ = LoadShader(GL_VERTEX_SHADER, kVertexShader);
bool is_gles = gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2; bool is_gles = gl_context_->GetVersionInfo()->is_es;
fragment_shader_ = LoadShader( fragment_shader_ = LoadShader(
GL_FRAGMENT_SHADER, GL_FRAGMENT_SHADER,
base::StringPrintf("%s%s", is_gles ? kShaderDefaultFloatPrecision : "", base::StringPrintf("%s%s", is_gles ? kShaderDefaultFloatPrecision : "",
......
...@@ -206,7 +206,7 @@ bool GLContextCGL::ForceGpuSwitchIfNeeded() { ...@@ -206,7 +206,7 @@ bool GLContextCGL::ForceGpuSwitchIfNeeded() {
YUVToRGBConverter* GLContextCGL::GetYUVToRGBConverter() { YUVToRGBConverter* GLContextCGL::GetYUVToRGBConverter() {
if (!yuv_to_rgb_converter_) if (!yuv_to_rgb_converter_)
yuv_to_rgb_converter_.reset(new YUVToRGBConverter); yuv_to_rgb_converter_.reset(new YUVToRGBConverter(*GetVersionInfo()));
return yuv_to_rgb_converter_.get(); return yuv_to_rgb_converter_.get();
} }
......
...@@ -30,7 +30,7 @@ GLFence::~GLFence() { ...@@ -30,7 +30,7 @@ GLFence::~GLFence() {
bool GLFence::IsSupported() { bool GLFence::IsSupported() {
DCHECK(GetGLVersionInfo()); DCHECK(GetGLVersionInfo());
return g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 || return g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 ||
GetGLImplementation() == kGLImplementationDesktopGLCoreProfile || GetGLVersionInfo()->is_desktop_core_profile ||
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
g_driver_gl.ext.b_GL_APPLE_fence || g_driver_gl.ext.b_GL_APPLE_fence ||
#else #else
...@@ -52,7 +52,7 @@ GLFence* GLFence::Create() { ...@@ -52,7 +52,7 @@ GLFence* GLFence::Create() {
} else } else
#endif #endif
if (g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 || if (g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 ||
GetGLImplementation() == kGLImplementationDesktopGLCoreProfile) { GetGLVersionInfo()->is_desktop_core_profile) {
// Prefer ARB_sync which supports server-side wait. // Prefer ARB_sync which supports server-side wait.
fence.reset(new GLFenceARB); fence.reset(new GLFenceARB);
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
......
...@@ -217,7 +217,7 @@ static inline GLenum GetTexFormat(GLenum format) { ...@@ -217,7 +217,7 @@ static inline GLenum GetTexFormat(GLenum format) {
} }
static inline GLenum GetTexType(GLenum type) { static inline GLenum GetTexType(GLenum type) {
if (GetGLImplementation() != kGLImplementationEGLGLES2) { if (!g_version_info->is_es) {
if (type == GL_HALF_FLOAT_OES) if (type == GL_HALF_FLOAT_OES)
return GL_HALF_FLOAT_ARB; return GL_HALF_FLOAT_ARB;
} }
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_helper.h" #include "ui/gl/gl_helper.h"
#include "ui/gl/gl_image.h" #include "ui/gl/gl_image.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_surface.h" #include "ui/gl/gl_surface.h"
#include "ui/gl/gl_version_info.h"
#include "ui/gl/init/gl_factory.h" #include "ui/gl/init/gl_factory.h"
#include "ui/gl/test/gl_image_test_support.h" #include "ui/gl/test/gl_image_test_support.h"
#include "ui/gl/test/gl_test_helper.h" #include "ui/gl/test/gl_test_helper.h"
...@@ -51,7 +51,7 @@ GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) { ...@@ -51,7 +51,7 @@ GLuint LoadFragmentShader(unsigned target, const gfx::Size& size) {
); );
// clang-format on // clang-format on
bool is_gles = GetGLImplementation() == kGLImplementationEGLGLES2; bool is_gles = GLContext::GetCurrent()->GetVersionInfo()->is_es;
switch (target) { switch (target) {
case GL_TEXTURE_2D: case GL_TEXTURE_2D:
return GLHelper::LoadShader( return GLHelper::LoadShader(
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/strings/stringize_macros.h" #include "base/strings/stringize_macros.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "ui/gl/gl_helper.h" #include "ui/gl/gl_helper.h"
#include "ui/gl/gl_implementation.h" #include "ui/gl/gl_version_info.h"
#include "ui/gl/scoped_api.h" #include "ui/gl/scoped_api.h"
#include "ui/gl/scoped_binders.h" #include "ui/gl/scoped_binders.h"
...@@ -70,9 +70,8 @@ STRINGIZE( ...@@ -70,9 +70,8 @@ STRINGIZE(
} // namespace } // namespace
YUVToRGBConverter::YUVToRGBConverter() { YUVToRGBConverter::YUVToRGBConverter(const GLVersionInfo& gl_version_info) {
bool use_core_profile = bool use_core_profile = gl_version_info.is_desktop_core_profile;
GetGLImplementation() == kGLImplementationDesktopGLCoreProfile;
ScopedSetGLToRealGLApi scoped_set_gl_api; ScopedSetGLToRealGLApi scoped_set_gl_api;
glGenFramebuffersEXT(1, &framebuffer_); glGenFramebuffersEXT(1, &framebuffer_);
vertex_buffer_ = GLHelper::SetupQuadVertexBuffer(); vertex_buffer_ = GLHelper::SetupQuadVertexBuffer();
......
...@@ -9,9 +9,11 @@ ...@@ -9,9 +9,11 @@
namespace gl { namespace gl {
struct GLVersionInfo;
class YUVToRGBConverter { class YUVToRGBConverter {
public: public:
YUVToRGBConverter(); explicit YUVToRGBConverter(const GLVersionInfo& gl_version_info);
~YUVToRGBConverter(); ~YUVToRGBConverter();
// The input Y and UV textures should be bound to these texture objects // The input Y and UV textures should be bound to these texture objects
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment