| 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
|
|
|