scoped_cgl.cc 1.1 KB

123456789101112131415161718192021222324252627282930
  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.
  4. #include "ui/gl/scoped_cgl.h"
  5. #include <ostream>
  6. #include "base/check_op.h"
  7. namespace gl {
  8. ScopedCGLSetCurrentContext::ScopedCGLSetCurrentContext(CGLContextObj context) {
  9. CGLContextObj previous_context = CGLGetCurrentContext();
  10. // It is possible for the previous context to have a zero reference count,
  11. // because making a context current does not increment the reference count.
  12. // In that case, do not restore the previous context.
  13. if (previous_context && CGLGetContextRetainCount(previous_context)) {
  14. previous_context_.reset(previous_context, base::scoped_policy::RETAIN);
  15. }
  16. CGLError error = CGLSetCurrentContext(context);
  17. DCHECK_EQ(error, kCGLNoError) << "CGLSetCurrentContext should never fail";
  18. }
  19. ScopedCGLSetCurrentContext::~ScopedCGLSetCurrentContext() {
  20. CGLError error = CGLSetCurrentContext(previous_context_);
  21. DCHECK_EQ(error, kCGLNoError) << "CGLSetCurrentContext should never fail";
  22. }
  23. } // namespace gl