• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ppapi/proxy/ppp_graphics_3d_proxy.h"
6 
7 #include "ppapi/c/ppp_graphics_3d.h"
8 #include "ppapi/proxy/host_dispatcher.h"
9 #include "ppapi/proxy/plugin_dispatcher.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/proxy_lock.h"
12 
13 namespace ppapi {
14 namespace proxy {
15 
16 namespace {
17 
18 #if !defined(OS_NACL)
ContextLost(PP_Instance instance)19 void ContextLost(PP_Instance instance) {
20   HostDispatcher::GetForInstance(instance)->Send(
21       new PpapiMsg_PPPGraphics3D_ContextLost(API_ID_PPP_GRAPHICS_3D, instance));
22 }
23 
24 static const PPP_Graphics3D graphics_3d_interface = {
25   &ContextLost
26 };
27 #else
28 // The NaCl plugin doesn't need the host side interface - stub it out.
29 static const PPP_Graphics3D graphics_3d_interface = {};
30 #endif  // !defined(OS_NACL)
31 
32 }  // namespace
33 
PPP_Graphics3D_Proxy(Dispatcher * dispatcher)34 PPP_Graphics3D_Proxy::PPP_Graphics3D_Proxy(Dispatcher* dispatcher)
35     : InterfaceProxy(dispatcher),
36       ppp_graphics_3d_impl_(NULL) {
37   if (dispatcher->IsPlugin()) {
38     ppp_graphics_3d_impl_ = static_cast<const PPP_Graphics3D*>(
39         dispatcher->local_get_interface()(PPP_GRAPHICS_3D_INTERFACE));
40   }
41 }
42 
~PPP_Graphics3D_Proxy()43 PPP_Graphics3D_Proxy::~PPP_Graphics3D_Proxy() {
44 }
45 
46 // static
GetProxyInterface()47 const PPP_Graphics3D* PPP_Graphics3D_Proxy::GetProxyInterface() {
48   return &graphics_3d_interface;
49 }
50 
OnMessageReceived(const IPC::Message & msg)51 bool PPP_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
52   if (!dispatcher()->IsPlugin())
53     return false;
54 
55   bool handled = true;
56   IPC_BEGIN_MESSAGE_MAP(PPP_Graphics3D_Proxy, msg)
57     IPC_MESSAGE_HANDLER(PpapiMsg_PPPGraphics3D_ContextLost,
58                         OnMsgContextLost)
59     IPC_MESSAGE_UNHANDLED(handled = false)
60   IPC_END_MESSAGE_MAP()
61   return handled;
62 }
63 
OnMsgContextLost(PP_Instance instance)64 void PPP_Graphics3D_Proxy::OnMsgContextLost(PP_Instance instance) {
65   if (ppp_graphics_3d_impl_)
66     CallWhileUnlocked(ppp_graphics_3d_impl_->Graphics3DContextLost, instance);
67 }
68 
69 }  // namespace proxy
70 }  // namespace ppapi
71