Index: gpu/command_buffer/service/x_utils.h |
=================================================================== |
--- gpu/command_buffer/service/x_utils.h (revision 43138) |
+++ gpu/command_buffer/service/x_utils.h (working copy) |
@@ -13,36 +13,97 @@ |
namespace gpu { |
+// Abstracts between on-screen and off-screen GLX contexts. |
+class GLXContextWrapper { |
+ public: |
+ explicit GLXContextWrapper(Display* display) |
+ : display_(display), |
+ context_(NULL) { |
+ DCHECK(display_); |
+ } |
+ |
+ virtual ~GLXContextWrapper(); |
+ |
+ // Initializes the GL context. Subclasses should perform their |
+ // initialization work and then call the superclass implementation. |
+ virtual bool Initialize(); |
+ |
+ // Destroys the GL context. Subclasses may call this before or after |
+ // doing any necessary cleanup work. |
+ virtual void Destroy(); |
+ |
+ // Makes the GL context current on the current thread. |
+ virtual bool MakeCurrent() = 0; |
+ |
+ // Returns true if this context is offscreen. |
+ virtual bool IsOffscreen() = 0; |
+ |
+ // Swaps front and back buffers. This has no effect for off-screen |
+ // contexts. |
+ virtual void SwapBuffers() = 0; |
+ |
+ // Fetches the GLX context for sharing of server-side objects. |
+ GLXContext GetContext() { |
+ return context_; |
+ } |
+ |
+ protected: |
+ Display* GetDisplay() { |
+ return display_; |
+ } |
+ |
+ void SetContext(GLXContext context) { |
+ context_ = context; |
+ } |
+ |
+ private: |
+ Display* display_; |
+ GLXContext context_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GLXContextWrapper); |
+}; |
+ |
// This class is a wrapper around an X Window and associated GL context. It is |
// useful to isolate intrusive X headers, since it can be forward declared |
// (Window and GLXContext can't). |
-class XWindowWrapper { |
+class XWindowWrapper : public GLXContextWrapper { |
public: |
XWindowWrapper(Display *display, Window window) |
- : display_(display), |
+ : GLXContextWrapper(display), |
window_(window) { |
- DCHECK(display_); |
DCHECK(window_); |
} |
- // Initializes the GL context. |
- bool Initialize(); |
- // Destroys the GL context. |
- void Destroy(); |
+ virtual bool Initialize(); |
+ virtual bool MakeCurrent(); |
+ virtual bool IsOffscreen(); |
+ virtual void SwapBuffers(); |
- // Makes the GL context current on the current thread. |
- bool MakeCurrent(); |
- |
- // Swaps front and back buffers. |
- void SwapBuffers(); |
- |
private: |
- Display *display_; |
Window window_; |
- GLXContext context_; |
DISALLOW_COPY_AND_ASSIGN(XWindowWrapper); |
}; |
+// This class is a wrapper around a GLX pbuffer and associated GL context. It |
+// serves the same purpose as the XWindowWrapper for initializing off-screen |
+// rendering. |
+class GLXPbufferWrapper : public GLXContextWrapper { |
+ public: |
+ explicit GLXPbufferWrapper(Display* display) |
+ : GLXContextWrapper(display) { |
+ } |
+ |
+ virtual bool Initialize(); |
+ virtual void Destroy(); |
+ virtual bool MakeCurrent(); |
+ virtual bool IsOffscreen(); |
+ virtual void SwapBuffers(); |
+ |
+ private: |
+ GLXPbuffer pbuffer_; |
+ DISALLOW_COPY_AND_ASSIGN(GLXPbufferWrapper); |
+}; |
+ |
} // namespace gpu |
#endif // GPU_COMMAND_BUFFER_SERVICE_X_UTILS_H_ |