Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / gl / scoped_cgl.h
blob81e1e6ea36068c9fddd99123d5a9ac3733e6aa6e
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
3 // found in the LICENSE file.
5 #ifndef UI_GL_SCOPED_CGL_H_
6 #define UI_GL_SCOPED_CGL_H_
8 #include <OpenGL/OpenGL.h>
10 #include "base/mac/scoped_typeref.h"
11 #include "ui/gl/gl_export.h"
13 namespace base {
15 template<>
16 struct ScopedTypeRefTraits<CGLContextObj> {
17 static void Retain(CGLContextObj object) {
18 CGLRetainContext(object);
20 static void Release(CGLContextObj object) {
21 CGLReleaseContext(object);
25 template<>
26 struct ScopedTypeRefTraits<CGLPixelFormatObj> {
27 static void Retain(CGLPixelFormatObj object) {
28 CGLRetainPixelFormat(object);
30 static void Release(CGLPixelFormatObj object) {
31 CGLReleasePixelFormat(object);
35 } // namespace base
37 namespace gfx {
39 class GL_EXPORT ScopedCGLSetCurrentContext {
40 public:
41 explicit ScopedCGLSetCurrentContext(CGLContextObj context);
42 ~ScopedCGLSetCurrentContext();
43 private:
44 // Note that if a context is destroyed when it is current, then the current
45 // context is changed to NULL. Take out a reference on |previous_context_| to
46 // preserve this behavior (when this falls out of scope, |previous_context_|
47 // will be made current, then released, so NULL will be current if that
48 // release destroys the context).
49 base::ScopedTypeRef<CGLContextObj> previous_context_;
51 DISALLOW_COPY_AND_ASSIGN(ScopedCGLSetCurrentContext);
54 } // namespace gfx
56 #endif // UI_GL_SCOPED_CGL_H_