[tracing] Non-functional refactor of MemoryDumpManager
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_video_decoder_shared.cc
blob88c9ca2a4f23a21fd08705b2f95fb165434c7ea3
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
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/ppb_video_decoder_shared.h"
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/ppb_graphics_3d_shared.h"
11 #include "ppapi/shared_impl/resource_tracker.h"
12 #include "ppapi/thunk/enter.h"
14 namespace ppapi {
16 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(PP_Instance instance)
17 : Resource(OBJECT_IS_IMPL, instance),
18 graphics_context_(0),
19 gles2_impl_(NULL) {}
21 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(
22 const HostResource& host_resource)
23 : Resource(OBJECT_IS_PROXY, host_resource),
24 graphics_context_(0),
25 gles2_impl_(NULL) {}
27 PPB_VideoDecoder_Shared::~PPB_VideoDecoder_Shared() {
28 // Destroy() must be called before the object is destroyed.
29 DCHECK(graphics_context_ == 0);
32 thunk::PPB_VideoDecoder_Dev_API*
33 PPB_VideoDecoder_Shared::AsPPB_VideoDecoder_Dev_API() {
34 return this;
37 void PPB_VideoDecoder_Shared::InitCommon(
38 PP_Resource graphics_context,
39 gpu::gles2::GLES2Implementation* gles2_impl) {
40 DCHECK(graphics_context);
41 DCHECK(!gles2_impl_ && !graphics_context_);
42 gles2_impl_ = gles2_impl;
43 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context);
44 graphics_context_ = graphics_context;
47 void PPB_VideoDecoder_Shared::Destroy() {
48 if (graphics_context_) {
49 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(
50 graphics_context_);
51 graphics_context_ = 0;
53 gles2_impl_ = NULL;
56 bool PPB_VideoDecoder_Shared::SetFlushCallback(
57 scoped_refptr<TrackedCallback> callback) {
58 if (TrackedCallback::IsPending(flush_callback_))
59 return false;
60 flush_callback_ = callback;
61 return true;
64 bool PPB_VideoDecoder_Shared::SetResetCallback(
65 scoped_refptr<TrackedCallback> callback) {
66 if (TrackedCallback::IsPending(reset_callback_))
67 return false;
68 reset_callback_ = callback;
69 return true;
72 bool PPB_VideoDecoder_Shared::SetBitstreamBufferCallback(
73 int32 bitstream_buffer_id,
74 scoped_refptr<TrackedCallback> callback) {
75 return bitstream_buffer_callbacks_.insert(std::make_pair(bitstream_buffer_id,
76 callback)).second;
79 void PPB_VideoDecoder_Shared::RunFlushCallback(int32 result) {
80 flush_callback_->Run(result);
83 void PPB_VideoDecoder_Shared::RunResetCallback(int32 result) {
84 reset_callback_->Run(result);
87 void PPB_VideoDecoder_Shared::RunBitstreamBufferCallback(
88 int32 bitstream_buffer_id,
89 int32 result) {
90 CallbackById::iterator it =
91 bitstream_buffer_callbacks_.find(bitstream_buffer_id);
92 DCHECK(it != bitstream_buffer_callbacks_.end());
93 scoped_refptr<TrackedCallback> cc = it->second;
94 bitstream_buffer_callbacks_.erase(it);
95 cc->Run(PP_OK);
98 void PPB_VideoDecoder_Shared::FlushCommandBuffer() {
99 // Ensure that graphics_context is still live before using gles2_impl_.
100 // Our "plugin reference" is not enough to keep graphics_context alive if
101 // DidDeleteInstance() has been called.
102 if (PpapiGlobals::Get()->GetResourceTracker()->GetResource(
103 graphics_context_)) {
104 if (gles2_impl_)
105 gles2_impl_->Flush();
109 } // namespace ppapi