Chromium Code Reviews| Index: ui/gl/cgl_util.h |
| diff --git a/ui/gl/cgl_util.h b/ui/gl/cgl_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a86066a70cd7c9a449c28093b4f77522fe7f468b |
| --- /dev/null |
| +++ b/ui/gl/cgl_util.h |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GL_CGL_UTIL_H_ |
| +#define UI_GL_CGL_UTIL_H_ |
|
Nico
2014/02/08 02:52:27
We don't like _util files as they tend to become d
ccameron
2014/02/10 00:10:45
Hmm ... any suggestions for names? I'm drawing so
Nico
2014/02/10 00:14:09
Maybe scoped_cgl.h?
|
| + |
| +#include <OpenGL/OpenGL.h> |
| + |
| +#include "base/mac/scoped_typeref.h" |
| +#include "ui/gl/gl_export.h" |
| + |
| +namespace base { |
| + |
| +template<> |
| +struct ScopedTypeRefTraits<CGLContextObj> { |
| + static void Retain(CGLContextObj object) { |
| + CGLRetainContext(object); |
| + } |
| + static void Release(CGLContextObj object) { |
| + CGLReleaseContext(object); |
| + } |
| +}; |
| + |
| +template<> |
| +struct ScopedTypeRefTraits<CGLPixelFormatObj> { |
| + static void Retain(CGLPixelFormatObj object) { |
| + CGLRetainPixelFormat(object); |
| + } |
| + static void Release(CGLPixelFormatObj object) { |
| + CGLReleasePixelFormat(object); |
| + } |
| +}; |
| + |
| +} // namespace base |
| + |
| +namespace gfx { |
| + |
| +class GL_EXPORT ScopedCGLSetCurrentContext { |
| + public: |
| + explicit ScopedCGLSetCurrentContext(CGLContextObj context); |
| + ~ScopedCGLSetCurrentContext(); |
| + private: |
| + // Note that if a context is destroyed when it is current, then the current |
| + // context is changed to NULL. Take out a reference on |previous_context_| to |
| + // preserve this behavior (when this falls out of scope, |previous_context_| |
| + // will be made current, then released, so NULL will be current if that |
| + // release destroys the context). |
| + base::ScopedTypeRef<CGLContextObj> previous_context_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedCGLSetCurrentContext); |
| +}; |
| + |
| +} // namespace gfx |
| + |
| +#endif // UI_GL_CGL_UTIL_H_ |