本文整理汇总了C++中GrContext::drawRect方法的典型用法代码示例。如果您正苦于以下问题:C++ GrContext::drawRect方法的具体用法?C++ GrContext::drawRect怎么用?C++ GrContext::drawRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrContext
的用法示例。
在下文中一共展示了GrContext::drawRect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: filterImageGPU
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
const SkBitmap& src,
const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap background = src;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &background,
&backgroundOffset)) {
return onFilterImage(proxy, src, ctx, result, offset);
}
GrTexture* backgroundTex = background.getTexture();
SkBitmap foreground = src;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (getInput(1) && !getInput(1)->getInputResultGPU(proxy, src, ctx, &foreground,
&foregroundOffset)) {
return onFilterImage(proxy, src, ctx, result, offset);
}
GrTexture* foregroundTex = foreground.getTexture();
GrContext* context = foregroundTex->getContext();
GrFragmentProcessor* xferProcessor = NULL;
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag | kNoStencil_GrSurfaceFlag;
desc.fWidth = src.width();
desc.fHeight = src.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
if (!dst) {
return false;
}
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
if (!fMode || !fMode->asFragmentProcessor(&xferProcessor, backgroundTex)) {
// canFilterImageGPU() should've taken care of this
SkASSERT(false);
return false;
}
SkMatrix foregroundMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(foregroundTex);
foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOffset.fX),
SkIntToScalar(backgroundOffset.fY-foregroundOffset.fY));
SkRect srcRect;
src.getBounds(&srcRect);
GrPaint paint;
paint.addColorTextureProcessor(foregroundTex, foregroundMatrix);
paint.addColorProcessor(xferProcessor)->unref();
context->drawRect(paint, srcRect);
offset->fX = backgroundOffset.fX;
offset->fY = backgroundOffset.fY;
WrapTexture(dst, src.width(), src.height(), result);
return true;
}
示例2: filterImageGPU
bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, SkBitmap* result) {
#if SK_SUPPORT_GPU
SkBitmap input;
SkASSERT(fInputCount == 1);
if (!SkImageFilterUtils::GetInputResultGPU(this->getInput(0), proxy, src, &input)) {
return false;
}
GrTexture* srcTexture = (GrTexture*) input.getTexture();
SkRect rect;
src.getBounds(&rect);
GrContext* context = srcTexture->getContext();
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit,
desc.fWidth = input.width();
desc.fHeight = input.height();
desc.fConfig = kRGBA_8888_GrPixelConfig;
GrAutoScratchTexture dst(context, desc);
GrContext::AutoMatrix am;
am.setIdentity(context);
GrContext::AutoRenderTarget art(context, dst.texture()->asRenderTarget());
GrContext::AutoClip acs(context, rect);
GrEffectRef* effect;
this->asNewEffect(&effect, srcTexture);
SkASSERT(effect);
SkAutoUnref effectRef(effect);
GrPaint paint;
paint.colorStage(0)->setEffect(effect);
context->drawRect(paint, rect);
SkAutoTUnref<GrTexture> resultTex(dst.detach());
SkImageFilterUtils::WrapTexture(resultTex, input.width(), input.height(), result);
return true;
#else
return false;
#endif
}
示例3: filterImageGPU
bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
SkBitmap* result, SkIPoint* offset) const {
SkBitmap colorBM = src;
SkIPoint colorOffset = SkIPoint::Make(0, 0);
if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM,
&colorOffset)) {
return false;
}
SkBitmap displacementBM = src;
SkIPoint displacementOffset = SkIPoint::Make(0, 0);
if (getDisplacementInput() &&
!getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
&displacementOffset)) {
return false;
}
SkIRect bounds;
// Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to
// pad the color bitmap to bounds here.
if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) {
return false;
}
SkIRect displBounds;
if (!this->applyCropRect(ctx, proxy, displacementBM,
&displacementOffset, &displBounds, &displacementBM)) {
return false;
}
if (!bounds.intersect(displBounds)) {
return false;
}
GrTexture* color = colorBM.getTexture();
GrTexture* displacement = displacementBM.getTexture();
GrContext* context = color->getContext();
GrSurfaceDesc desc;
desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fWidth = bounds.width();
desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch));
if (!dst) {
return false;
}
SkVector scale = SkVector::Make(fScale, fScale);
ctx.ctm().mapVectors(&scale, 1);
GrPaint paint;
SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacement);
offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.fX),
SkIntToScalar(colorOffset.fY - displacementOffset.fY));
paint.addColorProcessor(
GrDisplacementMapEffect::Create(fXChannelSelector,
fYChannelSelector,
scale,
displacement,
offsetMatrix,
color,
colorBM.dimensions()))->unref();
SkIRect colorBounds = bounds;
colorBounds.offset(-colorOffset);
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
-SkIntToScalar(colorBounds.y()));
context->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, matrix,
SkRect::Make(colorBounds));
offset->fX = bounds.left();
offset->fY = bounds.top();
WrapTexture(dst, bounds.width(), bounds.height(), result);
return true;
}
示例4: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkDevice* device = canvas->getDevice();
GrRenderTarget* target = (GrRenderTarget*) device->accessRenderTarget();
GrContext* ctx = GetGr();
if (ctx && target) {
SkPMColor gTextureData[(2 * S) * (2 * S)];
static const int stride = 2 * S;
static const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
static const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
static const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
static const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
static const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
static const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
for (int i = 0; i < 2; ++i) {
int offset = 0;
// fill upper-left
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
// fill upper-right
offset = S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = white;
}
}
// fill lower left
offset = S * stride;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = black;
}
}
// fill lower right
offset = S * stride + S;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] = gray;
}
}
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;
GrTexture* texture =
ctx->createUncachedTexture(desc, gTextureData, 0);
if (!texture) {
return;
}
GrAutoUnref au(texture);
ctx->setClip(GrRect::MakeWH(2*S, 2*S));
ctx->setRenderTarget(target);
GrPaint paint;
paint.reset();
paint.fColor = 0xffffffff;
paint.fSrcBlendCoeff = kOne_BlendCoeff;
paint.fDstBlendCoeff = kISA_BlendCoeff;
GrMatrix vm;
if (i) {
vm.setRotate(90 * SK_Scalar1,
S * SK_Scalar1,
S * SK_Scalar1);
} else {
vm.reset();
}
ctx->setMatrix(vm);
GrMatrix tm;
tm = vm;
tm.postIDiv(2*S, 2*S);
paint.textureSampler(0)->setMatrix(tm);
paint.setTexture(0, texture);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
// now update the lower right of the texture in first pass
// or upper right in second pass
offset = 0;
for (int y = 0; y < S; ++y) {
for (int x = 0; x < S; ++x) {
gTextureData[offset + y * stride + x] =
((x + y) % 2) ? (i ? green : red) : blue;
}
}
texture->writePixels(S, (i ? 0 : S), S, S,
texture->config(), gTextureData,
4 * stride);
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
}
}
}
示例5: filterImageGPU
bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
const SkBitmap& src,
const SkMatrix& ctm,
SkBitmap* result,
SkIPoint* offset) {
SkBitmap background;
SkIPoint backgroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(0), proxy, src, ctm, &background,
&backgroundOffset)) {
return false;
}
GrTexture* backgroundTex = background.getTexture();
SkBitmap foreground;
SkIPoint foregroundOffset = SkIPoint::Make(0, 0);
if (!SkImageFilterUtils::GetInputResultGPU(getInput(1), proxy, src, ctm, &foreground,
&foregroundOffset)) {
return false;
}
GrTexture* foregroundTex = foreground.getTexture();
GrContext* context = foregroundTex->getContext();
GrEffectRef* xferEffect = NULL;
GrTextureDesc desc;
desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit;
desc.fWidth = src.width();
desc.fHeight = src.height();
desc.fConfig = kSkia8888_GrPixelConfig;
GrAutoScratchTexture ast(context, desc);
SkAutoTUnref<GrTexture> dst(ast.detach());
GrContext::AutoRenderTarget art(context, dst->asRenderTarget());
SkXfermode::Coeff sm, dm;
if (!SkXfermode::AsNewEffectOrCoeff(fMode, &xferEffect, &sm, &dm, backgroundTex)) {
return false;
}
SkMatrix foregroundMatrix = GrEffect::MakeDivByTextureWHMatrix(foregroundTex);
foregroundMatrix.preTranslate(SkIntToScalar(backgroundOffset.fX-foregroundOffset.fX),
SkIntToScalar(backgroundOffset.fY-foregroundOffset.fY));
SkRect srcRect;
src.getBounds(&srcRect);
if (NULL != xferEffect) {
GrPaint paint;
paint.addColorTextureEffect(foregroundTex, foregroundMatrix);
paint.addColorEffect(xferEffect)->unref();
context->drawRect(paint, srcRect);
} else {
GrPaint backgroundPaint;
SkMatrix backgroundMatrix = GrEffect::MakeDivByTextureWHMatrix(backgroundTex);
backgroundPaint.addColorTextureEffect(backgroundTex, backgroundMatrix);
context->drawRect(backgroundPaint, srcRect);
GrPaint foregroundPaint;
foregroundPaint.setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm));
foregroundPaint.addColorTextureEffect(foregroundTex, foregroundMatrix);
context->drawRect(foregroundPaint, srcRect);
}
offset->fX += backgroundOffset.fX;
offset->fY += backgroundOffset.fY;
return SkImageFilterUtils::WrapTexture(dst, src.width(), src.height(), result);
}