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"
16 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(PP_Instance instance
)
17 : Resource(OBJECT_IS_IMPL
, instance
),
22 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(
23 const HostResource
& host_resource
)
24 : Resource(OBJECT_IS_PROXY
, host_resource
),
29 PPB_VideoDecoder_Shared::~PPB_VideoDecoder_Shared() {
30 // Destroy() must be called before the object is destroyed.
31 DCHECK(graphics_context_
== 0);
34 thunk::PPB_VideoDecoder_API
* PPB_VideoDecoder_Shared::AsPPB_VideoDecoder_API() {
38 void PPB_VideoDecoder_Shared::InitCommon(
39 PP_Resource graphics_context
,
40 gpu::gles2::GLES2Implementation
* gles2_impl
) {
41 DCHECK(graphics_context
);
42 DCHECK(!gles2_impl_
&& !graphics_context_
);
43 gles2_impl_
= gles2_impl
;
44 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context
);
45 graphics_context_
= graphics_context
;
48 void PPB_VideoDecoder_Shared::Destroy() {
49 if (graphics_context_
) {
50 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(
52 graphics_context_
= 0;
57 bool PPB_VideoDecoder_Shared::SetFlushCallback(
58 scoped_refptr
<TrackedCallback
> callback
) {
59 if (TrackedCallback::IsPending(flush_callback_
))
61 flush_callback_
= callback
;
65 bool PPB_VideoDecoder_Shared::SetResetCallback(
66 scoped_refptr
<TrackedCallback
> callback
) {
67 if (TrackedCallback::IsPending(reset_callback_
))
69 reset_callback_
= callback
;
73 bool PPB_VideoDecoder_Shared::SetBitstreamBufferCallback(
74 int32 bitstream_buffer_id
,
75 scoped_refptr
<TrackedCallback
> callback
) {
76 return bitstream_buffer_callbacks_
.insert(
77 std::make_pair(bitstream_buffer_id
, callback
)).second
;
80 void PPB_VideoDecoder_Shared::RunFlushCallback(int32 result
) {
81 flush_callback_
->Run(result
);
84 void PPB_VideoDecoder_Shared::RunResetCallback(int32 result
) {
85 reset_callback_
->Run(result
);
88 void PPB_VideoDecoder_Shared::RunBitstreamBufferCallback(
89 int32 bitstream_buffer_id
, 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
);
98 void PPB_VideoDecoder_Shared::FlushCommandBuffer() {
100 // To call Flush() we have to tell Graphics3D that we hold the proxy lock.
101 thunk::EnterResource
<thunk::PPB_Graphics3D_API
, false> enter_g3d(
102 graphics_context_
, false);
103 DCHECK(enter_g3d
.succeeded());
104 PPB_Graphics3D_Shared
* graphics3d
=
105 static_cast<PPB_Graphics3D_Shared
*>(enter_g3d
.object());
106 PPB_Graphics3D_Shared::ScopedNoLocking
dont_lock(graphics3d
);
107 gles2_impl_
->Flush();