Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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_srgb_converter.h" | 5 #include "gpu/command_buffer/service/gles2_cmd_srgb_converter.h" |
| 6 | 6 |
| 7 #include "gpu/command_buffer/service/texture_manager.h" | 7 #include "gpu/command_buffer/service/texture_manager.h" |
| 8 #include "ui/gl/gl_version_info.h" | 8 #include "ui/gl/gl_version_info.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 // The steps are: | 191 // The steps are: |
| 192 // 1) Copy and crop pixels from source srgb image to the 1st texture(srgb). | 192 // 1) Copy and crop pixels from source srgb image to the 1st texture(srgb). |
| 193 // 2) Sampling from the 1st texture and drawing to the 2nd texture(linear). | 193 // 2) Sampling from the 1st texture and drawing to the 2nd texture(linear). |
| 194 // During this step, color space is converted from srgb to linear. | 194 // During this step, color space is converted from srgb to linear. |
| 195 // 3) Blit pixels from the 2nd texture to the 3rd texture(linear). | 195 // 3) Blit pixels from the 2nd texture to the 3rd texture(linear). |
| 196 // 4) Sampling from the 3rd texture and drawing to the dst image(srgb). | 196 // 4) Sampling from the 3rd texture and drawing to the dst image(srgb). |
| 197 // During this step, color space is converted from linear to srgb. | 197 // During this step, color space is converted from linear to srgb. |
| 198 // If we need to blit from linear to srgb or vice versa, some steps will be | 198 // If we need to blit from linear to srgb or vice versa, some steps will be |
| 199 // skipped. | 199 // skipped. |
| 200 DCHECK(srgb_converter_initialized_); | 200 DCHECK(srgb_converter_initialized_); |
| 201 // Use RGBA32F as the temp texture's internalformat to prevent precision | |
| 202 // loss during conversion. But it is not color-renderable and | |
| 203 // texture-filterable in ES context. | |
| 204 DCHECK(feature_info_->context_type() != CONTEXT_TYPE_OPENGLES2 && | |
|
Zhenyao Mo
2016/10/18 02:20:35
This is incorrect. If context_type() is ES2 or ES3
yunchao
2016/10/18 07:42:52
Done.
| |
| 205 feature_info_->context_type() != CONTEXT_TYPE_OPENGLES3); | |
| 201 | 206 |
| 202 // Set the states | 207 // Set the states |
| 203 glActiveTexture(GL_TEXTURE0); | 208 glActiveTexture(GL_TEXTURE0); |
| 204 glDisable(GL_SCISSOR_TEST); | 209 glDisable(GL_SCISSOR_TEST); |
| 205 glDisable(GL_DEPTH_TEST); | 210 glDisable(GL_DEPTH_TEST); |
| 206 glDisable(GL_STENCIL_TEST); | 211 glDisable(GL_STENCIL_TEST); |
| 207 glDisable(GL_CULL_FACE); | 212 glDisable(GL_CULL_FACE); |
| 208 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | 213 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 209 glDepthMask(GL_FALSE); | 214 glDepthMask(GL_FALSE); |
| 210 glDisable(GL_BLEND); | 215 glDisable(GL_BLEND); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 232 xoffset = c.x() - x; | 237 xoffset = c.x() - x; |
| 233 yoffset = c.y() - y; | 238 yoffset = c.y() - y; |
| 234 glCopyTexImage2D(GL_TEXTURE_2D, 0, src_framebuffer_internal_format, | 239 glCopyTexImage2D(GL_TEXTURE_2D, 0, src_framebuffer_internal_format, |
| 235 c.x(), c.y(), c.width(), c.height(), 0); | 240 c.x(), c.y(), c.width(), c.height(), 0); |
| 236 | 241 |
| 237 // Make a temporary linear texture as the 2nd texture, where we | 242 // Make a temporary linear texture as the 2nd texture, where we |
| 238 // render the converted (srgb to linear) result to. | 243 // render the converted (srgb to linear) result to. |
| 239 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | 244 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 240 | 245 |
| 241 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | 246 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); |
| 242 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | 247 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, |
| 243 c.width(), c.height(), | 248 c.width(), c.height(), |
| 244 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); | 249 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); |
| 245 glBindFramebufferEXT(GL_FRAMEBUFFER, srgb_decoder_fbo_); | 250 glBindFramebufferEXT(GL_FRAMEBUFFER, srgb_decoder_fbo_); |
| 246 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 251 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 247 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); | 252 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); |
| 248 | 253 |
| 249 // Sampling from the 1st texture(srgb) and drawing to the | 254 // Sampling from the 1st texture(srgb) and drawing to the |
| 250 // 2nd texture(linear), | 255 // 2nd texture(linear), |
| 251 glUseProgram(srgb_converter_program_); | 256 glUseProgram(srgb_converter_program_); |
| 252 glViewport(0, 0, width_read, height_read); | 257 glViewport(0, 0, width_read, height_read); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 265 // from the 2nd texture(linear) to the 3rd texture. Filtering is done | 270 // from the 2nd texture(linear) to the 3rd texture. Filtering is done |
| 266 // during bliting. Note that the src and dst coordinates may be reversed. | 271 // during bliting. Note that the src and dst coordinates may be reversed. |
| 267 GLuint width_draw = 0, height_draw = 0; | 272 GLuint width_draw = 0, height_draw = 0; |
| 268 if (encode) { | 273 if (encode) { |
| 269 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); | 274 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); |
| 270 | 275 |
| 271 width_draw = dstX1 > dstX0 ? dstX1 - dstX0 : dstX0 - dstX1; | 276 width_draw = dstX1 > dstX0 ? dstX1 - dstX0 : dstX0 - dstX1; |
| 272 height_draw = dstY1 > dstY0 ? dstY1 - dstY0 : dstY0 - dstY1; | 277 height_draw = dstY1 > dstY0 ? dstY1 - dstY0 : dstY0 - dstY1; |
| 273 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | 278 glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 274 glTexImage2D( | 279 glTexImage2D( |
| 275 GL_TEXTURE_2D, 0, decode ? GL_RGBA : src_framebuffer_internal_format, | 280 GL_TEXTURE_2D, 0, decode ? GL_RGBA32F : src_framebuffer_internal_format, |
| 276 width_draw, height_draw, 0, | 281 width_draw, height_draw, 0, |
| 277 decode ? GL_RGBA : src_framebuffer_format, | 282 decode ? GL_RGBA : src_framebuffer_format, |
| 278 decode ? GL_UNSIGNED_BYTE : src_framebuffer_type, | 283 decode ? GL_UNSIGNED_BYTE : src_framebuffer_type, |
| 279 nullptr); | 284 nullptr); |
| 280 | 285 |
| 281 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); | 286 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); |
| 282 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | 287 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 283 GL_TEXTURE_2D, srgb_converter_textures_[0], 0); | 288 GL_TEXTURE_2D, srgb_converter_textures_[0], 0); |
| 284 } else { | 289 } else { |
| 285 // Set approriate draw framebuffer if encoding is skipped. | 290 // Set approriate draw framebuffer if encoding is skipped. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 decoder->RestoreActiveTexture(); | 425 decoder->RestoreActiveTexture(); |
| 421 decoder->RestoreProgramBindings(); | 426 decoder->RestoreProgramBindings(); |
| 422 decoder->RestoreBufferBindings(); | 427 decoder->RestoreBufferBindings(); |
| 423 decoder->RestoreFramebufferBindings(); | 428 decoder->RestoreFramebufferBindings(); |
| 424 decoder->RestoreGlobalState(); | 429 decoder->RestoreGlobalState(); |
| 425 decoder->RestoreTextureState(tex->service_id()); | 430 decoder->RestoreTextureState(tex->service_id()); |
| 426 } | 431 } |
| 427 | 432 |
| 428 } // namespace gles2. | 433 } // namespace gles2. |
| 429 } // namespace gpu | 434 } // namespace gpu |
| OLD | NEW |