Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_decode_accelerator.cc
blob0e8af7faf39323904a71fb21eeadde3e4ddb7392
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 "content/common/gpu/media/gpu_video_decode_accelerator.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop/message_loop_proxy.h"
14 #include "base/stl_util.h"
16 #include "content/common/gpu/gpu_channel.h"
17 #include "content/common/gpu/gpu_messages.h"
18 #include "content/common/gpu/media/gpu_video_accelerator_util.h"
19 #include "content/public/common/content_switches.h"
20 #include "gpu/command_buffer/common/command_buffer.h"
21 #include "ipc/ipc_message_macros.h"
22 #include "ipc/ipc_message_utils.h"
23 #include "ipc/message_filter.h"
24 #include "media/base/limits.h"
25 #include "ui/gl/gl_context.h"
26 #include "ui/gl/gl_image.h"
27 #include "ui/gl/gl_surface_egl.h"
29 #if defined(OS_WIN)
30 #include "base/win/windows_version.h"
31 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
32 #elif defined(OS_MACOSX)
33 #include "content/common/gpu/media/vt_video_decode_accelerator.h"
34 #elif defined(OS_CHROMEOS)
35 #if defined(USE_V4L2_CODEC)
36 #include "content/common/gpu/media/v4l2_device.h"
37 #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h"
38 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
39 #endif
40 #if defined(ARCH_CPU_X86_FAMILY)
41 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
42 #include "ui/gl/gl_implementation.h"
43 #endif
44 #elif defined(USE_OZONE)
45 #include "media/ozone/media_ozone_platform.h"
46 #elif defined(OS_ANDROID)
47 #include "content/common/gpu/media/android_video_decode_accelerator.h"
48 #endif
50 #include "ui/gfx/geometry/size.h"
52 namespace content {
54 static bool MakeDecoderContextCurrent(
55 const base::WeakPtr<GpuCommandBufferStub> stub) {
56 if (!stub) {
57 DLOG(ERROR) << "Stub is gone; won't MakeCurrent().";
58 return false;
61 if (!stub->decoder()->MakeCurrent()) {
62 DLOG(ERROR) << "Failed to MakeCurrent()";
63 return false;
66 return true;
69 // DebugAutoLock works like AutoLock but only acquires the lock when
70 // DCHECK is on.
71 #if DCHECK_IS_ON()
72 typedef base::AutoLock DebugAutoLock;
73 #else
74 class DebugAutoLock {
75 public:
76 explicit DebugAutoLock(base::Lock&) {}
78 #endif
80 class GpuVideoDecodeAccelerator::MessageFilter : public IPC::MessageFilter {
81 public:
82 MessageFilter(GpuVideoDecodeAccelerator* owner, int32 host_route_id)
83 : owner_(owner), host_route_id_(host_route_id) {}
85 void OnChannelError() override { sender_ = NULL; }
87 void OnChannelClosing() override { sender_ = NULL; }
89 void OnFilterAdded(IPC::Sender* sender) override { sender_ = sender; }
91 void OnFilterRemoved() override {
92 // This will delete |owner_| and |this|.
93 owner_->OnFilterRemoved();
96 bool OnMessageReceived(const IPC::Message& msg) override {
97 if (msg.routing_id() != host_route_id_)
98 return false;
100 IPC_BEGIN_MESSAGE_MAP(MessageFilter, msg)
101 IPC_MESSAGE_FORWARD(AcceleratedVideoDecoderMsg_Decode, owner_,
102 GpuVideoDecodeAccelerator::OnDecode)
103 IPC_MESSAGE_UNHANDLED(return false;)
104 IPC_END_MESSAGE_MAP()
105 return true;
108 bool SendOnIOThread(IPC::Message* message) {
109 DCHECK(!message->is_sync());
110 if (!sender_) {
111 delete message;
112 return false;
114 return sender_->Send(message);
117 protected:
118 ~MessageFilter() override {}
120 private:
121 GpuVideoDecodeAccelerator* const owner_;
122 const int32 host_route_id_;
123 // The sender to which this filter was added.
124 IPC::Sender* sender_;
127 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(
128 int32 host_route_id,
129 GpuCommandBufferStub* stub,
130 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
131 : host_route_id_(host_route_id),
132 stub_(stub),
133 texture_target_(0),
134 filter_removed_(true, false),
135 child_message_loop_(base::MessageLoopProxy::current()),
136 io_message_loop_(io_message_loop),
137 weak_factory_for_io_(this) {
138 DCHECK(stub_);
139 stub_->AddDestructionObserver(this);
140 make_context_current_ =
141 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr());
144 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {
145 // This class can only be self-deleted from OnWillDestroyStub(), which means
146 // the VDA has already been destroyed in there.
147 DCHECK(!video_decode_accelerator_);
150 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) {
151 if (!video_decode_accelerator_)
152 return false;
154 bool handled = true;
155 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg)
156 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode)
157 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers,
158 OnAssignPictureBuffers)
159 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer,
160 OnReusePictureBuffer)
161 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush)
162 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset)
163 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy)
164 IPC_MESSAGE_UNHANDLED(handled = false)
165 IPC_END_MESSAGE_MAP()
166 return handled;
169 void GpuVideoDecodeAccelerator::ProvidePictureBuffers(
170 uint32 requested_num_of_buffers,
171 const gfx::Size& dimensions,
172 uint32 texture_target) {
173 if (dimensions.width() > media::limits::kMaxDimension ||
174 dimensions.height() > media::limits::kMaxDimension ||
175 dimensions.GetArea() > media::limits::kMaxCanvas) {
176 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
177 return;
179 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers(
180 host_route_id_,
181 requested_num_of_buffers,
182 dimensions,
183 texture_target))) {
184 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) "
185 << "failed";
187 texture_dimensions_ = dimensions;
188 texture_target_ = texture_target;
191 void GpuVideoDecodeAccelerator::DismissPictureBuffer(
192 int32 picture_buffer_id) {
193 // Notify client that picture buffer is now unused.
194 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer(
195 host_route_id_, picture_buffer_id))) {
196 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) "
197 << "failed";
199 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
200 uncleared_textures_.erase(picture_buffer_id);
203 void GpuVideoDecodeAccelerator::PictureReady(
204 const media::Picture& picture) {
205 // VDA may call PictureReady on IO thread. SetTextureCleared should run on
206 // the child thread. VDA is responsible to call PictureReady on the child
207 // thread when a picture buffer is delivered the first time.
208 if (child_message_loop_->BelongsToCurrentThread()) {
209 SetTextureCleared(picture);
210 } else {
211 DCHECK(io_message_loop_->BelongsToCurrentThread());
212 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
213 DCHECK_EQ(0u, uncleared_textures_.count(picture.picture_buffer_id()));
216 if (!Send(new AcceleratedVideoDecoderHostMsg_PictureReady(
217 host_route_id_, picture.picture_buffer_id(),
218 picture.bitstream_buffer_id(), picture.visible_rect(),
219 picture.allow_overlay()))) {
220 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_PictureReady) failed";
224 void GpuVideoDecodeAccelerator::NotifyError(
225 media::VideoDecodeAccelerator::Error error) {
226 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification(
227 host_route_id_, error))) {
228 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) "
229 << "failed";
233 void GpuVideoDecodeAccelerator::Initialize(
234 const media::VideoCodecProfile profile,
235 IPC::Message* init_done_msg) {
236 DCHECK(!video_decode_accelerator_.get());
238 if (!stub_->channel()->AddRoute(host_route_id_, this)) {
239 DLOG(ERROR) << "Initialize(): failed to add route";
240 SendCreateDecoderReply(init_done_msg, false);
243 #if !defined(OS_WIN)
244 // Ensure we will be able to get a GL context at all before initializing
245 // non-Windows VDAs.
246 if (!make_context_current_.Run()) {
247 SendCreateDecoderReply(init_done_msg, false);
248 return;
250 #endif
252 // Array of Create..VDA() function pointers, maybe applicable to the current
253 // platform. This list is ordered by priority of use and it should be the
254 // same as the order of querying supported profiles of VDAs.
255 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = {
256 &GpuVideoDecodeAccelerator::CreateDXVAVDA,
257 &GpuVideoDecodeAccelerator::CreateV4L2VDA,
258 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA,
259 &GpuVideoDecodeAccelerator::CreateVaapiVDA,
260 &GpuVideoDecodeAccelerator::CreateVTVDA,
261 &GpuVideoDecodeAccelerator::CreateOzoneVDA,
262 &GpuVideoDecodeAccelerator::CreateAndroidVDA};
264 for (const auto& create_vda_function : create_vda_fps) {
265 video_decode_accelerator_ = (this->*create_vda_function)();
266 if (!video_decode_accelerator_ ||
267 !video_decode_accelerator_->Initialize(profile, this))
268 continue;
270 if (video_decode_accelerator_->CanDecodeOnIOThread()) {
271 filter_ = new MessageFilter(this, host_route_id_);
272 stub_->channel()->AddFilter(filter_.get());
274 SendCreateDecoderReply(init_done_msg, true);
275 return;
277 video_decode_accelerator_.reset();
278 LOG(ERROR) << "HW video decode not available for profile " << profile;
279 SendCreateDecoderReply(init_done_msg, false);
282 scoped_ptr<media::VideoDecodeAccelerator>
283 GpuVideoDecodeAccelerator::CreateDXVAVDA() {
284 scoped_ptr<media::VideoDecodeAccelerator> decoder;
285 #if defined(OS_WIN)
286 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
287 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
288 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_,
289 stub_->decoder()->GetGLContext()));
290 } else {
291 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
293 #endif
294 return decoder.Pass();
297 scoped_ptr<media::VideoDecodeAccelerator>
298 GpuVideoDecodeAccelerator::CreateV4L2VDA() {
299 scoped_ptr<media::VideoDecodeAccelerator> decoder;
300 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
301 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
302 if (device.get()) {
303 decoder.reset(new V4L2VideoDecodeAccelerator(
304 gfx::GLSurfaceEGL::GetHardwareDisplay(),
305 stub_->decoder()->GetGLContext()->GetHandle(),
306 weak_factory_for_io_.GetWeakPtr(),
307 make_context_current_,
308 device,
309 io_message_loop_));
311 #endif
312 return decoder.Pass();
315 scoped_ptr<media::VideoDecodeAccelerator>
316 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() {
317 scoped_ptr<media::VideoDecodeAccelerator> decoder;
318 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
319 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
320 if (device.get()) {
321 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
322 device,
323 gfx::GLSurfaceEGL::GetHardwareDisplay(),
324 stub_->decoder()->GetGLContext()->GetHandle(),
325 weak_factory_for_io_.GetWeakPtr(),
326 make_context_current_,
327 io_message_loop_));
329 #endif
330 return decoder.Pass();
333 void GpuVideoDecodeAccelerator::BindImage(uint32 client_texture_id,
334 uint32 texture_target,
335 scoped_refptr<gfx::GLImage> image) {
336 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder();
337 gpu::gles2::TextureManager* texture_manager =
338 command_decoder->GetContextGroup()->texture_manager();
339 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id);
340 if (ref)
341 texture_manager->SetLevelImage(ref, texture_target, 0, image.get());
344 scoped_ptr<media::VideoDecodeAccelerator>
345 GpuVideoDecodeAccelerator::CreateVaapiVDA() {
346 scoped_ptr<media::VideoDecodeAccelerator> decoder;
347 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
348 decoder.reset(new VaapiVideoDecodeAccelerator(
349 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage,
350 base::Unretained(this))));
351 #endif
352 return decoder.Pass();
355 scoped_ptr<media::VideoDecodeAccelerator>
356 GpuVideoDecodeAccelerator::CreateVTVDA() {
357 scoped_ptr<media::VideoDecodeAccelerator> decoder;
358 #if defined(OS_MACOSX)
359 decoder.reset(new VTVideoDecodeAccelerator(
360 static_cast<CGLContextObj>(stub_->decoder()->GetGLContext()->GetHandle()),
361 make_context_current_));
362 #endif
363 return decoder.Pass();
366 scoped_ptr<media::VideoDecodeAccelerator>
367 GpuVideoDecodeAccelerator::CreateOzoneVDA() {
368 scoped_ptr<media::VideoDecodeAccelerator> decoder;
369 #if !defined(OS_CHROMEOS) && defined(USE_OZONE)
370 media::MediaOzonePlatform* platform =
371 media::MediaOzonePlatform::GetInstance();
372 decoder.reset(platform->CreateVideoDecodeAccelerator(make_context_current_));
373 #endif
374 return decoder.Pass();
377 scoped_ptr<media::VideoDecodeAccelerator>
378 GpuVideoDecodeAccelerator::CreateAndroidVDA() {
379 scoped_ptr<media::VideoDecodeAccelerator> decoder;
380 #if defined(OS_ANDROID)
381 decoder.reset(new AndroidVideoDecodeAccelerator(
382 stub_->decoder()->AsWeakPtr(),
383 make_context_current_));
384 #endif
385 return decoder.Pass();
388 // static
389 gpu::VideoDecodeAcceleratorSupportedProfiles
390 GpuVideoDecodeAccelerator::GetSupportedProfiles() {
391 media::VideoDecodeAccelerator::SupportedProfiles profiles;
392 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
393 if (cmd_line->HasSwitch(switches::kDisableAcceleratedVideoDecode))
394 return gpu::VideoDecodeAcceleratorSupportedProfiles();
396 // Query supported profiles for each VDA. The order of querying VDAs should
397 // be the same as the order of initializing VDAs. Then the returned profile
398 // can be initialized by corresponding VDA successfully.
399 #if defined(OS_WIN)
400 profiles = DXVAVideoDecodeAccelerator::GetSupportedProfiles();
401 #elif defined(OS_CHROMEOS)
402 media::VideoDecodeAccelerator::SupportedProfiles vda_profiles;
403 #if defined(USE_V4L2_CODEC)
404 vda_profiles = V4L2VideoDecodeAccelerator::GetSupportedProfiles();
405 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(vda_profiles, &profiles);
406 vda_profiles = V4L2SliceVideoDecodeAccelerator::GetSupportedProfiles();
407 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(vda_profiles, &profiles);
408 #endif
409 #if defined(ARCH_CPU_X86_FAMILY)
410 vda_profiles = VaapiVideoDecodeAccelerator::GetSupportedProfiles();
411 GpuVideoAcceleratorUtil::InsertUniqueDecodeProfiles(vda_profiles, &profiles);
412 #endif
413 #elif defined(OS_MACOSX)
414 profiles = VTVideoDecodeAccelerator::GetSupportedProfiles();
415 #elif defined(OS_ANDROID)
416 profiles = AndroidVideoDecodeAccelerator::GetSupportedProfiles();
417 #endif
418 return GpuVideoAcceleratorUtil::ConvertMediaToGpuDecodeProfiles(profiles);
421 // Runs on IO thread if video_decode_accelerator_->CanDecodeOnIOThread() is
422 // true, otherwise on the main thread.
423 void GpuVideoDecodeAccelerator::OnDecode(
424 base::SharedMemoryHandle handle, int32 id, uint32 size) {
425 DCHECK(video_decode_accelerator_.get());
426 if (id < 0) {
427 DLOG(ERROR) << "BitstreamBuffer id " << id << " out of range";
428 if (child_message_loop_->BelongsToCurrentThread()) {
429 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
430 } else {
431 child_message_loop_->PostTask(
432 FROM_HERE,
433 base::Bind(&GpuVideoDecodeAccelerator::NotifyError,
434 base::Unretained(this),
435 media::VideoDecodeAccelerator::INVALID_ARGUMENT));
437 return;
439 video_decode_accelerator_->Decode(media::BitstreamBuffer(id, handle, size));
442 void GpuVideoDecodeAccelerator::OnAssignPictureBuffers(
443 const std::vector<int32>& buffer_ids,
444 const std::vector<uint32>& texture_ids) {
445 if (buffer_ids.size() != texture_ids.size()) {
446 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
447 return;
450 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder();
451 gpu::gles2::TextureManager* texture_manager =
452 command_decoder->GetContextGroup()->texture_manager();
454 std::vector<media::PictureBuffer> buffers;
455 std::vector<scoped_refptr<gpu::gles2::TextureRef> > textures;
456 for (uint32 i = 0; i < buffer_ids.size(); ++i) {
457 if (buffer_ids[i] < 0) {
458 DLOG(ERROR) << "Buffer id " << buffer_ids[i] << " out of range";
459 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
460 return;
462 gpu::gles2::TextureRef* texture_ref = texture_manager->GetTexture(
463 texture_ids[i]);
464 if (!texture_ref) {
465 DLOG(ERROR) << "Failed to find texture id " << texture_ids[i];
466 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
467 return;
469 gpu::gles2::Texture* info = texture_ref->texture();
470 if (info->target() != texture_target_) {
471 DLOG(ERROR) << "Texture target mismatch for texture id "
472 << texture_ids[i];
473 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
474 return;
476 if (texture_target_ == GL_TEXTURE_EXTERNAL_OES ||
477 texture_target_ == GL_TEXTURE_RECTANGLE_ARB) {
478 // These textures have their dimensions defined by the underlying storage.
479 // Use |texture_dimensions_| for this size.
480 texture_manager->SetLevelInfo(texture_ref,
481 texture_target_,
483 GL_RGBA,
484 texture_dimensions_.width(),
485 texture_dimensions_.height(),
488 GL_RGBA,
490 false);
491 } else {
492 // For other targets, texture dimensions should already be defined.
493 GLsizei width = 0, height = 0;
494 info->GetLevelSize(texture_target_, 0, &width, &height);
495 if (width != texture_dimensions_.width() ||
496 height != texture_dimensions_.height()) {
497 DLOG(ERROR) << "Size mismatch for texture id " << texture_ids[i];
498 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
499 return;
502 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691
503 GLenum format =
504 video_decode_accelerator_.get()->GetSurfaceInternalFormat();
505 if (format != GL_RGBA) {
506 texture_manager->SetLevelInfo(texture_ref, texture_target_, 0, format,
507 width, height, 1, 0, format, 0, false);
510 buffers.push_back(media::PictureBuffer(buffer_ids[i], texture_dimensions_,
511 texture_ref->service_id(),
512 texture_ids[i]));
513 textures.push_back(texture_ref);
515 video_decode_accelerator_->AssignPictureBuffers(buffers);
516 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
517 for (uint32 i = 0; i < buffer_ids.size(); ++i)
518 uncleared_textures_[buffer_ids[i]] = textures[i];
521 void GpuVideoDecodeAccelerator::OnReusePictureBuffer(
522 int32 picture_buffer_id) {
523 DCHECK(video_decode_accelerator_.get());
524 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id);
527 void GpuVideoDecodeAccelerator::OnFlush() {
528 DCHECK(video_decode_accelerator_.get());
529 video_decode_accelerator_->Flush();
532 void GpuVideoDecodeAccelerator::OnReset() {
533 DCHECK(video_decode_accelerator_.get());
534 video_decode_accelerator_->Reset();
537 void GpuVideoDecodeAccelerator::OnDestroy() {
538 DCHECK(video_decode_accelerator_.get());
539 OnWillDestroyStub();
542 void GpuVideoDecodeAccelerator::OnFilterRemoved() {
543 // We're destroying; cancel all callbacks.
544 weak_factory_for_io_.InvalidateWeakPtrs();
545 filter_removed_.Signal();
548 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer(
549 int32 bitstream_buffer_id) {
550 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed(
551 host_route_id_, bitstream_buffer_id))) {
552 DLOG(ERROR)
553 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) "
554 << "failed";
558 void GpuVideoDecodeAccelerator::NotifyFlushDone() {
559 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_)))
560 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed";
563 void GpuVideoDecodeAccelerator::NotifyResetDone() {
564 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_)))
565 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed";
568 void GpuVideoDecodeAccelerator::OnWillDestroyStub() {
569 // The stub is going away, so we have to stop and destroy VDA here, before
570 // returning, because the VDA may need the GL context to run and/or do its
571 // cleanup. We cannot destroy the VDA before the IO thread message filter is
572 // removed however, since we cannot service incoming messages with VDA gone.
573 // We cannot simply check for existence of VDA on IO thread though, because
574 // we don't want to synchronize the IO thread with the ChildThread.
575 // So we have to wait for the RemoveFilter callback here instead and remove
576 // the VDA after it arrives and before returning.
577 if (filter_.get()) {
578 stub_->channel()->RemoveFilter(filter_.get());
579 filter_removed_.Wait();
582 stub_->channel()->RemoveRoute(host_route_id_);
583 stub_->RemoveDestructionObserver(this);
585 video_decode_accelerator_.reset();
586 delete this;
589 void GpuVideoDecodeAccelerator::SetTextureCleared(
590 const media::Picture& picture) {
591 DCHECK(child_message_loop_->BelongsToCurrentThread());
592 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
593 std::map<int32, scoped_refptr<gpu::gles2::TextureRef> >::iterator it;
594 it = uncleared_textures_.find(picture.picture_buffer_id());
595 if (it == uncleared_textures_.end())
596 return; // the texture has been cleared
598 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second;
599 GLenum target = texture_ref->texture()->target();
600 gpu::gles2::TextureManager* texture_manager =
601 stub_->decoder()->GetContextGroup()->texture_manager();
602 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0));
603 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true);
604 uncleared_textures_.erase(it);
607 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) {
608 if (filter_.get() && io_message_loop_->BelongsToCurrentThread())
609 return filter_->SendOnIOThread(message);
610 DCHECK(child_message_loop_->BelongsToCurrentThread());
611 return stub_->channel()->Send(message);
614 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message,
615 bool succeeded) {
616 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded);
617 Send(message);
620 } // namespace content