Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
GrContextFactoryTest.cpp File Reference
#include "include/core/SkExecutor.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/ContextType.h"
#include "tools/gpu/FenceSync.h"
#include <memory>

Go to the source code of this file.

Functions

 DEF_GANESH_TEST (GrContextFactory_abandon, reporter, options, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST (GrContextFactory_sharedContexts, reporter, options, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST (GrContextFactory_executorAndTaskGroup, reporter, options, CtsEnforcement::kNever)
 

Function Documentation

◆ DEF_GANESH_TEST() [1/3]

DEF_GANESH_TEST ( GrContextFactory_abandon  ,
reporter  ,
options  ,
CtsEnforcement::kNever   
)

Definition at line 22 of file GrContextFactoryTest.cpp.

22 {
23 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
24 GrContextFactory testFactory(options);
25 skgpu::ContextType ctxType = static_cast<skgpu::ContextType>(i);
26 ContextInfo info1 = testFactory.getContextInfo(ctxType);
27 if (!info1.directContext()) {
28 continue;
29 }
31 // Ref for comparison. The API does not explicitly say that this stays alive.
32 info1.directContext()->ref();
33 testFactory.abandonContexts();
34
35 // Test that we get different context after abandon.
36 ContextInfo info2 = testFactory.getContextInfo(ctxType);
39
41 // The GL context should also change, but it also could get the same address.
42
43 info1.directContext()->unref();
44 }
45}
const char * options
reporter
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void ref() const
Definition SkRefCnt.h:62
void unref() const
Definition SkRefCnt.h:72
GrDirectContext * directContext() const
TestContext * testContext() const
static const int kContextTypeCount
Definition ContextType.h:42

◆ DEF_GANESH_TEST() [2/3]

DEF_GANESH_TEST ( GrContextFactory_executorAndTaskGroup  ,
reporter  ,
options  ,
CtsEnforcement::kNever   
)

Definition at line 85 of file GrContextFactoryTest.cpp.

85 {
86 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
87 // Verify that contexts have a task group iff we supply an executor with context options
88 GrContextOptions contextOptions = options;
89 contextOptions.fExecutor = nullptr;
90 GrContextFactory serialFactory(contextOptions);
91
92 std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeFIFOThreadPool(1);
93 contextOptions.fExecutor = threadPool.get();
94 GrContextFactory threadedFactory(contextOptions);
95
96 skgpu::ContextType ctxType = static_cast<skgpu::ContextType>(i);
97 ContextInfo serialInfo = serialFactory.getContextInfo(ctxType);
98 if (auto serialContext = serialInfo.directContext()) {
99 REPORTER_ASSERT(reporter, nullptr == serialContext->priv().getTaskGroup());
100 }
101
102 ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType);
103 if (auto threadedContext = threadedInfo.directContext()) {
104 REPORTER_ASSERT(reporter, nullptr != threadedContext->priv().getTaskGroup());
105 }
106 }
107}
static std::unique_ptr< SkExecutor > MakeFIFOThreadPool(int threads=0, bool allowBorrowing=true)
SkExecutor * fExecutor

◆ DEF_GANESH_TEST() [3/3]

DEF_GANESH_TEST ( GrContextFactory_sharedContexts  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 47 of file GrContextFactoryTest.cpp.

47 {
48 for (int i = 0; i < skgpu::kContextTypeCount; ++i) {
49 GrContextFactory testFactory(options);
50 skgpu::ContextType ctxType = static_cast<skgpu::ContextType>(i);
51 ContextInfo info1 = testFactory.getContextInfo(ctxType);
52 if (!info1.directContext()) {
53 continue;
54 }
55
56 // Ref for passing in. The API does not explicitly say that this stays alive.
57 info1.directContext()->ref();
58 testFactory.abandonContexts();
59
60 // Test that creating a context in a share group with an abandoned context fails.
61 ContextInfo info2 = testFactory.getSharedContextInfo(info1.directContext());
63 info1.directContext()->unref();
64
65 // Create a new base context
66 ContextInfo info3 = testFactory.getContextInfo(ctxType);
67
68 // Creating a context in a share group may fail, but should never crash.
69 ContextInfo info4 = testFactory.getSharedContextInfo(info3.directContext());
70 if (!info4.directContext()) {
71 continue;
72 }
75
76 // Passing a different index should create a new (unique) context.
77 ContextInfo info5 = testFactory.getSharedContextInfo(info3.directContext(), 1);
82 }
83}