blob: 29f08c2972f56ab969c2be4328eb1f7b4bf26fc6 [file] [log] [blame]
[email protected]dbd3d212012-07-13 02:17:221// 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.
4
Sadrul Habib Chowdhury31c98712018-12-11 04:15:135#include "content/renderer/stream_texture_host_android.h"
[email protected]dbd3d212012-07-13 02:17:226
siva.gunturi6216f312016-10-21 06:49:557#include "base/unguessable_token.h"
[email protected]dbd3d212012-07-13 02:17:228#include "content/renderer/render_thread_impl.h"
penghuang346a46f92016-03-31 21:37:529#include "gpu/ipc/client/gpu_channel_host.h"
Eric Karl625afbbd2019-06-27 00:51:0010#include "gpu/ipc/common/command_buffer_id.h"
fsamuel19acfae2016-03-22 05:38:2411#include "gpu/ipc/common/gpu_messages.h"
[email protected]dbd3d212012-07-13 02:17:2212#include "ipc/ipc_message_macros.h"
13
14namespace content {
15
siva.gunturi6216f312016-10-21 06:49:5516StreamTextureHost::StreamTextureHost(scoped_refptr<gpu::GpuChannelHost> channel,
17 int32_t route_id)
Jeremy Roman877cf8b42019-08-14 20:18:2818 : route_id_(route_id), listener_(nullptr), channel_(std::move(channel)) {
piman9fc22f32016-05-02 22:21:2219 DCHECK(channel_);
tguilbert3717d9a2016-11-28 20:53:1020 DCHECK(route_id_);
[email protected]dbd3d212012-07-13 02:17:2221}
22
23StreamTextureHost::~StreamTextureHost() {
Eric Karl625afbbd2019-06-27 00:51:0024 if (channel_) {
25 // We destroy the StreamTexture as a deferred message followed by a flush
26 // to ensure this is ordered correctly with regards to previous deferred
27 // messages, such as CreateSharedImage.
28 uint32_t flush_id = channel_->EnqueueDeferredMessage(
29 GpuStreamTextureMsg_Destroy(route_id_));
30 channel_->EnsureFlush(flush_id);
siva.gunturi6216f312016-10-21 06:49:5531 channel_->RemoveRoute(route_id_);
Eric Karl625afbbd2019-06-27 00:51:0032 }
[email protected]dbd3d212012-07-13 02:17:2233}
34
siva.gunturi6216f312016-10-21 06:49:5535bool StreamTextureHost::BindToCurrentThread(Listener* listener) {
[email protected]01af26382014-01-23 22:23:2536 listener_ = listener;
tguilbert3717d9a2016-11-28 20:53:1037
38 if (channel_) {
siva.gunturi6216f312016-10-21 06:49:5539 channel_->AddRoute(route_id_, weak_ptr_factory_.GetWeakPtr());
40 channel_->Send(new GpuStreamTextureMsg_StartListening(route_id_));
[email protected]dbd3d212012-07-13 02:17:2241 return true;
42 }
43
44 return false;
45}
46
47bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP(StreamTextureHost, message)
tguilbert3717d9a2016-11-28 20:53:1050 IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable, OnFrameAvailable);
[email protected]dbd3d212012-07-13 02:17:2251 IPC_MESSAGE_UNHANDLED(handled = false)
52 IPC_END_MESSAGE_MAP()
53 DCHECK(handled);
54 return handled;
55}
56
[email protected]dbd3d212012-07-13 02:17:2257void StreamTextureHost::OnChannelError() {
tguilbert3717d9a2016-11-28 20:53:1058 channel_ = nullptr;
[email protected]dbd3d212012-07-13 02:17:2259}
60
61void StreamTextureHost::OnFrameAvailable() {
62 if (listener_)
63 listener_->OnFrameAvailable();
64}
65
siva.gunturi6216f312016-10-21 06:49:5566void StreamTextureHost::ForwardStreamTextureForSurfaceRequest(
67 const base::UnguessableToken& request_token) {
tguilbert3717d9a2016-11-28 20:53:1068 if (channel_) {
siva.gunturi6216f312016-10-21 06:49:5569 channel_->Send(new GpuStreamTextureMsg_ForwardForSurfaceRequest(
70 route_id_, request_token));
71 }
72}
73
Eric Karl625afbbd2019-06-27 00:51:0074gpu::Mailbox StreamTextureHost::CreateSharedImage(const gfx::Size& size) {
75 if (!channel_)
76 return gpu::Mailbox();
77
78 auto mailbox = gpu::Mailbox::GenerateForSharedImage();
79 channel_->EnqueueDeferredMessage(GpuStreamTextureMsg_CreateSharedImage(
80 route_id_, mailbox, size, ++release_id_));
81 return mailbox;
82}
83
84gpu::SyncToken StreamTextureHost::GenUnverifiedSyncToken() {
Vikas Sonia26e13fd2019-08-14 00:14:5885 // |channel_| can be set to null via OnChannelError() which means
86 // StreamTextureHost could still be alive when |channel_| is gone.
87 if (!channel_)
88 return gpu::SyncToken();
vikassonib14d87812019-08-01 19:08:1489
Eric Karl625afbbd2019-06-27 00:51:0090 return gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
91 gpu::CommandBufferIdFromChannelAndRoute(
92 channel_->channel_id(), route_id_),
93 release_id_);
94}
95
[email protected]dbd3d212012-07-13 02:17:2296} // namespace content