| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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/transport_texture_service.h" | |
| 6 | |
| 7 #include "base/stl_util-inl.h" | |
| 8 #include "content/common/child_process.h" | |
| 9 #include "content/common/gpu/gpu_messages.h" | |
| 10 #include "content/renderer/transport_texture_host.h" | |
| 11 | |
| 12 TransportTextureService::TransportTextureService() | |
| 13 : channel_(NULL), | |
| 14 next_host_id_(1) { | |
| 15 } | |
| 16 | |
| 17 TransportTextureService::~TransportTextureService() { | |
| 18 STLDeleteElements(&pending_messages_); | |
| 19 } | |
| 20 | |
| 21 void TransportTextureService::OnFilterAdded(IPC::Channel* channel) { | |
| 22 channel_ = channel; | |
| 23 router_.reset(new MessageRouter()); | |
| 24 | |
| 25 // Add all pending routes. | |
| 26 for (size_t i = 0; i < pending_routes_.size(); ++i) | |
| 27 router_->AddRoute(pending_routes_[i].first, pending_routes_[i].second); | |
| 28 pending_routes_.clear(); | |
| 29 | |
| 30 // Submit all pending messages. | |
| 31 for (size_t i = 0; i < pending_messages_.size(); ++i) | |
| 32 channel_->Send(pending_messages_[i]); | |
| 33 pending_messages_.clear(); | |
| 34 } | |
| 35 | |
| 36 void TransportTextureService::OnFilterRemoved() { | |
| 37 // TODO(hclam): Implement. | |
| 38 } | |
| 39 | |
| 40 void TransportTextureService::OnChannelClosing() { | |
| 41 channel_ = NULL; | |
| 42 } | |
| 43 | |
| 44 bool TransportTextureService::OnMessageReceived(const IPC::Message& msg) { | |
| 45 switch (msg.type()) { | |
| 46 case GpuTransportTextureHostMsg_TransportTextureCreated::ID: | |
| 47 case GpuTransportTextureHostMsg_CreateTextures::ID: | |
| 48 case GpuTransportTextureHostMsg_ReleaseTextures::ID: | |
| 49 case GpuTransportTextureHostMsg_TextureUpdated::ID: | |
| 50 if (!router_->RouteMessage(msg)) { | |
| 51 LOG(ERROR) << "GpuTransportTextureHostMsg cannot be dispatched."; | |
| 52 return false; | |
| 53 } | |
| 54 return true; | |
| 55 default: | |
| 56 return false; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 scoped_refptr<TransportTextureHost> | |
| 61 TransportTextureService::CreateTransportTextureHost( | |
| 62 RendererGLContext* context, int context_route_id) { | |
| 63 #if !defined(OS_MACOSX) | |
| 64 // TODO(hclam): Check this is on Render Thread. | |
| 65 | |
| 66 // Create the object and then add the route. | |
| 67 scoped_refptr<TransportTextureHost> host = new TransportTextureHost( | |
| 68 ChildProcess::current()->io_message_loop(), MessageLoop::current(), | |
| 69 this, this, context, context_route_id, next_host_id_); | |
| 70 | |
| 71 // Add route in the IO thread. | |
| 72 ChildProcess::current()->io_message_loop()->PostTask( | |
| 73 FROM_HERE, | |
| 74 NewRunnableMethod(this, &TransportTextureService::AddRouteInternal, | |
| 75 next_host_id_, host)); | |
| 76 | |
| 77 // Increment host ID for next object. | |
| 78 ++next_host_id_; | |
| 79 return host; | |
| 80 #else | |
| 81 // TransportTextureHost has problem compiling on Mac so skip it. | |
| 82 return NULL; | |
| 83 #endif | |
| 84 } | |
| 85 | |
| 86 void TransportTextureService::RemoveRoute(int32 host_id) { | |
| 87 ChildProcess::current()->io_message_loop()->PostTask( | |
| 88 FROM_HERE, | |
| 89 NewRunnableMethod(this, &TransportTextureService::RemoveRouteInternal, | |
| 90 host_id)); | |
| 91 } | |
| 92 | |
| 93 bool TransportTextureService::Send(IPC::Message* msg) { | |
| 94 ChildProcess::current()->io_message_loop()->PostTask( | |
| 95 FROM_HERE, | |
| 96 NewRunnableMethod(this, &TransportTextureService::SendInternal, msg)); | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 void TransportTextureService::AddRouteInternal( | |
| 101 int32 host_id, IPC::Channel::Listener* listener) { | |
| 102 DCHECK_EQ(ChildProcess::current()->io_message_loop(), | |
| 103 MessageLoop::current()); | |
| 104 | |
| 105 // If router is there then just add the route, or we have to save it. | |
| 106 if (router_.get()) | |
| 107 router_->AddRoute(host_id, listener); | |
| 108 else | |
| 109 pending_routes_.push_back(std::make_pair(host_id, listener)); | |
| 110 } | |
| 111 | |
| 112 void TransportTextureService::RemoveRouteInternal(int32 host_id) { | |
| 113 DCHECK_EQ(ChildProcess::current()->io_message_loop(), | |
| 114 MessageLoop::current()); | |
| 115 | |
| 116 if (router_.get()) | |
| 117 router_->RemoveRoute(host_id); | |
| 118 } | |
| 119 | |
| 120 void TransportTextureService::SendInternal(IPC::Message* msg) { | |
| 121 DCHECK_EQ(ChildProcess::current()->io_message_loop(), | |
| 122 MessageLoop::current()); | |
| 123 | |
| 124 if (channel_) | |
| 125 channel_->Send(msg); | |
| 126 else | |
| 127 pending_messages_.push_back(msg); | |
| 128 } | |
| OLD | NEW |