Flutter Engine
The Flutter Engine
GrGLDirectContext.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
12#include "include/gpu/GrTypes.h"
17
22
23#include <utility>
24
25#if defined(GR_TEST_UTILS)
26# include "src/base/SkRandom.h"
27# if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
28# include <sanitizer/lsan_interface.h>
29# endif
30#endif
31
32#if defined(SK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE)
34#endif
35
36namespace GrDirectContexts {
37
39 GrContextOptions defaultOptions;
40 return MakeGL(std::move(glInterface), defaultOptions);
41}
42
43#if !defined(SK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE)
45 return MakeGL(nullptr, options);
46}
47
49 GrContextOptions defaultOptions;
50 return MakeGL(nullptr, defaultOptions);
51}
52#endif
53
54#if defined(GR_TEST_UTILS)
55GrGLFunction<GrGLGetErrorFn> make_get_error_with_random_oom(GrGLFunction<GrGLGetErrorFn> original) {
56 // A SkRandom and a GrGLFunction<GrGLGetErrorFn> are too big to be captured by a
57 // GrGLFunction<GrGLGetError> (surprise, surprise). So we make a context object and
58 // capture that by pointer. However, GrGLFunction doesn't support calling a destructor
59 // on the thing it captures. So we leak the context.
60 struct GetErrorContext {
61 SkRandom fRandom;
63 };
64
65 auto errorContext = new GetErrorContext;
66
67#if defined(SK_ENABLE_SCOPED_LSAN_SUPPRESSIONS)
68 __lsan_ignore_object(errorContext);
69#endif
70
71 errorContext->fGetError = original;
72
73 return GrGLFunction<GrGLGetErrorFn>([errorContext]() {
74 GrGLenum error = errorContext->fGetError();
75 if (error == GR_GL_NO_ERROR && (errorContext->fRandom.nextU() % 300) == 0) {
76 error = GR_GL_OUT_OF_MEMORY;
77 }
78 return error;
79 });
80}
81#endif
82
85#if defined(SK_DISABLE_LEGACY_GL_MAKE_NATIVE_INTERFACE)
86 SkASSERT(glInterface);
87#endif
88 auto direct = GrDirectContextPriv::Make(
90 options,
92#if defined(GR_TEST_UTILS)
93 if (options.fRandomGLOOM) {
94 auto copy = sk_make_sp<GrGLInterface>(*glInterface);
95 copy->fFunctions.fGetError =
96 make_get_error_with_random_oom(glInterface->fFunctions.fGetError);
97#if GR_GL_CHECK_ERROR
98 // Suppress logging GL errors since we'll be synthetically generating them.
99 copy->suppressErrorLogging();
100#endif
101 glInterface = std::move(copy);
102 }
103#endif
105 GrGLGpu::Make(std::move(glInterface), options, direct.get()));
106 if (!GrDirectContextPriv::Init(direct)) {
107 return nullptr;
108 }
109 return direct;
110}
111
112} // namespace GrDirectContexts
const char * options
#define GR_GL_NO_ERROR
Definition: GrGLDefines.h:175
unsigned int GrGLenum
Definition: GrGLTypes.h:102
#define SkASSERT(cond)
Definition: SkAssert.h:116
static sk_sp< GrContextThreadSafeProxy > Make(GrBackendApi, const GrContextOptions &)
static void SetGpu(const sk_sp< GrDirectContext > &ctx, std::unique_ptr< GrGpu > gpu)
static bool Init(const sk_sp< GrDirectContext > &ctx)
static sk_sp< GrDirectContext > Make(GrBackendApi backend, const GrContextOptions &options, sk_sp< GrContextThreadSafeProxy > proxy)
static std::unique_ptr< GrGpu > Make(sk_sp< const GrGLInterface >, const GrContextOptions &, GrDirectContext *)
Definition: GrGLGpu.cpp:408
const uint8_t uint32_t uint32_t GError ** error
SK_API sk_sp< GrDirectContext > MakeGL(sk_sp< const GrGLInterface >, const GrContextOptions &)
Definition: copy.py:1
GrGLFunction< GrGLGetErrorFn > fGetError
struct GrGLInterface::Functions fFunctions