File: gl_surface_format.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (80 lines) | stat: -rw-r--r-- 2,677 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GL_GL_SURFACE_FORMAT_H_
#define UI_GL_GL_SURFACE_FORMAT_H_

#include "ui/gl/gl_export.h"

namespace gl {

// Expresses surface format properties that may vary depending
// on the underlying gl_surface implementation or specific usage
// scenarios. Intended usage is to support copying formats and
// checking compatibility.
class GL_EXPORT GLSurfaceFormat {
 public:
  // Default surface format for the underlying gl_surface subtype.
  // Use the setters below to change attributes if needed.
  GLSurfaceFormat();

  // Copy constructor from pre-existing format.
  GLSurfaceFormat(const GLSurfaceFormat& other);

  ~GLSurfaceFormat();

  // A given pair of surfaces is considered compatible if glSetSurface
  // can be used to switch between them without generating BAD_MATCH
  // errors, visual errors, or gross inefficiency, and incompatible
  // otherwise. For example, a pixel layout mismatch would be
  // considered incompatible. This comparison only makes sense within
  // the context of a single gl_surface subtype.
  bool IsCompatible(GLSurfaceFormat other_format) const;

  // Default pixel format is RGBA8888. Use this method to select
  // a preference of RGB565. This could be refactored to use individual
  // setter methods for more fine-grained control, but so far there hasn't
  // been a use case for that. See also GLES2CommandBufferStub::Initialize
  // which distinguishes between RGBA8888 and RGB565 modes.
  void SetRGB565();

  // Other properties for future use.
  void SetDepthBits(int depth_bits);
  int GetDepthBits() const { return depth_bits_; }

  void SetStencilBits(int stencil_bits);
  int GetStencilBits() const { return stencil_bits_; }

  void SetSamples(int samples);
  int GetSamples() const { return samples_; }

  enum SurfaceColorSpace {
    COLOR_SPACE_UNSPECIFIED = -1,
    COLOR_SPACE_SRGB,
    COLOR_SPACE_DISPLAY_P3,
  };
  void SetColorSpace(SurfaceColorSpace color_space) {
    color_space_ = color_space;
  }
  SurfaceColorSpace GetColorSpace() const { return color_space_; }

  // Compute number of bits needed for storing one pixel, not
  // including any padding. At this point mainly used to distinguish
  // RGB565 (16) from RGBA8888 (32).
  int GetBufferSize() const;

 private:
  SurfaceColorSpace color_space_ = COLOR_SPACE_UNSPECIFIED;
  int red_bits_ = -1;
  int green_bits_ = -1;
  int blue_bits_ = -1;
  int alpha_bits_ = -1;
  int depth_bits_ = -1;
  int samples_ = -1;
  int stencil_bits_ = -1;
};

}  // namespace gl

#endif  // UI_GL_GL_SURFACE_FORMAT_H_