File: gl_texture_holder.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (90 lines) | stat: -rw-r--r-- 3,223 bytes parent folder | download | duplicates (8)
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
81
82
83
84
85
86
87
88
89
90
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_GL_TEXTURE_HOLDER_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_GL_TEXTURE_HOLDER_H_

#include "gpu/command_buffer/service/shared_image/gl_common_image_backing_factory.h"
#include "gpu/command_buffer/service/shared_image/shared_image_format_service_utils.h"
#include "ui/gl/progress_reporter.h"

class GrPromiseImageTexture;

namespace gpu {

class SharedContextState;

// Helper class that holds a single GL texture, that works with either
// validating or passthrough command decoder.
class GLTextureHolder {
 public:
  // Returns the equivalent SharedImageFormat for plane specified by
  // `plane_index`.
  static viz::SharedImageFormat GetPlaneFormat(viz::SharedImageFormat format,
                                               int plane_index);

  // `format` must be single-planar format.
  GLTextureHolder(viz::SharedImageFormat format,
                  const gfx::Size& size,
                  bool is_passthrough,
                  gl::ProgressReporter* progress_reporter);
  GLTextureHolder(GLTextureHolder&& other);
  GLTextureHolder& operator=(GLTextureHolder&& other);
  ~GLTextureHolder();

  gles2::Texture* texture() { return texture_; }
  const scoped_refptr<gles2::TexturePassthrough>& passthrough_texture() {
    return passthrough_texture_;
  }

  // Returns the service GL texture id.
  GLuint GetServiceId() const;

  // Initialize by creating a new GL texture.
  void Initialize(const GLCommonImageBackingFactory::FormatInfo& format_info,
                  bool framebuffer_attachment_angle,
                  base::span<const uint8_t> pixel_data,
                  const std::string& debug_label);

  // Initialize with a GL texture created elsewhere.
  void InitializeWithTexture(const GLFormatDesc& format_desc,
                             scoped_refptr<gles2::TexturePassthrough> texture);

  // Initialize with a GL texture created elsewhere. Takes ownership of
  // lightweight ref on `texture`.
  void InitializeWithTexture(const GLFormatDesc& format_desc,
                             gles2::Texture* texture);

  // Uploads pixels from `pixmap` to GL texture.
  bool UploadFromMemory(const SkPixmap& pixmap);

  // Readback pixels from GL texture to `pixmap`.
  bool ReadbackToMemory(const SkPixmap& pixmap);

  // Returns a promise image for the GL texture.
  sk_sp<GrPromiseImageTexture> GetPromiseImage(
      SharedContextState* context_state);

  // Gets/sets cleared rect from gles2::Texture. Only valid to call with
  // validating command decoder.
  gfx::Rect GetClearedRect() const;
  void SetClearedRect(const gfx::Rect& cleared_rect);

  void SetContextLost();

 private:
  viz::SharedImageFormat format_;
  gfx::Size size_;
  bool is_passthrough_;
  bool context_lost_ = false;

  raw_ptr<gles2::Texture> texture_ = nullptr;
  scoped_refptr<gles2::TexturePassthrough> passthrough_texture_;
  GLFormatDesc format_desc_;
  raw_ptr<gl::ProgressReporter> progress_reporter_ = nullptr;
};

}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_GL_TEXTURE_HOLDER_H_