OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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/common/gpu/client/gpu_arc_accelerator_host.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/message_loop/message_loop.h" | |
9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | |
10 #include "content/common/gpu/client/gpu_channel_host.h" | |
11 #include "content/common/gpu/gpu_messages.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "ipc/ipc_message_macros.h" | |
14 #include "ipc/ipc_message_utils.h" | |
15 | |
16 namespace content { | |
17 | |
18 GpuArcAcceleratorHost::GpuArcAcceleratorHost() : route_id_(MSG_ROUTING_NONE) { | |
19 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
20 } | |
21 | |
22 GpuArcAcceleratorHost::~GpuArcAcceleratorHost() { | |
23 DCHECK(CalledOnValidThread()); | |
24 } | |
25 | |
26 bool GpuArcAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | |
27 DCHECK(CalledOnValidThread()); | |
28 bool handled = true; | |
29 IPC_BEGIN_MESSAGE_MAP(GpuArcAcceleratorHost, msg) | |
30 IPC_MESSAGE_HANDLER(GpuHostMsg_ArcAcceleratorCreated, | |
31 OnArcAcceleratorCreated) | |
32 IPC_MESSAGE_UNHANDLED(handled = false) | |
33 IPC_END_MESSAGE_MAP() | |
34 DCHECK(handled); | |
35 return handled; | |
36 } | |
37 | |
38 void GpuArcAcceleratorHost::OnChannelError() { | |
39 AbortPendingRequests(); | |
40 } | |
41 | |
42 void GpuArcAcceleratorHost::CreateArcAccelerator(uint32_t device_type, | |
43 const CreatedCallback& cb) { | |
44 DCHECK(CalledOnValidThread()); | |
45 DCHECK(BrowserGpuChannelHostFactory::instance()); | |
46 | |
47 if (gpu_channel_host_ && !gpu_channel_host_->IsLost()) { | |
48 CreateArcAcceleratorWithGpuChannel(device_type, cb); | |
49 return; | |
50 } | |
51 | |
52 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | |
53 CAUSE_FOR_GPU_LAUNCH_ARCACCELERATOR, | |
54 base::Bind(&GpuArcAcceleratorHost::GpuChannelEstablished, AsWeakPtr(), | |
55 device_type, cb)); | |
56 } | |
57 | |
58 void GpuArcAcceleratorHost::GpuChannelEstablished(uint32_t device_type, | |
59 const CreatedCallback& cb) { | |
60 DCHECK(CalledOnValidThread()); | |
61 DCHECK_EQ(MSG_ROUTING_NONE, route_id_); | |
62 | |
63 gpu_channel_host_ = BrowserGpuChannelHostFactory::instance()->GetGpuChannel(); | |
64 route_id_ = gpu_channel_host_->GenerateRouteID(); | |
65 gpu_channel_host_->AddRoute(route_id_, AsWeakPtr()); | |
66 | |
67 CreateArcAcceleratorWithGpuChannel(device_type, cb); | |
68 } | |
69 | |
70 void GpuArcAcceleratorHost::CreateArcAcceleratorWithGpuChannel( | |
71 uint32_t device_type, | |
72 const CreatedCallback& cb) { | |
73 DCHECK(CalledOnValidThread()); | |
74 DCHECK(gpu_channel_host_); | |
75 DCHECK(!gpu_channel_host_->IsLost()); | |
76 | |
77 pending_requests_.push(cb); | |
78 if (!gpu_channel_host_->Send(new GpuMsg_CreateArcAccelerator(device_type))) | |
79 AbortPendingRequests(); | |
80 } | |
81 | |
82 void GpuArcAcceleratorHost::AbortPendingRequests() { | |
83 DCHECK(CalledOnValidThread()); | |
84 if (gpu_channel_host_) { | |
85 DCHECK_NE(MSG_ROUTING_NONE, route_id_); | |
86 gpu_channel_host_->RemoveRoute(route_id_); | |
87 gpu_channel_host_ = nullptr; | |
88 route_id_ = MSG_ROUTING_NONE; | |
89 } | |
90 while (!pending_requests_.empty()) { | |
91 pending_requests_.front().Run(IPC::ChannelHandle(), 0); | |
Owen Lin
2015/11/26 03:54:40
I thought result "0" means success, but it is actu
kcwu
2015/11/26 10:34:42
Acknowledged.
| |
92 pending_requests_.pop(); | |
93 } | |
94 } | |
95 | |
96 void GpuArcAcceleratorHost::Shutdown() { | |
97 if (gpu_channel_host_ && !gpu_channel_host_->IsLost()) | |
98 gpu_channel_host_->Send(new GpuMsg_ShutdownArcAccelerators()); | |
99 AbortPendingRequests(); | |
100 } | |
101 | |
102 void GpuArcAcceleratorHost::OnArcAcceleratorCreated(IPC::ChannelHandle handle, | |
103 uint32_t result) { | |
104 DCHECK(CalledOnValidThread()); | |
105 | |
106 if (pending_requests_.empty()) { | |
107 // Maybe got reply after error or Shutdown(). | |
108 LOG(WARNING) << "Arc accelerator created but no pending requests."; | |
109 return; | |
110 } | |
111 | |
112 // The order of response messages must match the order of request messages. | |
113 // XXX(figure out before commit) Does this guarantee? | |
114 pending_requests_.front().Run(handle, result); | |
115 pending_requests_.pop(); | |
116 } | |
117 | |
118 } // namespace content | |
OLD | NEW |