本文整理汇总了C++中SkPaint::getShader方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::getShader方法的具体用法?C++ SkPaint::getShader怎么用?C++ SkPaint::getShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::getShader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: contextRec
DEF_TEST(Color4f_shader, reporter) {
struct {
sk_sp<SkShader> (*fFact)();
bool fSupports4f;
float fTolerance;
} recs[] = {
{ make_color_sh, true, 1.0f/255 },
// PMColor 4f gradients are interpolated in 255-multiplied values, so we need a
// slightly relaxed tolerance to accommodate the cumulative precision deviation.
{ make_grad_sh, true, 1.001f/255 },
{ make_image_sh, false, 1.0f/255 },
{ make_cf_sh, true, 1.0f/255 },
};
SkPaint paint;
for (const auto& rec : recs) {
uint32_t storage[300];
paint.setShader(rec.fFact());
// Encourage 4f context selection. At some point we may need
// to instantiate two separate contexts for optimal 4b/4f selection.
const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr,
SkShader::ContextRec::kPM4f_DstType);
SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage));
SkShader::Context* ctx = paint.getShader()->createContext(contextRec, storage);
if (rec.fSupports4f) {
const int N = 100;
SkPM4f buffer4f[N];
ctx->shadeSpan4f(0, 0, buffer4f, N);
SkPMColor buffer4b[N];
ctx->shadeSpan(0, 0, buffer4b, N);
REPORTER_ASSERT(reporter, compare_spans(buffer4f, buffer4b, N, rec.fTolerance));
}
ctx->~Context();
}
}
示例2: paint
void
DrawTargetSkia::MaskSurface(const Pattern &aSource,
SourceSurface *aMask,
Point aOffset,
const DrawOptions &aOptions)
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
TempBitmap bitmap = GetBitmapForSurface(aMask);
if (bitmap.mBitmap.colorType() == kAlpha_8_SkColorType) {
mCanvas->drawBitmap(bitmap.mBitmap, aOffset.x, aOffset.y, &paint.mPaint);
} else {
SkPaint maskPaint;
TempBitmap tmpBitmap;
SetPaintPattern(maskPaint, SurfacePattern(aMask, ExtendMode::CLAMP), tmpBitmap);
SkMatrix transform = maskPaint.getShader()->getLocalMatrix();
transform.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
maskPaint.getShader()->setLocalMatrix(transform);
SkLayerRasterizer::Builder builder;
builder.addLayer(maskPaint);
SkAutoTUnref<SkRasterizer> raster(builder.detachRasterizer());
paint.mPaint.setRasterizer(raster.get());
IntSize size = aMask->GetSize();
Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height);
mCanvas->drawRect(RectToSkRect(rect), paint.mPaint);
}
}
示例3: paint
void
DrawTargetSkia::MaskSurface(const Pattern &aSource,
SourceSurface *aMask,
Point aOffset,
const DrawOptions &aOptions)
{
MarkChanged();
AutoPaintSetup paint(mCanvas.get(), aOptions, aSource);
SkPaint maskPaint;
TempBitmap tmpBitmap;
SetPaintPattern(maskPaint, SurfacePattern(aMask, ExtendMode::CLAMP), tmpBitmap);
SkMatrix transform = maskPaint.getShader()->getLocalMatrix();
transform.postTranslate(SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y));
maskPaint.getShader()->setLocalMatrix(transform);
SkLayerRasterizer *raster = new SkLayerRasterizer();
raster->addLayer(maskPaint);
SkSafeUnref(paint.mPaint.setRasterizer(raster));
IntSize size = aMask->GetSize();
Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height);
mCanvas->drawRect(RectToSkRect(rect), paint.mPaint);
}
示例4: ShouldDither
bool SkPaintPriv::ShouldDither(const SkPaint& p, SkColorType dstCT) {
// The paint dither flag can veto.
if (!p.isDither()) {
return false;
}
// We always dither 565 or 4444 when requested.
if (dstCT == kRGB_565_SkColorType || dstCT == kARGB_4444_SkColorType) {
return true;
}
// Otherwise, dither is only needed for non-const paints.
return p.getImageFilter() || p.getMaskFilter()
|| !p.getShader() || !as_SB(p.getShader())->isConstant();
}
示例5: onDrawContent
void onDrawContent(SkCanvas* canvas) override {
const int nu = 10;
const int nv = 10;
SkPaint paint;
paint.setDither(true);
paint.setFilterQuality(kLow_SkFilterQuality);
canvas->translate(DX, DY);
Patch patch;
paint.setShader(fShader0);
if (fSize0.fX == 0) {
fSize0.fX = 1;
}
if (fSize0.fY == 0) {
fSize0.fY = 1;
}
patch.setBounds(fSize0.fX, fSize0.fY);
patch.setPatch(fPts);
drawpatches(canvas, paint, nu, nv, &patch);
paint.setShader(nullptr);
paint.setAntiAlias(true);
paint.setStrokeWidth(SkIntToScalar(5));
canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fPts, paint);
canvas->translate(0, SkIntToScalar(300));
paint.setAntiAlias(false);
paint.setShader(fShader1);
if (true) {
SkMatrix m;
m.setSkew(1, 0);
SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m);
paint.setShader(s)->unref();
}
if (true) {
SkMatrix m;
m.setRotate(fAngle);
SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m);
paint.setShader(s)->unref();
}
patch.setBounds(fSize1.fX, fSize1.fY);
drawpatches(canvas, paint, nu, nv, &patch);
}
示例6: apply
SkPaint SkColorSpaceXformer::apply(const SkPaint& src) {
const AutoCachePurge autoPurge(this);
SkPaint dst = src;
// All SkColorSpaces have the same black point.
if (src.getColor() & 0xffffff) {
dst.setColor(this->apply(src.getColor()));
}
if (auto shader = src.getShader()) {
dst.setShader(this->apply(shader));
}
if (auto cf = src.getColorFilter()) {
dst.setColorFilter(this->apply(cf));
}
if (auto looper = src.getDrawLooper()) {
dst.setDrawLooper(looper->makeColorSpace(this));
}
if (auto imageFilter = src.getImageFilter()) {
dst.setImageFilter(this->apply(imageFilter));
}
return dst;
}
示例7: drawPathWithMaskFilter
void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
GrDrawContext* drawContext,
const GrClip& clip,
const SkPath& origPath,
const SkPaint& paint,
const SkMatrix& origViewMatrix,
const SkMatrix* prePathMatrix,
const SkIRect& clipBounds,
bool pathIsMutable) {
SkASSERT(!pathIsMutable || origPath.isVolatile());
GrStyle style(paint);
// If we have a prematrix, apply it to the path, optimizing for the case
// where the original path can in fact be modified in place (even though
// its parameter type is const).
const SkPath* path = &origPath;
SkTLazy<SkPath> tmpPath;
SkMatrix viewMatrix = origViewMatrix;
if (prePathMatrix) {
// Styling, blurs, and shading are supposed to be applied *after* the prePathMatrix.
if (!paint.getMaskFilter() && !paint.getShader() && !style.applies()) {
viewMatrix.preConcat(*prePathMatrix);
} else {
SkPath* result = pathIsMutable ? const_cast<SkPath*>(path) : tmpPath.init();
pathIsMutable = true;
path->transform(*prePathMatrix, result);
path = result;
result->setIsVolatile(true);
}
}
// at this point we're done with prePathMatrix
SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
示例8: SkPaint2GrPaint
bool SkPaint2GrPaint(GrContext* context, GrRenderTarget* rt, const SkPaint& skPaint,
const SkMatrix& viewM, bool constantColor, GrPaint* grPaint) {
SkShader* shader = skPaint.getShader();
if (NULL == shader) {
return SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.getColor()),
constantColor, grPaint);
}
GrColor paintColor = SkColor2GrColor(skPaint.getColor());
// Start a new block here in order to preserve our context state after calling
// asFragmentProcessor(). Since these calls get passed back to the client, we don't really
// want them messing around with the context.
{
// Allow the shader to modify paintColor and also create an effect to be installed as
// the first color effect on the GrPaint.
GrFragmentProcessor* fp = NULL;
if (!shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintColor,
grPaint->getProcessorDataManager(), &fp)) {
return false;
}
if (fp) {
grPaint->addColorProcessor(fp)->unref();
constantColor = false;
}
}
// The grcolor is automatically set when calling asFragmentProcessor.
// If the shader can be seen as an effect it returns true and adds its effect to the grpaint.
return SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grPaint);
}
示例9: onDrawPaint
void SkOverdrawCanvas::onDrawPaint(const SkPaint& paint) {
if (0 == paint.getColor() && !paint.getColorFilter() && !paint.getShader()) {
// This is a clear, ignore it.
} else {
fList[0]->onDrawPaint(this->overdrawPaint(paint));
}
}
示例10: INHERITED
SkRGB16_Black_Blitter::SkRGB16_Black_Blitter(const SkPixmap& device, const SkPaint& paint)
: INHERITED(device, paint) {
SkASSERT(paint.getShader() == nullptr);
SkASSERT(paint.getColorFilter() == nullptr);
SkASSERT(paint.isSrcOver());
SkASSERT(paint.getColor() == SK_ColorBLACK);
}
示例11: test_analysis
/* Hit a few SkPicture::Analysis cases not handled elsewhere. */
static void test_analysis(skiatest::Reporter* reporter) {
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(100, 100);
{
canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
}
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
canvas = recorder.beginRecording(100, 100);
{
SkPaint paint;
// CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shader
// gets optimized into a non-bitmap form, so we create a 2x2 bitmap here.
SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
bitmap.eraseColor(SK_ColorBLUE);
*(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
paint.setShader(SkShader::MakeBitmapShader(bitmap, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode));
REPORTER_ASSERT(reporter, paint.getShader()->isABitmap());
canvas->drawRect(SkRect::MakeWH(10, 10), paint);
}
REPORTER_ASSERT(reporter, recorder.finishRecordingAsPicture()->willPlayBackBitmaps());
}
示例12: SkPaintToGrPaintWithTexture
bool SkPaintToGrPaintWithTexture(GrContext* context,
const SkPaint& paint,
const SkMatrix& viewM,
const GrFragmentProcessor* fp,
bool textureIsAlphaOnly,
GrPaint* grPaint) {
SkAutoTUnref<const GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
if (const SkShader* shader = paint.getShader()) {
shaderFP.reset(shader->asFragmentProcessor(context,
viewM,
nullptr,
paint.getFilterQuality()));
if (!shaderFP) {
return false;
}
const GrFragmentProcessor* fpSeries[] = { shaderFP.get(), fp };
shaderFP.reset(GrFragmentProcessor::RunInSeries(fpSeries, 2));
} else {
shaderFP.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp));
}
} else {
shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
}
return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), grPaint);
}
示例13: SkPaintToGrPaintWithTexture
bool SkPaintToGrPaintWithTexture(GrContext* context,
const GrColorSpaceInfo& colorSpaceInfo,
const SkPaint& paint,
const SkMatrix& viewM,
std::unique_ptr<GrFragmentProcessor> fp,
bool textureIsAlphaOnly,
GrPaint* grPaint) {
std::unique_ptr<GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
if (const auto* shader = as_SB(paint.getShader())) {
shaderFP = shader->asFragmentProcessor(GrFPArgs(
context, &viewM, nullptr, paint.getFilterQuality(), &colorSpaceInfo));
if (!shaderFP) {
return false;
}
std::unique_ptr<GrFragmentProcessor> fpSeries[] = { std::move(shaderFP), std::move(fp) };
shaderFP = GrFragmentProcessor::RunInSeries(fpSeries, 2);
} else {
shaderFP = GrFragmentProcessor::MakeInputPremulAndMulByOutput(std::move(fp));
}
} else {
shaderFP = GrFragmentProcessor::MulChildByInputAlpha(std::move(fp));
}
return SkPaintToGrPaintReplaceShader(context, colorSpaceInfo, paint, std::move(shaderFP),
grPaint);
}
示例14: INHERITED
SkRGB16_Black_Blitter::SkRGB16_Black_Blitter(const SkBitmap& device, const SkPaint& paint)
: INHERITED(device, paint) {
SkASSERT(paint.getShader() == NULL);
SkASSERT(paint.getColorFilter() == NULL);
SkASSERT(paint.getXfermode() == NULL);
SkASSERT(paint.getColor() == SK_ColorBLACK);
}
示例15: apply_paint_shader
static void apply_paint_shader(const SkPaint& paint, Json::Value* target, bool sendBinaries) {
SkFlattenable* shader = paint.getShader();
if (shader != nullptr) {
Json::Value jsonShader;
flatten(shader, &jsonShader, sendBinaries);
(*target)[SKJSONCANVAS_ATTRIBUTE_SHADER] = jsonShader;
}
}