OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 <stdio.h> | 5 #include <stdio.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include <iostream> | 8 #include <iostream> |
9 #include <queue> | 9 #include <queue> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 std::ostringstream stream_; | 106 std::ostringstream stream_; |
107 }; | 107 }; |
108 | 108 |
109 void InitializeDecoders(); | 109 void InitializeDecoders(); |
110 | 110 |
111 // GL-related functions. | 111 // GL-related functions. |
112 void InitGL(); | 112 void InitGL(); |
113 void CreateGLObjects(); | 113 void CreateGLObjects(); |
114 void Create2DProgramOnce(); | 114 void Create2DProgramOnce(); |
115 void CreateRectangleARBProgramOnce(); | 115 void CreateRectangleARBProgramOnce(); |
| 116 void CreateExternalOESProgramOnce(); |
116 Shader CreateProgram(const char* vertex_shader, const char* fragment_shader); | 117 Shader CreateProgram(const char* vertex_shader, const char* fragment_shader); |
117 void CreateShader(GLuint program, GLenum type, const char* source, int size); | 118 void CreateShader(GLuint program, GLenum type, const char* source, int size); |
118 void PaintNextPicture(); | 119 void PaintNextPicture(); |
119 void PaintFinished(int32_t result); | 120 void PaintFinished(int32_t result); |
120 | 121 |
121 pp::Size plugin_size_; | 122 pp::Size plugin_size_; |
122 bool is_painting_; | 123 bool is_painting_; |
123 // When decode outpaces render, we queue up decoded pictures for later | 124 // When decode outpaces render, we queue up decoded pictures for later |
124 // painting. | 125 // painting. |
125 typedef std::queue<PendingPicture> PendingPictureQueue; | 126 typedef std::queue<PendingPicture> PendingPictureQueue; |
(...skipping 12 matching lines...) Expand all Loading... |
138 | 139 |
139 // Owned data. | 140 // Owned data. |
140 pp::Graphics3D* context_; | 141 pp::Graphics3D* context_; |
141 typedef std::vector<Decoder*> DecoderList; | 142 typedef std::vector<Decoder*> DecoderList; |
142 DecoderList video_decoders_; | 143 DecoderList video_decoders_; |
143 | 144 |
144 // Shader program to draw GL_TEXTURE_2D target. | 145 // Shader program to draw GL_TEXTURE_2D target. |
145 Shader shader_2d_; | 146 Shader shader_2d_; |
146 // Shader program to draw GL_TEXTURE_RECTANGLE_ARB target. | 147 // Shader program to draw GL_TEXTURE_RECTANGLE_ARB target. |
147 Shader shader_rectangle_arb_; | 148 Shader shader_rectangle_arb_; |
| 149 // Shader program to draw GL_TEXTURE_EXTERNAL_OES target. |
| 150 Shader shader_external_oes_; |
148 }; | 151 }; |
149 | 152 |
150 class Decoder { | 153 class Decoder { |
151 public: | 154 public: |
152 Decoder(MyInstance* instance, int id, const pp::Graphics3D& graphics_3d); | 155 Decoder(MyInstance* instance, int id, const pp::Graphics3D& graphics_3d); |
153 ~Decoder(); | 156 ~Decoder(); |
154 | 157 |
155 int id() const { return id_; } | 158 int id() const { return id_; } |
156 bool flushing() const { return flushing_; } | 159 bool flushing() const { return flushing_; } |
157 bool resetting() const { return resetting_; } | 160 bool resetting() const { return resetting_; } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 386 |
384 MyInstance::~MyInstance() { | 387 MyInstance::~MyInstance() { |
385 if (!context_) | 388 if (!context_) |
386 return; | 389 return; |
387 | 390 |
388 PP_Resource graphics_3d = context_->pp_resource(); | 391 PP_Resource graphics_3d = context_->pp_resource(); |
389 if (shader_2d_.program) | 392 if (shader_2d_.program) |
390 gles2_if_->DeleteProgram(graphics_3d, shader_2d_.program); | 393 gles2_if_->DeleteProgram(graphics_3d, shader_2d_.program); |
391 if (shader_rectangle_arb_.program) | 394 if (shader_rectangle_arb_.program) |
392 gles2_if_->DeleteProgram(graphics_3d, shader_rectangle_arb_.program); | 395 gles2_if_->DeleteProgram(graphics_3d, shader_rectangle_arb_.program); |
| 396 if (shader_external_oes_.program) |
| 397 gles2_if_->DeleteProgram(graphics_3d, shader_external_oes_.program); |
393 | 398 |
394 for (DecoderList::iterator it = video_decoders_.begin(); | 399 for (DecoderList::iterator it = video_decoders_.begin(); |
395 it != video_decoders_.end(); | 400 it != video_decoders_.end(); |
396 ++it) | 401 ++it) |
397 delete *it; | 402 delete *it; |
398 | 403 |
399 delete context_; | 404 delete context_; |
400 } | 405 } |
401 | 406 |
402 void MyInstance::DidChangeView(const pp::Rect& position, | 407 void MyInstance::DidChangeView(const pp::Rect& position, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 x = half_width; | 476 x = half_width; |
472 y = half_height; | 477 y = half_height; |
473 } | 478 } |
474 | 479 |
475 PP_Resource graphics_3d = context_->pp_resource(); | 480 PP_Resource graphics_3d = context_->pp_resource(); |
476 if (picture.texture_target == GL_TEXTURE_2D) { | 481 if (picture.texture_target == GL_TEXTURE_2D) { |
477 Create2DProgramOnce(); | 482 Create2DProgramOnce(); |
478 gles2_if_->UseProgram(graphics_3d, shader_2d_.program); | 483 gles2_if_->UseProgram(graphics_3d, shader_2d_.program); |
479 gles2_if_->Uniform2f( | 484 gles2_if_->Uniform2f( |
480 graphics_3d, shader_2d_.texcoord_scale_location, 1.0, 1.0); | 485 graphics_3d, shader_2d_.texcoord_scale_location, 1.0, 1.0); |
481 } else { | 486 } else if (picture.texture_target == GL_TEXTURE_RECTANGLE_ARB) { |
482 assert(picture.texture_target == GL_TEXTURE_RECTANGLE_ARB); | |
483 CreateRectangleARBProgramOnce(); | 487 CreateRectangleARBProgramOnce(); |
484 gles2_if_->UseProgram(graphics_3d, shader_rectangle_arb_.program); | 488 gles2_if_->UseProgram(graphics_3d, shader_rectangle_arb_.program); |
485 gles2_if_->Uniform2f(graphics_3d, | 489 gles2_if_->Uniform2f(graphics_3d, |
486 shader_rectangle_arb_.texcoord_scale_location, | 490 shader_rectangle_arb_.texcoord_scale_location, |
487 picture.texture_size.width, | 491 picture.texture_size.width, |
488 picture.texture_size.height); | 492 picture.texture_size.height); |
| 493 } else { |
| 494 assert(picture.texture_target == GL_TEXTURE_EXTERNAL_OES); |
| 495 CreateExternalOESProgramOnce(); |
| 496 gles2_if_->UseProgram(graphics_3d, shader_external_oes_.program); |
| 497 gles2_if_->Uniform2f( |
| 498 graphics_3d, shader_external_oes_.texcoord_scale_location, 1.0, 1.0); |
489 } | 499 } |
490 | 500 |
491 gles2_if_->Viewport(graphics_3d, x, y, half_width, half_height); | 501 gles2_if_->Viewport(graphics_3d, x, y, half_width, half_height); |
492 gles2_if_->ActiveTexture(graphics_3d, GL_TEXTURE0); | 502 gles2_if_->ActiveTexture(graphics_3d, GL_TEXTURE0); |
493 gles2_if_->BindTexture( | 503 gles2_if_->BindTexture( |
494 graphics_3d, picture.texture_target, picture.texture_id); | 504 graphics_3d, picture.texture_target, picture.texture_id); |
495 gles2_if_->DrawArrays(graphics_3d, GL_TRIANGLE_STRIP, 0, 4); | 505 gles2_if_->DrawArrays(graphics_3d, GL_TRIANGLE_STRIP, 0, 4); |
496 | 506 |
497 gles2_if_->UseProgram(graphics_3d, 0); | 507 gles2_if_->UseProgram(graphics_3d, 0); |
498 | 508 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 "#extension GL_ARB_texture_rectangle : require\n" | 633 "#extension GL_ARB_texture_rectangle : require\n" |
624 "precision mediump float; \n" | 634 "precision mediump float; \n" |
625 "varying vec2 v_texCoord; \n" | 635 "varying vec2 v_texCoord; \n" |
626 "uniform sampler2DRect s_texture; \n" | 636 "uniform sampler2DRect s_texture; \n" |
627 "void main() \n" | 637 "void main() \n" |
628 "{" | 638 "{" |
629 " gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" | 639 " gl_FragColor = texture2DRect(s_texture, v_texCoord).rgba; \n" |
630 "}"; | 640 "}"; |
631 shader_rectangle_arb_ = | 641 shader_rectangle_arb_ = |
632 CreateProgram(kVertexShader, kFragmentShaderRectangle); | 642 CreateProgram(kVertexShader, kFragmentShaderRectangle); |
| 643 assertNoGLError(); |
| 644 } |
| 645 |
| 646 void MyInstance::CreateExternalOESProgramOnce() { |
| 647 if (shader_external_oes_.program) |
| 648 return; |
| 649 static const char kFragmentShaderExternal[] = |
| 650 "#extension GL_OES_EGL_image_external : require\n" |
| 651 "precision mediump float; \n" |
| 652 "varying vec2 v_texCoord; \n" |
| 653 "uniform samplerExternalOES s_texture; \n" |
| 654 "void main() \n" |
| 655 "{" |
| 656 " gl_FragColor = texture2D(s_texture, v_texCoord); \n" |
| 657 "}"; |
| 658 shader_external_oes_ = CreateProgram(kVertexShader, kFragmentShaderExternal); |
| 659 assertNoGLError(); |
633 } | 660 } |
634 | 661 |
635 Shader MyInstance::CreateProgram(const char* vertex_shader, | 662 Shader MyInstance::CreateProgram(const char* vertex_shader, |
636 const char* fragment_shader) { | 663 const char* fragment_shader) { |
637 Shader shader; | 664 Shader shader; |
638 | 665 |
639 // Create shader program. | 666 // Create shader program. |
640 shader.program = gles2_if_->CreateProgram(context_->pp_resource()); | 667 shader.program = gles2_if_->CreateProgram(context_->pp_resource()); |
641 CreateShader( | 668 CreateShader( |
642 shader.program, GL_VERTEX_SHADER, vertex_shader, strlen(vertex_shader)); | 669 shader.program, GL_VERTEX_SHADER, vertex_shader, strlen(vertex_shader)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 }; | 731 }; |
705 | 732 |
706 } // anonymous namespace | 733 } // anonymous namespace |
707 | 734 |
708 namespace pp { | 735 namespace pp { |
709 // Factory function for your specialization of the Module object. | 736 // Factory function for your specialization of the Module object. |
710 Module* CreateModule() { | 737 Module* CreateModule() { |
711 return new MyModule(); | 738 return new MyModule(); |
712 } | 739 } |
713 } // namespace pp | 740 } // namespace pp |
OLD | NEW |