File: webgl_context_object_support.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (75 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download | duplicates (5)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_CONTEXT_OBJECT_SUPPORT_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_CONTEXT_OBJECT_SUPPORT_H_

#include <bitset>

#include "base/task/single_thread_task_runner.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/webgl/webgl_extension_name.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/khronos/GLES3/gl31.h"

namespace gpu::gles2 {
class GLES2Interface;
}

namespace blink {

// Base classes for WebGL rendering contexts that contains all the information
// needed by WebGLObject and child classes. This is used to avoid a dependency
// on WebGLRenderingContextBase and keep logic and effects more local.
class MODULES_EXPORT WebGLContextObjectSupport : public ScriptWrappable {
 public:
  // The GLES2Interface to use for the underlying GL context, it is nullptr when
  // the context is lost.
  gpu::gles2::GLES2Interface* ContextGL() const { return gles2_interface_; }

  bool IsWebGL2() const { return is_webgl2_; }
  bool IsLost() const { return is_lost_; }

  // How many context losses there were, to check whether a WebGLObject was
  // created since the last context resoration or before that (and hence invalid
  // to use).
  uint32_t NumberOfContextLosses() const { return number_of_context_losses_; }

  bool ExtensionEnabled(WebGLExtensionName name) const {
    return extensions_enabled_.test(name);
  }

  scoped_refptr<base::SingleThreadTaskRunner> GetContextTaskRunner();
  void Trace(Visitor*) const override;

 protected:
  WebGLContextObjectSupport(
      scoped_refptr<base::SingleThreadTaskRunner> task_runner,
      bool is_webgl2);

  // Must be called when the WebGL context is lost.
  void OnContextLost();
  // Must be called when the WebGL context is created or restored, also sets up
  // the GLES2Interface that will be used for the duration that this context is
  // active.
  void OnContextRestored(gpu::gles2::GLES2Interface*);

  void MarkExtensionEnabled(WebGLExtensionName name);

 private:
  scoped_refptr<base::SingleThreadTaskRunner> task_runner_;

  std::bitset<kWebGLExtensionNameCount> extensions_enabled_ = {};
  raw_ptr<gpu::gles2::GLES2Interface> gles2_interface_ = nullptr;

  uint32_t number_of_context_losses_ = 0;
  bool is_lost_ = true;
  bool is_webgl2_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_CONTEXT_OBJECT_SUPPORT_H_