Move prefs::kLastPolicyStatisticsUpdate to the policy component.
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_video_decoder_shared.cc
blob7d8d021b5b398156252ac8ac5e121aa58acf78f2
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) {
22 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(
23 const HostResource& host_resource)
24 : Resource(OBJECT_IS_PROXY, host_resource),
25 graphics_context_(0),
26 gles2_impl_(NULL) {
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() {
35 return this;
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(
51 graphics_context_);
52 graphics_context_ = 0;
54 gles2_impl_ = NULL;
57 bool PPB_VideoDecoder_Shared::SetFlushCallback(
58 scoped_refptr<TrackedCallback> callback) {
59 if (TrackedCallback::IsPending(flush_callback_))
60 return false;
61 flush_callback_ = callback;
62 return true;
65 bool PPB_VideoDecoder_Shared::SetResetCallback(
66 scoped_refptr<TrackedCallback> callback) {
67 if (TrackedCallback::IsPending(reset_callback_))
68 return false;
69 reset_callback_ = callback;
70 return true;
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);
95 cc->Run(PP_OK);
98 void PPB_VideoDecoder_Shared::FlushCommandBuffer() {
99 if (gles2_impl_) {
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();
111 } // namespace ppapi