Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc

Issue 2764833003: Make gl_clear_broken workaround support core profile and use it under AMD Linux Catalyst driver (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc
diff --git a/gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc b/gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc
index b0fcd5f61958e38bde5bfcde865ee18c8d8a9735..9e6eccebc4b92bfde846db72d6b00636ff4ed795 100644
--- a/gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc
+++ b/gpu/command_buffer/service/gles2_cmd_clear_framebuffer.cc
@@ -7,6 +7,7 @@
#include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "ui/gfx/geometry/size.h"
+#include "ui/gl/gl_version_info.h"
namespace {
@@ -34,8 +35,16 @@ const char* g_fragment_shader_source = {
),
};
-void CompileShader(GLuint shader, const char* shader_source) {
- glShaderSource(shader, 1, &shader_source, 0);
+void CompileShader(GLuint shader,
+ const char* shader_source,
+ bool is_desktop_core_profile) {
+ if (is_desktop_core_profile) {
+ const char* version = "#version 150\n";
+ const char* shader_sources[2] = {version, shader_source};
+ glShaderSource(shader, 2, shader_sources, 0);
+ } else {
+ glShaderSource(shader, 1, &shader_source, 0);
+ }
glCompileShader(shader);
#if DCHECK_IS_ON()
GLint compile_status = GL_FALSE;
@@ -57,8 +66,13 @@ namespace gpu {
namespace gles2 {
ClearFramebufferResourceManager::ClearFramebufferResourceManager(
- const gles2::GLES2Decoder* decoder)
- : initialized_(false), program_(0u), buffer_id_(0u) {
+ const gles2::GLES2Decoder* decoder,
+ const gl::GLVersionInfo& gl_version_info)
+ : initialized_(false),
+ is_desktop_core_profile_(gl_version_info.is_desktop_core_profile),
+ program_(0u),
+ vao_(0),
Zhenyao Mo 2017/03/23 17:11:40 nit: 0u to be consistent with above and below
+ buffer_id_(0u) {
Initialize(decoder);
}
@@ -82,6 +96,15 @@ void ClearFramebufferResourceManager::Initialize(
-1.0f, 1.0f};
glBufferData(
GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW);
+
+ if (is_desktop_core_profile_) {
+ glGenVertexArraysOES(1, &vao_);
+ glBindVertexArrayOES(vao_);
+ glEnableVertexAttribArray(kVertexPositionAttrib);
+ glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ decoder->RestoreAllAttributes();
+ }
+
decoder->RestoreBufferBindings();
initialized_ = true;
}
@@ -91,6 +114,10 @@ void ClearFramebufferResourceManager::Destroy() {
return;
glDeleteProgram(program_);
+ if (vao_ != 0) {
+ glDeleteVertexArraysOES(1, &vao_);
+ vao_ = 0;
+ }
glDeleteBuffersARB(1, &buffer_id_);
buffer_id_ = 0;
}
@@ -113,10 +140,12 @@ void ClearFramebufferResourceManager::ClearFramebuffer(
if (!program_) {
program_ = glCreateProgram();
GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
- CompileShader(vertex_shader, g_vertex_shader_source);
+ CompileShader(vertex_shader, g_vertex_shader_source,
+ is_desktop_core_profile_);
glAttachShader(program_, vertex_shader);
GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);
- CompileShader(fragment_shader, g_fragment_shader_source);
+ CompileShader(fragment_shader, g_fragment_shader_source,
+ is_desktop_core_profile_);
glAttachShader(program_, fragment_shader);
glBindAttribLocation(program_, kVertexPositionAttrib, "a_position");
glLinkProgram(program_);
@@ -141,11 +170,15 @@ void ClearFramebufferResourceManager::ClearFramebuffer(
DLOG(ERROR) << "Invalid shader.";
#endif
- decoder->ClearAllAttributes();
- glEnableVertexAttribArray(kVertexPositionAttrib);
+ if (vao_) {
+ glBindVertexArrayOES(vao_);
+ } else {
+ decoder->ClearAllAttributes();
+ glEnableVertexAttribArray(kVertexPositionAttrib);
- glBindBuffer(GL_ARRAY_BUFFER, buffer_id_);
- glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ glBindBuffer(GL_ARRAY_BUFFER, buffer_id_);
+ glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ }
glUniform1f(depth_handle_, clear_depth_value);
glUniform4f(color_handle_, clear_color_red, clear_color_green,
@@ -180,9 +213,11 @@ void ClearFramebufferResourceManager::ClearFramebuffer(
glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height());
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ if (vao_ == 0) {
+ decoder->RestoreBufferBindings();
+ }
decoder->RestoreAllAttributes();
decoder->RestoreProgramBindings();
- decoder->RestoreBufferBindings();
decoder->RestoreGlobalState();
}
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698