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 GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_ 7 8 #include "base/callback.h" 9 #include "base/compiler_specific.h" 10 #include "gles2_impl_export.h" 11 #include "ui/gfx/native_widget_types.h" 12 #include "ui/gl/gl_surface.h" 13 #include "ui/gl/gpu_preference.h" 14 15 namespace gfx { 16 class Size; 17 } 18 19 #if defined(OS_ANDROID) 20 namespace gfx { 21 class SurfaceTextureBridge; 22 } 23 #endif 24 25 namespace gpu { 26 27 namespace gles2 { 28 class GLES2Implementation; 29 } 30 31 class GpuMemoryBufferFactory; 32 33 // The default uninitialized value is -1. 34 struct GLES2_IMPL_EXPORT GLInProcessContextAttribs { 35 GLInProcessContextAttribs(); 36 37 int32 alpha_size; 38 int32 blue_size; 39 int32 green_size; 40 int32 red_size; 41 int32 depth_size; 42 int32 stencil_size; 43 int32 samples; 44 int32 sample_buffers; 45 }; 46 47 class GLES2_IMPL_EXPORT GLInProcessContext { 48 public: 49 virtual ~GLInProcessContext() {} 50 51 // Must be called before any GLInProcessContext instances are created. 52 static void SetGpuMemoryBufferFactory(GpuMemoryBufferFactory* factory); 53 54 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an 55 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list 56 // of attribute/value pairs. 57 static GLInProcessContext* CreateContext( 58 bool is_offscreen, 59 gfx::AcceleratedWidget window, 60 const gfx::Size& size, 61 bool share_resources, 62 const char* allowed_extensions, 63 const GLInProcessContextAttribs& attribs, 64 gfx::GpuPreference gpu_preference); 65 66 // Create context with the provided GLSurface. All other arguments match 67 // CreateContext factory above. Can only be called if the command buffer 68 // service runs on the same thread as this client because GLSurface is not 69 // thread safe. 70 static GLInProcessContext* CreateWithSurface( 71 scoped_refptr<gfx::GLSurface> surface, 72 bool share_resources, 73 const char* allowed_extensions, 74 const GLInProcessContextAttribs& attribs, 75 gfx::GpuPreference gpu_preference); 76 77 virtual void SetContextLostCallback(const base::Closure& callback) = 0; 78 79 virtual void SignalSyncPoint(unsigned sync_point, 80 const base::Closure& callback) = 0; 81 82 virtual void SignalQuery(unsigned query, const base::Closure& callback) = 0; 83 84 // Allows direct access to the GLES2 implementation so a GLInProcessContext 85 // can be used without making it current. 86 virtual gles2::GLES2Implementation* GetImplementation() = 0; 87 88 #if defined(OS_ANDROID) 89 virtual scoped_refptr<gfx::SurfaceTextureBridge> GetSurfaceTexture( 90 uint32 stream_id) = 0; 91 #endif 92 }; 93 94 } // namespace gpu 95 96 #endif // GPU_COMMAND_BUFFER_CLIENT_GL_IN_PROCESS_CONTEXT_H_ 97