OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GL_SCOPED_CGL_H_ | 5 #ifndef UI_GL_SCOPED_CGL_H_ |
6 #define UI_GL_SCOPED_CGL_H_ | 6 #define UI_GL_SCOPED_CGL_H_ |
7 | 7 |
8 #include <OpenGL/OpenGL.h> | 8 #include <OpenGL/OpenGL.h> |
9 | 9 |
10 #include "base/mac/scoped_typeref.h" | 10 #include "base/mac/scoped_typeref.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "ui/gl/gl_export.h" | 12 #include "ui/gl/gl_export.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 template<> | 16 template<> |
17 struct ScopedTypeRefTraits<CGLContextObj> { | 17 struct ScopedTypeRefTraits<CGLContextObj> { |
18 static CGLContextObj InvalidValue() { return nullptr; } | 18 static CGLContextObj InvalidValue() { return nullptr; } |
19 static void Retain(CGLContextObj object) { | 19 static CGLContextObj Retain(CGLContextObj object) { |
20 CGLRetainContext(object); | 20 return CGLRetainContext(object); |
21 } | 21 } |
22 static void Release(CGLContextObj object) { | 22 static void Release(CGLContextObj object) { |
23 CGLReleaseContext(object); | 23 CGLReleaseContext(object); |
24 } | 24 } |
25 }; | 25 }; |
26 | 26 |
27 template<> | 27 template<> |
28 struct ScopedTypeRefTraits<CGLPixelFormatObj> { | 28 struct ScopedTypeRefTraits<CGLPixelFormatObj> { |
29 static CGLPixelFormatObj InvalidValue() { return nullptr; } | 29 static CGLPixelFormatObj InvalidValue() { return nullptr; } |
30 static void Retain(CGLPixelFormatObj object) { | 30 static CGLPixelFormatObj Retain(CGLPixelFormatObj object) { |
31 CGLRetainPixelFormat(object); | 31 return CGLRetainPixelFormat(object); |
32 } | 32 } |
33 static void Release(CGLPixelFormatObj object) { | 33 static void Release(CGLPixelFormatObj object) { |
34 CGLReleasePixelFormat(object); | 34 CGLReleasePixelFormat(object); |
35 } | 35 } |
36 }; | 36 }; |
37 | 37 |
38 } // namespace base | 38 } // namespace base |
39 | 39 |
40 namespace gfx { | 40 namespace gfx { |
41 | 41 |
42 class GL_EXPORT ScopedCGLSetCurrentContext { | 42 class GL_EXPORT ScopedCGLSetCurrentContext { |
43 public: | 43 public: |
44 explicit ScopedCGLSetCurrentContext(CGLContextObj context); | 44 explicit ScopedCGLSetCurrentContext(CGLContextObj context); |
45 ~ScopedCGLSetCurrentContext(); | 45 ~ScopedCGLSetCurrentContext(); |
46 private: | 46 private: |
47 // Note that if a context is destroyed when it is current, then the current | 47 // Note that if a context is destroyed when it is current, then the current |
48 // context is changed to NULL. Take out a reference on |previous_context_| to | 48 // context is changed to NULL. Take out a reference on |previous_context_| to |
49 // preserve this behavior (when this falls out of scope, |previous_context_| | 49 // preserve this behavior (when this falls out of scope, |previous_context_| |
50 // will be made current, then released, so NULL will be current if that | 50 // will be made current, then released, so NULL will be current if that |
51 // release destroys the context). | 51 // release destroys the context). |
52 base::ScopedTypeRef<CGLContextObj> previous_context_; | 52 base::ScopedTypeRef<CGLContextObj> previous_context_; |
53 | 53 |
54 DISALLOW_COPY_AND_ASSIGN(ScopedCGLSetCurrentContext); | 54 DISALLOW_COPY_AND_ASSIGN(ScopedCGLSetCurrentContext); |
55 }; | 55 }; |
56 | 56 |
57 } // namespace gfx | 57 } // namespace gfx |
58 | 58 |
59 #endif // UI_GL_SCOPED_CGL_H_ | 59 #endif // UI_GL_SCOPED_CGL_H_ |
OLD | NEW |