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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 // Restore state | 315 // Restore state |
| 316 decoder->RestoreAllAttributes(); | 316 decoder->RestoreAllAttributes(); |
| 317 decoder->RestoreTextureUnitBindings(0); | 317 decoder->RestoreTextureUnitBindings(0); |
| 318 decoder->RestoreActiveTexture(); | 318 decoder->RestoreActiveTexture(); |
| 319 decoder->RestoreProgramBindings(); | 319 decoder->RestoreProgramBindings(); |
| 320 decoder->RestoreBufferBindings(); | 320 decoder->RestoreBufferBindings(); |
| 321 decoder->RestoreFramebufferBindings(); | 321 decoder->RestoreFramebufferBindings(); |
| 322 decoder->RestoreGlobalState(); | 322 decoder->RestoreGlobalState(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void SRGBConverter::SRGBGenerateMipmap(const gles2::GLES2Decoder* decoder, | |
| 326 Texture* tex, | |
| 327 GLenum target) { | |
| 328 // This function generateMipmap for srgb texture. | |
| 329 // The steps are: | |
| 330 // 1) Copy the base level of the sRGB texture |tex| into a linear (non-sRGB) | |
| 331 // texture | |
| 332 // 2) Perform the glGenerateMipmap call against the linear texture | |
| 333 // 3) Copy each mip level of the linear texture back into the sRGB texture | |
| 334 // |tex| | |
| 335 DCHECK(srgb_converter_initialized_); | |
| 336 | |
| 337 GLsizei width; | |
| 338 GLsizei height; | |
| 339 GLsizei depth; | |
| 340 GLenum type = 0; | |
| 341 GLenum internal_format = 0; | |
| 342 GLsizei base_level = tex->base_level(); | |
| 343 tex->GetLevelSize(target, base_level, &width, &height, &depth); | |
| 344 tex->GetLevelType(target, base_level, &type, &internal_format); | |
| 345 const GLint mipmap_levels = | |
| 346 TextureManager::ComputeMipMapCount(target, width, height, depth); | |
| 347 | |
| 348 // bind srgb_decoder_textures_[1] to draw framebuffer | |
| 349 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 350 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, | |
| 351 GL_UNSIGNED_BYTE, nullptr); | |
| 352 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_); | |
| 353 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 354 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); | |
| 355 | |
| 356 // bind texture with srgb format and render with srgb_converter_program_ | |
| 357 glUseProgram(srgb_converter_program_); | |
| 358 glViewport(0, 0, width, height); | |
| 359 glDisable(GL_SCISSOR_TEST); | |
| 360 glDisable(GL_DEPTH_TEST); | |
| 361 glDisable(GL_STENCIL_TEST); | |
| 362 glDisable(GL_CULL_FACE); | |
| 363 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | |
| 364 glDepthMask(GL_FALSE); | |
| 365 glDisable(GL_BLEND); | |
| 366 glDisable(GL_DITHER); | |
| 367 | |
| 368 glBindVertexArrayOES(srgb_converter_vao_); | |
| 369 glActiveTexture(GL_TEXTURE0); | |
| 370 // glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); | |
|
piman
2016/09/21 23:45:32
nit: remove commented code.
yizhou.jiang
2016/09/22 03:56:51
Done.
| |
| 371 glBindTexture(GL_TEXTURE_2D, tex->service_id()); | |
| 372 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
|
piman
2016/09/21 23:45:32
Because we modify the filters of the source textur
yizhou.jiang
2016/09/22 03:56:50
Done.
yizhou.jiang
2016/09/22 03:56:51
Done.
| |
| 373 | |
| 374 glDrawArrays(GL_TRIANGLES, 0, 6); | |
| 375 | |
| 376 // generateMipmap for srgb_decoder_textures_[1] | |
| 377 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 378 glGenerateMipmapEXT(GL_TEXTURE_2D); | |
| 379 | |
| 380 // bind tex with rgba format and render with srgb_converter_program_ | |
| 381 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); | |
| 382 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 383 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | |
| 384 GL_NEAREST_MIPMAP_NEAREST); | |
| 385 glBindTexture(GL_TEXTURE_2D, tex->service_id()); | |
| 386 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
| 387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
|
piman
2016/09/21 23:45:32
Why is this needed? The following code doesn't sam
yizhou.jiang
2016/09/22 03:56:51
Done.
| |
| 388 | |
| 389 width >>= 1; | |
| 390 height >>= 1; | |
| 391 | |
| 392 for (GLint level = base_level + 1; level < base_level + mipmap_levels; ++level ) { | |
|
piman
2016/09/21 23:45:32
nit: 80 columns limit. Maybe run 'git cl format'?
yizhou.jiang
2016/09/22 03:56:51
Done.
| |
| 393 // copy mipmaps level by level from srgb_converter_textures_[1] to tex | |
| 394 // generate mipmap for tex manually | |
| 395 glBindTexture(GL_TEXTURE_2D, tex->service_id()); | |
| 396 glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height, 0, | |
| 397 GL_SRGB, type, NULL); | |
| 398 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 399 GL_TEXTURE_2D, tex->service_id(), level); | |
| 400 | |
| 401 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 402 glViewport(0, 0, width, height); | |
| 403 glDrawArrays(GL_TRIANGLES, 0, 6); | |
| 404 width >>= 1; | |
| 405 height >>= 1; | |
| 406 } | |
| 407 | |
| 408 // Restore state | |
| 409 decoder->RestoreAllAttributes(); | |
| 410 decoder->RestoreTextureUnitBindings(0); | |
| 411 decoder->RestoreActiveTexture(); | |
| 412 decoder->RestoreProgramBindings(); | |
| 413 decoder->RestoreBufferBindings(); | |
| 414 decoder->RestoreFramebufferBindings(); | |
| 415 decoder->RestoreGlobalState(); | |
| 416 } | |
| 417 | |
| 325 } // namespace gles2. | 418 } // namespace gles2. |
| 326 } // namespace gpu | 419 } // namespace gpu |
| OLD | NEW |