SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType,
this->config.ctxOptions),
- SkBudgeted::kNo, info,
+ SkSurface::kNo_Budgeted, info,
this->config.samples, &props));
this->gl = gGrFactory->getContextInfo(this->config.ctxType,
this->config.ctxOptions).fGLContext;
std::cout << "Using opengl surface" << std::endl;
std::shared_ptr<GrContext> grContext = adopt(GrContext::Create(kOpenGL_GrBackend, 0));
return adopt(SkSurface::NewRenderTarget(grContext.get(),
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(w,h)));
}
bool useDIText) {
uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
- return SkSurface::NewRenderTarget(grFactory->get(type, options), SkBudgeted::kNo,
+ return SkSurface::NewRenderTarget(grFactory->get(type, options), SkSurface::kNo_Budgeted,
info, samples, &props);
}
SkAutoTUnref<SkSurface> surface(
SkSurface::NewRenderTarget(
grContext,
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(options.size)));
if (!surface) {
fputs("Unable to get render surface.\n", stderr);
desc.fConfig = config;
desc.fWidth = width + kXPad;
desc.fHeight = height + kYPad;
- SkAutoTUnref<GrTexture> texture(ctx->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, pixels.get(), rowBytes));
+ SkAutoTUnref<GrTexture> texture(ctx->textureProvider()->createTexture(desc, true, pixels.get(),
+ rowBytes));
if (!texture) {
return false;
SkImageInfo info = SkImageInfo::MakeN32Premul(onISize());
SkSurfaceProps props(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
SkSurfaceProps::kLegacyFontHost_InitType);
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0, &props));
SkCanvas* canvas = surface.get() ? surface->getCanvas() : inputCanvas;
// init our new canvas with the old canvas's matrix
size.fWidth /= 10;
size.fHeight /= 10;
SkImageInfo info = SkImageInfo::MakeN32Premul(size);
- SkSurface* surface = SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info);
+ SkSurface* surface = SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info);
if (nullptr == surface) {
return;
#if SK_SUPPORT_GPU
surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(),
- SkBudgeted::kNo, info));
+ SkSurface::kNo_Budgeted, info));
#endif
test_surface(canvas, surf0, true);
static SkImage* make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(SkCanvas*)) {
if (!ctx) { return nullptr; }
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info));
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info));
draw(surface->getCanvas());
return surface->newImageSnapshot();
}
// Create a texture image
[context, render_image]() -> SkImage* {
SkAutoTUnref<SkSurface> surface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kYes,
+ SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted,
SkImageInfo::MakeN32Premul(kSize, kSize)));
if (!surface) {
return nullptr;
: SkImageGenerator(info)
, fCtx(SkRef(ctx))
{
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0));
surface->getCanvas()->clear(0);
surface->getCanvas()->translate(-100, -100);
desc.fWidth = subset->width();
desc.fHeight = subset->height();
- GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted::kNo);
+ GrTexture* dst = fCtx->textureProvider()->createTexture(desc, false);
fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0));
return dst;
}
// No API to draw a GrTexture directly, so we cheat and create a private image subclass
SkAutoTUnref<SkImage> image(new SkImage_Gpu(cache->info().width(), cache->info().height(),
cache->uniqueID(), kPremul_SkAlphaType, texture,
- SkBudgeted::kNo));
+ SkSurface::kNo_Budgeted));
canvas->drawImage(image, x, y);
#endif
}
if (!ctx) {
return nullptr;
}
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted,
info, 0));
surface->getCanvas()->clear(0);
surface->getCanvas()->drawPicture(pic);
SkAutoTUnref<SkSurface> surface;
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
if (context) {
- surface.reset(SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0));
+ surface.reset(SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0));
} else {
surface.reset(SkSurface::NewRaster(info));
}
SkSurfaceProps props(flags, geo);
if (ctx) {
- return SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props);
+ return SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0, &props);
} else {
return SkSurface::NewRaster(info, &props);
}
desc.fWidth = 2 * S;
desc.fHeight = 2 * S;
GrTexture* texture = ctx->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, gTextureData.get(), 0);
+ desc, false, gTextureData.get(), 0);
if (!texture) {
return;
SkImageInfo info = SkImageInfo::MakeN32Premul(onISize());
SkSurfaceProps props(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
SkSurfaceProps::kLegacyFontHost_InitType);
- surface.reset(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info, 0,
+ surface.reset(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info, 0,
&props));
canvas = surface.get() ? surface->getCanvas() : inputCanvas;
// init our new canvas with the old canvas's matrix
SkImageInfo baseInfo = baseCanvas->imageInfo();
SkImageInfo info = SkImageInfo::Make(w, h, baseInfo.colorType(), baseInfo.alphaType(),
baseInfo.profileType());
- return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr);
+ return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
#else
return nullptr;
#endif
class SK_API SkSurface : public SkRefCnt {
public:
/**
+ * Indicates whether a new surface or image should count against a cache budget. Currently this
+ * is only used by the GPU backend (sw-raster surfaces and images are never counted against the
+ * resource cache budget.)
+ */
+ enum Budgeted {
+ /** The surface or image does not count against the cache budget. */
+ kNo_Budgeted,
+ /** The surface or image counts against the cache budget. */
+ kYes_Budgeted
+ };
+
+ /**
* Create a new surface, using the specified pixels/rowbytes as its
* backend.
*
* additional textures.
*/
static SkSurface* NewRenderTarget(
- GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount,
- const SkSurfaceProps* = NULL, GrTextureStorageAllocator = GrTextureStorageAllocator());
+ GrContext*, Budgeted, const SkImageInfo&, int sampleCount, const SkSurfaceProps* = NULL,
+ GrTextureStorageAllocator = GrTextureStorageAllocator());
- static SkSurface* NewRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) {
+ static SkSurface* NewRenderTarget(GrContext* gr, Budgeted b, const SkImageInfo& info) {
return NewRenderTarget(gr, b, info, 0);
}
* parameter controls whether it counts against the resource budget
* (currently for the gpu backend only).
*/
- SkImage* newImageSnapshot(SkBudgeted = SkBudgeted::kYes);
+ SkImage* newImageSnapshot(Budgeted = kYes_Budgeted);
/**
* In rare instances a client may want a unique copy of the SkSurface's contents in an image
kNo_ForceUnique,
kYes_ForceUnique
};
- SkImage* newImageSnapshot(SkBudgeted, ForceUnique);
+ SkImage* newImageSnapshot(Budgeted, ForceUnique);
/**
* Though the caller could get a snapshot image explicitly, and draw that,
return SkTMax(SkTMin(value, max), min);
}
-
-///////////////////////////////////////////////////////////////////////////////
-
-/**
- * Indicates whether an allocation should count against a cache budget.
- */
-enum class SkBudgeted : bool {
- kNo = false,
- kYes = true
-};
-
///////////////////////////////////////////////////////////////////////////////
/** Use to combine multiple bits in a bitmask in a type safe way.
* implies tightly packed rows. For compressed pixel configs, this
* field is ignored.
*/
- GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const void* srcData,
+ GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
size_t rowBytes);
/** Shortcut for creating a texture with no initial data to upload. */
- GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted) {
+ GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) {
return this->createTexture(desc, budgeted, NULL, 0);
}
if (kApprox_ScratchTexMatch == match) {
return this->createApproxTexture(desc);
} else {
- return this->createTexture(desc, SkBudgeted::kYes);
+ return this->createTexture(desc, true);
}
}
GrContext* context = grFactory.get(GrContextFactory::kNative_GLContextType);
SkImageInfo info = SkImageInfo:: MakeN32Premul(width, height);
SkAutoTUnref<SkSurface> gpuSurface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info));
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info));
if (!gpuSurface) {
SkDebugf("SkSurface::NewRenderTarget returned null\n");
return;
// TODO: we should actually only copy the portion of the source needed to apply the image
// filter
GrContext* context = srcRT->getContext();
- SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(srcRT->desc(),
- SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(srcRT->desc(), true));
context->copySurface(tex, srcRT);
}
desc.fConfig = config;
- return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, rawStart, 0);
+ return ctx->textureProvider()->createTexture(desc, true, rawStart, 0);
}
class Generator_GrYUVProvider : public GrYUVProvider {
//
// TODO: respect the usage, by possibly creating a different (pow2) surface
//
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kYes,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx,
+ SkSurface::kYes_Budgeted,
surfaceInfo));
if (!surface.get()) {
return nullptr;
if (!blurProfile) {
SkAutoTDeleteArray<uint8_t> profile(create_profile(halfWH, sigma));
- blurProfile = textureProvider->createTexture(texDesc, SkBudgeted::kYes, profile.get(), 0);
+ blurProfile = textureProvider->createTexture(texDesc, true, profile.get(), 0);
if (blurProfile) {
textureProvider->assignUniqueKeyToTexture(key, blurProfile);
}
if (!blurProfile) {
SkAutoTDeleteArray<uint8_t> profile(SkBlurMask::ComputeBlurProfile(sigma));
- blurProfile = textureProvider->createTexture(texDesc, SkBudgeted::kYes, profile.get(), 0);
+ blurProfile = textureProvider->createTexture(texDesc, true, profile.get(), 0);
if (blurProfile) {
textureProvider->assignUniqueKeyToTexture(key, blurProfile);
}
texDesc.fConfig = kAlpha_8_GrPixelConfig;
blurNinePatchTexture.reset(
- texProvider->createTexture(texDesc, SkBudgeted::kYes , blurredMask.fImage, 0));
+ texProvider->createTexture(texDesc, true, blurredMask.fImage, 0));
SkMask::FreeImage(blurredMask.fImage);
if (!blurNinePatchTexture) {
return nullptr;
context->textureProvider()->findAndRefTextureByUniqueKey(key));
if (!textureCube) {
textureCube.reset(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, fCubeData->data(), 0));
+ desc, true, fCubeData->data(), 0));
if (textureCube) {
context->textureProvider()->assignUniqueKeyToTexture(key, textureCube);
} else {
}
SkAutoTUnref<GrTexture> temp;
if (tempDrawInfo.fUseExactScratch) {
- temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTempSurfaceDesc,
- SkBudgeted::kYes));
+ temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTempSurfaceDesc, true));
} else {
temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc));
}
}
}
-GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budgeted,
+GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, bool budgeted,
const void* srcData, size_t rowBytes) {
GrSurfaceDesc desc = origDesc;
}
}
- GrGpuResource::LifeCycle lifeCycle = SkBudgeted::kYes == budgeted ?
- GrGpuResource::kCached_LifeCycle :
- GrGpuResource::kUncached_LifeCycle;
+ GrGpuResource::LifeCycle lifeCycle = budgeted ? GrGpuResource::kCached_LifeCycle :
+ GrGpuResource::kUncached_LifeCycle;
desc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
// Attempt to catch un- or wrongly initialized sample counts;
*
* @return The texture object if successful, otherwise nullptr.
*/
- GrTexture* createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+ GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted,
const void* srcData, size_t rowBytes);
/**
SkASSERT(key.isValid());
// Wrapped and uncached resources can never have a unique key.
- if (SkBudgeted::kNo == this->resourcePriv().isBudgeted()) {
+ if (!this->resourcePriv().isBudgeted()) {
return;
}
*/
bool isScratch() const {
return !fResource->getUniqueKey().isValid() && fResource->fScratchKey.isValid() &&
- SkBudgeted::kYes == fResource->resourcePriv().isBudgeted();
+ fResource->resourcePriv().isBudgeted();
}
/**
/**
* Does the resource count against the resource budget?
*/
- SkBudgeted isBudgeted() const {
+ bool isBudgeted() const {
bool ret = GrGpuResource::kCached_LifeCycle == fResource->fLifeCycle;
SkASSERT(ret || !fResource->getUniqueKey().isValid());
- return SkBudgeted(ret);
+ return ret;
}
/**
desc.fHeight = fBackingTextureSize.height();
desc.fConfig = fPixelConfig;
- fTexture.reset(fTexProvider->createTexture(desc, SkBudgeted::kYes, nullptr, 0));
+ fTexture.reset(fTexProvider->createTexture(desc, true, nullptr, 0));
fTexture->resourcePriv().setUniqueKey(get_layer_atlas_key());
}
// TODO: make the test for exact match depend on the image filters themselves
SkAutoTUnref<GrTexture> tex;
if (layer->fFilter) {
- tex.reset(fContext->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+ tex.reset(fContext->textureProvider()->createTexture(desc, true));
} else {
tex.reset(fContext->textureProvider()->createApproxTexture(desc));
}
fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount);
fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
#endif
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
+ if (resource->resourcePriv().isBudgeted()) {
++fBudgetedCount;
fBudgetedBytes += size;
TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget", "used",
size_t size = resource->gpuMemorySize();
SkDEBUGCODE(--fCount;)
fBytes -= size;
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
+ if (resource->resourcePriv().isBudgeted()) {
--fBudgetedCount;
fBudgetedBytes -= size;
TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget", "used",
this->removeFromNonpurgeableArray(resource);
fPurgeableQueue.insert(resource);
- if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
+ if (!resource->resourcePriv().isBudgeted()) {
// Check whether this resource could still be used as a scratch resource.
if (!resource->cacheAccess().isExternal() &&
resource->resourcePriv().getScratchKey().isValid()) {
#if GR_CACHE_STATS
fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes);
#endif
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
+ if (resource->resourcePriv().isBudgeted()) {
fBudgetedBytes += delta;
TRACE_COUNTER2(TRACE_DISABLED_BY_DEFAULT("skia.gpu.cache"), "skia budget", "used",
fBudgetedBytes, "free", fMaxBytes - fBudgetedBytes);
size_t size = resource->gpuMemorySize();
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
+ if (resource->resourcePriv().isBudgeted()) {
++fBudgetedCount;
fBudgetedBytes += size;
#if GR_CACHE_STATS
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
SkASSERT(!resource->cacheAccess().isExternal());
} else if (resource->resourcePriv().getScratchKey().isValid()) {
- SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted() ||
+ SkASSERT(!resource->resourcePriv().isBudgeted() ||
resource->getUniqueKey().isValid());
++fCouldBeScratch;
SkASSERT(fScratchMap->countForKey(resource->resourcePriv().getScratchKey()));
++fContent;
SkASSERT(fUniqueHash->find(uniqueKey) == resource);
SkASSERT(!resource->cacheAccess().isExternal());
- SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
+ SkASSERT(resource->resourcePriv().isBudgeted());
}
- if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) {
+ if (resource->resourcePriv().isBudgeted()) {
++fBudgetedCount;
fBudgetedBytes += resource->gpuMemorySize();
}
if (resource->cacheAccess().isAdopted()) {
++fAdopted;
}
- if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
+ if (!resource->resourcePriv().isBudgeted()) {
fUnbudgetedSize += resource->gpuMemorySize();
}
}
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fSampleCnt = 0;
- SkAutoTUnref<GrTexture> texture(this->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0));
+ SkAutoTUnref<GrTexture> texture(this->textureProvider()->createTexture(desc, false,
+ nullptr, 0));
if (nullptr == texture) {
return;
}
}
}
- SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(rtDesc,
- SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(rtDesc, true));
if (!copy) {
return nullptr;
}
{
}
-GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
+GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budgeted,
const void* srcData, size_t rowBytes) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
if (GrTexture* texture = this->refScratchTexture(desc, kFlags)) {
if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
srcData, rowBytes)) {
- if (SkBudgeted::kNo == budgeted) {
+ if (!budgeted) {
texture->resourcePriv().makeUnbudgeted();
}
return texture;
}
if (!(kNoCreate_ScratchTextureFlag & flags)) {
- return fGpu->createTexture(*desc, SkBudgeted::kYes, nullptr, 0);
+ return fGpu->createTexture(*desc, true, nullptr, 0);
}
return nullptr;
bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) ||
(yuvDesc.fHeight != yuvInfo.fSize[0].fHeight);
if (needsExactTexture) {
- yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes));
+ yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, true));
} else {
yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuvDesc));
}
GrSurfaceDesc rtDesc = desc;
rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc, SkBudgeted::kYes,
- nullptr, 0));
+ SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc, true, nullptr, 0));
if (!result) {
return nullptr;
}
return new SkGpuDevice(rt, width, height, props, flags);
}
-SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkBudgeted budgeted,
+SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgeted,
const SkImageInfo& info, int sampleCount,
const SkSurfaceProps* props, InitContents init,
GrTextureStorageAllocator customAllocator) {
}
GrRenderTarget* SkGpuDevice::CreateRenderTarget(
- GrContext* context, SkBudgeted budgeted, const SkImageInfo& origInfo,
+ GrContext* context, SkSurface::Budgeted budgeted, const SkImageInfo& origInfo,
int sampleCount, GrTextureStorageAllocator textureStorageAllocator) {
if (kUnknown_SkColorType == origInfo.colorType() ||
origInfo.width() < 0 || origInfo.height() < 0) {
desc.fConfig = SkImageInfo2GrPixelConfig(info);
desc.fSampleCnt = sampleCount;
desc.fTextureStorageAllocator = textureStorageAllocator;
- GrTexture* texture = context->textureProvider()->createTexture(desc, budgeted, nullptr, 0);
+ GrTexture* texture = context->textureProvider()->createTexture(
+ desc, SkToBool(budgeted), nullptr, 0);
if (nullptr == texture) {
return nullptr;
}
void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) {
ASSERT_SINGLE_OWNER
- SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted();
+ SkSurface::Budgeted budgeted =
+ fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgeted
+ : SkSurface::kNo_Budgeted;
SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget(
this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSampleCnt,
if (kNever_TileUsage == cinfo.fTileUsage) {
texture.reset(fContext->textureProvider()->createApproxTexture(desc));
} else {
- texture.reset(fContext->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+ texture.reset(fContext->textureProvider()->createTexture(desc, true));
}
if (texture) {
SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
ASSERT_SINGLE_OWNER
// TODO: Change the signature of newSurface to take a budgeted parameter.
- static const SkBudgeted kBudgeted = SkBudgeted::kNo;
+ static const SkSurface::Budgeted kBudgeted = SkSurface::kNo_Budgeted;
return SkSurface::NewRenderTarget(fContext, kBudgeted, info, fRenderTarget->desc().fSampleCnt,
&props);
}
* sampleCount. The Budgeted param controls whether the device's backing store counts against
* the resource cache budget. On failure, returns nullptr.
*/
- static SkGpuDevice* Create(GrContext*, SkBudgeted, const SkImageInfo&,
+ static SkGpuDevice* Create(GrContext*, SkSurface::Budgeted, const SkImageInfo&,
int sampleCount, const SkSurfaceProps*,
InitContents, GrTextureStorageAllocator = GrTextureStorageAllocator());
bool drawDashLine(const SkPoint pts[2], const SkPaint& paint);
- static GrRenderTarget* CreateRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&,
+ static GrRenderTarget* CreateRenderTarget(GrContext*, SkSurface::Budgeted, const SkImageInfo&,
int sampleCount, GrTextureStorageAllocator);
friend class GrAtlasTextContext;
return nullptr;
}
- return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, startOfTexData, 0);
+ return ctx->textureProvider()->createTexture(desc, true, startOfTexData, 0);
}
GrTexture* GrUploadBitmapToTexture(GrContext* ctx, const SkBitmap& bmp) {
// our compressed data will be trimmed, so pass width() for its
// "rowBytes", since they are the same now.
- return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, storage.get(),
+ return ctx->textureProvider()->createTexture(desc, true, storage.get(),
bitmap->width());
} else {
bmp.copyTo(&tmpBitmap, kN32_SkColorType);
return nullptr;
}
- return ctx->textureProvider()->createTexture(desc, SkBudgeted::kYes, bitmap->getPixels(),
+ return ctx->textureProvider()->createTexture(desc, true, bitmap->getPixels(),
bitmap->rowBytes());
}
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT);
desc.fTextureStorageAllocator = texture->desc().fTextureStorageAllocator;
- GrTexture* dst = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
+ GrTexture* dst = context->textureProvider()->createTexture(desc, false, nullptr, 0);
if (nullptr == dst) {
return nullptr;
}
desc.fHeight = 256;
desc.fConfig = kRGBA_8888_GrPixelConfig;
- SkAutoTUnref<GrTexture> readTex(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, nullptr, 0));
+ SkAutoTUnref<GrTexture> readTex(context->textureProvider()->createTexture(desc, true, nullptr, 0));
if (!readTex.get()) {
return;
}
- SkAutoTUnref<GrTexture> tempTex(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, nullptr, 0));
+ SkAutoTUnref<GrTexture> tempTex(context->textureProvider()->createTexture(desc, true, nullptr, 0));
if (!tempTex.get()) {
return;
}
desc.fFlags = kNone_GrSurfaceFlags;
- SkAutoTUnref<GrTexture> dataTex(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, data, 0));
+ SkAutoTUnref<GrTexture> dataTex(context->textureProvider()->createTexture(desc, true, data, 0));
if (!dataTex.get()) {
return;
}
fTexture = fDesc.fContext->textureProvider()->findAndRefTextureByUniqueKey(key);
if (nullptr == fTexture) {
- fTexture = fDesc.fContext->textureProvider()->createTexture(texDesc, SkBudgeted::kYes,
- nullptr, 0);
+ fTexture = fDesc.fContext->textureProvider()->createTexture(texDesc, true, nullptr, 0);
if (!fTexture) {
return;
}
desc.fConfig = rtConfig;
desc.fWidth = desc.fHeight = 16;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> temp(this->createTexture(desc, SkBudgeted::kNo, nullptr, 0));
+ SkAutoTUnref<GrTexture> temp(this->createTexture(desc, false, nullptr, 0));
if (!temp) {
return false;
}
if (GrTexture* tex = pr->getTexture()) {
SkAutoTUnref<GrTexture> unrefCopy;
if (!bm.isImmutable()) {
- tex = GrDeepCopyTexture(tex, SkBudgeted::kNo);
+ const bool notBudgeted = false;
+ tex = GrDeepCopyTexture(tex, notBudgeted);
if (nullptr == tex) {
return nullptr;
}
}
const SkImageInfo info = bm.info();
return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
- tex, SkBudgeted::kNo);
+ tex, SkSurface::kNo_Budgeted);
}
#endif
// surface needs to perform a copy-on-write
extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
-GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted);
+GrTexture* GrDeepCopyTexture(GrTexture* src, bool isBudgeted);
#endif
#include "SkPixelRef.h"
SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex,
- SkBudgeted budgeted)
+ SkSurface::Budgeted budgeted)
: INHERITED(w, h, uniqueID)
, fTexture(SkRef(tex))
, fAlphaType(at)
desc.fWidth = subset.width();
desc.fHeight = subset.height();
- GrTexture* subTx = ctx->textureProvider()->createTexture(desc, fBudgeted);
+ GrTexture* subTx = ctx->textureProvider()->createTexture(desc,
+ SkSurface::kYes_Budgeted == fBudgeted);
if (!subTx) {
return nullptr;
}
tex->setRelease(releaseProc, releaseCtx);
}
- const SkBudgeted budgeted = SkBudgeted::kNo;
+ const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted;
return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
}
return nullptr;
}
- SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes));
+ const bool isBudgeted = true;
+ SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, isBudgeted));
if (!dst) {
return nullptr;
}
+ const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
- SkBudgeted::kYes);
+ budgeted);
}
SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
const GrBackendObject yuvTextureHandles[3],
const SkISize yuvSizes[3],
GrSurfaceOrigin origin) {
- const SkBudgeted budgeted = SkBudgeted::kYes;
+ const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 ||
dstDesc.fConfig = kRGBA_8888_GrPixelConfig;
dstDesc.fSampleCnt = 0;
- SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, true));
if (!dst) {
return nullptr;
}
return nullptr;
}
return new SkImage_Gpu(texture->width(), texture->height(), id, at, texture,
- SkBudgeted::kNo);
+ SkSurface::kNo_Budgeted);
}
SkImage* SkImage::newTextureImage(GrContext *context) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
-GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted budgeted) {
+GrTexture* GrDeepCopyTexture(GrTexture* src, bool budgeted) {
GrContext* ctx = src->getContext();
GrSurfaceDesc desc = src->desc();
* An "image" can be a subset/window into a larger texture, so we explicit take the
* width and height.
*/
- SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkBudgeted);
+ SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, SkSurface::Budgeted);
~SkImage_Gpu() override;
void applyBudgetDecision() const {
GrTexture* tex = this->getTexture();
SkASSERT(tex);
- if (SkBudgeted::kYes == fBudgeted) {
+ if (fBudgeted) {
tex->resourcePriv().makeBudgeted();
} else {
tex->resourcePriv().makeUnbudgeted();
int srcX, int srcY, CachingHint) const override;
SkSurface* onNewSurface(const SkImageInfo& info) const override {
- return SkSurface::NewRenderTarget(fTexture->getContext(), SkBudgeted::kNo, info);
+ return SkSurface::NewRenderTarget(fTexture->getContext(), SkSurface::kNo_Budgeted, info);
}
bool asBitmapForImageFilters(SkBitmap* bitmap) const override;
private:
SkAutoTUnref<GrTexture> fTexture;
const SkAlphaType fAlphaType;
- const SkBudgeted fBudgeted;
+ const SkSurface::Budgeted fBudgeted;
mutable SkAtomic<bool> fAddedRasterVersionToCache;
}
void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
- SkImage* image = this->newImageSnapshot(SkBudgeted::kYes);
+ SkImage* image = this->newImageSnapshot(kYes_Budgeted);
if (image) {
canvas->drawImage(image, x, y, paint);
image->unref();
return asSB(this)->getCachedCanvas();
}
-SkImage* SkSurface::newImageSnapshot(SkBudgeted budgeted) {
+SkImage* SkSurface::newImageSnapshot(Budgeted budgeted) {
// the caller will call unref() to balance this
return asSB(this)->refCachedImage(budgeted, kNo_ForceUnique);
}
-SkImage* SkSurface::newImageSnapshot(SkBudgeted budgeted, ForceUnique unique) {
+SkImage* SkSurface::newImageSnapshot(Budgeted budgeted, ForceUnique unique) {
// the caller will call unref() to balance this
return asSB(this)->refCachedImage(budgeted, unique);
}
return nullptr;
}
-SkSurface* SkSurface::NewRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int,
+SkSurface* SkSurface::NewRenderTarget(GrContext*, Budgeted, const SkImageInfo&, int,
const SkSurfaceProps*, GrTextureStorageAllocator) {
return nullptr;
}
* must faithfully represent the current contents, even if the surface
* is changed after this called (e.g. it is drawn to via its canvas).
*/
- virtual SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) = 0;
+ virtual SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) = 0;
/**
* Default implementation:
virtual void onPrepareForExternalIO() {}
inline SkCanvas* getCachedCanvas();
- inline SkImage* refCachedImage(SkBudgeted, ForceUnique);
+ inline SkImage* refCachedImage(Budgeted, ForceUnique);
bool hasCachedImage() const { return fCachedImage != nullptr; }
return fCachedCanvas;
}
-SkImage* SkSurface_Base::refCachedImage(SkBudgeted budgeted, ForceUnique unique) {
+SkImage* SkSurface_Base::refCachedImage(Budgeted budgeted, ForceUnique unique) {
SkImage* snap = fCachedImage;
if (kYes_ForceUnique == unique && snap && !snap->unique()) {
snap = nullptr;
GrRenderTarget* rt = fDevice->accessRenderTarget();
int sampleCount = rt->numColorSamples();
// TODO: Make caller specify this (change virtual signature of onNewSurface).
- static const SkBudgeted kBudgeted = SkBudgeted::kNo;
+ static const Budgeted kBudgeted = kNo_Budgeted;
return SkSurface::NewRenderTarget(fDevice->context(), kBudgeted, info, sampleCount,
&this->props());
}
-SkImage* SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) {
+SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted, ForceCopyMode forceCopyMode) {
GrRenderTarget* rt = fDevice->accessRenderTarget();
SkASSERT(rt);
GrTexture* tex = rt->asTexture();
GrSurfaceDesc desc = fDevice->accessRenderTarget()->desc();
GrContext* ctx = fDevice->context();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
- copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
+ copy.reset(ctx->textureProvider()->createTexture(desc, kYes_Budgeted == budgeted));
if (!copy) {
return nullptr;
}
GrRenderTarget* rt = fDevice->accessRenderTarget();
// are we sharing our render target with the image? Note this call should never create a new
// image because onCopyOnWrite is only called when there is a cached image.
- SkAutoTUnref<SkImage> image(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique));
+ SkAutoTUnref<SkImage> image(this->refCachedImage(kNo_Budgeted, kNo_ForceUnique));
SkASSERT(image);
if (rt->asTexture() == as_IB(image)->getTexture()) {
this->fDevice->replaceRenderTarget(SkSurface::kRetain_ContentChangeMode == mode);
return new SkSurface_Gpu(device);
}
-SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, SkBudgeted budgeted, const SkImageInfo& info,
+SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, Budgeted budgeted, const SkImageInfo& info,
int sampleCount, const SkSurfaceProps* props,
GrTextureStorageAllocator customAllocator) {
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(
bool onGetRenderTargetHandle(GrBackendObject*, BackendHandleAccess) override;
SkCanvas* onNewCanvas() override;
SkSurface* onNewSurface(const SkImageInfo&) override;
- SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) override;
+ SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) override;
void onCopyOnWrite(ContentChangeMode) override;
void onDiscard() override;
void onPrepareForExternalIO() override;
SkCanvas* onNewCanvas() override;
SkSurface* onNewSurface(const SkImageInfo&) override;
- SkImage* onNewImageSnapshot(SkBudgeted, ForceCopyMode) override;
+ SkImage* onNewImageSnapshot(Budgeted, ForceCopyMode) override;
void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) override;
void onCopyOnWrite(ContentChangeMode) override;
void onRestoreBackingMutability() override;
canvas->drawBitmap(fBitmap, x, y, paint);
}
-SkImage* SkSurface_Raster::onNewImageSnapshot(SkBudgeted, ForceCopyMode forceCopyMode) {
+SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted, ForceCopyMode forceCopyMode) {
if (fWeOwnThePixels) {
// SkImage_raster requires these pixels are immutable for its full lifetime.
// We'll undo this via onRestoreBackingMutability() if we can avoid the COW.
void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
// are we sharing pixelrefs with the image?
- SkAutoTUnref<SkImage> cached(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique));
+ SkAutoTUnref<SkImage> cached(this->refCachedImage(kNo_Budgeted, kNo_ForceUnique));
SkASSERT(cached);
if (SkBitmapImageGetPixelRef(cached) == fBitmap.pixelRef()) {
SkASSERT(fWeOwnThePixels);
desc.fWidth = subset->width();
desc.fHeight = subset->height();
- GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted::kNo);
+ GrTexture* dst = fCtx->textureProvider()->createTexture(desc, false);
fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0));
return dst;
}
const void* srcData = (kSkia8888_GrPixelConfig == desc.fConfig) ? kData : swizData;
SkAutoTUnref<GrTexture> texture(
- ctx->textureProvider()->createTexture(desc, SkBudgeted::kNo, srcData, 0));
+ ctx->textureProvider()->createTexture(desc, false, srcData, 0));
if (!texture) {
continue;
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctx) {
SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted::kNo, info));
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkSurface::kNo_Budgeted, info));
SkCanvas* canvas = surface->getCanvas();
SkRect r = SkRect::MakeXYWH(10, 10, 100, 100);
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
- rtKeepAlive->reset(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
+ rtKeepAlive->reset(context->textureProvider()->createTexture(desc, true));
if (!(*rtKeepAlive)) {
return false;
}
desc.fHeight = kYSize;
SkAutoTUnref<GrTexture> texture(
- context->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0));
+ context->textureProvider()->createTexture(desc, false, nullptr, 0));
if (!texture) {
return;
}
dstDesc.fFlags = dFlags;
SkAutoTUnref<GrTexture> src(
- context->textureProvider()->createTexture(srcDesc, SkBudgeted::kNo,
+ context->textureProvider()->createTexture(srcDesc, false,
srcPixels.get(),
kRowBytes));
SkAutoTUnref<GrTexture> dst(
- context->textureProvider()->createTexture(dstDesc, SkBudgeted::kNo,
+ context->textureProvider()->createTexture(dstDesc, false,
dstPixels.get(),
kRowBytes));
if (!src || !dst) {
copyDesc.fWidth = externalTexture->width();
copyDesc.fHeight = externalTexture->height();
copyDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(
- copyDesc, SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> copy(context->textureProvider()->createTexture(copyDesc, true));
context->copySurface(copy, externalTexture);
test_read_pixels(reporter, context, copy, expectedPixelValues);
}
desc.fOrigin = 0 == origin ?
kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, controlPixelData.begin(), 0));
+ desc, false, controlPixelData.begin(), 0));
// Floating point textures are NOT supported everywhere
if (nullptr == fpTexture) {
continue;
GrTexture* texture = textureProvider->findAndRefTextureByUniqueKey(key);
if (!texture) {
- texture = textureProvider->createTexture(texDesc, SkBudgeted::kYes);
+ texture = textureProvider->createTexture(texDesc, true);
if (texture) {
textureProvider->assignUniqueKeyToTexture(key, texture);
}
dummyDesc.fWidth = 34;
dummyDesc.fHeight = 18;
SkAutoTUnref<GrTexture> dummyTexture1(
- context->textureProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0));
+ context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
dummyDesc.fFlags = kNone_GrSurfaceFlags;
dummyDesc.fConfig = kAlpha_8_GrPixelConfig;
dummyDesc.fWidth = 16;
dummyDesc.fHeight = 22;
SkAutoTUnref<GrTexture> dummyTexture2(
- context->textureProvider()->createTexture(dummyDesc, SkBudgeted::kNo, nullptr, 0));
+ context->textureProvider()->createTexture(dummyDesc, false, nullptr, 0));
if (!dummyTexture1 || ! dummyTexture2) {
SkDebugf("Could not allocate dummy textures");
rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrRenderTarget> rt(
- context->textureProvider()->createTexture(rtDesc, SkBudgeted::kNo)->asRenderTarget());
+ context->textureProvider()->createTexture(rtDesc, false)->asRenderTarget());
int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
for (int i = 0; i < fpFactoryCnt; ++i) {
// Since FP factories internally randomize, call each 10 times.
for (auto& sampleCount : {0, 4, 16}) {
SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255);
SkAutoTUnref<SkSurface> surface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info,
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info,
sampleCount, nullptr));
if (!surface) {
continue;
desc.fWidth = 256;
desc.fHeight = 256;
desc.fSampleCnt = 0;
- GrSurface* texRT1 = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0);
+ GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget());
REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture());
static_cast<GrSurface*>(texRT1->asTexture()));
desc.fFlags = kNone_GrSurfaceFlags;
- GrSurface* tex1 = context->textureProvider()->createTexture(desc, SkBudgeted::kNo, nullptr, 0);
+ GrSurface* tex1 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget());
REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
desc.fWidth = 256;
desc.fHeight = 256;
desc.fSampleCnt = 0;
- GrSurface* texRT1 = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0);
- GrSurface* texRT2 = context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0);
+ GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
+ GrSurface* texRT2 = context->textureProvider()->createTexture(desc, false, nullptr, 0);
REPORTER_ASSERT(reporter, nullptr != texRT1);
REPORTER_ASSERT(reporter, nullptr != texRT2);
GrTexture* tex = texRT1->asTexture();
desc.fWidth = kFullSize;
desc.fHeight = kFullSize;
- return context->textureProvider()->createTexture(desc, SkBudgeted::kNo, srcBM.getPixels(), 0);
+ return context->textureProvider()->createTexture(desc, false, srcBM.getPixels(), 0);
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, context) {
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(100, 100),
0,
&props,
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(100, 100),
0,
&props,
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(1, 1),
0,
&props,
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(context,
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
SkImageInfo::MakeN32Premul(1, 1),
0,
&props,
DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) {
SkAutoTUnref<SkSurface> surface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kYes,
+ SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted,
SkImageInfo::MakeN32Premul(100, 100)));
test_large_blur_input(reporter, surface->getCanvas());
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, context) {
SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5);
SkAutoTUnref<SkSurface> surfaceTransparent(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, infoTransparent));
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, infoTransparent));
check_isopaque(reporter, surfaceTransparent, false);
SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
SkAutoTUnref<SkSurface> surfaceOpaque(
- SkSurface::NewRenderTarget(context,SkBudgeted::kNo, infoOpaque));
+ SkSurface::NewRenderTarget(context,SkSurface::kNo_Budgeted, infoOpaque));
check_isopaque(reporter, surfaceOpaque, true);
}
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
SkAutoTUnref<SkSurface> sourceSurface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info));
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info));
SkAutoTUnref<SkSurface> destinationSurface(
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info));
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info));
runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5);
SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRenderTarget(context,
- SkBudgeted::kNo, info));
+ SkSurface::kNo_Budgeted, info));
SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRaster(info));
runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRaster(info));
SkAutoTUnref<SkSurface> destinationSurface(SkSurface::NewRenderTarget(context,
- SkBudgeted::kNo, info));
+ SkSurface::kNo_Budgeted, info));
runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info);
}
#if SK_SUPPORT_GPU
static SkImage* create_gpu_image(GrContext* context) {
const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkBudgeted::kNo,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted,
info));
draw_image_test_pattern(surface->getCanvas());
return surface->newImageSnapshot();
desc.fHeight = h;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fSampleCnt = 0;
- SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, SkBudgeted::kNo, storage, w * 4));
+ SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4));
if (!tex) {
REPORTER_ASSERT(reporter, false);
return;
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
SkAutoTUnref<SkBaseDevice> device(
- SkGpuDevice::Create(context, SkBudgeted::kNo, info, 0, &props,
+ SkGpuDevice::Create(context, SkSurface::kNo_Budgeted, info, 0, &props,
SkGpuDevice::kUninit_InitContents));
test_premul_alpha_roundtrip(reporter, device);
}
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
SkAutoTUnref<GrTexture> surfaceTexture(
- context->textureProvider()->createTexture(desc, SkBudgeted::kNo));
+ context->textureProvider()->createTexture(desc, false));
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(surfaceTexture->asRenderTarget()));
desc.fFlags = kNone_GrSurfaceFlags;
test_readpixels(reporter, surface, kLast_BitmapInit);
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
desc.fFlags = kNone_GrSurfaceFlags;
- texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kNo));
+ texture.reset(context->textureProvider()->createTexture(desc, false));
test_readpixels_texture(reporter, texture);
}
}
// do they draw the same?
const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
- SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0));
- SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0));
+ SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
+ SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0));
if (false) {
//
// We are initializing the texture with zeros here
memset(alphaData, 0, X_SIZE * Y_SIZE);
SkAutoTUnref<GrTexture> texture(
- context->textureProvider()->createTexture(desc, SkBudgeted::kNo , alphaData, 0));
+ context->textureProvider()->createTexture(desc, false, alphaData, 0));
if (!texture) {
if (!rt) {
ERRORF(reporter, "Could not create alpha texture.");
}
}
SkAutoTUnref<GrTexture> texture(
- context->textureProvider()->createTexture(desc, SkBudgeted::kNo, rgbaData, 0));
+ context->textureProvider()->createTexture(desc, false, rgbaData, 0));
if (!texture) {
// We always expect to be able to create a RGBA texture
if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) {
desc.fHeight = kHeight;
desc.fSampleCnt = 0;
- texture.reset(context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo, nullptr, 0));
+ texture.reset(context->textureProvider()->createTexture(desc, false, nullptr, 0));
layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight), false);
}
copyDstDesc.fWidth = rectangleTexture->width();
copyDstDesc.fHeight = rectangleTexture->height();
copyDstDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(
- copyDstDesc, SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> dst(context->textureProvider()->createTexture(copyDstDesc, true));
context->copySurface(dst, rectangleTexture);
test_read_pixels(reporter, context, dst, expectedPixelValues);
}
copySrcDesc.fWidth = rectangleTexture->width();
copySrcDesc.fHeight = rectangleTexture->height();
copySrcDesc.fFlags = kRenderTarget_GrSurfaceFlag;
- SkAutoTUnref<GrTexture> src(context->textureProvider()->createTexture(
- copySrcDesc, SkBudgeted::kYes, pixels.get(), 0));
+ SkAutoTUnref<GrTexture> src(context->textureProvider()->createTexture(copySrcDesc, true,
+ pixels.get(), 0));
context->copySurface(rectangleTexture, src);
test_read_pixels(reporter, context, rectangleTexture, pixels.get());
desc.fHeight = gHeight;
SkImageInfo info = SkImageInfo::MakeN32Premul(gWidth, gHeight);
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context,
- SkBudgeted::kNo, info));
+ SkSurface::kNo_Budgeted, info));
SkCanvas* canvas = surface->getCanvas();
const SkIRect size = SkIRect::MakeWH(gWidth, gHeight);
GrTextureProvider* cache = context->textureProvider();
GrResourceProvider* resourceProvider = context->resourceProvider();
// Test that two budgeted RTs with the same desc share a stencil buffer.
- SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, true));
if (smallRT0 && smallRT0->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget());
}
- SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, SkBudgeted::kYes));
+ SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, true));
if (smallRT1 && smallRT1->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget());
}
resourceProvider->attachStencilAttachment(smallRT1->asRenderTarget()));
// An unbudgeted RT with the same desc should also share.
- SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, false));
if (smallRT2 && smallRT2->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallRT2->asRenderTarget());
}
bigDesc.fWidth = 400;
bigDesc.fHeight = 200;
bigDesc.fSampleCnt = 0;
- SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, false));
if (bigRT && bigRT->asRenderTarget()) {
resourceProvider->attachStencilAttachment(bigRT->asRenderTarget());
}
// An RT with a different sample count should not share.
GrSurfaceDesc smallMSAADesc = smallDesc;
smallMSAADesc.fSampleCnt = 4;
- SkAutoTUnref<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, false));
if (smallMSAART0 && smallMSAART0->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget());
}
resourceProvider->attachStencilAttachment(smallRT0->asRenderTarget()) !=
resourceProvider->attachStencilAttachment(smallMSAART0->asRenderTarget()));
// A second MSAA RT should share with the first MSAA RT.
- SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, false));
if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget());
}
smallMSAART0 && smallMSAART0->asRenderTarget() &&
smallMSAART0->asRenderTarget()->numColorSamples() < 8) {
smallMSAADesc.fSampleCnt = 8;
- smallMSAART1.reset(cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
- SkAutoTUnref<GrTexture> smallMSAART1(
- cache->createTexture(smallMSAADesc, SkBudgeted::kNo));
+ smallMSAART1.reset(cache->createTexture(smallMSAADesc, false));
+ SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, false));
if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
resourceProvider->attachStencilAttachment(smallMSAART1->asRenderTarget());
}
// Since this resource is unbudgeted, it should not be reachable as scratch.
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
- REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().isBudgeted());
+ REPORTER_ASSERT(reporter, !resource->resourcePriv().isBudgeted());
REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, 0));
REPORTER_ASSERT(reporter, 1 == cache->getResourceCount());
REPORTER_ASSERT(reporter, size == cache->getResourceBytes());
REPORTER_ASSERT(reporter, resource);
REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key);
REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch());
- REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
+ REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted());
if (0 == i) {
// If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try
REPORTER_ASSERT(reporter, size == cache->getBudgetedResourceBytes());
REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid());
REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch());
- REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted());
+ REPORTER_ASSERT(reporter, resource->resourcePriv().isBudgeted());
// now when it is unrefed it should die since it has no key.
resource->unref();
desc.fConfig = kSRGBA_8888_GrPixelConfig;
if (context->caps()->isConfigRenderable(desc.fConfig, false) &&
context->caps()->isConfigTexturable(desc.fConfig)) {
- SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(
- desc, SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(desc, false));
if (!tex) {
ERRORF(reporter, "Could not create SRGBA texture.");
return;
}
desc.fConfig = kRGBA_8888_GrPixelConfig;
- tex.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kNo));
+ tex.reset(context->textureProvider()->createTexture(desc, false));
if (!tex) {
ERRORF(reporter, "Could not create RGBA texture.");
return;
desc.fWidth = kFullSize;
desc.fHeight = kFullSize;
- SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, SkBudgeted::kNo,
+ SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, false,
bm.getPixels(), 0));
if (!texture) {
return;
if (requestedInfo) {
*requestedInfo = info;
}
- return SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr);
+ return SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr);
}
static SkSurface* create_gpu_scratch_surface(GrContext* context,
SkAlphaType at = kPremul_SkAlphaType,
if (requestedInfo) {
*requestedInfo = info;
}
- return SkSurface::NewRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr);
+ return SkSurface::NewRenderTarget(context, SkSurface::kYes_Budgeted, info, 0, nullptr);
}
#endif
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) {
const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType);
REPORTER_ASSERT(reporter, nullptr ==
- SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr));
+ SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr));
}
#endif
std::function<intptr_t(SkSurface*)> surfaceBackingStore) {
std::function<intptr_t(SkImage*)> ibs = imageBackingStore;
std::function<intptr_t(SkSurface*)> sbs = surfaceBackingStore;
- static const SkBudgeted kB = SkBudgeted::kNo;
+ static const SkSurface::Budgeted kB = SkSurface::kNo_Budgeted;
{
SkAutoTUnref<SkImage> image(surface->newImageSnapshot(kB, SkSurface::kYes_ForceUnique));
REPORTER_ASSERT(reporter, !same_image_surf(image, surface, ibs, sbs));
#include "SkImage_Gpu.h"
#include "SkSurface_Gpu.h"
-static SkBudgeted is_budgeted(SkSurface* surf) {
- return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted();
+static SkSurface::Budgeted is_budgeted(SkSurface* surf) {
+ return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePriv().isBudgeted() ?
+ SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
}
-static SkBudgeted is_budgeted(SkImage* image) {
- return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted();
+static SkSurface::Budgeted is_budgeted(SkImage* image) {
+ return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ?
+ SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) {
SkImageInfo info = SkImageInfo::MakeN32Premul(8,8);
- for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
- for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
+ for (int i = 0; i < 2; ++i) {
+ SkSurface::Budgeted sbudgeted = i ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
+ for (int j = 0; j < 2; ++j) {
+ SkSurface::Budgeted ibudgeted = j ? SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
SkAutoTUnref<SkSurface>
surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0));
SkASSERT(surface);
}
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType);
- SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info,
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info,
0, &props));
REPORTER_ASSERT(reporter, surface);
if (!surface) {
grAllocator.fCtx = &allocator;
SkAutoTUnref<SkSurface> surface(SkSurface_Gpu::NewRenderTarget(
- context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0,
+ context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0,
NULL, grAllocator));
REPORTER_ASSERT(reporter, surface);
GrGLuint id = allocator.m_mostRecentlyAllocatedStorage;
grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateTextureStorage;
grAllocator.fCtx = &allocator;
SkAutoTUnref<SkSurface> surface(SkSurface_Gpu::NewRenderTarget(
- context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0,
+ context, SkSurface_Gpu::kNo_Budgeted, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0,
NULL, grAllocator));
REPORTER_ASSERT(reporter, !surface);
}
desc.fHeight = DEV_H;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = origin;
- SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc,
- SkBudgeted::kNo));
+ SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc, false));
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(texture->asRenderTarget()));
test_write_pixels(reporter, surface);
}
private:
void setupOffScreen(SkCanvas* canvas) override {
fOffScreen.reset(SkSurface::NewRenderTarget(canvas->getGrContext(),
- SkBudgeted::kNo,
+ SkSurface::kNo_Budgeted,
canvas->imageInfo(),
fNumSamples,
&this->surfaceProps()));
0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
fSurface.reset(SkSurface::NewRenderTarget(context,
- SkBudgeted::kNo, info,
+ SkSurface::kNo_Budgeted, info,
numSamples, &props));
fGL = factory->getContextInfo(ctxType, ctxOptions).fGLContext;
if (!fSurface.get()) {
kN32_SkColorType, kPremul_SkAlphaType);
uint32_t flags = 0;
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
- SkSurface* surface = SkSurface::NewRenderTarget(context, SkBudgeted::kNo, info, 0,
+ SkSurface* surface = SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0,
&props);
return surface;
}