OLD | NEW |
| (Empty) |
1 // Copyright 2010 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 | |
5 #ifndef C_SALT_NPAPI_BROWSER_3D_DEVICE_H_ | |
6 #define C_SALT_NPAPI_BROWSER_3D_DEVICE_H_ | |
7 | |
8 /// | |
9 /// @file | |
10 /// Browser3DContext provides the browser-specific support for managing a | |
11 /// 3D context in the browser. Currently, all 3D browser contexts support | |
12 /// OpenGL ES 2.0. | |
13 /// @see c_salt/opengl_context.h | |
14 /// | |
15 | |
16 #include <pgl/pgl.h> | |
17 | |
18 #include "boost/noncopyable.hpp" | |
19 #include "c_salt/browser_3d_device.h" | |
20 | |
21 namespace c_salt { | |
22 class Instance; | |
23 class OpenGLContext; | |
24 | |
25 namespace npapi { | |
26 | |
27 /// | |
28 /// @class Browser3DContext | |
29 /// @a Browser3DContext manages access to the 3D device in the browser and a 3D | |
30 /// rendering context on that device. | |
31 /// | |
32 class Browser3DDeviceNPAPI : public Browser3DDevice, | |
33 public boost::noncopyable { | |
34 public: | |
35 /// A newly constructed @a Browser3DContext is invalid until | |
36 /// @a AcquireBrowser3DDevice() is called. After acquiring the 3D device in | |
37 /// the browser, you then have to create a context by calling | |
38 /// @a CreateBrowser3DContext(). | |
39 /// @param instance The Instance instance associated with the in-browser | |
40 /// 3D device and context. | |
41 /// @see AcquireBrowser3DDevice() | |
42 /// @see CreateBrowser3DContext() | |
43 explicit Browser3DDeviceNPAPI(const Instance& instance); | |
44 | |
45 /// Deletes all active in-browser 3D contexts and releases the 3D device. | |
46 virtual ~Browser3DDeviceNPAPI(); | |
47 | |
48 /// Acquire the 3D device in the browser that is associated with the | |
49 /// @a Instance instance passed into the ctor. If the 3D device has | |
50 /// already been acquired by a previous call, then this is a no-op. | |
51 /// @return success. | |
52 virtual bool AcquireBrowser3DDevice(); | |
53 | |
54 /// Create a 3D rendering context in the browser, and bind to @a context. | |
55 /// This can be called more than once to create many 3D rendering contexts | |
56 /// associated with the browser's 3D device. | |
57 virtual PGLContext CreateBrowser3DContext(OpenGLContext* context); | |
58 | |
59 /// Delete the in-browser 3D context and release the 3D device. After calling | |
60 /// this method, the context is no longer valid. | |
61 virtual void DeleteBrowser3DContext(); | |
62 | |
63 /// The browser context is considered valid when the 3D device has been | |
64 /// succesfully acquired, and a 3D context has been initialized. | |
65 /// @return true if the 3D device is aquired. | |
66 virtual bool is_valid() const { | |
67 return device3d_ != NULL; | |
68 } | |
69 | |
70 private: | |
71 // Called by the browser whenever the 3D context needs to be repainted. | |
72 // This callback is a simple wrapper that calls the @a RenderContext() | |
73 // method on the associated @a OpenGLContext. | |
74 static void RepaintCallback(NPP npp, NPDeviceContext3D* context); | |
75 // Augment the Pepper V1 context struct so that it can carry user data in | |
76 // its payload. | |
77 struct DeviceContext3DExt : public NPDeviceContext3D { | |
78 // A raw pointer seems kind of scary here, but this is all very temporary | |
79 // so I'm not inclined to think about it too much... | |
80 OpenGLContext* user_data_; | |
81 }; | |
82 const Instance& instance_; // Weak reference. | |
83 // |device3d_| is managed by the browser. This class maintains a weak | |
84 // reference to it. | |
85 NPDevice* device3d_; | |
86 DeviceContext3DExt context3d_; | |
87 | |
88 // Not implemented - do not use. | |
89 Browser3DDeviceNPAPI(); | |
90 }; | |
91 | |
92 } // namespace npapi | |
93 } // namespace c_salt | |
94 #endif // C_SALT_NPAPI_BROWSER_3D_DEVICE_H_ | |
OLD | NEW |