| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/gpu/client/gl_helper_scaling.h" | 5 #include "content/browser/compositor/gl_helper_scaling.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 color_weights_[3] = 0.0; | 139 color_weights_[3] = 0.0; |
| 140 } | 140 } |
| 141 shader_program_ = | 141 shader_program_ = |
| 142 scaler_helper_->GetShaderProgram(spec_.shader, spec_.swizzle); | 142 scaler_helper_->GetShaderProgram(spec_.shader, spec_.swizzle); |
| 143 | 143 |
| 144 if (subscaler_) { | 144 if (subscaler_) { |
| 145 intermediate_texture_ = 0u; | 145 intermediate_texture_ = 0u; |
| 146 gl_->GenTextures(1, &intermediate_texture_); | 146 gl_->GenTextures(1, &intermediate_texture_); |
| 147 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, | 147 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, |
| 148 intermediate_texture_); | 148 intermediate_texture_); |
| 149 gl_->TexImage2D(GL_TEXTURE_2D, | 149 gl_->TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spec_.src_size.width(), |
| 150 0, | 150 spec_.src_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 151 GL_RGBA, | |
| 152 spec_.src_size.width(), | |
| 153 spec_.src_size.height(), | |
| 154 0, | |
| 155 GL_RGBA, | |
| 156 GL_UNSIGNED_BYTE, | |
| 157 NULL); | 151 NULL); |
| 158 } | 152 } |
| 159 } | 153 } |
| 160 | 154 |
| 161 ~ScalerImpl() override { | 155 ~ScalerImpl() override { |
| 162 if (intermediate_texture_) { | 156 if (intermediate_texture_) { |
| 163 gl_->DeleteTextures(1, &intermediate_texture_); | 157 gl_->DeleteTextures(1, &intermediate_texture_); |
| 164 } | 158 } |
| 165 } | 159 } |
| 166 | 160 |
| 167 // GLHelperShader::ShaderInterface implementation. | 161 // GLHelperShader::ShaderInterface implementation. |
| 168 void Execute(GLuint source_texture, | 162 void Execute(GLuint source_texture, |
| 169 const std::vector<GLuint>& dest_textures) override { | 163 const std::vector<GLuint>& dest_textures) override { |
| 170 if (subscaler_) { | 164 if (subscaler_) { |
| 171 subscaler_->Scale(source_texture, intermediate_texture_); | 165 subscaler_->Scale(source_texture, intermediate_texture_); |
| 172 source_texture = intermediate_texture_; | 166 source_texture = intermediate_texture_; |
| 173 } | 167 } |
| 174 | 168 |
| 175 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder( | 169 ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder( |
| 176 gl_, dst_framebuffer_); | 170 gl_, dst_framebuffer_); |
| 177 DCHECK_GT(dest_textures.size(), 0U); | 171 DCHECK_GT(dest_textures.size(), 0U); |
| 178 scoped_ptr<GLenum[]> buffers(new GLenum[dest_textures.size()]); | 172 scoped_ptr<GLenum[]> buffers(new GLenum[dest_textures.size()]); |
| 179 for (size_t t = 0; t < dest_textures.size(); t++) { | 173 for (size_t t = 0; t < dest_textures.size(); t++) { |
| 180 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dest_textures[t]); | 174 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, dest_textures[t]); |
| 181 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, | 175 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + t, |
| 182 GL_COLOR_ATTACHMENT0 + t, | 176 GL_TEXTURE_2D, dest_textures[t], 0); |
| 183 GL_TEXTURE_2D, | |
| 184 dest_textures[t], | |
| 185 0); | |
| 186 buffers[t] = GL_COLOR_ATTACHMENT0 + t; | 177 buffers[t] = GL_COLOR_ATTACHMENT0 + t; |
| 187 } | 178 } |
| 188 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, source_texture); | 179 ScopedTextureBinder<GL_TEXTURE_2D> texture_binder(gl_, source_texture); |
| 189 | 180 |
| 190 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 181 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 191 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 182 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 192 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 183 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 193 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 184 gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 194 | 185 |
| 195 ScopedBufferBinder<GL_ARRAY_BUFFER> buffer_binder( | 186 ScopedBufferBinder<GL_ARRAY_BUFFER> buffer_binder( |
| 196 gl_, scaler_helper_->vertex_attributes_buffer_); | 187 gl_, scaler_helper_->vertex_attributes_buffer_); |
| 197 shader_program_->UseProgram(spec_.src_size, | 188 shader_program_->UseProgram(spec_.src_size, spec_.src_subrect, |
| 198 spec_.src_subrect, | 189 spec_.dst_size, spec_.scale_x, |
| 199 spec_.dst_size, | 190 spec_.vertically_flip_texture, color_weights_); |
| 200 spec_.scale_x, | |
| 201 spec_.vertically_flip_texture, | |
| 202 color_weights_); | |
| 203 gl_->Viewport(0, 0, spec_.dst_size.width(), spec_.dst_size.height()); | 191 gl_->Viewport(0, 0, spec_.dst_size.width(), spec_.dst_size.height()); |
| 204 | 192 |
| 205 if (dest_textures.size() > 1) { | 193 if (dest_textures.size() > 1) { |
| 206 DCHECK_LE(static_cast<int>(dest_textures.size()), | 194 DCHECK_LE(static_cast<int>(dest_textures.size()), |
| 207 scaler_helper_->helper_->MaxDrawBuffers()); | 195 scaler_helper_->helper_->MaxDrawBuffers()); |
| 208 gl_->DrawBuffersEXT(dest_textures.size(), buffers.get()); | 196 gl_->DrawBuffersEXT(dest_textures.size(), buffers.get()); |
| 209 } | 197 } |
| 210 // Conduct texture mapping by drawing a quad composed of two triangles. | 198 // Conduct texture mapping by drawing a quad composed of two triangles. |
| 211 gl_->DrawArrays(GL_TRIANGLE_STRIP, 0, 4); | 199 gl_->DrawArrays(GL_TRIANGLE_STRIP, 0, 4); |
| 212 if (dest_textures.size() > 1) { | 200 if (dest_textures.size() > 1) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 x_passes = 1; | 363 x_passes = 1; |
| 376 } | 364 } |
| 377 | 365 |
| 378 for (int i = 0; i < x_passes; i++) { | 366 for (int i = 0; i < x_passes; i++) { |
| 379 x_ops->front().UpdateSize(&intermediate_size); | 367 x_ops->front().UpdateSize(&intermediate_size); |
| 380 x_ops->pop_front(); | 368 x_ops->pop_front(); |
| 381 } | 369 } |
| 382 } | 370 } |
| 383 } | 371 } |
| 384 | 372 |
| 385 scaler_stages->push_back(ScalerStage(current_shader, | 373 scaler_stages->push_back(ScalerStage(current_shader, src_size, src_subrect, |
| 386 src_size, | 374 intermediate_size, scale_x, |
| 387 src_subrect, | 375 vertically_flip_texture, swizzle)); |
| 388 intermediate_size, | |
| 389 scale_x, | |
| 390 vertically_flip_texture, | |
| 391 swizzle)); | |
| 392 src_size = intermediate_size; | 376 src_size = intermediate_size; |
| 393 src_subrect = gfx::Rect(intermediate_size); | 377 src_subrect = gfx::Rect(intermediate_size); |
| 394 vertically_flip_texture = false; | 378 vertically_flip_texture = false; |
| 395 swizzle = false; | 379 swizzle = false; |
| 396 } | 380 } |
| 397 } | 381 } |
| 398 | 382 |
| 399 void GLHelperScaling::ComputeScalerStages( | 383 void GLHelperScaling::ComputeScalerStages( |
| 400 GLHelper::ScalerQuality quality, | 384 GLHelper::ScalerQuality quality, |
| 401 const gfx::Size& src_size, | 385 const gfx::Size& src_size, |
| 402 const gfx::Rect& src_subrect, | 386 const gfx::Rect& src_subrect, |
| 403 const gfx::Size& dst_size, | 387 const gfx::Size& dst_size, |
| 404 bool vertically_flip_texture, | 388 bool vertically_flip_texture, |
| 405 bool swizzle, | 389 bool swizzle, |
| 406 std::vector<ScalerStage>* scaler_stages) { | 390 std::vector<ScalerStage>* scaler_stages) { |
| 407 if (quality == GLHelper::SCALER_QUALITY_FAST || | 391 if (quality == GLHelper::SCALER_QUALITY_FAST || |
| 408 src_subrect.size() == dst_size) { | 392 src_subrect.size() == dst_size) { |
| 409 scaler_stages->push_back(ScalerStage(SHADER_BILINEAR, | 393 scaler_stages->push_back(ScalerStage(SHADER_BILINEAR, src_size, src_subrect, |
| 410 src_size, | 394 dst_size, false, |
| 411 src_subrect, | 395 vertically_flip_texture, swizzle)); |
| 412 dst_size, | |
| 413 false, | |
| 414 vertically_flip_texture, | |
| 415 swizzle)); | |
| 416 return; | 396 return; |
| 417 } | 397 } |
| 418 | 398 |
| 419 std::deque<GLHelperScaling::ScaleOp> x_ops, y_ops; | 399 std::deque<GLHelperScaling::ScaleOp> x_ops, y_ops; |
| 420 GLHelperScaling::ScaleOp::AddOps(src_subrect.width(), | 400 GLHelperScaling::ScaleOp::AddOps(src_subrect.width(), dst_size.width(), true, |
| 421 dst_size.width(), | |
| 422 true, | |
| 423 quality == GLHelper::SCALER_QUALITY_GOOD, | 401 quality == GLHelper::SCALER_QUALITY_GOOD, |
| 424 &x_ops); | 402 &x_ops); |
| 425 GLHelperScaling::ScaleOp::AddOps(src_subrect.height(), | 403 GLHelperScaling::ScaleOp::AddOps( |
| 426 dst_size.height(), | 404 src_subrect.height(), dst_size.height(), false, |
| 427 false, | 405 quality == GLHelper::SCALER_QUALITY_GOOD, &y_ops); |
| 428 quality == GLHelper::SCALER_QUALITY_GOOD, | |
| 429 &y_ops); | |
| 430 | 406 |
| 431 ConvertScalerOpsToScalerStages(quality, | 407 ConvertScalerOpsToScalerStages(quality, src_size, src_subrect, dst_size, |
| 432 src_size, | 408 vertically_flip_texture, swizzle, &x_ops, |
| 433 src_subrect, | 409 &y_ops, scaler_stages); |
| 434 dst_size, | |
| 435 vertically_flip_texture, | |
| 436 swizzle, | |
| 437 &x_ops, | |
| 438 &y_ops, | |
| 439 scaler_stages); | |
| 440 } | 410 } |
| 441 | 411 |
| 442 GLHelper::ScalerInterface* GLHelperScaling::CreateScaler( | 412 GLHelper::ScalerInterface* GLHelperScaling::CreateScaler( |
| 443 GLHelper::ScalerQuality quality, | 413 GLHelper::ScalerQuality quality, |
| 444 gfx::Size src_size, | 414 gfx::Size src_size, |
| 445 gfx::Rect src_subrect, | 415 gfx::Rect src_subrect, |
| 446 const gfx::Size& dst_size, | 416 const gfx::Size& dst_size, |
| 447 bool vertically_flip_texture, | 417 bool vertically_flip_texture, |
| 448 bool swizzle) { | 418 bool swizzle) { |
| 449 std::vector<ScalerStage> scaler_stages; | 419 std::vector<ScalerStage> scaler_stages; |
| 450 ComputeScalerStages(quality, | 420 ComputeScalerStages(quality, src_size, src_subrect, dst_size, |
| 451 src_size, | 421 vertically_flip_texture, swizzle, &scaler_stages); |
| 452 src_subrect, | |
| 453 dst_size, | |
| 454 vertically_flip_texture, | |
| 455 swizzle, | |
| 456 &scaler_stages); | |
| 457 | 422 |
| 458 ScalerImpl* ret = NULL; | 423 ScalerImpl* ret = NULL; |
| 459 for (unsigned int i = 0; i < scaler_stages.size(); i++) { | 424 for (unsigned int i = 0; i < scaler_stages.size(); i++) { |
| 460 ret = new ScalerImpl(gl_, this, scaler_stages[i], ret, NULL); | 425 ret = new ScalerImpl(gl_, this, scaler_stages[i], ret, NULL); |
| 461 } | 426 } |
| 462 return ret; | 427 return ret; |
| 463 } | 428 } |
| 464 | 429 |
| 465 GLHelper::ScalerInterface* GLHelperScaling::CreatePlanarScaler( | 430 GLHelper::ScalerInterface* GLHelperScaling::CreatePlanarScaler( |
| 466 const gfx::Size& src_size, | 431 const gfx::Size& src_size, |
| 467 const gfx::Rect& src_subrect, | 432 const gfx::Rect& src_subrect, |
| 468 const gfx::Size& dst_size, | 433 const gfx::Size& dst_size, |
| 469 bool vertically_flip_texture, | 434 bool vertically_flip_texture, |
| 470 bool swizzle, | 435 bool swizzle, |
| 471 const float color_weights[4]) { | 436 const float color_weights[4]) { |
| 472 ScalerStage stage(SHADER_PLANAR, | 437 ScalerStage stage(SHADER_PLANAR, src_size, src_subrect, dst_size, true, |
| 473 src_size, | 438 vertically_flip_texture, swizzle); |
| 474 src_subrect, | |
| 475 dst_size, | |
| 476 true, | |
| 477 vertically_flip_texture, | |
| 478 swizzle); | |
| 479 return new ScalerImpl(gl_, this, stage, NULL, color_weights); | 439 return new ScalerImpl(gl_, this, stage, NULL, color_weights); |
| 480 } | 440 } |
| 481 | 441 |
| 482 GLHelperScaling::ShaderInterface* GLHelperScaling::CreateYuvMrtShader( | 442 GLHelperScaling::ShaderInterface* GLHelperScaling::CreateYuvMrtShader( |
| 483 const gfx::Size& src_size, | 443 const gfx::Size& src_size, |
| 484 const gfx::Rect& src_subrect, | 444 const gfx::Rect& src_subrect, |
| 485 const gfx::Size& dst_size, | 445 const gfx::Size& dst_size, |
| 486 bool vertically_flip_texture, | 446 bool vertically_flip_texture, |
| 487 bool swizzle, | 447 bool swizzle, |
| 488 ShaderType shader) { | 448 ShaderType shader) { |
| 489 DCHECK(shader == SHADER_YUV_MRT_PASS1 || shader == SHADER_YUV_MRT_PASS2); | 449 DCHECK(shader == SHADER_YUV_MRT_PASS1 || shader == SHADER_YUV_MRT_PASS2); |
| 490 ScalerStage stage(shader, | 450 ScalerStage stage(shader, src_size, src_subrect, dst_size, true, |
| 491 src_size, | 451 vertically_flip_texture, swizzle); |
| 492 src_subrect, | |
| 493 dst_size, | |
| 494 true, | |
| 495 vertically_flip_texture, | |
| 496 swizzle); | |
| 497 return new ScalerImpl(gl_, this, stage, NULL, NULL); | 452 return new ScalerImpl(gl_, this, stage, NULL, NULL); |
| 498 } | 453 } |
| 499 | 454 |
| 500 const GLfloat GLHelperScaling::kVertexAttributes[] = { | 455 const GLfloat GLHelperScaling::kVertexAttributes[] = { |
| 501 -1.0f, -1.0f, 0.0f, 0.0f, // vertex 0 | 456 -1.0f, -1.0f, 0.0f, 0.0f, // vertex 0 |
| 502 1.0f, -1.0f, 1.0f, 0.0f, // vertex 1 | 457 1.0f, -1.0f, 1.0f, 0.0f, // vertex 1 |
| 503 -1.0f, 1.0f, 0.0f, 1.0f, // vertex 2 | 458 -1.0f, 1.0f, 0.0f, 1.0f, // vertex 2 |
| 504 1.0f, 1.0f, 1.0f, 1.0f, }; // vertex 3 | 459 1.0f, 1.0f, 1.0f, 1.0f, |
| 460 }; // vertex 3 |
| 505 | 461 |
| 506 void GLHelperScaling::InitBuffer() { | 462 void GLHelperScaling::InitBuffer() { |
| 507 ScopedBufferBinder<GL_ARRAY_BUFFER> buffer_binder(gl_, | 463 ScopedBufferBinder<GL_ARRAY_BUFFER> buffer_binder(gl_, |
| 508 vertex_attributes_buffer_); | 464 vertex_attributes_buffer_); |
| 509 gl_->BufferData(GL_ARRAY_BUFFER, | 465 gl_->BufferData(GL_ARRAY_BUFFER, sizeof(kVertexAttributes), kVertexAttributes, |
| 510 sizeof(kVertexAttributes), | |
| 511 kVertexAttributes, | |
| 512 GL_STATIC_DRAW); | 466 GL_STATIC_DRAW); |
| 513 } | 467 } |
| 514 | 468 |
| 515 scoped_refptr<ShaderProgram> GLHelperScaling::GetShaderProgram(ShaderType type, | 469 scoped_refptr<ShaderProgram> GLHelperScaling::GetShaderProgram(ShaderType type, |
| 516 bool swizzle) { | 470 bool swizzle) { |
| 517 ShaderProgramKeyType key(type, swizzle); | 471 ShaderProgramKeyType key(type, swizzle); |
| 518 scoped_refptr<ShaderProgram>& cache_entry(shader_programs_[key]); | 472 scoped_refptr<ShaderProgram>& cache_entry(shader_programs_[key]); |
| 519 if (!cache_entry.get()) { | 473 if (!cache_entry.get()) { |
| 520 cache_entry = new ShaderProgram(gl_, helper_); | 474 cache_entry = new ShaderProgram(gl_, helper_); |
| 521 std::basic_string<GLchar> vertex_program; | 475 std::basic_string<GLchar> vertex_program; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 " v_texcoords.zw = texcoord + step * 0.5;\n"); | 759 " v_texcoords.zw = texcoord + step * 0.5;\n"); |
| 806 fragment_directives.append("#extension GL_EXT_draw_buffers : enable\n"); | 760 fragment_directives.append("#extension GL_EXT_draw_buffers : enable\n"); |
| 807 fragment_program.append( | 761 fragment_program.append( |
| 808 " vec4 lo_uuvv = texture2D(s_texture, v_texcoords.xy);\n" | 762 " vec4 lo_uuvv = texture2D(s_texture, v_texcoords.xy);\n" |
| 809 " vec4 hi_uuvv = texture2D(s_texture, v_texcoords.zw);\n" | 763 " vec4 hi_uuvv = texture2D(s_texture, v_texcoords.zw);\n" |
| 810 " gl_FragData[0] = vec4(lo_uuvv.rg, hi_uuvv.rg);\n" | 764 " gl_FragData[0] = vec4(lo_uuvv.rg, hi_uuvv.rg);\n" |
| 811 " gl_FragData[1] = vec4(lo_uuvv.ba, hi_uuvv.ba);\n"); | 765 " gl_FragData[1] = vec4(lo_uuvv.ba, hi_uuvv.ba);\n"); |
| 812 break; | 766 break; |
| 813 } | 767 } |
| 814 if (swizzle) { | 768 if (swizzle) { |
| 815 switch(type) { | 769 switch (type) { |
| 816 case SHADER_YUV_MRT_PASS1: | 770 case SHADER_YUV_MRT_PASS1: |
| 817 fragment_program.append(" gl_FragData[0] = gl_FragData[0].bgra;\n"); | 771 fragment_program.append(" gl_FragData[0] = gl_FragData[0].bgra;\n"); |
| 818 break; | 772 break; |
| 819 case SHADER_YUV_MRT_PASS2: | 773 case SHADER_YUV_MRT_PASS2: |
| 820 fragment_program.append(" gl_FragData[0] = gl_FragData[0].bgra;\n"); | 774 fragment_program.append(" gl_FragData[0] = gl_FragData[0].bgra;\n"); |
| 821 fragment_program.append(" gl_FragData[1] = gl_FragData[1].bgra;\n"); | 775 fragment_program.append(" gl_FragData[1] = gl_FragData[1].bgra;\n"); |
| 822 break; | 776 break; |
| 823 default: | 777 default: |
| 824 fragment_program.append(" gl_FragColor = gl_FragColor.bgra;\n"); | 778 fragment_program.append(" gl_FragColor = gl_FragColor.bgra;\n"); |
| 825 break; | 779 break; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 const gfx::Rect& src_subrect, | 836 const gfx::Rect& src_subrect, |
| 883 const gfx::Size& dst_size, | 837 const gfx::Size& dst_size, |
| 884 bool scale_x, | 838 bool scale_x, |
| 885 bool flip_y, | 839 bool flip_y, |
| 886 GLfloat color_weights[4]) { | 840 GLfloat color_weights[4]) { |
| 887 gl_->UseProgram(program_); | 841 gl_->UseProgram(program_); |
| 888 | 842 |
| 889 // OpenGL defines the last parameter to VertexAttribPointer as type | 843 // OpenGL defines the last parameter to VertexAttribPointer as type |
| 890 // "const GLvoid*" even though it is actually an offset into the buffer | 844 // "const GLvoid*" even though it is actually an offset into the buffer |
| 891 // object's data store and not a pointer to the client's address space. | 845 // object's data store and not a pointer to the client's address space. |
| 892 const void* offsets[2] = { | 846 const void* offsets[2] = {0, |
| 893 0, reinterpret_cast<const void*>(2 * sizeof(GLfloat)) | 847 reinterpret_cast<const void*>(2 * sizeof(GLfloat))}; |
| 894 }; | |
| 895 | 848 |
| 896 gl_->VertexAttribPointer(position_location_, | 849 gl_->VertexAttribPointer(position_location_, 2, GL_FLOAT, GL_FALSE, |
| 897 2, | 850 4 * sizeof(GLfloat), offsets[0]); |
| 898 GL_FLOAT, | |
| 899 GL_FALSE, | |
| 900 4 * sizeof(GLfloat), | |
| 901 offsets[0]); | |
| 902 gl_->EnableVertexAttribArray(position_location_); | 851 gl_->EnableVertexAttribArray(position_location_); |
| 903 | 852 |
| 904 gl_->VertexAttribPointer(texcoord_location_, | 853 gl_->VertexAttribPointer(texcoord_location_, 2, GL_FLOAT, GL_FALSE, |
| 905 2, | 854 4 * sizeof(GLfloat), offsets[1]); |
| 906 GL_FLOAT, | |
| 907 GL_FALSE, | |
| 908 4 * sizeof(GLfloat), | |
| 909 offsets[1]); | |
| 910 gl_->EnableVertexAttribArray(texcoord_location_); | 855 gl_->EnableVertexAttribArray(texcoord_location_); |
| 911 | 856 |
| 912 gl_->Uniform1i(texture_location_, 0); | 857 gl_->Uniform1i(texture_location_, 0); |
| 913 | 858 |
| 914 // Convert |src_subrect| to texture coordinates. | 859 // Convert |src_subrect| to texture coordinates. |
| 915 GLfloat src_subrect_texcoord[] = { | 860 GLfloat src_subrect_texcoord[] = { |
| 916 static_cast<float>(src_subrect.x()) / src_size.width(), | 861 static_cast<float>(src_subrect.x()) / src_size.width(), |
| 917 static_cast<float>(src_subrect.y()) / src_size.height(), | 862 static_cast<float>(src_subrect.y()) / src_size.height(), |
| 918 static_cast<float>(src_subrect.width()) / src_size.width(), | 863 static_cast<float>(src_subrect.width()) / src_size.width(), |
| 919 static_cast<float>(src_subrect.height()) / src_size.height(), }; | 864 static_cast<float>(src_subrect.height()) / src_size.height(), |
| 865 }; |
| 920 if (flip_y) { | 866 if (flip_y) { |
| 921 src_subrect_texcoord[1] += src_subrect_texcoord[3]; | 867 src_subrect_texcoord[1] += src_subrect_texcoord[3]; |
| 922 src_subrect_texcoord[3] *= -1.0; | 868 src_subrect_texcoord[3] *= -1.0; |
| 923 } | 869 } |
| 924 gl_->Uniform4fv(src_subrect_location_, 1, src_subrect_texcoord); | 870 gl_->Uniform4fv(src_subrect_location_, 1, src_subrect_texcoord); |
| 925 | 871 |
| 926 gl_->Uniform2f(src_pixelsize_location_, src_size.width(), src_size.height()); | 872 gl_->Uniform2f(src_pixelsize_location_, src_size.width(), src_size.height()); |
| 927 gl_->Uniform2f(dst_pixelsize_location_, | 873 gl_->Uniform2f(dst_pixelsize_location_, static_cast<float>(dst_size.width()), |
| 928 static_cast<float>(dst_size.width()), | |
| 929 static_cast<float>(dst_size.height())); | 874 static_cast<float>(dst_size.height())); |
| 930 | 875 |
| 931 gl_->Uniform2f( | 876 gl_->Uniform2f(scaling_vector_location_, scale_x ? 1.0 : 0.0, |
| 932 scaling_vector_location_, scale_x ? 1.0 : 0.0, scale_x ? 0.0 : 1.0); | 877 scale_x ? 0.0 : 1.0); |
| 933 gl_->Uniform4fv(color_weights_location_, 1, color_weights); | 878 gl_->Uniform4fv(color_weights_location_, 1, color_weights); |
| 934 } | 879 } |
| 935 | 880 |
| 936 } // namespace content | 881 } // namespace content |
| OLD | NEW |