Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / ui / gl / gl_surface_osmesa.cc
index 9a556bc..4c49166 100644 (file)
@@ -3,6 +3,7 @@
 // found in the LICENSE file.
 
 #include "base/logging.h"
+#include "third_party/mesa/src/include/GL/osmesa.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) {
+GLSurfaceOSMesa::GLSurfaceOSMesa(OSMesaSurfaceFormat format,
+                                 const gfx::Size& size)
+    : size_(size) {
+  switch (format) {
+    case OSMesaSurfaceFormatBGRA:
+      format_ = OSMESA_BGRA;
+      break;
+    case OSMesaSurfaceFormatRGBA:
+      format_ = OSMESA_RGBA;
+      break;
+  }
+  // Implementations of OSMesa surface do not support having a 0 size. In such
+  // cases use a (1, 1) surface.
+  if (size_.GetArea() == 0)
+    size_.SetSize(1, 1);
 }
 
 bool GLSurfaceOSMesa::Initialize() {
@@ -82,4 +95,14 @@ GLSurfaceOSMesa::~GLSurfaceOSMesa() {
   Destroy();
 }
 
+bool GLSurfaceOSMesaHeadless::IsOffscreen() { return false; }
+
+bool GLSurfaceOSMesaHeadless::SwapBuffers() { return true; }
+
+GLSurfaceOSMesaHeadless::GLSurfaceOSMesaHeadless()
+    : GLSurfaceOSMesa(OSMesaSurfaceFormatBGRA, gfx::Size(1, 1)) {
+}
+
+GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); }
+
 }  // namespace gfx