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 "ppapi/shared_impl/ppb_video_decoder_shared.h" | 5 #include "ppapi/shared_impl/ppb_video_decoder_shared.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/shared_impl/resource_tracker.h" | 10 #include "ppapi/shared_impl/resource_tracker.h" |
11 #include "ppapi/thunk/enter.h" | 11 #include "ppapi/thunk/enter.h" |
12 | 12 |
13 namespace ppapi { | 13 namespace ppapi { |
14 | 14 |
15 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared() | 15 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(PP_Instance instance) |
16 : flush_callback_(PP_MakeCompletionCallback(NULL, NULL)), | 16 : Resource(instance), |
17 reset_callback_(PP_MakeCompletionCallback(NULL, NULL)), | |
18 graphics_context_(0), | 17 graphics_context_(0), |
19 gles2_impl_(NULL) { | 18 gles2_impl_(NULL) { |
20 } | 19 } |
20 | |
21 PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared( | |
22 const HostResource& host_resource) | |
23 : Resource(host_resource), | |
24 graphics_context_(0), | |
25 gles2_impl_(NULL) { | |
26 } | |
21 | 27 |
22 PPB_VideoDecoder_Shared::~PPB_VideoDecoder_Shared() { | 28 PPB_VideoDecoder_Shared::~PPB_VideoDecoder_Shared() { |
23 } | 29 } |
24 | 30 |
31 thunk::PPB_VideoDecoder_API* PPB_VideoDecoder_Shared::AsPPB_VideoDecoder_API() { | |
32 return this; | |
33 } | |
34 | |
25 void PPB_VideoDecoder_Shared::InitCommon( | 35 void PPB_VideoDecoder_Shared::InitCommon( |
26 PP_Resource graphics_context, | 36 PP_Resource graphics_context, |
27 gpu::gles2::GLES2Implementation* gles2_impl) { | 37 gpu::gles2::GLES2Implementation* gles2_impl) { |
28 DCHECK(graphics_context); | 38 DCHECK(graphics_context); |
29 DCHECK(!gles2_impl_ && !graphics_context_); | 39 DCHECK(!gles2_impl_ && !graphics_context_); |
30 gles2_impl_ = gles2_impl; | 40 gles2_impl_ = gles2_impl; |
31 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context); | 41 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(graphics_context); |
32 graphics_context_ = graphics_context; | 42 graphics_context_ = graphics_context; |
33 } | 43 } |
34 | 44 |
35 void PPB_VideoDecoder_Shared::Destroy() { | 45 void PPB_VideoDecoder_Shared::Destroy() { |
36 graphics_context_ = 0; | 46 graphics_context_ = 0; |
37 gles2_impl_ = NULL; | 47 gles2_impl_ = NULL; |
38 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); | 48 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(graphics_context_); |
39 } | 49 } |
40 | 50 |
41 bool PPB_VideoDecoder_Shared::SetFlushCallback(PP_CompletionCallback callback) { | 51 bool PPB_VideoDecoder_Shared::SetFlushCallback(PP_CompletionCallback callback) { |
42 CHECK(callback.func); | 52 CHECK(callback.func); |
43 if (flush_callback_.func) | 53 if (flush_callback_.get()) |
44 return false; | 54 return false; |
45 flush_callback_ = callback; | 55 flush_callback_ = new TrackedCallback(this, callback); |
46 return true; | 56 return true; |
47 } | 57 } |
48 | 58 |
49 bool PPB_VideoDecoder_Shared::SetResetCallback(PP_CompletionCallback callback) { | 59 bool PPB_VideoDecoder_Shared::SetResetCallback(PP_CompletionCallback callback) { |
50 CHECK(callback.func); | 60 CHECK(callback.func); |
51 if (reset_callback_.func) | 61 if (reset_callback_.get()) |
viettrungluu
2012/01/03 22:43:46
&& !reset_callback_->completed() ?
(Though I supp
| |
52 return false; | 62 return false; |
53 reset_callback_ = callback; | 63 reset_callback_ = new TrackedCallback(this, callback); |
54 return true; | 64 return true; |
55 } | 65 } |
56 | 66 |
57 bool PPB_VideoDecoder_Shared::SetBitstreamBufferCallback( | 67 bool PPB_VideoDecoder_Shared::SetBitstreamBufferCallback( |
58 int32 bitstream_buffer_id, PP_CompletionCallback callback) { | 68 int32 bitstream_buffer_id, |
69 PP_CompletionCallback callback) { | |
59 return bitstream_buffer_callbacks_.insert( | 70 return bitstream_buffer_callbacks_.insert( |
60 std::make_pair(bitstream_buffer_id, callback)).second; | 71 std::make_pair(bitstream_buffer_id, |
72 new TrackedCallback(this, callback))).second; | |
61 } | 73 } |
62 | 74 |
63 void PPB_VideoDecoder_Shared::RunFlushCallback(int32 result) { | 75 void PPB_VideoDecoder_Shared::RunFlushCallback(int32 result) { |
64 DCHECK(flush_callback_.func); | 76 TrackedCallback::ClearAndRun(&flush_callback_, result); |
65 PP_RunAndClearCompletionCallback(&flush_callback_, result); | |
66 } | 77 } |
67 | 78 |
68 void PPB_VideoDecoder_Shared::RunResetCallback(int32 result) { | 79 void PPB_VideoDecoder_Shared::RunResetCallback(int32 result) { |
69 DCHECK(reset_callback_.func); | 80 TrackedCallback::ClearAndRun(&reset_callback_, result); |
70 PP_RunAndClearCompletionCallback(&reset_callback_, result); | |
71 } | 81 } |
72 | 82 |
73 void PPB_VideoDecoder_Shared::RunBitstreamBufferCallback( | 83 void PPB_VideoDecoder_Shared::RunBitstreamBufferCallback( |
74 int32 bitstream_buffer_id, int32 result) { | 84 int32 bitstream_buffer_id, int32 result) { |
75 CallbackById::iterator it = | 85 CallbackById::iterator it = |
76 bitstream_buffer_callbacks_.find(bitstream_buffer_id); | 86 bitstream_buffer_callbacks_.find(bitstream_buffer_id); |
77 DCHECK(it != bitstream_buffer_callbacks_.end()); | 87 DCHECK(it != bitstream_buffer_callbacks_.end()); |
78 PP_CompletionCallback cc = it->second; | 88 scoped_refptr<TrackedCallback> cc = it->second; |
79 bitstream_buffer_callbacks_.erase(it); | 89 bitstream_buffer_callbacks_.erase(it); |
80 PP_RunCompletionCallback(&cc, PP_OK); | 90 cc->Run(PP_OK); |
81 } | 91 } |
82 | 92 |
83 void PPB_VideoDecoder_Shared::FlushCommandBuffer() { | 93 void PPB_VideoDecoder_Shared::FlushCommandBuffer() { |
84 if (gles2_impl_) | 94 if (gles2_impl_) |
85 gles2_impl_->Flush(); | 95 gles2_impl_->Flush(); |
86 } | 96 } |
87 | 97 |
88 } // namespace ppapi | 98 } // namespace ppapi |
OLD | NEW |