OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 enum { kNumConcurrentDecodes = 7 }; | 66 enum { kNumConcurrentDecodes = 7 }; |
67 | 67 |
68 // Helper struct that stores data used by the shader program. | 68 // Helper struct that stores data used by the shader program. |
69 struct ShaderInfo { | 69 struct ShaderInfo { |
70 GLint pos_location; | 70 GLint pos_location; |
71 GLint tc_location; | 71 GLint tc_location; |
72 GLint tex_location; | 72 GLint tex_location; |
73 GLuint vertex_buffers[2]; | 73 GLuint vertex_buffers[2]; |
74 }; | 74 }; |
75 | 75 |
76 // Serialize PPB_Video_Decoder_Dev operations w.r.t. GPU command buffer. | |
77 // TODO(fischman): figure out how much of this is actually necessary. | |
78 // Probably any necessary serialization ought to be happening in the | |
79 // PPAPI implementation, not in the plugin! | |
80 void FinishGL() { | |
81 gles2_if_->Finish(context_->pp_resource()); | |
82 } | |
83 | |
84 // Initialize Video Decoder. | 76 // Initialize Video Decoder. |
85 void InitializeDecoder(); | 77 void InitializeDecoder(); |
86 | 78 |
87 // Callbacks passed into pp:VideoDecoder_Dev functions. | 79 // Callbacks passed into pp:VideoDecoder_Dev functions. |
88 void DecoderInitDone(int32_t result); | 80 void DecoderInitDone(int32_t result); |
89 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); | 81 void DecoderBitstreamDone(int32_t result, int bitstream_buffer_id); |
90 void DecoderFlushDone(int32_t result); | 82 void DecoderFlushDone(int32_t result); |
91 void DecoderAbortDone(int32_t result); | 83 void DecoderAbortDone(int32_t result); |
92 | 84 |
93 // Decode helpers. | 85 // Decode helpers. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 PP_PictureBufferType_Dev type) { | 257 PP_PictureBufferType_Dev type) { |
266 std::vector<PP_GLESBuffer_Dev> buffers; | 258 std::vector<PP_GLESBuffer_Dev> buffers; |
267 for (uint32_t i = 0; i < req_num_of_bufs; i++) { | 259 for (uint32_t i = 0; i < req_num_of_bufs; i++) { |
268 PP_GLESBuffer_Dev buffer; | 260 PP_GLESBuffer_Dev buffer; |
269 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); | 261 buffer.texture_id = CreateTexture(dimensions.width, dimensions.height); |
270 int id = ++next_picture_buffer_id_; | 262 int id = ++next_picture_buffer_id_; |
271 buffer.info.id= id; | 263 buffer.info.id= id; |
272 buffers.push_back(buffer); | 264 buffers.push_back(buffer); |
273 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); | 265 assert(buffers_by_id_.insert(std::make_pair(id, buffer)).second); |
274 } | 266 } |
275 FinishGL(); | |
276 video_decoder_->AssignGLESBuffers(buffers); | 267 video_decoder_->AssignGLESBuffers(buffers); |
277 } | 268 } |
278 | 269 |
279 void GLES2DemoInstance::DismissPictureBuffer( | 270 void GLES2DemoInstance::DismissPictureBuffer( |
280 pp::VideoDecoder_Dev decoder, int32_t picture_buffer_id) { | 271 pp::VideoDecoder_Dev decoder, int32_t picture_buffer_id) { |
281 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); | 272 PictureBufferMap::iterator it = buffers_by_id_.find(picture_buffer_id); |
282 assert(it != buffers_by_id_.end()); | 273 assert(it != buffers_by_id_.end()); |
283 DeleteTexture(it->second.texture_id); | 274 DeleteTexture(it->second.texture_id); |
284 buffers_by_id_.erase(it); | 275 buffers_by_id_.erase(it); |
285 | |
286 FinishGL(); | |
287 } | 276 } |
288 | 277 |
289 void GLES2DemoInstance::PictureReady( | 278 void GLES2DemoInstance::PictureReady( |
290 pp::VideoDecoder_Dev decoder, const PP_Picture_Dev& picture) { | 279 pp::VideoDecoder_Dev decoder, const PP_Picture_Dev& picture) { |
291 PictureBufferMap::iterator it = | 280 PictureBufferMap::iterator it = |
292 buffers_by_id_.find(picture.picture_buffer_id); | 281 buffers_by_id_.find(picture.picture_buffer_id); |
293 assert(it != buffers_by_id_.end()); | 282 assert(it != buffers_by_id_.end()); |
294 Render(it->second); | 283 Render(it->second); |
295 } | 284 } |
296 | 285 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 322 |
334 // Set viewport window size and clear color bit. | 323 // Set viewport window size and clear color bit. |
335 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); | 324 gles2_if_->Clear(context_->pp_resource(), GL_COLOR_BUFFER_BIT); |
336 gles2_if_->Viewport(context_->pp_resource(), 0, 0, | 325 gles2_if_->Viewport(context_->pp_resource(), 0, 0, |
337 position_size_.width(), position_size_.height()); | 326 position_size_.width(), position_size_.height()); |
338 | 327 |
339 assert(BindGraphics(*surface_)); | 328 assert(BindGraphics(*surface_)); |
340 assertNoGLError(); | 329 assertNoGLError(); |
341 | 330 |
342 CreateGLObjects(); | 331 CreateGLObjects(); |
343 | |
344 FinishGL(); | |
345 } | 332 } |
346 | 333 |
347 void GLES2DemoInstance::Render(const PP_GLESBuffer_Dev& buffer) { | 334 void GLES2DemoInstance::Render(const PP_GLESBuffer_Dev& buffer) { |
348 if (is_painting_) { | 335 if (is_painting_) { |
349 // We are dropping frames if we don't render fast enough - | 336 // We are dropping frames if we don't render fast enough - |
350 // that is why sometimes the last frame rendered is < 249. | 337 // that is why sometimes the last frame rendered is < 249. |
351 if (video_decoder_) { | 338 if (video_decoder_) |
352 FinishGL(); | |
353 video_decoder_->ReusePictureBuffer(buffer.info.id); | 339 video_decoder_->ReusePictureBuffer(buffer.info.id); |
354 } | |
355 return; | 340 return; |
356 } | 341 } |
357 is_painting_ = true; | 342 is_painting_ = true; |
358 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 343 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
359 gles2_if_->BindTexture( | 344 gles2_if_->BindTexture( |
360 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); | 345 context_->pp_resource(), GL_TEXTURE_2D, buffer.texture_id); |
361 gles2_if_->Uniform1i(context_->pp_resource(), program_data_.tex_location, 0); | 346 gles2_if_->Uniform1i(context_->pp_resource(), program_data_.tex_location, 0); |
362 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); | 347 gles2_if_->DrawArrays(context_->pp_resource(), GL_TRIANGLE_STRIP, 0, 4); |
363 pp::CompletionCallback cb = | 348 pp::CompletionCallback cb = |
364 callback_factory_.NewCallback( | 349 callback_factory_.NewCallback( |
365 &GLES2DemoInstance::PaintFinished, buffer.info.id); | 350 &GLES2DemoInstance::PaintFinished, buffer.info.id); |
366 assert(surface_->SwapBuffers(cb) == PP_ERROR_WOULDBLOCK); | 351 assert(surface_->SwapBuffers(cb) == PP_ERROR_WOULDBLOCK); |
367 assertNoGLError(); | 352 assertNoGLError(); |
368 } | 353 } |
369 | 354 |
370 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { | 355 void GLES2DemoInstance::PaintFinished(int32_t result, int picture_buffer_id) { |
371 is_painting_ = false; | 356 is_painting_ = false; |
372 FinishGL(); | |
373 if (video_decoder_) | 357 if (video_decoder_) |
374 video_decoder_->ReusePictureBuffer(picture_buffer_id); | 358 video_decoder_->ReusePictureBuffer(picture_buffer_id); |
375 } | 359 } |
376 | 360 |
377 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { | 361 GLuint GLES2DemoInstance::CreateTexture(int32_t width, int32_t height) { |
378 GLuint texture_id; | 362 GLuint texture_id; |
379 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); | 363 gles2_if_->GenTextures(context_->pp_resource(), 1, &texture_id); |
380 assertNoGLError(); | 364 assertNoGLError(); |
381 // Assign parameters. | 365 // Assign parameters. |
382 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); | 366 gles2_if_->ActiveTexture(context_->pp_resource(), GL_TEXTURE0); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 gles2_if_->DeleteShader(context_->pp_resource(), shader); | 491 gles2_if_->DeleteShader(context_->pp_resource(), shader); |
508 } | 492 } |
509 } // anonymous namespace | 493 } // anonymous namespace |
510 | 494 |
511 namespace pp { | 495 namespace pp { |
512 // Factory function for your specialization of the Module object. | 496 // Factory function for your specialization of the Module object. |
513 Module* CreateModule() { | 497 Module* CreateModule() { |
514 return new GLES2DemoModule(); | 498 return new GLES2DemoModule(); |
515 } | 499 } |
516 } // namespace pp | 500 } // namespace pp |
OLD | NEW |