Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
sk_gpu_test::GrContextFactory Class Reference

#include <GrContextFactory.h>

Inheritance diagram for sk_gpu_test::GrContextFactory:
SkNoncopyable

Public Types

enum class  ContextOverrides { kNone = 0x0 , kAvoidStencilBuffers = 0x1 , kFakeGLESVersionAs2 = 0x2 , kReducedShaders = 0x4 }
 
using ContextType = skgpu::ContextType
 

Public Member Functions

 GrContextFactory (const GrContextOptions &opts)
 
 GrContextFactory ()
 
 ~GrContextFactory ()
 
void destroyContexts ()
 
void abandonContexts ()
 
void releaseResourcesAndAbandonContexts ()
 
ContextInfo getContextInfo (ContextType type, ContextOverrides=ContextOverrides::kNone)
 
ContextInfo getSharedContextInfo (GrDirectContext *shareContext, uint32_t shareIndex=0)
 
GrDirectContextget (ContextType type, ContextOverrides overrides=ContextOverrides::kNone)
 
const GrContextOptionsgetGlobalOptions () const
 

Detailed Description

This is a simple class that is useful in test apps that use different GrContexts backed by different types of GL contexts. It manages creating the GL context and a GrContext that uses it. The GL/Gr contexts persist until the factory is destroyed (though the caller can always grab a ref on the returned Gr and GL contexts to make them outlive the factory).

Definition at line 34 of file GrContextFactory.h.

Member Typedef Documentation

◆ ContextType

Definition at line 36 of file GrContextFactory.h.

Member Enumeration Documentation

◆ ContextOverrides

Overrides for the initial GrContextOptions provided at construction time, and required features that will cause context creation to fail if not present.

Enumerator
kNone 
kAvoidStencilBuffers 
kFakeGLESVersionAs2 
kReducedShaders 

Definition at line 42 of file GrContextFactory.h.

Constructor & Destructor Documentation

◆ GrContextFactory() [1/2]

sk_gpu_test::GrContextFactory::GrContextFactory ( const GrContextOptions opts)
explicit

Definition at line 50 of file GrContextFactory.cpp.

51 : fGlobalOptions(opts) {}

◆ GrContextFactory() [2/2]

sk_gpu_test::GrContextFactory::GrContextFactory ( )

Definition at line 48 of file GrContextFactory.cpp.

48{}

◆ ~GrContextFactory()

sk_gpu_test::GrContextFactory::~GrContextFactory ( )

Definition at line 53 of file GrContextFactory.cpp.

53 {
54 this->destroyContexts();
55}

Member Function Documentation

◆ abandonContexts()

void sk_gpu_test::GrContextFactory::abandonContexts ( )

Definition at line 78 of file GrContextFactory.cpp.

78 {
79 // We must abandon the test contexts in reverse order so that any child context is finished and
80 // abandoned before a parent context. This relies on the fact that when we make a new context we
81 // append it to the end of fContexts array.
82 // TODO: Look into keeping a dependency dag for contexts and deletion order
83 for (int i = fContexts.size() - 1; i >= 0; --i) {
84 Context& context = fContexts[i];
85 if (!context.fAbandoned) {
86 if (context.fTestContext) {
87 auto restore = context.fTestContext->makeCurrentAndAutoRestore();
88 context.fTestContext->testAbandon();
89 }
90 GrBackendApi api = context.fGrContext->backend();
91 bool requiresEarlyAbandon = api == GrBackendApi::kVulkan;
92 if (requiresEarlyAbandon) {
93 context.fGrContext->abandonContext();
94 }
95 if (context.fTestContext) {
96 delete(context.fTestContext);
97 context.fTestContext = nullptr;
98 }
99 if (!requiresEarlyAbandon) {
100 context.fGrContext->abandonContext();
101 }
102 context.fAbandoned = true;
103 }
104 }
105}
GrBackendApi
Definition GrTypes.h:95
int size() const
Definition SkTArray.h:416

◆ destroyContexts()

