| 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..24a664930f95b153e3522052d82cbd8bd9db2a14
|
| --- /dev/null
|
| +++ b/ui/gl/gl_surface_format.cc
|
| @@ -0,0 +1,126 @@
|
| +// 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(SurfacePixelLayout layout) {
|
| + is_default = false;
|
| + pixel_layout = layout;
|
| +}
|
| +
|
| +GLSurfaceFormat::GLSurfaceFormat(const GLSurfaceFormat& other) = default;
|
| +
|
| +GLSurfaceFormat::~GLSurfaceFormat() {
|
| +}
|
| +
|
| +bool GLSurfaceFormat::IsSurfaceless() {
|
| + return is_surfaceless;
|
| +}
|
| +
|
| +GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() {
|
| + return pixel_layout;
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetDefaultPixelLayout(SurfacePixelLayout layout) {
|
| + if (pixel_layout == PIXEL_LAYOUT_DONT_CARE &&
|
| + layout != PIXEL_LAYOUT_DONT_CARE) {
|
| + pixel_layout = layout;
|
| + is_default = false;
|
| + }
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetRGB565() {
|
| + red_bits = blue_bits = 5;
|
| + green_bits = 6;
|
| + alpha_bits = 0;
|
| + is_default = false;
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetIsSurfaceless() {
|
| + is_surfaceless = true;
|
| + is_default = false;
|
| +}
|
| +
|
| +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 (IsDefault() && other.IsDefault()) return true;
|
| +
|
| + if (GetBitSize(red_bits) == GetBitSize(other.red_bits) &&
|
| + GetBitSize(green_bits) == GetBitSize(other.green_bits) &&
|
| + GetBitSize(blue_bits) == GetBitSize(other.blue_bits) &&
|
| + GetBitSize(alpha_bits) == GetBitSize(other.alpha_bits) &&
|
| + GetValue(stencil_bits, 8) == GetValue(other.stencil_bits, 8) &&
|
| + GetValue(depth_bits, 24) == GetValue(other.depth_bits, 24) &&
|
| + GetValue(samples, 0) == GetValue(other.samples, 0) &&
|
| + is_surfaceless == other.is_surfaceless &&
|
| + pixel_layout == other.pixel_layout) {
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetDepthBits(int bits) {
|
| + if (bits != -1) {
|
| + depth_bits = bits;
|
| + is_default = false;
|
| + }
|
| +}
|
| +
|
| +int GLSurfaceFormat::GetDepthBits() {
|
| + return depth_bits;
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetStencilBits(int bits) {
|
| + if (bits != -1) {
|
| + stencil_bits = bits;
|
| + is_default = false;
|
| + }
|
| +}
|
| +
|
| +int GLSurfaceFormat::GetStencilBits() {
|
| + return stencil_bits;
|
| +}
|
| +
|
| +void GLSurfaceFormat::SetSamples(int num) {
|
| + if (num != -1) {
|
| + samples = num;
|
| + is_default = false;
|
| + }
|
| +}
|
| +
|
| +int GLSurfaceFormat::GetSamples() {
|
| + return samples;
|
| +}
|
| +
|
| +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
|
|
|