Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Unified Diff: ui/gl/gl_surface_format.cc

Issue 2616723002: Refactor GL surface format handling (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gl/gl_surface_format.cc
diff --git a/ui/gl/gl_surface_format.cc b/ui/gl/gl_surface_format.cc
new file mode 100644
index 0000000000000000000000000000000000000000..91c8898e149de0e88c0a583db55872e8c29df34b
--- /dev/null
+++ b/ui/gl/gl_surface_format.cc
@@ -0,0 +1,103 @@
+// Copyright (c) 2017 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_surface_format.h"
+
+namespace gl {
+
+GLSurfaceFormat::GLSurfaceFormat() {
+}
+
+GLSurfaceFormat::GLSurfaceFormat(SurfaceFormat format) {
+ is_default = false;
+ switch (format) {
+ case SURFACE_ARGB8888:
+ red_bits = green_bits = blue_bits = alpha_bits = 8;
+ // For backwards compatibility, treat this as equivalent to the
+ // default format.
+ is_default = true;
+ break;
+ case SURFACE_RGB565:
+ red_bits = blue_bits = 5;
+ green_bits = 6;
+ alpha_bits = 0;
+ break;
+ case SURFACE_OSMESA_BGRA:
+ pixel_layout = SURFACE_PIXEL_LAYOUT_BGRA;
+ break;
+ case SURFACE_OSMESA_RGBA:
+ pixel_layout = SURFACE_PIXEL_LAYOUT_RGBA;
+ break;
+ case SURFACE_SURFACELESS:
+ is_surfaceless = true;
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+bool GLSurfaceFormat::IsSurfaceless() {
+ return is_surfaceless;
+}
+
+GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() {
+ return pixel_layout;
+}
+
+static int GetValue(int num, int default_value) {
+ return num == -1 ? default_value : num;
+}
+
+static int GetBitSize(int num) {
+ return GetValue(num, 8);
+}
+
+
+bool GLSurfaceFormat::IsDefault() {
+ return is_default;
+}
+
+bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) {
+ if (this->IsDefault() && other.IsDefault()) return true;
+
+ if (GetBitSize(this->red_bits) == GetBitSize(other.red_bits) &&
+ GetBitSize(this->green_bits) == GetBitSize(other.green_bits) &&
+ GetBitSize(this->blue_bits) == GetBitSize(other.blue_bits) &&
+ GetBitSize(this->alpha_bits) == GetBitSize(other.alpha_bits) &&
+ GetValue(this->stencil_bits, 8) == GetValue(other.stencil_bits, 8) &&
+ GetValue(this->depth_bits, 24) == GetValue(other.depth_bits, 24) &&
+ GetValue(this->samples, 0) == GetValue(other.samples, 0) &&
+ this->is_surfaceless == other.is_surfaceless &&
+ this->pixel_layout == other.pixel_layout) {
+ return true;
+ }
+ return false;
+}
+
+void GLSurfaceFormat::SetDepthBits(int bits) {
+ depth_bits = bits;
+}
+
+void GLSurfaceFormat::SetStencilBits(int bits) {
+ stencil_bits = bits;
+}
+
+void GLSurfaceFormat::SetSamples(int num) {
+ samples = num;
+}
+
+int GLSurfaceFormat::GetBufferSize() {
+ int bits = GetBitSize(red_bits) + GetBitSize(green_bits) +
+ GetBitSize(blue_bits) + GetBitSize(alpha_bits);
+ if (bits <= 16) {
+ return 16;
+ } else if (bits <= 32) {
+ return 32;
+ }
+ NOTREACHED();
+ return 64;
+}
+
+} // namespace gl
« ui/gl/gl_surface_egl.cc ('K') | « ui/gl/gl_surface_format.h ('k') | ui/gl/gl_surface_glx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698