Remove GrAALevel enum, use explicit sample count

Review URL: http://codereview.appspot.com/5600045/



git-svn-id: http://skia.googlecode.com/svn/trunk@3106 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-01-30 18:09:31 +00:00
parent fa4d5bd09f
commit 78d6cf9f43
9 changed files with 66 additions and 82 deletions

View File

@ -75,13 +75,13 @@ protected:
}
GrTextureDesc desc;
desc.fAALevel = kNone_GrAALevel;
// use RT flag bit because in GL it makes the texture be bottom-up
desc.fFlags = i ? kRenderTarget_GrTextureFlagBit :
kNone_GrTextureFlags;
desc.fConfig = kSkia8888_PM_GrPixelConfig;
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
desc.fSampleCnt = 0;
GrTexture* texture =
ctx->createUncachedTexture(desc, gTextureData, 0);

View File

@ -429,18 +429,10 @@ static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
}
/**
* Used to control the level of antialiasing available for a rendertarget.
* Anti-alias quality levels depend on the underlying API/GPU capabilities.
*/
enum GrAALevels {
kNone_GrAALevel, //<! No antialiasing available.
kLow_GrAALevel, //<! Low quality antialiased rendering. Actual
// interpretation is platform-dependent.
kMed_GrAALevel, //<! Medium quality antialiased rendering. Actual
// interpretation is platform-dependent.
kHigh_GrAALevel, //<! High quality antialiased rendering. Actual
// interpretation is platform-dependent.
};
* DEPRECATED: This will be removed as soon as WebKit no longer references
* this (former) enum value.
*/
static const int kNone_GrAALevel = 0;
/**
* Optional bitfield flags that can be passed to createTexture.
@ -479,18 +471,31 @@ enum {
*/
struct GrTextureDesc {
GrTextureFlags fFlags; //!< bitfield of TextureFlags
/**
* The level of antialiasing available for a rendertarget texture. Only used
* fFlags contains kRenderTarget_GrTextureFlag.
*/
GrAALevels fAALevel;
int fWidth; //!< Width of the texture
int fHeight; //!< Height of the texture
/**
* Format of source data of the texture. Not guaraunteed to be the same as
* internal format used by 3D API.
*/
GrPixelConfig fConfig;
/**
* The number of samples per pixel or 0 to disable full scene AA. This only
* applies if the kRenderTarget_GrTextureFlagBit is set. The actual number
* of samples may not exactly match the request. The request will be rounded
* up to the next supported sample count, or down if it is larger than the
* max supportex count.
*/
union {
/**
* This field has two names for legacy reasons. Use the fSampleCnt name.
* fAALevel is deprecated and will be removed as soon as WebKit no
* longer uses it.
*/
int fSampleCnt;
int fAALevel;
};
};
/**

View File

@ -179,10 +179,10 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
if (NULL == fTexture[format]) {
GrTextureDesc desc = {
kDynamicUpdate_GrTextureFlagBit,
kNone_GrAALevel,
GR_ATLAS_TEXTURE_WIDTH,
GR_ATLAS_TEXTURE_HEIGHT,
maskformat2pixelconfig(format)
maskformat2pixelconfig(format),
{0} // samples
};
fTexture[format] = fGpu->createTexture(desc, NULL, 0);
if (NULL == fTexture[format]) {

View File

@ -167,6 +167,7 @@ bool gen_texture_key_values(const GrGpu* gpu,
GrContext::TextureKey clientKey,
int width,
int height,
int sampleCnt,
bool scratch,
uint32_t v[4]) {
GR_STATIC_ASSERT(sizeof(GrContext::TextureKey) == sizeof(uint64_t));
@ -178,7 +179,9 @@ bool gen_texture_key_values(const GrGpu* gpu,
v[1] = (clientKey >> 32) & 0xffffffffUL;
v[2] = width | (height << 16);
v[3] = 0;
v[3] = (sampleCnt << 24);
GrAssert(sampleCnt >= 0 && sampleCnt < 256);
if (!gpu->getCaps().fNPOTTextureTileSupport) {
bool isPow2 = GrIsPow2(width) && GrIsPow2(height);
@ -227,7 +230,7 @@ GrContext::TextureCacheEntry GrContext::findAndLockTexture(
int height,
const GrSamplerState* sampler) {
uint32_t v[4];
gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
gen_texture_key_values(fGpu, sampler, key, width, height, 0, false, v);
GrResourceKey resourceKey(v);
return TextureCacheEntry(fTextureCache->findAndLock(resourceKey,
GrResourceCache::kNested_LockType));
@ -238,7 +241,7 @@ bool GrContext::isTextureInCache(TextureKey key,
int height,
const GrSamplerState* sampler) const {
uint32_t v[4];
gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
gen_texture_key_values(fGpu, sampler, key, width, height, 0, false, v);
GrResourceKey resourceKey(v);
return fTextureCache->hasKey(resourceKey);
}
@ -313,7 +316,8 @@ GrContext::TextureCacheEntry GrContext::createAndLockTexture(
TextureCacheEntry entry;
uint32_t v[4];
bool special = gen_texture_key_values(fGpu, sampler, key,
desc.fWidth, desc.fHeight, false, v);
desc.fWidth, desc.fHeight,
desc.fSampleCnt, false, v);
GrResourceKey resourceKey(v);
if (special) {
@ -417,13 +421,12 @@ inline void gen_scratch_tex_key_values(const GrGpu* gpu,
uint32_t v[4]) {
// Instead of a client-provided key of the texture contents
// we create a key of from the descriptor.
GrContext::TextureKey descKey = desc.fAALevel |
(desc.fFlags << 8) |
GrContext::TextureKey descKey = (desc.fFlags << 8) |
((uint64_t) desc.fConfig << 32);
// this code path isn't friendly to tiling with NPOT restricitons
// We just pass ClampNoFilter()
gen_texture_key_values(gpu, NULL, descKey, desc.fWidth,
desc.fHeight, true, v);
desc.fHeight, desc.fSampleCnt, true, v);
}
}
@ -439,9 +442,6 @@ GrContext::TextureCacheEntry GrContext::lockScratchTexture(
desc.fHeight = GrMax(MIN_SIZE, GrNextPow2(desc.fHeight));
}
uint32_t p0 = desc.fConfig;
uint32_t p1 = (desc.fAALevel << 16) | desc.fFlags;
GrResourceEntry* entry;
int origWidth = desc.fWidth;
int origHeight = desc.fHeight;
@ -713,13 +713,15 @@ bool GrContext::prepareForOffscreenAA(GrDrawTarget* target,
if (PREFER_MSAA_OFFSCREEN_AA && fGpu->getCaps().fFSAASupport) {
record->fDownsample = OffscreenRecord::kFSAA_Downsample;
record->fScale = 1;
desc.fAALevel = kMed_GrAALevel;
// 16 samples matches what the skia sw rasterizer uses. (There is no
// accessible constant to reference from sw code).
desc.fSampleCnt = 16;
} else {
record->fDownsample = OffscreenRecord::k4x4SinglePass_Downsample;
record->fScale = OFFSCREEN_SSAA_SCALE;
// both downsample paths assume this
GR_STATIC_ASSERT(4 == OFFSCREEN_SSAA_SCALE);
desc.fAALevel = kNone_GrAALevel;
desc.fSampleCnt = 0;
}
desc.fWidth *= record->fScale;
@ -1547,10 +1549,10 @@ bool sw_draw_path_to_mask_texture(const GrPath& clientPath,
const GrTextureDesc desc = {
kNone_GrTextureFlags,
kNone_GrAALevel,
bounds.fRight,
bounds.fBottom,
kAlpha_8_GrPixelConfig
kAlpha_8_GrPixelConfig,
{0} // samples
};
tex->set(context, desc);
@ -1844,9 +1846,9 @@ bool GrContext::internalReadRenderTargetPixels(GrRenderTarget* target,
// readTexturePixels as of yet (it calls this function).
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit,
kNone_GrAALevel,
width, height,
config
config,
{0}, // samples
};
// When a full readback is faster than a partial we could always make
@ -1964,7 +1966,7 @@ void GrContext::internalWriteRenderTargetPixels(GrRenderTarget* target,
}
const GrTextureDesc desc = {
kNone_GrTextureFlags, kNone_GrAALevel, width, height, config
kNone_GrTextureFlags, width, height, config, {0}
};
GrAutoScratchTexture ast(this, desc);
GrTexture* texture = ast.texture();

View File

@ -373,12 +373,6 @@ void GrGpuGL::initCaps() {
}
void GrGpuGL::initFSAASupport() {
// TODO: Get rid of GrAALevel and use # samples directly.
GR_STATIC_ASSERT(0 == kNone_GrAALevel);
GR_STATIC_ASSERT(1 == kLow_GrAALevel);
GR_STATIC_ASSERT(2 == kMed_GrAALevel);
GR_STATIC_ASSERT(3 == kHigh_GrAALevel);
memset(fGLCaps.fAASamples, 0, sizeof(fGLCaps.fAASamples));
fGLCaps.fMSFBOType = GLCaps::kNone_MSFBO;
if (kDesktop_GrGLBinding != this->glBinding()) {
@ -398,19 +392,7 @@ void GrGpuGL::initFSAASupport() {
}
}
if (GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType) {
GrGLint maxSamples;
GR_GL_GetIntegerv(fGL, GR_GL_MAX_SAMPLES, &maxSamples);
if (maxSamples > 1 ) {
fGLCaps.fAASamples[kNone_GrAALevel] = 0;
fGLCaps.fAASamples[kLow_GrAALevel] =
GrMax(2, GrFixedFloorToInt((GR_FixedHalf) * maxSamples));
fGLCaps.fAASamples[kMed_GrAALevel] =
GrMax(2, GrFixedFloorToInt(((GR_Fixed1*3)/4) * maxSamples));
fGLCaps.fAASamples[kHigh_GrAALevel] = maxSamples;
}
}
fCaps.fFSAASupport = fGLCaps.fAASamples[kHigh_GrAALevel] > 0;
fCaps.fFSAASupport = GLCaps::kNone_MSFBO != fGLCaps.fMSFBOType;
}
void GrGpuGL::initStencilFormats() {
@ -982,10 +964,13 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
GrGLTexture::Desc glTexDesc;
GrGLRenderTarget::Desc glRTDesc;
// Attempt to catch un- or wrongly initialized sample counts;
GrAssert(desc.fSampleCnt >= 0 && desc.fSampleCnt <= 64);
glTexDesc.fWidth = desc.fWidth;
glTexDesc.fHeight = desc.fHeight;
glTexDesc.fConfig = desc.fConfig;
glTexDesc.fOwnsID = true;
glTexDesc.fConfig = desc.fConfig;
glTexDesc.fOwnsID = true;
glRTDesc.fMSColorRenderbufferID = 0;
glRTDesc.fRTFBOID = 0;
@ -1003,11 +988,10 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
glTexDesc.fOrientation = renderTarget ? GrGLTexture::kBottomUp_Orientation :
GrGLTexture::kTopDown_Orientation;
GrAssert(as_size_t(desc.fAALevel) < GR_ARRAY_COUNT(fGLCaps.fAASamples));
glRTDesc.fSampleCnt = fGLCaps.fAASamples[desc.fAALevel];
glRTDesc.fSampleCnt = desc.fSampleCnt;
if (GLCaps::kNone_MSFBO == fGLCaps.fMSFBOType &&
desc.fAALevel != kNone_GrAALevel) {
GrPrintf("AA RT requested but not supported on this platform.");
desc.fSampleCnt) {
GrPrintf("MSAA RT requested but not supported on this platform.");
}
if (renderTarget) {
@ -2459,9 +2443,6 @@ void GrGpuGL::GLCaps::print() const {
"Apple",
};
GrPrintf("MSAA Type: %s\n", gMSFBOExtStr[fMSFBOType]);
for (int i = 0; i < (int)GR_ARRAY_COUNT(fAASamples); ++i) {
GrPrintf("AA Level %d has %d samples\n", i, fAASamples[i]);
}
GrPrintf("Max FS Uniform Vectors: %d\n", fMaxFragmentUniformVectors);
GrPrintf("Support RGBA8 Render Buffer: %s\n",
(fRGBA8RenderbufferSupport ? "YES": "NO"));

View File

@ -60,7 +60,6 @@ protected:
, fPackFlipYSupport(false)
, fTextureUsageSupport(false)
, fTexStorageSupport(false) {
memset(fAASamples, 0, sizeof(fAASamples));
}
SkTArray<GrGLStencilBuffer::Format, true> fStencilFormats;
@ -83,9 +82,6 @@ protected:
kAppleES_MSFBO,
} fMSFBOType;
// TODO: get rid of GrAALevel and use sample cnt directly
GrGLuint fAASamples[4];
// The maximum number of fragment uniform vectors (GLES has min. 16).
int fMaxFragmentUniformVectors;

View File

@ -216,10 +216,10 @@ SkGpuDevice::SkGpuDevice(GrContext* context, SkBitmap::Config config, int width,
#else
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit,
kNone_GrAALevel,
width,
height,
SkGr::Bitmap2PixelConfig(bm)
SkGr::Bitmap2PixelConfig(bm),
{0} // samples
};
fTexture = fContext->createUncachedTexture(desc, NULL, 0);
@ -765,10 +765,10 @@ static GrTexture* gaussianBlur(GrContext* context, GrTexture* srcTexture,
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit,
kNone_GrAALevel,
srcRect.width(),
srcRect.height(),
kRGBA_8888_GrPixelConfig
kRGBA_8888_GrPixelConfig,
{0} // samples
};
temp1->set(context, desc);
@ -900,12 +900,12 @@ static bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path,
srcRect.offset(offset);
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit,
kNone_GrAALevel,
srcRect.width(),
srcRect.height(),
// We actually only need A8, but it often isn't supported as a
// render target
kRGBA_8888_PM_GrPixelConfig
kRGBA_8888_PM_GrPixelConfig,
{0} // samples
};
GrAutoScratchTexture pathEntry(context, desc);
@ -1032,10 +1032,10 @@ static bool drawWithMaskFilter(GrContext* context, const SkPath& path,
const GrTextureDesc desc = {
kNone_GrTextureFlags,
kNone_GrAALevel,
dstM.fBounds.width(),
dstM.fBounds.height(),
kAlpha_8_GrPixelConfig
kAlpha_8_GrPixelConfig,
{0}, // samples
};
GrAutoScratchTexture ast(context, desc);
@ -1783,10 +1783,10 @@ SkGpuDevice::TexCache SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap,
if (kBitmap_TexType != type) {
const GrTextureDesc desc = {
kRenderTarget_GrTextureFlagBit,
kNone_GrAALevel,
bitmap.width(),
bitmap.height(),
SkGr::Bitmap2PixelConfig(bitmap)
SkGr::Bitmap2PixelConfig(bitmap),
{0} // samples
};
GrContext::ScratchTexMatch match;
if (kSaveLayerDeviceRenderTarget_TexType == type) {

View File

@ -73,10 +73,10 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
GrTextureDesc desc = {
kNone_GrTextureFlags,
kNone_GrAALevel,
bitmap->width(),
bitmap->height(),
SkGr::Bitmap2PixelConfig(*bitmap)
SkGr::Bitmap2PixelConfig(*bitmap),
{0} // samples
};
if (SkBitmap::kIndex8_Config == bitmap->config()) {

View File

@ -63,7 +63,7 @@ static SkGrTexturePixelRef* copyToTexturePixelRef(GrTexture* texture,
desc.fHeight = texture->height();
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig, false);
desc.fAALevel = kNone_GrAALevel;
desc.fSampleCnt = 0;
GrTexture* dst = context->createUncachedTexture(desc, NULL, 0);
if (NULL == dst) {