Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / common / gpu / media / gpu_video_decode_accelerator.cc
blob9f78d2301aa56f621228e4dabcf53bb9015bfa8f
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/location.h"
12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/stl_util.h"
16 #include "base/thread_task_runner_handle.h"
18 #include "content/common/gpu/gpu_channel.h"
19 #include "content/common/gpu/gpu_messages.h"
20 #include "content/common/gpu/media/gpu_video_accelerator_util.h"
21 #include "content/public/common/content_switches.h"
22 #include "gpu/command_buffer/common/command_buffer.h"
23 #include "ipc/ipc_message_macros.h"
24 #include "ipc/ipc_message_utils.h"
25 #include "ipc/message_filter.h"
26 #include "media/base/limits.h"
27 #include "ui/gl/gl_context.h"
28 #include "ui/gl/gl_image.h"
29 #include "ui/gl/gl_surface_egl.h"
31 #if defined(OS_WIN)
32 #include "base/win/windows_version.h"
33 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
34 #elif defined(OS_MACOSX)
35 #include "content/common/gpu/media/vt_video_decode_accelerator.h"
36 #elif defined(OS_CHROMEOS)
37 #if defined(USE_V4L2_CODEC)
38 #include "content/common/gpu/media/v4l2_device.h"
39 #include "content/common/gpu/media/v4l2_slice_video_decode_accelerator.h"
40 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
41 #endif
42 #if defined(ARCH_CPU_X86_FAMILY)
43 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
44 #include "ui/gl/gl_implementation.h"
45 #endif
46 #elif defined(USE_OZONE)
47 #include "media/ozone/media_ozone_platform.h"
48 #elif defined(OS_ANDROID)
49 #include "content/common/gpu/media/android_video_decode_accelerator.h"
50 #endif
52 #include "ui/gfx/geometry/size.h"
54 namespace content {
56 static bool MakeDecoderContextCurrent(
57 const base::WeakPtr<GpuCommandBufferStub> stub) {
58 if (!stub) {
59 DLOG(ERROR) << "Stub is gone; won't MakeCurrent().";
60 return false;
63 if (!stub->decoder()->MakeCurrent()) {
64 DLOG(ERROR) << "Failed to MakeCurrent()";
65 return false;
68 return true;
71 // DebugAutoLock works like AutoLock but only acquires the lock when
72 // DCHECK is on.
73 #if DCHECK_IS_ON()
74 typedef base::AutoLock DebugAutoLock;
75 #else
76 class DebugAutoLock {
77 public:
78 explicit DebugAutoLock(base::Lock&) {}
80 #endif
82 class GpuVideoDecodeAccelerator::MessageFilter : public IPC::MessageFilter {
83 public:
84 MessageFilter(GpuVideoDecodeAccelerator* owner, int32 host_route_id)
85 : owner_(owner), host_route_id_(host_route_id) {}
87 void OnChannelError() override { sender_ = NULL; }
89 void OnChannelClosing() override { sender_ = NULL; }
91 void OnFilterAdded(IPC::Sender* sender) override { sender_ = sender; }
93 void OnFilterRemoved() override {
94 // This will delete |owner_| and |this|.
95 owner_->OnFilterRemoved();
98 bool OnMessageReceived(const IPC::Message& msg) override {
99 if (msg.routing_id() != host_route_id_)
100 return false;
102 IPC_BEGIN_MESSAGE_MAP(MessageFilter, msg)
103 IPC_MESSAGE_FORWARD(AcceleratedVideoDecoderMsg_Decode, owner_,
104 GpuVideoDecodeAccelerator::OnDecode)
105 IPC_MESSAGE_UNHANDLED(return false;)
106 IPC_END_MESSAGE_MAP()
107 return true;
110 bool SendOnIOThread(IPC::Message* message) {
111 DCHECK(!message->is_sync());
112 if (!sender_) {
113 delete message;
114 return false;
116 return sender_->Send(message);
119 protected:
120 ~MessageFilter() override {}
122 private:
123 GpuVideoDecodeAccelerator* const owner_;
124 const int32 host_route_id_;
125 // The sender to which this filter was added.
126 IPC::Sender* sender_;
129 GpuVideoDecodeAccelerator::GpuVideoDecodeAccelerator(
130 int32 host_route_id,
131 GpuCommandBufferStub* stub,
132 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
133 : host_route_id_(host_route_id),
134 stub_(stub),
135 texture_target_(0),
136 filter_removed_(true, false),
137 child_task_runner_(base::ThreadTaskRunnerHandle::Get()),
138 io_task_runner_(io_task_runner),
139 weak_factory_for_io_(this) {
140 DCHECK(stub_);
141 stub_->AddDestructionObserver(this);
142 make_context_current_ =
143 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr());
146 GpuVideoDecodeAccelerator::~GpuVideoDecodeAccelerator() {
147 // This class can only be self-deleted from OnWillDestroyStub(), which means
148 // the VDA has already been destroyed in there.
149 DCHECK(!video_decode_accelerator_);
152 bool GpuVideoDecodeAccelerator::OnMessageReceived(const IPC::Message& msg) {
153 if (!video_decode_accelerator_)
154 return false;
156 bool handled = true;
157 IPC_BEGIN_MESSAGE_MAP(GpuVideoDecodeAccelerator, msg)
158 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Decode, OnDecode)
159 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_AssignPictureBuffers,
160 OnAssignPictureBuffers)
161 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_ReusePictureBuffer,
162 OnReusePictureBuffer)
163 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Flush, OnFlush)
164 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Reset, OnReset)
165 IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderMsg_Destroy, OnDestroy)
166 IPC_MESSAGE_UNHANDLED(handled = false)
167 IPC_END_MESSAGE_MAP()
168 return handled;
171 void GpuVideoDecodeAccelerator::ProvidePictureBuffers(
172 uint32 requested_num_of_buffers,
173 const gfx::Size& dimensions,
174 uint32 texture_target) {
175 if (dimensions.width() > media::limits::kMaxDimension ||
176 dimensions.height() > media::limits::kMaxDimension ||
177 dimensions.GetArea() > media::limits::kMaxCanvas) {
178 NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
179 return;
181 if (!Send(new AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers(
182 host_route_id_,
183 requested_num_of_buffers,
184 dimensions,
185 texture_target))) {
186 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers) "
187 << "failed";
189 texture_dimensions_ = dimensions;
190 texture_target_ = texture_target;
193 void GpuVideoDecodeAccelerator::DismissPictureBuffer(
194 int32 picture_buffer_id) {
195 // Notify client that picture buffer is now unused.
196 if (!Send(new AcceleratedVideoDecoderHostMsg_DismissPictureBuffer(
197 host_route_id_, picture_buffer_id))) {
198 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer) "
199 << "failed";
201 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
202 uncleared_textures_.erase(picture_buffer_id);
205 void GpuVideoDecodeAccelerator::PictureReady(
206 const media::Picture& picture) {
207 // VDA may call PictureReady on IO thread. SetTextureCleared should run on
208 // the child thread. VDA is responsible to call PictureReady on the child
209 // thread when a picture buffer is delivered the first time.
210 if (child_task_runner_->BelongsToCurrentThread()) {
211 SetTextureCleared(picture);
212 } else {
213 DCHECK(io_task_runner_->BelongsToCurrentThread());
214 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
215 DCHECK_EQ(0u, uncleared_textures_.count(picture.picture_buffer_id()));
218 if (!Send(new AcceleratedVideoDecoderHostMsg_PictureReady(
219 host_route_id_, picture.picture_buffer_id(),
220 picture.bitstream_buffer_id(), picture.visible_rect(),
221 picture.allow_overlay()))) {
222 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_PictureReady) failed";
226 void GpuVideoDecodeAccelerator::NotifyError(
227 media::VideoDecodeAccelerator::Error error) {
228 if (!Send(new AcceleratedVideoDecoderHostMsg_ErrorNotification(
229 host_route_id_, error))) {
230 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ErrorNotification) "
231 << "failed";
235 void GpuVideoDecodeAccelerator::Initialize(
236 const media::VideoCodecProfile profile,
237 IPC::Message* init_done_msg) {
238 DCHECK(!video_decode_accelerator_.get());
240 if (!stub_->channel()->AddRoute(host_route_id_, this)) {
241 DLOG(ERROR) << "Initialize(): failed to add route";
242 SendCreateDecoderReply(init_done_msg, false);
245 #if !defined(OS_WIN)
246 // Ensure we will be able to get a GL context at all before initializing
247 // non-Windows VDAs.
248 if (!make_context_current_.Run()) {
249 SendCreateDecoderReply(init_done_msg, false);
250 return;
252 #endif
254 // Array of Create..VDA() function pointers, maybe applicable to the current
255 // platform. This list is ordered by priority of use and it should be the
256 // same as the order of querying supported profiles of VDAs.
257 const GpuVideoDecodeAccelerator::CreateVDAFp create_vda_fps[] = {
258 &GpuVideoDecodeAccelerator::CreateDXVAVDA,
259 &GpuVideoDecodeAccelerator::CreateV4L2VDA,
260 &GpuVideoDecodeAccelerator::CreateV4L2SliceVDA,
261 &GpuVideoDecodeAccelerator::CreateVaapiVDA,
262 &GpuVideoDecodeAccelerator::CreateVTVDA,
263 &GpuVideoDecodeAccelerator::CreateOzoneVDA,
264 &GpuVideoDecodeAccelerator::CreateAndroidVDA};
266 for (const auto& create_vda_function : create_vda_fps) {
267 video_decode_accelerator_ = (this->*create_vda_function)();
268 if (!video_decode_accelerator_ ||
269 !video_decode_accelerator_->Initialize(profile, this))
270 continue;
272 if (video_decode_accelerator_->CanDecodeOnIOThread()) {
273 filter_ = new MessageFilter(this, host_route_id_);
274 stub_->channel()->AddFilter(filter_.get());
276 SendCreateDecoderReply(init_done_msg, true);
277 return;
279 video_decode_accelerator_.reset();
280 LOG(ERROR) << "HW video decode not available for profile " << profile;
281 SendCreateDecoderReply(init_done_msg, false);
284 scoped_ptr<media::VideoDecodeAccelerator>
285 GpuVideoDecodeAccelerator::CreateDXVAVDA() {
286 scoped_ptr<media::VideoDecodeAccelerator> decoder;
287 #if defined(OS_WIN)
288 if (base::win::GetVersion() >= base::win::VERSION_WIN7) {
289 DVLOG(0) << "Initializing DXVA HW decoder for windows.";
290 decoder.reset(new DXVAVideoDecodeAccelerator(make_context_current_,
291 stub_->decoder()->GetGLContext()));
292 } else {
293 NOTIMPLEMENTED() << "HW video decode acceleration not available.";
295 #endif
296 return decoder.Pass();
299 scoped_ptr<media::VideoDecodeAccelerator>
300 GpuVideoDecodeAccelerator::CreateV4L2VDA() {
301 scoped_ptr<media::VideoDecodeAccelerator> decoder;
302 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
303 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
304 if (device.get()) {
305 decoder.reset(new V4L2VideoDecodeAccelerator(
306 gfx::GLSurfaceEGL::GetHardwareDisplay(),
307 stub_->decoder()->GetGLContext()->GetHandle(),
308 weak_factory_for_io_.GetWeakPtr(),
309 make_context_current_,
310 device,
311 io_task_runner_));
313 #endif
314 return decoder.Pass();
317 scoped_ptr<media::VideoDecodeAccelerator>
318 GpuVideoDecodeAccelerator::CreateV4L2SliceVDA() {
319 scoped_ptr<media::VideoDecodeAccelerator> decoder;
320 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
321 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
322 if (device.get()) {
323 decoder.reset(new V4L2SliceVideoDecodeAccelerator(
324 device,
325 gfx::GLSurfaceEGL::GetHardwareDisplay(),
326 stub_->decoder()->GetGLContext()->GetHandle(),
327 weak_factory_for_io_.GetWeakPtr(),
328 make_context_current_,
329 io_task_runner_));
331 #endif
332 return decoder.Pass();
335 void GpuVideoDecodeAccelerator::BindImage(uint32 client_texture_id,
336 uint32 texture_target,
337 scoped_refptr<gfx::GLImage> image) {
338 gpu::gles2::GLES2Decoder* command_decoder = stub_->decoder();
339 gpu::gles2::TextureManager* texture_manager =
340 command_decoder->GetContextGroup()->texture_manager();
341 gpu::gles2::TextureRef* ref = texture_manager->GetTexture(client_texture_id);
342 if (ref)
343 texture_manager->SetLevelImage(ref, texture_target, 0, image.get());
346 scoped_ptr<media::VideoDecodeAccelerator>
347 GpuVideoDecodeAccelerator::CreateVaapiVDA() {
348 scoped_ptr<media::VideoDecodeAccelerator> decoder;
349 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
350 decoder.reset(new VaapiVideoDecodeAccelerator(
351 make_context_current_, base::Bind(&GpuVideoDecodeAccelerator::BindImage,
352 base::Unretained(this))));
353 #endif
354 return decoder.Pass();
357 scoped_ptr<media::VideoDecodeAccelerator>
358 GpuVideoDecodeAccelerator::CreateVTVDA() {
359 scoped_ptr<media::VideoDecodeAccelerator> decoder;
360 #if defined(OS_MACOSX)
361 decoder.reset(new VTVideoDecodeAccelerator(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_task_runner_->BelongsToCurrentThread()) {
429 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
430 } else {
431 child_task_runner_->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(
481 texture_ref, texture_target_, 0, GL_RGBA, texture_dimensions_.width(),
482 texture_dimensions_.height(), 1, 0, GL_RGBA, 0, gfx::Rect());
483 } else {
484 // For other targets, texture dimensions should already be defined.
485 GLsizei width = 0, height = 0;
486 info->GetLevelSize(texture_target_, 0, &width, &height, nullptr);
487 if (width != texture_dimensions_.width() ||
488 height != texture_dimensions_.height()) {
489 DLOG(ERROR) << "Size mismatch for texture id " << texture_ids[i];
490 NotifyError(media::VideoDecodeAccelerator::INVALID_ARGUMENT);
491 return;
494 // TODO(dshwang): after moving to D3D11, remove this. crbug.com/438691
495 GLenum format =
496 video_decode_accelerator_.get()->GetSurfaceInternalFormat();
497 if (format != GL_RGBA) {
498 texture_manager->SetLevelInfo(texture_ref, texture_target_, 0, format,
499 width, height, 1, 0, format, 0,
500 gfx::Rect());
503 buffers.push_back(media::PictureBuffer(buffer_ids[i], texture_dimensions_,
504 texture_ref->service_id(),
505 texture_ids[i]));
506 textures.push_back(texture_ref);
508 video_decode_accelerator_->AssignPictureBuffers(buffers);
509 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
510 for (uint32 i = 0; i < buffer_ids.size(); ++i)
511 uncleared_textures_[buffer_ids[i]] = textures[i];
514 void GpuVideoDecodeAccelerator::OnReusePictureBuffer(
515 int32 picture_buffer_id) {
516 DCHECK(video_decode_accelerator_.get());
517 video_decode_accelerator_->ReusePictureBuffer(picture_buffer_id);
520 void GpuVideoDecodeAccelerator::OnFlush() {
521 DCHECK(video_decode_accelerator_.get());
522 video_decode_accelerator_->Flush();
525 void GpuVideoDecodeAccelerator::OnReset() {
526 DCHECK(video_decode_accelerator_.get());
527 video_decode_accelerator_->Reset();
530 void GpuVideoDecodeAccelerator::OnDestroy() {
531 DCHECK(video_decode_accelerator_.get());
532 OnWillDestroyStub();
535 void GpuVideoDecodeAccelerator::OnFilterRemoved() {
536 // We're destroying; cancel all callbacks.
537 weak_factory_for_io_.InvalidateWeakPtrs();
538 filter_removed_.Signal();
541 void GpuVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer(
542 int32 bitstream_buffer_id) {
543 if (!Send(new AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed(
544 host_route_id_, bitstream_buffer_id))) {
545 DLOG(ERROR)
546 << "Send(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed) "
547 << "failed";
551 void GpuVideoDecodeAccelerator::NotifyFlushDone() {
552 if (!Send(new AcceleratedVideoDecoderHostMsg_FlushDone(host_route_id_)))
553 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_FlushDone) failed";
556 void GpuVideoDecodeAccelerator::NotifyResetDone() {
557 if (!Send(new AcceleratedVideoDecoderHostMsg_ResetDone(host_route_id_)))
558 DLOG(ERROR) << "Send(AcceleratedVideoDecoderHostMsg_ResetDone) failed";
561 void GpuVideoDecodeAccelerator::OnWillDestroyStub() {
562 // The stub is going away, so we have to stop and destroy VDA here, before
563 // returning, because the VDA may need the GL context to run and/or do its
564 // cleanup. We cannot destroy the VDA before the IO thread message filter is
565 // removed however, since we cannot service incoming messages with VDA gone.
566 // We cannot simply check for existence of VDA on IO thread though, because
567 // we don't want to synchronize the IO thread with the ChildThread.
568 // So we have to wait for the RemoveFilter callback here instead and remove
569 // the VDA after it arrives and before returning.
570 if (filter_.get()) {
571 stub_->channel()->RemoveFilter(filter_.get());
572 filter_removed_.Wait();
575 stub_->channel()->RemoveRoute(host_route_id_);
576 stub_->RemoveDestructionObserver(this);
578 video_decode_accelerator_.reset();
579 delete this;
582 void GpuVideoDecodeAccelerator::SetTextureCleared(
583 const media::Picture& picture) {
584 DCHECK(child_task_runner_->BelongsToCurrentThread());
585 DebugAutoLock auto_lock(debug_uncleared_textures_lock_);
586 std::map<int32, scoped_refptr<gpu::gles2::TextureRef> >::iterator it;
587 it = uncleared_textures_.find(picture.picture_buffer_id());
588 if (it == uncleared_textures_.end())
589 return; // the texture has been cleared
591 scoped_refptr<gpu::gles2::TextureRef> texture_ref = it->second;
592 GLenum target = texture_ref->texture()->target();
593 gpu::gles2::TextureManager* texture_manager =
594 stub_->decoder()->GetContextGroup()->texture_manager();
595 DCHECK(!texture_ref->texture()->IsLevelCleared(target, 0));
596 texture_manager->SetLevelCleared(texture_ref.get(), target, 0, true);
597 uncleared_textures_.erase(it);
600 bool GpuVideoDecodeAccelerator::Send(IPC::Message* message) {
601 if (filter_.get() && io_task_runner_->BelongsToCurrentThread())
602 return filter_->SendOnIOThread(message);
603 DCHECK(child_task_runner_->BelongsToCurrentThread());
604 return stub_->channel()->Send(message);
607 void GpuVideoDecodeAccelerator::SendCreateDecoderReply(IPC::Message* message,
608 bool succeeded) {
609 GpuCommandBufferMsg_CreateVideoDecoder::WriteReplyParams(message, succeeded);
610 Send(message);
613 } // namespace content