summaryrefslogtreecommitdiffstats
path: root/o3d/gpu_plugin/gpu_plugin_object.h
blob: 38b684bef63c0d117e5c2b1e865050e60a1bd5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef O3D_GPU_PLUGIN_GPU_PLUGIN_OBJECT_H_
#define O3D_GPU_PLUGIN_GPU_PLUGIN_OBJECT_H_

#include <string>

#include "o3d/gpu_plugin/command_buffer.h"
#include "o3d/gpu_plugin/np_utils/dispatched_np_object.h"
#include "o3d/gpu_plugin/np_utils/np_dispatcher.h"
#include "o3d/gpu_plugin/np_utils/np_plugin_object.h"
#include "o3d/gpu_plugin/np_utils/np_utils.h"
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"

namespace o3d {
namespace gpu_plugin {

// The scriptable object for the GPU plugin.
class GPUPluginObject : public DefaultNPObject<NPObject>,
                        public PluginObject {
 public:
  static const NPUTF8 kPluginType[];

  explicit GPUPluginObject(NPP npp);

  virtual NPError New(NPMIMEType plugin_type,
                      int16 argc,
                      char* argn[],
                      char* argv[],
                      NPSavedData* saved);

  virtual NPError SetWindow(NPWindow* new_window);
  const NPWindow& GetWindow() { return window_; }

  virtual int16 HandleEvent(NPEvent* event);

  virtual NPError Destroy(NPSavedData** saved);

  virtual void Release();

  virtual NPObject* GetScriptableNPObject();

  // Initializes and returns the command buffer object.
  NPObjectPointer<NPObject> OpenCommandBuffer();

  NP_UTILS_BEGIN_DISPATCHER_CHAIN(GPUPluginObject, DefaultNPObject<NPObject>)
    NP_UTILS_DISPATCHER(OpenCommandBuffer, NPObjectPointer<NPObject>())
  NP_UTILS_END_DISPATCHER_CHAIN

 private:
  NPError PlatformSpecificSetWindow(NPWindow* new_window);

  enum Status {
    CREATED,
    INITIALIZED,
    DESTROYED,
  };

  NPP npp_;
  Status status_;
  NPWindow window_;
  NPObjectPointer<CommandBuffer> command_buffer_object_;
  NPSharedMemory* shared_memory_;
};

}  // namespace gpu_plugin
}  // namespace o3d

#endif  // O3D_GPU_PLUGIN_GPU_PLUGIN_OBJECT_H_