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 <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 BitstreamBufferMap bitstream_buffers_by_id_; | 128 BitstreamBufferMap bitstream_buffers_by_id_; |
129 }; | 129 }; |
130 | 130 |
131 // Initialize Video Decoders. | 131 // Initialize Video Decoders. |
132 void InitializeDecoders(); | 132 void InitializeDecoders(); |
133 | 133 |
134 // GL-related functions. | 134 // GL-related functions. |
135 void InitGL(); | 135 void InitGL(); |
136 GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target); | 136 GLuint CreateTexture(int32_t width, int32_t height, GLenum texture_target); |
137 void CreateGLObjects(); | 137 void CreateGLObjects(); |
138 void Create2DProgramOnce(); | |
139 void CreateARBProgramOnce(); | |
sail
2012/08/10 17:45:45
I think ARB isn't specific enough. Maybe Create2DR
Ami GONE FROM CHROMIUM
2012/08/10 17:56:19
Changed to CreateRectangleARBProgramOnce to parall
| |
138 Shader CreateProgram(const char* vertex_shader, | 140 Shader CreateProgram(const char* vertex_shader, |
139 const char* fragment_shader); | 141 const char* fragment_shader); |
140 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 142 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
141 void DeleteTexture(GLuint id); | 143 void DeleteTexture(GLuint id); |
142 void PaintFinished(int32_t result, PP_Resource decoder, | 144 void PaintFinished(int32_t result, PP_Resource decoder, |
143 int picture_buffer_id); | 145 int picture_buffer_id); |
144 | 146 |
145 // Log an error to the developer console and stderr (though the latter may be | 147 // Log an error to the developer console and stderr (though the latter may be |
146 // closed due to sandboxing or blackholed for other reasons) by creating a | 148 // closed due to sandboxing or blackholed for other reasons) by creating a |
147 // temporary of this type and streaming to it. Example usage: | 149 // temporary of this type and streaming to it. Example usage: |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 assert(!is_painting_); | 419 assert(!is_painting_); |
418 is_painting_ = true; | 420 is_painting_ = true; |
419 int x = 0; | 421 int x = 0; |
420 int y = 0; | 422 int y = 0; |
421 if (client != video_decoders_.begin()->second) { | 423 if (client != video_decoders_.begin()->second) { |
422 x = plugin_size_.width() / kNumDecoders; | 424 x = plugin_size_.width() / kNumDecoders; |
423 y = plugin_size_.height() / kNumDecoders; | 425 y = plugin_size_.height() / kNumDecoders; |
424 } | 426 } |
425 | 427 |
426 if (info.texture_target == GL_TEXTURE_2D) { | 428 if (info.texture_target == GL_TEXTURE_2D) { |
429 Create2DProgramOnce(); | |
427 gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program); | 430 gles2_if_->UseProgram(context_->pp_resource(), shader_2d_.program); |
428 gles2_if_->Uniform2f( | 431 gles2_if_->Uniform2f( |
429 context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0); | 432 context_->pp_resource(), shader_2d_.texcoord_scale_location, 1.0, 1.0); |
430 } else { | 433 } else { |
431 assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB); | 434 assert(info.texture_target == GL_TEXTURE_RECTANGLE_ARB); |
435 CreateARBProgramOnce(); | |
432 gles2_if_->UseProgram( | 436 gles2_if_->UseProgram( |
433 context_->pp_resource(), shader_rectangle_arb_.program); | 437 context_->pp_resource(), shader_rectangle_arb_.program); |
434 gles2_if_->Uniform2f(context_->pp_resource(), | 438 gles2_if_->Uniform2f(context_->pp_resource(), |
435 shader_rectangle_arb_.texcoord_scale_location, | 439 shader_rectangle_arb_.texcoord_scale_location, |
436 info.buffer.size.width, | 440 info.buffer.size.width, |
437 info.buffer.size.height); | 441 info.buffer.size.height); |
438 } | 442 } |
439 | 443 |
440 gles2_if_->Viewport(context_->pp_resource(), x, y, | 444 gles2_if_->Viewport(context_->pp_resource(), x, y, |
441 plugin_size_.width() / kNumDecoders, | 445 plugin_size_.width() / kNumDecoders, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
557 } | 561 } |
558 assertNoGLError(); | 562 assertNoGLError(); |
559 return texture_id; | 563 return texture_id; |
560 } | 564 } |
561 | 565 |
562 void VideoDecodeDemoInstance::DeleteTexture(GLuint id) { | 566 void VideoDecodeDemoInstance::DeleteTexture(GLuint id) { |
563 gles2_if_->DeleteTextures(context_->pp_resource(), 1, &id); | 567 gles2_if_->DeleteTextures(context_->pp_resource(), 1, &id); |
564 } | 568 } |
565 | 569 |
566 void VideoDecodeDemoInstance::CreateGLObjects() { | 570 void VideoDecodeDemoInstance::CreateGLObjects() { |
567 // Code and constants for shader. | 571 // Assign vertex positions and texture coordinates to buffers for use in |
568 static const char kVertexShader[] = | 572 // shader program. |
569 "varying vec2 v_texCoord; \n" | 573 static const float kVertices[] = { |
570 "attribute vec4 a_position; \n" | 574 -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates. |
571 "attribute vec2 a_texCoord; \n" | 575 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. |
572 "uniform vec2 v_scale; \n" | 576 }; |
573 "void main() \n" | |
574 "{ \n" | |
575 " v_texCoord = v_scale * a_texCoord; \n" | |
576 " gl_Position = a_position; \n" | |
577 "}"; | |
578 | 577 |
578 GLuint buffer; | |
579 gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer); | |
580 gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer); | |
581 | |
582 gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER, | |
583 sizeof(kVertices), kVertices, GL_STATIC_DRAW); | |
584 assertNoGLError(); | |
585 } | |
586 | |
587 static const char kVertexShader[] = | |
588 "varying vec2 v_texCoord; \n" | |
589 "attribute vec4 a_position; \n" | |
590 "attribute vec2 a_texCoord; \n" | |
591 "uniform vec2 v_scale; \n" | |
592 "void main() \n" | |
593 "{ \n" | |
594 " v_texCoord = v_scale * a_texCoord; \n" | |
595 " gl_Position = a_position; \n" | |
596 "}"; | |
597 | |
598 void VideoDecodeDemoInstance::Create2DProgramOnce() { | |
599 if (shader_2d_.program) | |
600 return; | |
579 static const char kFragmentShader2D[] = | 601 static const char kFragmentShader2D[] = |
580 "precision mediump float; \n" | 602 "precision mediump float; \n" |
581 "varying vec2 v_texCoord; \n" | 603 "varying vec2 v_texCoord; \n" |
582 "uniform sampler2D s_texture; \n" | 604 "uniform sampler2D s_texture; \n" |
583 "void main() \n" | 605 "void main() \n" |
584 "{" | 606 "{" |
585 " gl_FragColor = texture2D(s_texture, v_texCoord); \n" | 607 " gl_FragColor = texture2D(s_texture, v_texCoord); \n" |
586 "}"; | 608 "}"; |
609 shader_2d_ = CreateProgram(kVertexShader, kFragmentShader2D); | |
610 assertNoGLError(); | |
611 } | |
587 | 612 |
613 void VideoDecodeDemoInstance::CreateARBProgramOnce() { | |
614 if (shader_rectangle_arb_.program) | |
615 return; | |
588 static const char kFragmentShaderRectangle[] = | 616 static const char kFragmentShaderRectangle[] = |
589 "#extension GL_ARB_texture_rectangle : require\n" | 617 "#extension GL_ARB_texture_rectangle : require\n" |
590 "precision mediump float; \n" | 618 "precision mediump float; \n" |
591 "varying vec2 v_texCoord; \n" | 619 "varying vec2 v_texCoord; \n" |
592 "uniform sampler2DRect s_texture; \n" | 620 "uniform sampler2DRect s_texture; \n" |
593 "void main() \n" | 621 "void main() \n" |
594 "{" | 622 "{" |
595 " gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" | 623 " gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" |
596 "}"; | 624 "}"; |
597 | |
598 // Assign vertex positions and texture coordinates to buffers for use in | |
599 // shader program. | |
600 static const float kVertices[] = { | |
601 -1, 1, -1, -1, 1, 1, 1, -1, // Position coordinates. | |
602 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. | |
603 }; | |
604 | |
605 GLuint buffer; | |
606 gles2_if_->GenBuffers(context_->pp_resource(), 1, &buffer); | |
607 gles2_if_->BindBuffer(context_->pp_resource(), GL_ARRAY_BUFFER, buffer); | |
608 | |
609 gles2_if_->BufferData(context_->pp_resource(), GL_ARRAY_BUFFER, | |
610 sizeof(kVertices), kVertices, GL_STATIC_DRAW); | |
611 assertNoGLError(); | |
612 | |
613 shader_2d_ = CreateProgram(kVertexShader, kFragmentShader2D); | |
614 shader_rectangle_arb_ = | 625 shader_rectangle_arb_ = |
615 CreateProgram(kVertexShader, kFragmentShaderRectangle); | 626 CreateProgram(kVertexShader, kFragmentShaderRectangle); |
616 } | 627 } |
617 | 628 |
618 Shader VideoDecodeDemoInstance::CreateProgram(const char* vertex_shader, | 629 Shader VideoDecodeDemoInstance::CreateProgram(const char* vertex_shader, |
619 const char* fragment_shader) { | 630 const char* fragment_shader) { |
620 Shader shader; | 631 Shader shader; |
621 | 632 |
622 // Create shader program. | 633 // Create shader program. |
623 shader.program = gles2_if_->CreateProgram(context_->pp_resource()); | 634 shader.program = gles2_if_->CreateProgram(context_->pp_resource()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
664 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 675 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
665 } | 676 } |
666 } // anonymous namespace | 677 } // anonymous namespace |
667 | 678 |
668 namespace pp { | 679 namespace pp { |
669 // Factory function for your specialization of the Module object. | 680 // Factory function for your specialization of the Module object. |
670 Module* CreateModule() { | 681 Module* CreateModule() { |
671 return new VideoDecodeDemoModule(); | 682 return new VideoDecodeDemoModule(); |
672 } | 683 } |
673 } // namespace pp | 684 } // namespace pp |
OLD | NEW |