void sk_gpu_test::GrContextFactory::destroyContexts ( )

Definition at line 57 of file GrContextFactory.cpp.

57 {
58 // We must delete the test contexts in reverse order so that any child context is finished and
59 // deleted before a parent context. This relies on the fact that when we make a new context we
60 // append it to the end of fContexts array.
61 // TODO: Look into keeping a dependency dag for contexts and deletion order
62 for (int i = fContexts.size() - 1; i >= 0; --i) {
63 Context& context = fContexts[i];
64 SkScopeExit restore(nullptr);
65 if (context.fTestContext) {
66 restore = context.fTestContext->makeCurrentAndAutoRestore();
67 }
68 if (!context.fGrContext->unique()) {
69 context.fGrContext->releaseResourcesAndAbandonContext();
70 context.fAbandoned = true;
71 }
72 context.fGrContext->unref();
73 delete context.fTestContext;
74 }
75 fContexts.clear();
76}

◆ get()

GrDirectContext * sk_gpu_test::GrContextFactory::get ( ContextType  type,
ContextOverrides  overrides = ContextOverrides::kNone 
)

Get a GrContext initialized with a type of GL context. It also makes the GL context current.

Definition at line 129 of file GrContextFactory.cpp.

129 {
130 return this->getContextInfo(type, overrides).directContext();
131}
GrDirectContext * directContext() const
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)

◆ getContextInfo()

ContextInfo sk_gpu_test::GrContextFactory::getContextInfo ( ContextType  type,
ContextOverrides  overrides = ContextOverrides::kNone 
)

Get a context initialized with a type of GL context. It also makes the GL context current.

Definition at line 332 of file GrContextFactory.cpp.

332 {
333 return this->getContextInfoInternal(type, overrides, nullptr, 0);
334}

◆ getGlobalOptions()

const GrContextOptions & sk_gpu_test::GrContextFactory::getGlobalOptions ( ) const
inline

Definition at line 74 of file GrContextFactory.h.

74{ return fGlobalOptions; }

◆ getSharedContextInfo()

ContextInfo sk_gpu_test::GrContextFactory::getSharedContextInfo ( GrDirectContext shareContext,
uint32_t  shareIndex = 0 
)

Get a context in the same share group as the passed in GrContext, with the same type and overrides. To get multiple contexts in a single share group, pass the same shareContext, with different values for shareIndex.

Definition at line 336 of file GrContextFactory.cpp.

337 {
338 SkASSERT(shareContext);
339 for (int i = 0; i < fContexts.size(); ++i) {
340 if (!fContexts[i].fAbandoned && fContexts[i].fGrContext == shareContext) {
341 return this->getContextInfoInternal(fContexts[i].fType, fContexts[i].fOverrides,
342 shareContext, shareIndex);
343 }
344 }
345
346 return ContextInfo();
347}
#define SkASSERT(cond)
Definition SkAssert.h:116

◆ releaseResourcesAndAbandonContexts()

void sk_gpu_test::GrContextFactory::releaseResourcesAndAbandonContexts ( )

Definition at line 107 of file GrContextFactory.cpp.

107 {
108 // We must abandon the test contexts in reverse order so that any child context is finished and
109 // abandoned before a parent context. This relies on the fact that when we make a new context we
110 // append it to the end of fContexts array.
111 // TODO: Look into keeping a dependency dag for contexts and deletion order
112 for (int i = fContexts.size() - 1; i >= 0; --i) {
113 Context& context = fContexts[i];
114 SkScopeExit restore(nullptr);
115 if (!context.fAbandoned) {
116 if (context.fTestContext) {
117 restore = context.fTestContext->makeCurrentAndAutoRestore();
118 }
119 context.fGrContext->releaseResourcesAndAbandonContext();
120 if (context.fTestContext) {
121 delete context.fTestContext;
122 context.fTestContext = nullptr;
123 }
124 context.fAbandoned = true;
125 }
126 }
127}

The documentation for this class was generated from the following files: