summaryrefslogtreecommitdiffstats
path: root/ui/gl/gl_surface_osmesa.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 21:17:27 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-12 21:17:27 +0000
commitc9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7 (patch)
treee33d97dc2edae8702ddb6a17ba0d89a506412693 /ui/gl/gl_surface_osmesa.cc
parentfc25fd35147b2d5e74d5450e8586592c6a10813d (diff)
downloadchromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.zip
chromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.tar.gz
chromium_src-c9e2cbbbcad5f0ae5b9c5ccaf6a36a8a4a61e0e7.tar.bz2
ui: Move gl/ directory out of gfx/, up to ui/.
BUG=104040 R=ben@chromium.org TBR=tony@chromium.org Review URL: https://chromiumcodereview.appspot.com/10392068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136777 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl/gl_surface_osmesa.cc')
-rw-r--r--ui/gl/gl_surface_osmesa.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/ui/gl/gl_surface_osmesa.cc b/ui/gl/gl_surface_osmesa.cc
new file mode 100644
index 0000000..a1fd360
--- /dev/null
+++ b/ui/gl/gl_surface_osmesa.cc
@@ -0,0 +1,82 @@
+// Copyright (c) 2012 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.
+
+#include "base/logging.h"
+#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_context.h"
+#include "ui/gl/gl_surface_osmesa.h"
+
+namespace gfx {
+
+GLSurfaceOSMesa::GLSurfaceOSMesa(unsigned format, const gfx::Size& size)
+ : format_(format),
+ size_(size) {
+}
+
+bool GLSurfaceOSMesa::Initialize() {
+ return Resize(size_);
+}
+
+void GLSurfaceOSMesa::Destroy() {
+ buffer_.reset();
+}
+
+bool GLSurfaceOSMesa::Resize(const gfx::Size& new_size) {
+ GLContext* current_context = GLContext::GetCurrent();
+ bool was_current = current_context && current_context->IsCurrent(this);
+ if (was_current)
+ current_context->ReleaseCurrent(this);
+
+ // Preserve the old buffer.
+ scoped_array<int32> old_buffer(buffer_.release());
+
+ // Allocate a new one.
+ buffer_.reset(new int32[new_size.GetArea()]);
+ memset(buffer_.get(), 0, new_size.GetArea() * sizeof(buffer_[0]));
+
+ // Copy the old back buffer into the new buffer.
+ if (old_buffer.get()) {
+ int copy_width = std::min(size_.width(), new_size.width());
+ int copy_height = std::min(size_.height(), new_size.height());
+ for (int y = 0; y < copy_height; ++y) {
+ for (int x = 0; x < copy_width; ++x) {
+ buffer_[y * new_size.width() + x] = old_buffer[y * size_.width() + x];
+ }
+ }
+ }
+
+ size_ = new_size;
+
+ if (was_current)
+ return current_context->MakeCurrent(this);
+
+ return true;
+}
+
+bool GLSurfaceOSMesa::IsOffscreen() {
+ return true;
+}
+
+bool GLSurfaceOSMesa::SwapBuffers() {
+ NOTREACHED() << "Should not call SwapBuffers on an GLSurfaceOSMesa.";
+ return false;
+}
+
+gfx::Size GLSurfaceOSMesa::GetSize() {
+ return size_;
+}
+
+void* GLSurfaceOSMesa::GetHandle() {
+ return buffer_.get();
+}
+
+unsigned GLSurfaceOSMesa::GetFormat() {
+ return format_;
+}
+
+GLSurfaceOSMesa::~GLSurfaceOSMesa() {
+ Destroy();
+}
+
+} // namespace gfx