Chromium Code Reviews| Index: media/gpu/content_video_view_overlay.cc |
| diff --git a/media/gpu/content_video_view_overlay.cc b/media/gpu/content_video_view_overlay.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c426d6e6f65fcdc015f4570da88ba03e9189d011 |
| --- /dev/null |
| +++ b/media/gpu/content_video_view_overlay.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/gpu/content_video_view_overlay.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/logging.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "gpu/ipc/common/gpu_surface_lookup.h" |
| + |
| +namespace media { |
| + |
| +ContentVideoViewOverlay::ContentVideoViewOverlay( |
| + AVDACodecAllocator* codec_allocator, |
| + int surface_id, |
| + const AndroidOverlay::Config& config) |
| + : codec_allocator_(codec_allocator), |
| + surface_id_(surface_id), |
| + config_(config), |
| + weak_factory_(this) { |
| + if (codec_allocator_->AllocateSurface(this, surface_id_)) { |
| + // We have the surface -- post a callback to our OnSurfaceAvailable. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&ContentVideoViewOverlay::OnSurfaceAvailable, |
| + weak_factory_.GetWeakPtr(), true)); |
| + } |
| +} |
| + |
| +ContentVideoViewOverlay::~ContentVideoViewOverlay() { |
| + // Deallocate the surface. It's okay if we don't own it. |
| + codec_allocator_->DeallocateSurface(this, surface_id_); |
| +} |
| + |
| +void ContentVideoViewOverlay::ScheduleLayout(const gfx::Rect& rect) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +const base::android::JavaRef<jobject>& ContentVideoViewOverlay::GetJavaSurface() |
| + const { |
| + return surface_.j_surface(); |
| +} |
| + |
| +void ContentVideoViewOverlay::OnSurfaceAvailable(bool success) { |
| + if (!success) { |
| + // Notify that the surface won't be available. |
| + config_.failed_cb.Run(); |
| + // |this| may be deleted. |
| + return; |
| + } |
| + |
| + // Get the surface and notify our client. |
| + surface_ = |
| + gpu::GpuSurfaceLookup::GetInstance()->AcquireJavaSurface(surface_id_); |
|
watk
2017/03/10 02:19:44
I wonder if we should check whether this is a non
liberato (no reviews please)
2017/03/10 17:40:56
i like that better. definitely should run the fai
|
| + config_.ready_cb.Run(); |
| +} |
| + |
| +void ContentVideoViewOverlay::OnSurfaceDestroyed() { |
| + config_.destroyed_cb.Run(); |
| + // |this| may be deleted, or deletion might be posted elsewhere. |
| +} |
| + |
| +} // namespace media |