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

Public Member Functions

 SamplerObjectCache (GrGLGpu *gpu)
 
 ~SamplerObjectCache ()
 
void bindSampler (int unitIdx, GrSamplerState state)
 
void unbindSampler (int unitIdx)
 
void invalidateBindings ()
 
void abandon ()
 
void release ()
 

Detailed Description

Definition at line 277 of file GrGLGpu.cpp.

Constructor & Destructor Documentation

◆ SamplerObjectCache()

GrGLGpu::SamplerObjectCache::SamplerObjectCache ( GrGLGpu gpu)
inline

Definition at line 279 of file GrGLGpu.cpp.

279 : fGpu(gpu) {
280 fNumTextureUnits = fGpu->glCaps().shaderCaps()->fMaxFragmentSamplers;
281 fTextureUnitStates = std::make_unique<UnitState[]>(fNumTextureUnits);
282 }
const GrShaderCaps * shaderCaps() const
Definition GrCaps.h:63
const GrGLCaps & glCaps() const
Definition GrGLGpu.h:108
int fMaxFragmentSamplers

◆ ~SamplerObjectCache()

GrGLGpu::SamplerObjectCache::~SamplerObjectCache ( )
inline

Definition at line 284 of file GrGLGpu.cpp.

284 {
285 if (!fNumTextureUnits) {
286 // We've already been abandoned.
287 return;
288 }
289 }

Member Function Documentation

◆ abandon()

void GrGLGpu::SamplerObjectCache::abandon ( )
inline

Definition at line 347 of file GrGLGpu.cpp.

347 {
348 fSamplers.foreach([](uint32_t* key, Sampler* sampler) { sampler->abandon(); });
349 fTextureUnitStates.reset();
350 fNumTextureUnits = 0;
351 }
void foreach(Fn &&fn)
Definition SkLRUCache.h:88

◆ bindSampler()

void GrGLGpu::SamplerObjectCache::bindSampler ( int  unitIdx,
GrSamplerState  state 
)
inline

Definition at line 291 of file GrGLGpu.cpp.

291 {
292 if (unitIdx >= fNumTextureUnits) {
293 return;
294 }
295 // In GL the max aniso value is specified in addition to min/mag filters and the driver
296 // is encouraged to consider the other filter settings when doing aniso.
297 uint32_t key = state.asKey(/*anisoIsOrthogonal=*/true);
298 const Sampler* sampler = fSamplers.find(key);
299 if (!sampler) {
300 GrGLuint s;
301 GR_GL_CALL(fGpu->glInterface(), GenSamplers(1, &s));
302 if (!s) {
303 return;
304 }
305 sampler = fSamplers.insert(key, Sampler(s, fGpu->glInterface()));
306 GrGLenum minFilter = filter_to_gl_min_filter(state.filter(), state.mipmapMode());
307 GrGLenum magFilter = filter_to_gl_mag_filter(state.filter());
308 GrGLenum wrapX = wrap_mode_to_gl_wrap(state.wrapModeX(), fGpu->glCaps());
309 GrGLenum wrapY = wrap_mode_to_gl_wrap(state.wrapModeY(), fGpu->glCaps());
310 GR_GL_CALL(fGpu->glInterface(),
311 SamplerParameteri(s, GR_GL_TEXTURE_MIN_FILTER, minFilter));
312 GR_GL_CALL(fGpu->glInterface(),
313 SamplerParameteri(s, GR_GL_TEXTURE_MAG_FILTER, magFilter));
314 GR_GL_CALL(fGpu->glInterface(), SamplerParameteri(s, GR_GL_TEXTURE_WRAP_S, wrapX));
315 GR_GL_CALL(fGpu->glInterface(), SamplerParameteri(s, GR_GL_TEXTURE_WRAP_T, wrapY));
316 SkASSERT(fGpu->glCaps().anisoSupport() || !state.isAniso());
317 if (fGpu->glCaps().anisoSupport()) {
318 float maxAniso = std::min(static_cast<GrGLfloat>(state.maxAniso()),
320 GR_GL_CALL(fGpu->glInterface(), SamplerParameterf(s,
322 maxAniso));
323 }
324 }
325 SkASSERT(sampler && sampler->id());
326 if (!fTextureUnitStates[unitIdx].fKnown ||
327 fTextureUnitStates[unitIdx].fSamplerIDIfKnown != sampler->id()) {
328 GR_GL_CALL(fGpu->glInterface(), BindSampler(unitIdx, sampler->id()));
329 fTextureUnitStates[unitIdx].fSamplerIDIfKnown = sampler->id();
330 fTextureUnitStates[unitIdx].fKnown = true;
331 }
332 }
#define GR_GL_TEXTURE_MAX_ANISOTROPY
#define GR_GL_TEXTURE_WRAP_T
#define GR_GL_TEXTURE_MAG_FILTER
#define GR_GL_TEXTURE_WRAP_S
#define GR_GL_TEXTURE_MIN_FILTER
static GrGLenum wrap_mode_to_gl_wrap(GrSamplerState::WrapMode wrapMode, const GrCaps &caps)
Definition GrGLGpu.cpp:240
static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter, GrSamplerState::MipmapMode mm)
Definition GrGLGpu.cpp:219
static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter)
Definition GrGLGpu.cpp:211
unsigned int GrGLuint
Definition GrGLTypes.h:113
float GrGLfloat
Definition GrGLTypes.h:116
unsigned int GrGLenum
Definition GrGLTypes.h:102
#define GR_GL_CALL(IFACE, X)
Definition GrGLUtil.h:381
#define SkASSERT(cond)
Definition SkAssert.h:116
bool anisoSupport() const
Definition GrCaps.h:74
float maxTextureMaxAnisotropy() const
Definition GrGLCaps.h:170
const GrGLInterface * glInterface() const
Definition GrGLGpu.h:103
V * find(const K &key)
Definition SkLRUCache.h:49
V * insert(const K &key, V value)
Definition SkLRUCache.h:62
struct MyStruct s
AtkStateType state
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...

◆ invalidateBindings()

void GrGLGpu::SamplerObjectCache::invalidateBindings ( )
inline

Definition at line 343 of file GrGLGpu.cpp.

343 {
344 std::fill_n(fTextureUnitStates.get(), fNumTextureUnits, UnitState{});
345 }

◆ release()

void GrGLGpu::SamplerObjectCache::release ( )
inline

Definition at line 353 of file GrGLGpu.cpp.

353 {
354 if (!fNumTextureUnits) {
355 // We've already been abandoned.
356 return;
357 }
358 fSamplers.reset();
359 // Deleting a bound sampler implicitly binds sampler 0. We just invalidate all of our
360 // knowledge.
361 std::fill_n(fTextureUnitStates.get(), fNumTextureUnits, UnitState{});
362 }
void reset()
Definition SkLRUCache.h:96

◆ unbindSampler()

void GrGLGpu::SamplerObjectCache::unbindSampler ( int  unitIdx)
inline

Definition at line 334 of file GrGLGpu.cpp.

334 {
335 if (!fTextureUnitStates[unitIdx].fKnown ||
336 fTextureUnitStates[unitIdx].fSamplerIDIfKnown != 0) {
337 GR_GL_CALL(fGpu->glInterface(), BindSampler(unitIdx, 0));
338 fTextureUnitStates[unitIdx].fSamplerIDIfKnown = 0;
339 fTextureUnitStates[unitIdx].fKnown = true;
340 }
341 }

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