2012-09-11 13:29:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrTextureAccess_DEFINED
|
|
|
|
#define GrTextureAccess_DEFINED
|
|
|
|
|
2014-09-17 15:05:40 +00:00
|
|
|
#include "GrGpuResourceRef.h"
|
2014-09-16 20:54:53 +00:00
|
|
|
#include "GrTexture.h"
|
2015-10-12 17:39:46 +00:00
|
|
|
#include "GrTextureParams.h"
|
2012-09-11 15:45:20 +00:00
|
|
|
#include "SkRefCnt.h"
|
2012-09-18 14:14:49 +00:00
|
|
|
#include "SkShader.h"
|
2012-09-11 13:29:29 +00:00
|
|
|
|
2012-09-11 15:45:20 +00:00
|
|
|
/** A class representing the swizzle access pattern for a texture. Note that if the texture is
|
|
|
|
* an alpha-only texture then the alpha channel is substituted for other components. Any mangling
|
|
|
|
* to handle the r,g,b->a conversions for alpha textures is automatically included in the stage
|
2014-09-23 16:50:21 +00:00
|
|
|
* key. However, if a GrProcessor uses different swizzles based on its input then it must
|
2012-09-11 15:45:20 +00:00
|
|
|
* consider that variation in its key-generation.
|
2012-09-11 13:29:29 +00:00
|
|
|
*/
|
2014-09-05 21:27:43 +00:00
|
|
|
class GrTextureAccess : public SkNoncopyable {
|
2012-09-11 13:29:29 +00:00
|
|
|
public:
|
2012-09-11 15:45:20 +00:00
|
|
|
/**
|
2014-09-23 16:50:21 +00:00
|
|
|
* A default GrTextureAccess must have reset() called on it in a GrProcessor subclass's
|
|
|
|
* constructor if it will be accessible via GrProcessor::textureAccess().
|
2012-09-11 15:45:20 +00:00
|
|
|
*/
|
|
|
|
GrTextureAccess();
|
2012-09-11 13:29:29 +00:00
|
|
|
|
2012-09-11 15:45:20 +00:00
|
|
|
/**
|
2012-09-18 14:14:49 +00:00
|
|
|
* Uses the default swizzle, "rgba".
|
2012-09-11 15:45:20 +00:00
|
|
|
*/
|
2012-09-18 14:14:49 +00:00
|
|
|
GrTextureAccess(GrTexture*, const GrTextureParams&);
|
|
|
|
explicit GrTextureAccess(GrTexture*,
|
2013-07-25 18:49:07 +00:00
|
|
|
GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
|
2012-09-18 14:14:49 +00:00
|
|
|
SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
|
2012-09-11 13:29:29 +00:00
|
|
|
|
2012-09-11 15:45:20 +00:00
|
|
|
/**
|
2012-09-18 14:14:49 +00:00
|
|
|
* swizzle must be a string between one and four (inclusive) characters containing only 'r',
|
|
|
|
* 'g', 'b', and/or 'a'.
|
2012-09-11 15:45:20 +00:00
|
|
|
*/
|
2012-09-18 14:14:49 +00:00
|
|
|
GrTextureAccess(GrTexture*, const char* swizzle, const GrTextureParams&);
|
|
|
|
GrTextureAccess(GrTexture*,
|
|
|
|
const char* swizzle,
|
2013-07-25 18:49:07 +00:00
|
|
|
GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
|
2012-09-18 14:14:49 +00:00
|
|
|
SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
|
2012-09-11 13:29:29 +00:00
|
|
|
|
2012-09-18 14:14:49 +00:00
|
|
|
void reset(GrTexture*, const GrTextureParams&);
|
|
|
|
void reset(GrTexture*,
|
2013-07-25 18:49:07 +00:00
|
|
|
GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
|
2012-09-18 14:14:49 +00:00
|
|
|
SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
|
|
|
|
void reset(GrTexture*, const char* swizzle, const GrTextureParams&);
|
|
|
|
void reset(GrTexture*,
|
|
|
|
const char* swizzle,
|
2013-07-25 18:49:07 +00:00
|
|
|
GrTextureParams::FilterMode = GrTextureParams::kNone_FilterMode,
|
2012-09-18 14:14:49 +00:00
|
|
|
SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode);
|
|
|
|
|
|
|
|
bool operator== (const GrTextureAccess& other) const {
|
2013-08-28 14:17:03 +00:00
|
|
|
#ifdef SK_DEBUG
|
2012-09-18 14:14:49 +00:00
|
|
|
// below assumes all chars in fSwizzle are initialized even if string is < 4 chars long.
|
2013-08-17 00:02:59 +00:00
|
|
|
SkASSERT(memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1) ==
|
2012-09-18 14:14:49 +00:00
|
|
|
strcmp(fSwizzle, other.fSwizzle));
|
|
|
|
#endif
|
|
|
|
return fParams == other.fParams &&
|
2014-09-05 21:27:43 +00:00
|
|
|
(this->getTexture() == other.getTexture()) &&
|
2012-09-20 15:37:30 +00:00
|
|
|
(0 == memcmp(fSwizzle, other.fSwizzle, sizeof(fSwizzle)-1));
|
2012-09-18 14:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!= (const GrTextureAccess& other) const { return !(*this == other); }
|
2012-09-11 15:45:20 +00:00
|
|
|
|
2014-09-16 20:54:53 +00:00
|
|
|
GrTexture* getTexture() const { return fTexture.get(); }
|
2014-09-05 21:27:43 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-23 16:50:21 +00:00
|
|
|
* For internal use by GrProcessor.
|
2014-09-05 21:27:43 +00:00
|
|
|
*/
|
2014-09-17 15:05:40 +00:00
|
|
|
const GrGpuResourceRef* getProgramTexture() const { return &fTexture; }
|
2012-09-11 15:45:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representing the swizzle. The string is is null-terminated.
|
|
|
|
*/
|
|
|
|
const char* getSwizzle() const { return fSwizzle; }
|
|
|
|
|
2013-03-28 13:46:42 +00:00
|
|
|
/** Returns a mask indicating which components are referenced in the swizzle. The return
|
|
|
|
is a bitfield of GrColorComponentFlags. */
|
2012-09-11 15:45:20 +00:00
|
|
|
uint32_t swizzleMask() const { return fSwizzleMask; }
|
2012-09-11 13:29:29 +00:00
|
|
|
|
2012-09-18 14:14:49 +00:00
|
|
|
const GrTextureParams& getParams() const { return fParams; }
|
|
|
|
|
2012-09-11 13:29:29 +00:00
|
|
|
private:
|
2012-09-18 14:14:49 +00:00
|
|
|
void setSwizzle(const char*);
|
|
|
|
|
2014-09-17 15:05:40 +00:00
|
|
|
typedef GrTGpuResourceRef<GrTexture> ProgramTexture;
|
2014-09-16 20:54:53 +00:00
|
|
|
|
|
|
|
ProgramTexture fTexture;
|
2014-09-05 21:27:43 +00:00
|
|
|
GrTextureParams fParams;
|
|
|
|
uint32_t fSwizzleMask;
|
|
|
|
char fSwizzle[5];
|
2012-09-18 14:14:49 +00:00
|
|
|
|
2013-09-18 13:00:55 +00:00
|
|
|
typedef SkNoncopyable INHERITED;
|
2012-09-11 13:29:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|