[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame^] | 5 | #ifndef APP_GFX_GL_GL_CONTEXT_OSMESA_H_ |
6 | #define APP_GFX_GL_GL_CONTEXT_OSMESA_H_ | ||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 7 | |
8 | #include "base/scoped_ptr.h" | ||||
9 | #include "gfx/size.h" | ||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame^] | 10 | #include "app/gfx/gl/gl_context.h" |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 11 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame^] | 12 | typedef struct osmesa_context *OSMesaContext; |
13 | |||||
14 | namespace gfx { | ||||
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 15 | |
16 | // Encapsulates an OSMesa OpenGL context that uses software rendering. | ||||
17 | class OSMesaGLContext : public GLContext { | ||||
18 | public: | ||||
19 | OSMesaGLContext(); | ||||
20 | virtual ~OSMesaGLContext(); | ||||
21 | |||||
22 | // Initialize an OSMesa GL context with the default 1 x 1 initial size. | ||||
23 | bool Initialize(void* shared_handle); | ||||
24 | |||||
25 | // Implement GLContext. | ||||
26 | virtual void Destroy(); | ||||
27 | virtual bool MakeCurrent(); | ||||
28 | virtual bool IsCurrent(); | ||||
29 | virtual bool IsOffscreen(); | ||||
30 | virtual void SwapBuffers(); | ||||
31 | virtual gfx::Size GetSize(); | ||||
32 | virtual void* GetHandle(); | ||||
33 | |||||
34 | // Resize the back buffer, preserving the old content. Does nothing if the | ||||
35 | // size is unchanged. | ||||
36 | void Resize(const gfx::Size& new_size); | ||||
37 | |||||
38 | const void* buffer() const { | ||||
39 | return buffer_.get(); | ||||
40 | } | ||||
41 | |||||
42 | protected: | ||||
43 | bool InitializeCommon(); | ||||
44 | |||||
45 | private: | ||||
46 | #if !defined(UNIT_TEST) | ||||
47 | gfx::Size size_; | ||||
48 | scoped_array<int32> buffer_; | ||||
49 | OSMesaContext context_; | ||||
50 | #endif | ||||
51 | |||||
52 | DISALLOW_COPY_AND_ASSIGN(OSMesaGLContext); | ||||
53 | }; | ||||
54 | |||||
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame^] | 55 | } // namespace gfx |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 56 | |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame^] | 57 | #endif // APP_GFX_GL_GL_CONTEXT_OSMESA_H_ |