| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/shared_impl/video_decoder_impl.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | |
| 9 #include "ppapi/c/pp_errors.h" | |
| 10 #include "ppapi/shared_impl/resource_tracker.h" | |
| 11 #include "ppapi/thunk/enter.h" | |
| 12 | |
| 13 namespace ppapi { | |
| 14 | |
| 15 VideoDecoderImpl::VideoDecoderImpl() | |
| 16 : flush_callback_(PP_MakeCompletionCallback(NULL, NULL)), | |
| 17 reset_callback_(PP_MakeCompletionCallback(NULL, NULL)), | |
| 18 graphics_context_(0), | |
| 19 gles2_impl_(NULL) { | |
| 20 } | |
| 21 | |
| 22 VideoDecoderImpl::~VideoDecoderImpl() { | |
| 23 } | |
| 24 | |
| 25 void VideoDecoderImpl::InitCommon( | |
| 26 PP_Resource graphics_context, | |
| 27 gpu::gles2::GLES2Implementation* gles2_impl) { | |
| 28 DCHECK(graphics_context); | |
| 29 DCHECK(!gles2_impl_ && !graphics_context_); | |
| 30 gles2_impl_ = gles2_impl; | |
| 31 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context); | |
| 32 graphics_context_ = graphics_context; | |
| 33 } | |
| 34 | |
| 35 void VideoDecoderImpl::Destroy() { | |
| 36 graphics_context_ = 0; | |
| 37 gles2_impl_ = NULL; | |
| 38 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); | |
| 39 } | |
| 40 | |
| 41 bool VideoDecoderImpl::SetFlushCallback(PP_CompletionCallback callback) { | |
| 42 CHECK(callback.func); | |
| 43 if (flush_callback_.func) | |
| 44 return false; | |
| 45 flush_callback_ = callback; | |
| 46 return true; | |
| 47 } | |
| 48 | |
| 49 bool VideoDecoderImpl::SetResetCallback(PP_CompletionCallback callback) { | |
| 50 CHECK(callback.func); | |
| 51 if (reset_callback_.func) | |
| 52 return false; | |
| 53 reset_callback_ = callback; | |
| 54 return true; | |
| 55 } | |
| 56 | |
| 57 bool VideoDecoderImpl::SetBitstreamBufferCallback( | |
| 58 int32 bitstream_buffer_id, PP_CompletionCallback callback) { | |
| 59 return bitstream_buffer_callbacks_.insert( | |
| 60 std::make_pair(bitstream_buffer_id, callback)).second; | |
| 61 } | |
| 62 | |
| 63 void VideoDecoderImpl::RunFlushCallback(int32 result) { | |
| 64 DCHECK(flush_callback_.func); | |
| 65 PP_RunAndClearCompletionCallback(&flush_callback_, result); | |
| 66 } | |
| 67 | |
| 68 void VideoDecoderImpl::RunResetCallback(int32 result) { | |
| 69 DCHECK(reset_callback_.func); | |
| 70 PP_RunAndClearCompletionCallback(&reset_callback_, result); | |
| 71 } | |
| 72 | |
| 73 void VideoDecoderImpl::RunBitstreamBufferCallback( | |
| 74 int32 bitstream_buffer_id, int32 result) { | |
| 75 CallbackById::iterator it = | |
| 76 bitstream_buffer_callbacks_.find(bitstream_buffer_id); | |
| 77 DCHECK(it != bitstream_buffer_callbacks_.end()); | |
| 78 PP_CompletionCallback cc = it->second; | |
| 79 bitstream_buffer_callbacks_.erase(it); | |
| 80 PP_RunCompletionCallback(&cc, PP_OK); | |
| 81 } | |
| 82 | |
| 83 void VideoDecoderImpl::FlushCommandBuffer() { | |
| 84 if (gles2_impl_) | |
| 85 gles2_impl_->Flush(); | |
| 86 } | |
| 87 | |
| 88 } // namespace ppapi | |
| OLD | NEW |