| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/service/gl_utils.h" | 7 #include "gpu/command_buffer/service/gl_utils.h" |
| 8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" | 8 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 9 #include "ui/gfx/geometry/size.h" | 9 #include "ui/gfx/geometry/size.h" |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DLOG(ERROR) << "Shader compilation failure."; | 49 DLOG(ERROR) << "Shader compilation failure."; |
| 50 } | 50 } |
| 51 #endif | 51 #endif |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 namespace gpu { | 56 namespace gpu { |
| 57 | 57 |
| 58 ClearFramebufferResourceManager::ClearFramebufferResourceManager( | 58 ClearFramebufferResourceManager::ClearFramebufferResourceManager( |
| 59 const gles2::GLES2Decoder* decoder, | 59 const gles2::GLES2Decoder* decoder) |
| 60 const gles2::FeatureInfo::FeatureFlags& feature_flags) | 60 : initialized_(false), program_(0u), buffer_id_(0u) { |
| 61 : initialized_(false), program_(0u), vao_(0), buffer_id_(0u) { | 61 Initialize(decoder); |
| 62 Initialize(decoder, feature_flags); | |
| 63 } | 62 } |
| 64 | 63 |
| 65 ClearFramebufferResourceManager::~ClearFramebufferResourceManager() { | 64 ClearFramebufferResourceManager::~ClearFramebufferResourceManager() { |
| 66 Destroy(); | 65 Destroy(); |
| 67 DCHECK(!buffer_id_); | 66 DCHECK(!buffer_id_); |
| 68 } | 67 } |
| 69 | 68 |
| 70 void ClearFramebufferResourceManager::Initialize( | 69 void ClearFramebufferResourceManager::Initialize( |
| 71 const gles2::GLES2Decoder* decoder, | 70 const gles2::GLES2Decoder* decoder) { |
| 72 const gles2::FeatureInfo::FeatureFlags& feature_flags) { | |
| 73 static_assert( | 71 static_assert( |
| 74 kVertexPositionAttrib == 0u, | 72 kVertexPositionAttrib == 0u, |
| 75 "kVertexPositionAttrib must be 0"); | 73 "kVertexPositionAttrib must be 0"); |
| 74 DCHECK(!buffer_id_); |
| 76 | 75 |
| 77 DCHECK(!buffer_id_); | |
| 78 glGenBuffersARB(1, &buffer_id_); | 76 glGenBuffersARB(1, &buffer_id_); |
| 79 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 77 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
| 80 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, | 78 const GLfloat kQuadVertices[] = {-1.0f, -1.0f, |
| 81 1.0f, -1.0f, | 79 1.0f, -1.0f, |
| 82 1.0f, 1.0f, | 80 1.0f, 1.0f, |
| 83 -1.0f, 1.0f}; | 81 -1.0f, 1.0f}; |
| 84 glBufferData( | 82 glBufferData( |
| 85 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); | 83 GL_ARRAY_BUFFER, sizeof(kQuadVertices), kQuadVertices, GL_STATIC_DRAW); |
| 86 | |
| 87 DCHECK(!vao_); | |
| 88 | |
| 89 if (feature_flags.native_vertex_array_object) { | |
| 90 glGenVertexArraysOES(1, &vao_); | |
| 91 | |
| 92 glBindVertexArrayOES(vao_); | |
| 93 glEnableVertexAttribArray(kVertexPositionAttrib); | |
| 94 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
| 95 | |
| 96 decoder->RestoreAllAttributes(); | |
| 97 } | |
| 98 | |
| 99 decoder->RestoreBufferBindings(); | 84 decoder->RestoreBufferBindings(); |
| 100 initialized_ = true; | 85 initialized_ = true; |
| 101 } | 86 } |
| 102 | 87 |
| 103 void ClearFramebufferResourceManager::Destroy() { | 88 void ClearFramebufferResourceManager::Destroy() { |
| 104 if (!initialized_) | 89 if (!initialized_) |
| 105 return; | 90 return; |
| 106 | 91 |
| 107 glDeleteProgram(program_); | 92 glDeleteProgram(program_); |
| 108 | |
| 109 if (vao_ != 0) { | |
| 110 glDeleteVertexArraysOES(1, &vao_); | |
| 111 vao_ = 0; | |
| 112 } | |
| 113 | |
| 114 glDeleteBuffersARB(1, &buffer_id_); | 93 glDeleteBuffersARB(1, &buffer_id_); |
| 115 buffer_id_ = 0; | 94 buffer_id_ = 0; |
| 116 } | 95 } |
| 117 | 96 |
| 118 void ClearFramebufferResourceManager::ClearFramebuffer( | 97 void ClearFramebufferResourceManager::ClearFramebuffer( |
| 119 const gles2::GLES2Decoder* decoder, | 98 const gles2::GLES2Decoder* decoder, |
| 120 const gfx::Size& framebuffer_size, | 99 const gfx::Size& framebuffer_size, |
| 121 GLbitfield mask, | 100 GLbitfield mask, |
| 122 GLfloat clear_color_red, | 101 GLfloat clear_color_red, |
| 123 GLfloat clear_color_green, | 102 GLfloat clear_color_green, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 154 glUseProgram(program_); | 133 glUseProgram(program_); |
| 155 | 134 |
| 156 #if DCHECK_IS_ON() | 135 #if DCHECK_IS_ON() |
| 157 glValidateProgram(program_); | 136 glValidateProgram(program_); |
| 158 GLint validation_status = GL_FALSE; | 137 GLint validation_status = GL_FALSE; |
| 159 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); | 138 glGetProgramiv(program_, GL_VALIDATE_STATUS, &validation_status); |
| 160 if (GL_TRUE != validation_status) | 139 if (GL_TRUE != validation_status) |
| 161 DLOG(ERROR) << "Invalid shader."; | 140 DLOG(ERROR) << "Invalid shader."; |
| 162 #endif | 141 #endif |
| 163 | 142 |
| 164 if (vao_) { | 143 decoder->ClearAllAttributes(); |
| 165 glBindVertexArrayOES(vao_); | 144 glEnableVertexAttribArray(kVertexPositionAttrib); |
| 166 } else { | 145 |
| 167 decoder->ClearAllAttributes(); | 146 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); |
| 168 glBindBuffer(GL_ARRAY_BUFFER, buffer_id_); | 147 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); |
| 169 glEnableVertexAttribArray(kVertexPositionAttrib); | |
| 170 glVertexAttribPointer(kVertexPositionAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0); | |
| 171 } | |
| 172 | 148 |
| 173 glUniform1f(depth_handle_, clear_depth_value); | 149 glUniform1f(depth_handle_, clear_depth_value); |
| 174 glUniform4f(color_handle_, clear_color_red, clear_color_green, | 150 glUniform4f(color_handle_, clear_color_red, clear_color_green, |
| 175 clear_color_blue, clear_color_alpha); | 151 clear_color_blue, clear_color_alpha); |
| 176 | 152 |
| 177 if (!(mask & GL_COLOR_BUFFER_BIT)) { | 153 if (!(mask & GL_COLOR_BUFFER_BIT)) { |
| 178 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | 154 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); |
| 179 } | 155 } |
| 180 | 156 |
| 181 if (mask & GL_DEPTH_BUFFER_BIT) { | 157 if (mask & GL_DEPTH_BUFFER_BIT) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 196 glStencilMask(0); | 172 glStencilMask(0); |
| 197 } | 173 } |
| 198 | 174 |
| 199 glDisable(GL_CULL_FACE); | 175 glDisable(GL_CULL_FACE); |
| 200 glDisable(GL_BLEND); | 176 glDisable(GL_BLEND); |
| 201 glDisable(GL_POLYGON_OFFSET_FILL); | 177 glDisable(GL_POLYGON_OFFSET_FILL); |
| 202 | 178 |
| 203 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); | 179 glViewport(0, 0, framebuffer_size.width(), framebuffer_size.height()); |
| 204 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 180 glDrawArrays(GL_TRIANGLE_FAN, 0, 4); |
| 205 | 181 |
| 206 if (vao_ == 0) { | |
| 207 decoder->RestoreBufferBindings(); | |
| 208 } | |
| 209 decoder->RestoreAllAttributes(); | 182 decoder->RestoreAllAttributes(); |
| 210 decoder->RestoreProgramBindings(); | 183 decoder->RestoreProgramBindings(); |
| 184 decoder->RestoreBufferBindings(); |
| 211 decoder->RestoreGlobalState(); | 185 decoder->RestoreGlobalState(); |
| 212 } | 186 } |
| 213 | 187 |
| 214 } // namespace gpu | 188 } // namespace gpu |
| OLD | NEW |