gl_surface_egl.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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#ifndef UI_GL_GL_SURFACE_EGL_H_ 6#define UI_GL_GL_SURFACE_EGL_H_ 7 8#if defined(OS_WIN) 9#include <windows.h> 10#endif 11 12#include <string> 13 14#include "base/compiler_specific.h" 15#include "base/time.h" 16#include "ui/gfx/native_widget_types.h" 17#include "ui/gfx/size.h" 18#include "ui/gl/gl_bindings.h" 19#include "ui/gl/gl_surface.h" 20#include "ui/gl/vsync_provider.h" 21 22namespace gfx { 23 24// Interface for EGL surface. 25class GL_EXPORT GLSurfaceEGL : public GLSurface { 26 public: 27 GLSurfaceEGL(); 28 29 // Implement GLSurface. 30 virtual EGLDisplay GetDisplay() OVERRIDE; 31 32 static bool InitializeOneOff(); 33 static EGLDisplay GetHardwareDisplay(); 34 static EGLDisplay GetSoftwareDisplay(); 35 static EGLNativeDisplayType GetNativeDisplay(); 36 37 // These aren't particularly tied to surfaces, but since we already 38 // have the static InitializeOneOff here, it's easiest to reuse its 39 // initialization guards. 40 static const char* GetEGLExtensions(); 41 static bool HasEGLExtension(const char* name); 42 static bool IsCreateContextRobustnessSupported(); 43 44 protected: 45 virtual ~GLSurfaceEGL(); 46 47 bool software_; 48 49 private: 50 DISALLOW_COPY_AND_ASSIGN(GLSurfaceEGL); 51}; 52 53// Encapsulates an EGL surface bound to a view. 54class GL_EXPORT NativeViewGLSurfaceEGL : public GLSurfaceEGL { 55 public: 56 NativeViewGLSurfaceEGL(bool software, gfx::AcceleratedWidget window); 57 58 // Implement GLSurface. 59 virtual EGLConfig GetConfig() OVERRIDE; 60 virtual bool Initialize() OVERRIDE; 61 virtual void Destroy() OVERRIDE; 62 virtual bool Resize(const gfx::Size& size) OVERRIDE; 63 virtual bool Recreate() OVERRIDE; 64 virtual bool IsOffscreen() OVERRIDE; 65 virtual bool SwapBuffers() OVERRIDE; 66 virtual gfx::Size GetSize() OVERRIDE; 67 virtual EGLSurface GetHandle() OVERRIDE; 68 virtual std::string GetExtensions() OVERRIDE; 69 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; 70 virtual VSyncProvider* GetVSyncProvider() OVERRIDE; 71 72 // Create a NativeViewGLSurfaceEGL with an externally provided VSyncProvider. 73 virtual bool Initialize(VSyncProvider* sync_provider); 74 75 protected: 76 virtual ~NativeViewGLSurfaceEGL(); 77 void SetHandle(EGLSurface surface); 78 79 private: 80 gfx::AcceleratedWidget window_; 81 EGLSurface surface_; 82 bool supports_post_sub_buffer_; 83 EGLConfig config_; 84 85 scoped_ptr<VSyncProvider> vsync_provider_; 86 87 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceEGL); 88}; 89 90// Encapsulates a pbuffer EGL surface. 91class GL_EXPORT PbufferGLSurfaceEGL : public GLSurfaceEGL { 92 public: 93 PbufferGLSurfaceEGL(bool software, const gfx::Size& size); 94 95 // Implement GLSurface. 96 virtual EGLConfig GetConfig() OVERRIDE; 97 virtual bool Initialize() OVERRIDE; 98 virtual void Destroy() OVERRIDE; 99 virtual bool IsOffscreen() OVERRIDE; 100 virtual bool SwapBuffers() OVERRIDE; 101 virtual gfx::Size GetSize() OVERRIDE; 102 virtual bool Resize(const gfx::Size& size) OVERRIDE; 103 virtual EGLSurface GetHandle() OVERRIDE; 104 virtual void* GetShareHandle() OVERRIDE; 105 106 protected: 107 virtual ~PbufferGLSurfaceEGL(); 108 109 private: 110 gfx::Size size_; 111 EGLSurface surface_; 112 113 DISALLOW_COPY_AND_ASSIGN(PbufferGLSurfaceEGL); 114}; 115 116} // namespace gfx 117 118#endif // UI_GL_GL_SURFACE_EGL_H_ 119