本文整理汇总了C++中GrTexture类的典型用法代码示例。如果您正苦于以下问题:C++ GrTexture类的具体用法?C++ GrTexture怎么用?C++ GrTexture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GrTexture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createTexture
GrTexture* GrGpu::createTexture(const GrTextureDesc& desc,
const void* srcData, size_t rowBytes) {
this->handleDirtyContext();
GrTexture* tex = this->onCreateTexture(desc, srcData, rowBytes);
if (NULL != tex &&
(kRenderTarget_GrTextureFlagBit & desc.fFlags) &&
!(kNoStencil_GrTextureFlagBit & desc.fFlags)) {
GrAssert(NULL != tex->asRenderTarget());
// TODO: defer this and attach dynamically
if (!this->attachStencilBufferToRenderTarget(tex->asRenderTarget())) {
tex->unref();
return NULL;
}
}
return tex;
}
示例2: internal_dispose
/**
* This method allows us to interrupt the normal deletion process and place
* textures back in the texture cache when their ref count goes to zero.
*/
void GrTexture::internal_dispose() const {
if (this->impl()->isSetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit) &&
this->INHERITED::getContext()) {
GrTexture* nonConstThis = const_cast<GrTexture *>(this);
this->ref(); // restore ref count to initial setting
nonConstThis->impl()->resetFlag((GrTextureFlags) GrTextureImpl::kReturnToCache_FlagBit);
nonConstThis->INHERITED::getContext()->addExistingTextureToCache(nonConstThis);
// Note: "this" texture might be freed inside addExistingTextureToCache
// if it is purged.
return;
}
this->INHERITED::internal_dispose();
}
示例3: wrapBackendTexture
GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc) {
this->handleDirtyContext();
GrTexture* tex = this->onWrapBackendTexture(desc);
if (NULL == tex) {
return NULL;
}
// TODO: defer this and attach dynamically
GrRenderTarget* tgt = tex->asRenderTarget();
if (NULL != tgt &&
!this->attachStencilBufferToRenderTarget(tgt)) {
tex->unref();
return NULL;
} else {
return tex;
}
}
示例4: GenKey
static inline void GenKey(const GrGeometryProcessor& gp,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFieldA8TextGeoProc>();
uint32_t key = dfTexEffect.getFlags();
key |= dfTexEffect.colorIgnored() << 16;
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25;
b->add32(key);
// Currently we hardcode numbers to convert atlas coordinates to normalized floating point
SkASSERT(gp.numTextures() == 1);
GrTexture* atlas = gp.textureAccess(0).getTexture();
SkASSERT(atlas);
b->add32(atlas->width());
b->add32(atlas->height());
}
示例5: map_sigma
bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
#if SK_SUPPORT_GPU
SkBitmap input = src;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (!this->filterInputGPU(0, proxy, src, ctx, &input, &srcOffset)) {
return false;
}
SkIRect srcBounds = input.bounds();
srcBounds.offset(srcOffset);
SkIRect dstBounds;
if (!this->applyCropRect(this->mapContext(ctx), srcBounds, &dstBounds)) {
return false;
}
if (!srcBounds.intersect(dstBounds)) {
return false;
}
SkVector sigma = map_sigma(fSigma, ctx.ctm());
if (sigma.x() == 0 && sigma.y() == 0) {
input.extractSubset(result, srcBounds);
offset->fX = srcBounds.x();
offset->fY = srcBounds.y();
return true;
}
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
srcBounds.offset(-srcOffset);
dstBounds.offset(-srcOffset);
SkRect srcBoundsF(SkRect::Make(srcBounds));
GrTexture* inputTexture = input.getTexture();
SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->getContext(),
inputTexture,
false,
SkRect::Make(dstBounds),
&srcBoundsF,
sigma.x(),
sigma.y()));
if (!tex) {
return false;
}
GrWrapTextureInBitmap(tex, dstBounds.width(), dstBounds.height(), false, result);
return true;
#else
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
#endif
}
示例6: create_mask_GPU
// Create a mask of 'devPath' and place the result in 'mask'.
static GrTexture* create_mask_GPU(GrContext* context,
const SkRect& maskRect,
const SkPath& devPath,
const GrStrokeInfo& strokeInfo,
bool doAA,
int sampleCnt) {
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = SkScalarCeilToInt(maskRect.width());
desc.fHeight = SkScalarCeilToInt(maskRect.height());
desc.fSampleCnt = doAA ? sampleCnt : 0;
// We actually only need A8, but it often isn't supported as a
// render target so default to RGBA_8888
desc.fConfig = kRGBA_8888_GrPixelConfig;
if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) {
desc.fConfig = kAlpha_8_GrPixelConfig;
}
GrTexture* mask = context->textureProvider()->createApproxTexture(desc);
if (nullptr == mask) {
return nullptr;
}
SkRect clipRect = SkRect::MakeWH(maskRect.width(), maskRect.height());
GrDrawContext* drawContext = context->drawContext();
if (!drawContext) {
return nullptr;
}
drawContext->clear(mask->asRenderTarget(), nullptr, 0x0, true);
GrPaint tempPaint;
tempPaint.setAntiAlias(doAA);
tempPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
// setup new clip
GrClip clip(clipRect);
// Draw the mask into maskTexture with the path's top-left at the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
drawContext->drawPath(mask->asRenderTarget(), clip, tempPaint, translate, devPath, strokeInfo);
return mask;
}
示例7: GenKey
static inline void GenKey(const GrGeometryProcessor& proc,
const GrGLSLCaps&,
GrProcessorKeyBuilder* b) {
const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>();
uint32_t key = 0;
key |= gp.usesLocalCoords() && gp.localMatrix().hasPerspective() ? 0x1 : 0x0;
key |= gp.colorIgnored() ? 0x2 : 0x0;
key |= gp.maskFormat() << 3;
b->add32(key);
// Currently we hardcode numbers to convert atlas coordinates to normalized floating point
SkASSERT(gp.numTextures() == 1);
GrTexture* atlas = gp.textureAccess(0).getTexture();
SkASSERT(atlas);
b->add32(atlas->width());
b->add32(atlas->height());
}
示例8: TestCreate
GrFragmentProcessor* GrMagnifierEffect::TestCreate(SkRandom* random,
GrContext* context,
const GrDrawTargetCaps&,
GrTexture** textures) {
GrTexture* texture = textures[0];
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const int kMaxInset = 20;
uint32_t width = random->nextULessThan(kMaxWidth);
uint32_t height = random->nextULessThan(kMaxHeight);
uint32_t x = random->nextULessThan(kMaxWidth - width);
uint32_t y = random->nextULessThan(kMaxHeight - height);
uint32_t inset = random->nextULessThan(kMaxInset);
GrFragmentProcessor* effect = GrMagnifierEffect::Create(
texture,
(float) width / texture->width(),
(float) height / texture->height(),
texture->width() / (float) x,
texture->height() / (float) y,
(float) inset / texture->width(),
(float) inset / texture->height());
SkASSERT(effect);
return effect;
}
示例9: dump
void GrBatchFontCache::dump() const {
static int gDumpCount = 0;
for (int i = 0; i < kMaskFormatCount; ++i) {
if (fAtlases[i]) {
GrTexture* texture = fAtlases[i]->getTexture();
if (texture) {
SkString filename;
#ifdef SK_BUILD_FOR_ANDROID
filename.printf("/sdcard/fontcache_%d%d.png", gDumpCount, i);
#else
filename.printf("fontcache_%d%d.png", gDumpCount, i);
#endif
texture->surfacePriv().savePixels(filename.c_str());
}
}
}
++gDumpCount;
}
示例10: dump
void GrFontCache::dump() const {
static int gDumpCount = 0;
for (int i = 0; i < kAtlasCount; ++i) {
if (NULL != fAtlasMgr[i]) {
GrTexture* texture = fAtlasMgr[i]->getTexture();
if (NULL != texture) {
SkString filename;
#ifdef SK_BUILD_FOR_ANDROID
filename.printf("/sdcard/fontcache_%d%d.png", gDumpCount, i);
#else
filename.printf("fontcache_%d%d.png", gDumpCount, i);
#endif
texture->savePixels(filename.c_str());
}
}
}
++gDumpCount;
}
示例11: writePathVertices
void writePathVertices(GrDrawBatch::Target* target,
GrBatchAtlas* atlas,
intptr_t offset,
GrColor color,
size_t vertexStride,
const SkMatrix& viewMatrix,
const ShapeData* shapeData) const {
GrTexture* texture = atlas->getTexture();
SkScalar dx = shapeData->fBounds.fLeft;
SkScalar dy = shapeData->fBounds.fTop;
SkScalar width = shapeData->fBounds.width();
SkScalar height = shapeData->fBounds.height();
SkScalar invScale = 1.0f / shapeData->fScale;
dx *= invScale;
dy *= invScale;
width *= invScale;
height *= invScale;
SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
// vertex positions
// TODO make the vertex attributes a struct
SkRect r = SkRect::MakeXYWH(dx, dy, width, height);
positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertexStride);
// colors
for (int i = 0; i < kVerticesPerQuad; i++) {
GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertexStride);
*colorPtr = color;
}
const SkScalar tx = SkIntToScalar(shapeData->fAtlasLocation.fX);
const SkScalar ty = SkIntToScalar(shapeData->fAtlasLocation.fY);
// vertex texture coords
SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(GrColor));
textureCoords->setRectFan(tx / texture->width(),
ty / texture->height(),
(tx + shapeData->fBounds.width()) / texture->width(),
(ty + shapeData->fBounds.height()) / texture->height(),
vertexStride);
}
示例12: SkASSERT
bool GrDrawTarget::copySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint) {
SkASSERT(dst);
SkASSERT(src);
SkIRect clippedSrcRect;
SkIPoint clippedDstPoint;
// If the rect is outside the src or dst then we've already succeeded.
if (!clip_srcrect_and_dstpoint(dst,
src,
srcRect,
dstPoint,
&clippedSrcRect,
&clippedDstPoint)) {
return true;
}
if (this->onCopySurface(dst, src, clippedSrcRect, clippedDstPoint)) {
return true;
}
GrRenderTarget* rt = dst->asRenderTarget();
GrTexture* tex = src->asTexture();
if ((dst == src) || !rt || !tex) {
return false;
}
GrPipelineBuilder pipelineBuilder;
pipelineBuilder.setRenderTarget(rt);
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(clippedSrcRect.fLeft - clippedDstPoint.fX),
SkIntToScalar(clippedSrcRect.fTop - clippedDstPoint.fY));
matrix.postIDiv(tex->width(), tex->height());
pipelineBuilder.addColorTextureProcessor(tex, matrix);
SkIRect dstRect = SkIRect::MakeXYWH(clippedDstPoint.fX,
clippedDstPoint.fY,
clippedSrcRect.width(),
clippedSrcRect.height());
this->drawSimpleRect(&pipelineBuilder, GrColor_WHITE, SkMatrix::I(), dstRect);
return true;
}
示例13: copy_to_new_texture_pixelref
static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorType dstCT,
SkColorProfileType dstPT, const SkIRect* subset) {
if (NULL == texture || kUnknown_SkColorType == dstCT) {
return NULL;
}
GrContext* context = texture->getContext();
if (NULL == context) {
return NULL;
}
GrSurfaceDesc desc;
SkIRect srcRect;
if (!subset) {
desc.fWidth = texture->width();
desc.fHeight = texture->height();
srcRect = SkIRect::MakeWH(texture->width(), texture->height());
} else {
SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*subset));
// Create a new texture that is the size of subset.
desc.fWidth = subset->width();
desc.fHeight = subset->height();
srcRect = *subset;
}
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT);
GrTexture* dst = context->createTexture(desc, false, NULL, 0);
if (NULL == dst) {
return NULL;
}
// Blink is relying on the above copy being sent to GL immediately in the case when the source
// is a WebGL canvas backing store. We could have a TODO to remove this flush flag, but we have
// a larger TODO to remove SkGrPixelRef entirely.
context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make(0,0),
GrContext::kFlushWrites_PixelOp);
SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPremul_SkAlphaType,
dstPT);
SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst));
SkSafeUnref(dst);
return pixelRef;
}
示例14: createCachedMask
GrTexture* GrClipMaskManager::createCachedMask(int width, int height, const GrUniqueKey& key,
bool renderTarget) {
GrSurfaceDesc desc;
desc.fWidth = width;
desc.fHeight = height;
desc.fFlags = renderTarget ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
if (!renderTarget || fDrawTarget->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
desc.fConfig = kAlpha_8_GrPixelConfig;
} else {
desc.fConfig = kRGBA_8888_GrPixelConfig;
}
GrTexture* texture = fDrawTarget->cmmAccess().resourceProvider()->createApproxTexture(desc, 0);
if (!texture) {
return nullptr;
}
texture->resourcePriv().setUniqueKey(key);
return texture;
}
示例15: wrap_tex_test
void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) {
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->getGpu());
GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig,
false);
const GrVkImageInfo* backendTex = reinterpret_cast<const GrVkImageInfo*>(backendObj);
// check basic borrowed creation
GrBackendTextureDesc desc;
desc.fConfig = kPixelConfig;
desc.fWidth = kW;
desc.fHeight = kH;
desc.fTextureHandle = backendObj;
GrTexture* tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
tex->unref();
// image is null
GrVkImageInfo backendCopy = *backendTex;
backendCopy.fImage = VK_NULL_HANDLE;
desc.fTextureHandle = (GrBackendObject) &backendCopy;
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// alloc is null
backendCopy.fImage = backendTex->fImage;
backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0 };
tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, !tex);
// check adopt creation
backendCopy.fAlloc = backendTex->fAlloc;
tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership);
REPORTER_ASSERT(reporter, tex);
tex->unref();
gpu->deleteTestingOnlyBackendTexture(backendObj, true);
}