• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 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 
5 #include "ui/gl/scoped_make_current.h"
6 
7 #include "base/logging.h"
8 #include "ui/gl/gl_context.h"
9 #include "ui/gl/gl_surface.h"
10 
11 namespace ui {
12 
ScopedMakeCurrent(gfx::GLContext * context,gfx::GLSurface * surface)13 ScopedMakeCurrent::ScopedMakeCurrent(gfx::GLContext* context,
14                                      gfx::GLSurface* surface)
15     : previous_context_(gfx::GLContext::GetCurrent()),
16       previous_surface_(gfx::GLSurface::GetCurrent()),
17       context_(context),
18       surface_(surface),
19       succeeded_(false) {
20   DCHECK(context);
21   DCHECK(surface);
22   succeeded_ = context->MakeCurrent(surface);
23 }
24 
~ScopedMakeCurrent()25 ScopedMakeCurrent::~ScopedMakeCurrent() {
26   if (previous_context_.get()) {
27     DCHECK(previous_surface_.get());
28     previous_context_->MakeCurrent(previous_surface_.get());
29   } else {
30     context_->ReleaseCurrent(surface_.get());
31   }
32 }
33 
Succeeded() const34 bool ScopedMakeCurrent::Succeeded() const {
35   return succeeded_;
36 }
37 
38 }  // namespace ui
39