Home | History | Annotate | Download | only in gpu
      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.
      4 
      5 #include "content/renderer/gpu/stream_texture_host_android.h"
      6 
      7 #include "content/common/gpu/client/gpu_channel_host.h"
      8 #include "content/common/gpu/gpu_messages.h"
      9 #include "content/renderer/render_thread_impl.h"
     10 #include "ipc/ipc_message_macros.h"
     11 
     12 namespace content {
     13 
     14 StreamTextureHost::StreamTextureHost(GpuChannelHost* channel)
     15     : stream_id_(0),
     16       listener_(NULL),
     17       channel_(channel),
     18       weak_ptr_factory_(this) {
     19   DCHECK(channel);
     20 }
     21 
     22 StreamTextureHost::~StreamTextureHost() {
     23   if (channel_.get() && stream_id_)
     24     channel_->RemoveRoute(stream_id_);
     25 }
     26 
     27 bool StreamTextureHost::BindToCurrentThread(int32 stream_id,
     28                                             Listener* listener) {
     29   listener_ = listener;
     30   if (channel_.get() && stream_id && !stream_id_) {
     31     stream_id_ = stream_id;
     32     channel_->AddRoute(stream_id, weak_ptr_factory_.GetWeakPtr());
     33     channel_->Send(new GpuStreamTextureMsg_StartListening(stream_id));
     34     return true;
     35   }
     36 
     37   return false;
     38 }
     39 
     40 bool StreamTextureHost::OnMessageReceived(const IPC::Message& message) {
     41   bool handled = true;
     42   IPC_BEGIN_MESSAGE_MAP(StreamTextureHost, message)
     43     IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_FrameAvailable,
     44                         OnFrameAvailable);
     45     IPC_MESSAGE_HANDLER(GpuStreamTextureMsg_MatrixChanged,
     46                         OnMatrixChanged);
     47     IPC_MESSAGE_UNHANDLED(handled = false)
     48   IPC_END_MESSAGE_MAP()
     49   DCHECK(handled);
     50   return handled;
     51 }
     52 
     53 void StreamTextureHost::OnChannelError() {
     54 }
     55 
     56 void StreamTextureHost::OnFrameAvailable() {
     57   if (listener_)
     58     listener_->OnFrameAvailable();
     59 }
     60 
     61 void StreamTextureHost::OnMatrixChanged(
     62     const GpuStreamTextureMsg_MatrixChanged_Params& params) {
     63   COMPILE_ASSERT(sizeof(params) == sizeof(float) * 16,
     64                  bad_GpuStreamTextureMsg_MatrixChanged_Params_format);
     65   if (listener_)
     66     listener_->OnMatrixChanged((const float*)&params);
     67 }
     68 
     69 }  // namespace content
     70