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) { | |
|
Ken Russell (switch to Gerrit)
2016/09/21 01:00:14
Could you add some high-level comments for this fu
yizhou.jiang
2016/09/23 04:32:06
hi kbr, I'm not quite sure if I understand correct
| |
| 328 DCHECK(srgb_converter_initialized_); | |
| 329 | |
| 330 GLsizei width; | |
| 331 GLsizei height; | |
| 332 GLsizei depth; | |
| 333 GLenum type = 0; | |
| 334 GLenum internal_format = 0; | |
| 335 GLsizei base_level = tex->base_level(); | |
| 336 tex->GetLevelSize(target, base_level, &width, &height, &depth); | |
| 337 tex->GetLevelType(target, 0, &type, &internal_format); | |
|
piman
2016/09/20 21:53:30
Should this be base_level instead of 0?
yizhou.jiang
2016/09/21 08:59:22
Done.
| |
| 338 const GLint mipmap_level = | |
|
piman
2016/09/20 21:53:30
nit: maybe mipmap_levels, since it's a count, not
yizhou.jiang
2016/09/21 08:59:22
Done.
| |
| 339 TextureManager::ComputeMipMapCount(target, width, height, depth); | |
| 340 | |
| 341 // copy tex to srgb_decoder_textures_[0] with srgb format | |
| 342 glBindTexture(target, tex->service_id()); | |
| 343 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, srgb_decoder_fbo_); | |
| 344 glFramebufferTexture2DEXT(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 345 GL_TEXTURE_2D, tex->service_id(), 0); | |
|
piman
2016/09/20 21:53:30
Should this be base_level instead of 0?
yizhou.jiang
2016/09/21 08:59:22
Done.
| |
| 346 | |
| 347 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); | |
| 348 glCopyTexImage2D(GL_TEXTURE_2D, 0, internal_format, 0, 0, width, height, 0); | |
|
piman
2016/09/20 21:53:30
Do we need to make that extra copy, could we use t
yizhou.jiang
2016/09/21 08:59:22
I removed copy tex to srgb_decoder_textures_[0]
| |
| 349 | |
| 350 // bind srgb_decoder_textures_[1] to draw framebuffer | |
| 351 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 352 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, | |
| 353 GL_UNSIGNED_BYTE, nullptr); | |
| 354 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_decoder_fbo_); | |
| 355 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 356 GL_TEXTURE_2D, srgb_converter_textures_[1], 0); | |
| 357 | |
| 358 // bind texture with srgb format and render with srgb_converter_program_ | |
| 359 glUseProgram(srgb_converter_program_); | |
| 360 glViewport(0, 0, width, height); | |
| 361 glDisable(GL_SCISSOR_TEST); | |
| 362 glDisable(GL_DEPTH_TEST); | |
| 363 glDisable(GL_STENCIL_TEST); | |
| 364 glDisable(GL_CULL_FACE); | |
| 365 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | |
| 366 glDepthMask(GL_FALSE); | |
| 367 glDisable(GL_BLEND); | |
| 368 glDisable(GL_DITHER); | |
| 369 | |
| 370 glBindVertexArrayOES(srgb_converter_vao_); | |
| 371 glActiveTexture(GL_TEXTURE0); | |
| 372 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[0]); | |
| 373 glDrawArrays(GL_TRIANGLES, 0, 6); | |
| 374 | |
| 375 // generateMipmap for tex and srgb_decoder_textures_[1] | |
| 376 glBindTexture(GL_TEXTURE_2D, tex->service_id()); | |
| 377 glGenerateMipmapEXT(GL_TEXTURE_2D); | |
|
piman
2016/09/20 21:53:30
Why this one, is it to generate the image levels o
yizhou.jiang
2016/09/21 08:59:22
Done.
| |
| 378 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 379 glGenerateMipmapEXT(GL_TEXTURE_2D); | |
| 380 | |
| 381 // bind tex with rgba format and render with srgb_converter_program_ | |
| 382 glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, srgb_encoder_fbo_); | |
| 383 glBindTexture(GL_TEXTURE_2D, srgb_converter_textures_[1]); | |
| 384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, | |
| 385 GL_NEAREST_MIPMAP_NEAREST); | |
| 386 width >>= 1; | |
| 387 height >>= 1; | |
| 388 | |
| 389 for (GLint level = base_level + 1; level < mipmap_level; ++level) { | |
|
piman
2016/09/20 21:53:30
mipmap_level is computed as the number of levels i
yizhou.jiang
2016/09/21 08:59:22
Done.
| |
| 390 glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, | |
| 391 GL_TEXTURE_2D, tex->service_id(), level); | |
| 392 | |
| 393 glViewport(0, 0, width, height); | |
| 394 glDrawArrays(GL_TRIANGLES, 0, 6); | |
|
Ken Russell (switch to Gerrit)
2016/09/21 01:00:14
What's the intent of this loop? Is it intended to
yizhou.jiang
2016/09/21 08:59:22
Yes. I try to sampling converter_textures_[1] to c
| |
| 395 width >>= 1; | |
| 396 height >>= 1; | |
| 397 } | |
| 398 | |
| 399 // Restore state | |
| 400 decoder->RestoreAllAttributes(); | |
| 401 decoder->RestoreTextureUnitBindings(0); | |
| 402 decoder->RestoreActiveTexture(); | |
| 403 decoder->RestoreProgramBindings(); | |
| 404 decoder->RestoreBufferBindings(); | |
| 405 decoder->RestoreFramebufferBindings(); | |
| 406 decoder->RestoreGlobalState(); | |
| 407 } | |
| 408 | |
| 325 } // namespace gles2. | 409 } // namespace gles2. |
| 326 } // namespace gpu | 410 } // namespace gpu |
| OLD | NEW |