本文整理汇总了C++中SkPaint::setFilterLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ SkPaint::setFilterLevel方法的具体用法?C++ SkPaint::setFilterLevel怎么用?C++ SkPaint::setFilterLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkPaint
的用法示例。
在下文中一共展示了SkPaint::setFilterLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkRect srcR;
srcR.set(fSrcPts[0], fSrcPts[1]);
srcR = SkRect::MakeXYWH(fSrcPts[0].fX, fSrcPts[0].fY, 32, 32);
srcR.offset(-srcR.width()/2, -srcR.height()/2);
SkPaint paint;
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(SK_ColorYELLOW);
SkBitmap bitmap;
make_bitmap(&bitmap);
canvas->translate(20, 20);
canvas->drawBitmap(bitmap, 0, 0, &paint);
canvas->drawRect(srcR, paint);
for (int i = 0; i < 2; ++i) {
paint.setFilterLevel(1 == i ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
canvas->drawBitmapRectToRect(bitmap, &srcR, fDstR[i], &paint);
canvas->drawRect(fDstR[i], paint);
}
this->bounce();
this->inval(NULL);
}
示例2: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkBitmap bm;
SkIRect center;
make_bitmap(&bm, ¢er);
// amount of bm that should not be stretched (unless we have to)
const SkScalar fixed = SkIntToScalar(bm.width() - center.width());
const SkTSize<SkScalar> size[] = {
{ fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
{ fixed * 4 / 5, fixed * 4 }, // shrink in X
{ fixed * 4, fixed * 4 / 5 }, // shrink in Y
{ fixed * 4, fixed * 4 }
};
canvas->drawBitmap(bm, SkIntToScalar(10), SkIntToScalar(10), NULL);
SkScalar x = SkIntToScalar(100);
SkScalar y = SkIntToScalar(100);
SkPaint paint;
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
for (int iy = 0; iy < 2; ++iy) {
for (int ix = 0; ix < 2; ++ix) {
int i = ix * 2 + iy;
SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed,
size[i].width(), size[i].height());
canvas->drawBitmapNine(bm, center, r, &paint);
}
}
}
示例3: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
canvas->translate(this->width()/2, this->height()/2);
Sk3DView view;
view.rotateX(fRX);
view.rotateY(fRY);
view.applyToCanvas(canvas);
SkPaint paint;
if (fShaders.count() > 0) {
bool frontFace = view.dotWithNormal(0, 0, SK_Scalar1) < 0;
if (frontFace != fFrontFace) {
fFrontFace = frontFace;
fShaderIndex = (fShaderIndex + 1) % fShaders.count();
}
paint.setAntiAlias(true);
paint.setShader(fShaders[fShaderIndex]);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
SkRect r = { -150, -150, 150, 150 };
canvas->drawRoundRect(r, 30, 30, paint);
}
fRY += SampleCode::GetAnimSecondsDelta() * 90;
if (fRY >= SkIntToScalar(360)) {
fRY = 0;
}
this->inval(NULL);
}
示例4: onDraw
virtual void onDraw(SkCanvas* canvas) {
SkMatrix m;
m.reset();
m.setRotate(33 * SK_Scalar1);
m.postScale(3000 * SK_Scalar1, 3000 * SK_Scalar1);
m.postTranslate(6000 * SK_Scalar1, -5000 * SK_Scalar1);
canvas->concat(m);
SkPaint paint;
paint.setColor(SK_ColorRED);
paint.setAntiAlias(true);
bool success = m.invert(&m);
SkASSERT(success);
(void) success; // silence compiler :(
SkPath path;
SkPoint pt = {10 * SK_Scalar1, 10 * SK_Scalar1};
SkScalar small = 1 / (500 * SK_Scalar1);
m.mapPoints(&pt, 1);
path.addCircle(pt.fX, pt.fY, small);
canvas->drawPath(path, paint);
pt.set(30 * SK_Scalar1, 10 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkRect rect = {pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small};
canvas->drawRect(rect, paint);
SkBitmap bmp;
bmp.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
bmp.allocPixels();
bmp.lockPixels();
uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels());
pixels[0] = SkPackARGB32(0xFF, 0xFF, 0x00, 0x00);
pixels[1] = SkPackARGB32(0xFF, 0x00, 0xFF, 0x00);
pixels[2] = SkPackARGB32(0x80, 0x00, 0x00, 0x00);
pixels[3] = SkPackARGB32(0xFF, 0x00, 0x00, 0xFF);
bmp.unlockPixels();
pt.set(30 * SK_Scalar1, 30 * SK_Scalar1);
m.mapPoints(&pt, 1);
SkShader* shader = SkShader::CreateBitmapShader(
bmp,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
SkMatrix s;
s.reset();
s.setScale(SK_Scalar1 / 1000, SK_Scalar1 / 1000);
shader->setLocalMatrix(s);
paint.setShader(shader)->unref();
paint.setAntiAlias(false);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
rect.setLTRB(pt.fX - small, pt.fY - small,
pt.fX + small, pt.fY + small);
canvas->drawRect(rect, paint);
}
示例5: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
SkIRect srcRect;
SkRect dstRect;
SkPaint paint;
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
// Test that bitmap draws from malloc-backed bitmaps respect
// the constrained texture domain.
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(fBM, &srcRect, dstRect, &paint);
// Test that bitmap draws across separate devices also respect
// the constrainted texture domain.
// Note: GPU-backed bitmaps follow a different rendering path
// when copying from one GPU device to another.
SkAutoTUnref<SkBaseDevice> secondDevice(canvas->createCompatibleDevice(
SkBitmap::kARGB_8888_Config, 5, 5, true));
SkCanvas secondCanvas(secondDevice.get());
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(1.0f, 1.0f, 3.0f, 3.0f);
secondCanvas.drawBitmapRect(fBM, &srcRect, dstRect, &paint);
SkBitmap deviceBitmap = secondDevice->accessBitmap(false);
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(405.0f, 5.0f, 305.0f, 305.0f);
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Test that bitmap blurring using a subrect
// renders correctly
srcRect.setXYWH(1, 1, 3, 3);
dstRect.setXYWH(5.0f, 405.0f, 305.0f, 305.0f);
SkMaskFilter* mf = SkBlurMaskFilter::Create(
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkBlurMaskFilter::kHighQuality_BlurFlag |
SkBlurMaskFilter::kIgnoreTransform_BlurFlag);
paint.setMaskFilter(mf)->unref();
canvas->drawBitmapRect(deviceBitmap, &srcRect, dstRect, &paint);
// Blur and a rotation + NULL src rect
// This should not trigger the texture domain code
// but it will test a code path in SkGpuDevice::drawBitmap
// that handles blurs with rects transformed to non-
// orthogonal rects. It also tests the NULL src rect handling
mf = SkBlurMaskFilter::Create(
SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)),
SkBlurMaskFilter::kHighQuality_BlurFlag);
paint.setMaskFilter(mf)->unref();
dstRect.setXYWH(-150.0f, -150.0f, 300.0f, 300.0f);
canvas->translate(550, 550);
canvas->rotate(45);
canvas->drawBitmapRect(fBM, NULL, dstRect, &paint);
}
示例6: draw_row
static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) {
SkPaint paint;
SkAutoCanvasRestore acr(canvas, true);
canvas->drawBitmapMatrix(bm, mat, &paint);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
canvas->translate(dx, 0);
canvas->drawBitmapMatrix(bm, mat, &paint);
paint.setFilterLevel(SkPaint::kMedium_FilterLevel);
canvas->translate(dx, 0);
canvas->drawBitmapMatrix(bm, mat, &paint);
paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
canvas->translate(dx, 0);
canvas->drawBitmapMatrix(bm, mat, &paint);
}
示例7: OnDraw
void Panel::OnDraw(SkCanvas* canvas, const SkRect& clip_rect) {
SkPaint paint;
paint.setFilterLevel(SkPaint::kMedium_FilterLevel);
SkRect rect = SkRect::MakeXYWH(
SkIntToScalar(0), SkIntToScalar(0),
SkIntToScalar(Width()), SkIntToScalar(Height()));
auto bitmaps = Bitmap();
!bitmaps.empty() ? GetRenderTactics()->Draw(canvas, bitmaps[0], rect, paint) :
canvas->clear(SK_AlphaTRANSPARENT);
}
示例8: onFilterImage
bool SkDownSampleImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src,
const Context&,
SkBitmap* result, SkIPoint*) const {
SkScalar scale = fScale;
if (scale > SK_Scalar1 || scale <= 0) {
return false;
}
int dstW = SkScalarRoundToInt(src.width() * scale);
int dstH = SkScalarRoundToInt(src.height() * scale);
if (dstW < 1) {
dstW = 1;
}
if (dstH < 1) {
dstH = 1;
}
SkBitmap tmp;
// downsample
{
SkBaseDevice* dev = proxy->createDevice(dstW, dstH);
if (NULL == dev) {
return false;
}
OwnDeviceCanvas canvas(dev);
SkPaint paint;
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
canvas.scale(scale, scale);
canvas.drawBitmap(src, 0, 0, &paint);
tmp = dev->accessBitmap(false);
}
// upscale
{
SkBaseDevice* dev = proxy->createDevice(src.width(), src.height());
if (NULL == dev) {
return false;
}
OwnDeviceCanvas canvas(dev);
SkRect r = SkRect::MakeWH(SkIntToScalar(src.width()),
SkIntToScalar(src.height()));
canvas.drawBitmapRect(tmp, NULL, r, NULL);
*result = dev->accessBitmap(false);
}
return true;
}
示例9: SkIntToScalar
// Draw ~1/4 of the large bitmap
void drawCase3(SkCanvas* canvas, int transX, int transY,
SkCanvas::DrawBitmapRectFlags flags, SkPaint::FilterLevel filter) {
SkRect src = SkRect::MakeXYWH(2, 2,
SkIntToScalar(fBitmapBig.width()/2-2),
SkIntToScalar(fBitmapBig.height()/2-2));
SkRect dst = SkRect::MakeXYWH(0, 0, SkIntToScalar(kBlockSize), SkIntToScalar(kBlockSize));
SkPaint paint;
paint.setFilterLevel(filter);
canvas->save();
canvas->translate(SkIntToScalar(transX), SkIntToScalar(transY));
canvas->drawBitmapRectToRect(fBitmapBig, &src, dst, &paint, flags);
canvas->restore();
}
示例10: onDrawContent
virtual void onDrawContent(SkCanvas* canvas) {
canvas->translate(SkIntToScalar(10), SkIntToScalar(50));
const SkScalar W = SkIntToScalar(fBitmaps[0].width() + 1);
const SkScalar H = SkIntToScalar(fBitmaps[0].height() + 1);
SkPaint paint;
const SkScalar scale = 0.897917f;
canvas->scale(SK_Scalar1, scale);
for (int k = 0; k < 2; k++) {
paint.setFilterLevel(k == 1 ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel);
for (int j = 0; j < 2; j++) {
paint.setDither(j == 1);
for (int i = 0; i < fBitmapCount; i++) {
SkScalar x = (k * fBitmapCount + j) * W;
SkScalar y = i * H;
x = SkScalarRoundToScalar(x);
y = SkScalarRoundToScalar(y);
canvas->drawBitmap(fBitmaps[i], x, y, &paint);
if (i == 0) {
SkPaint p;
p.setAntiAlias(true);
p.setTextAlign(SkPaint::kCenter_Align);
p.setTextSize(SkIntToScalar(18));
SkString s("dither=");
s.appendS32(paint.isDither());
s.append(" filter=");
s.appendS32(paint.getFilterLevel() != SkPaint::kNone_FilterLevel);
canvas->drawText(s.c_str(), s.size(), x + W/2,
y - p.getTextSize(), p);
}
if (k+j == 2) {
SkPaint p;
p.setAntiAlias(true);
p.setTextSize(SkIntToScalar(18));
SkString s;
s.append(" depth=");
s.appendS32(fBitmaps[i].colorType() == kRGB_565_SkColorType ? 16 : 32);
canvas->drawText(s.c_str(), s.size(), x + W + SkIntToScalar(4),
y + H/2, p);
}
}
}
}
}
示例11: mesh_slide
static void mesh_slide(SkCanvas* canvas) {
Rec fRecs[3];
SkIPoint size;
SkShader* fShader0 = make_shader0(&size);
SkShader* fShader1 = make_shader1(size);
SkAutoUnref aur0(fShader0);
SkAutoUnref aur1(fShader1);
make_strip(&fRecs[0], size.fX, size.fY);
make_fan(&fRecs[1], size.fX, size.fY);
make_tris(&fRecs[2]);
SkPaint paint;
paint.setDither(true);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
canvas->save();
paint.setShader(NULL);
canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
fRecs[i].fVerts, fRecs[i].fTexs,
NULL, NULL, NULL, 0, paint);
canvas->translate(SkIntToScalar(210), 0);
paint.setShader(fShader0);
canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
fRecs[i].fVerts, fRecs[i].fTexs,
NULL, NULL, NULL, 0, paint);
canvas->translate(SkIntToScalar(210), 0);
paint.setShader(fShader1);
canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount,
fRecs[i].fVerts, fRecs[i].fTexs,
NULL, NULL, NULL, 0, paint);
canvas->restore();
canvas->translate(0, SkIntToScalar(250));
}
}
示例12: onFilterImage
bool SkMatrixImageFilter::onFilterImage(Proxy* proxy,
const SkBitmap& source,
const Context& ctx,
SkBitmap* result,
SkIPoint* offset) const {
SkBitmap src = source;
SkIPoint srcOffset = SkIPoint::Make(0, 0);
if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcOffset)) {
return false;
}
SkRect dstRect;
SkIRect srcBounds, dstBounds;
src.getBounds(&srcBounds);
srcBounds.offset(srcOffset);
SkRect srcRect = SkRect::Make(srcBounds);
SkMatrix matrix;
if (!ctx.ctm().invert(&matrix)) {
return false;
}
matrix.postConcat(fTransform);
matrix.postConcat(ctx.ctm());
matrix.mapRect(&dstRect, srcRect);
dstRect.roundOut(&dstBounds);
SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(dstBounds.width(), dstBounds.height()));
if (NULL == device.get()) {
return false;
}
SkCanvas canvas(device.get());
canvas.translate(-SkIntToScalar(dstBounds.x()), -SkIntToScalar(dstBounds.y()));
canvas.concat(matrix);
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
paint.setFilterLevel(fFilterLevel);
canvas.drawBitmap(src, srcRect.x(), srcRect.y(), &paint);
*result = device.get()->accessBitmap(false);
offset->fX = dstBounds.fLeft;
offset->fY = dstBounds.fTop;
return true;
}
开发者ID:xin3liang,项目名称:platform_external_chromium_org_third_party_skia,代码行数:44,代码来源:SkMatrixImageFilter.cpp
示例13: destCanvas
static void
Transform(DataSourceSurface* aDest,
DataSourceSurface* aSource,
const gfx3DMatrix& aTransform,
const Point& aDestOffset)
{
if (aTransform.IsSingular()) {
return;
}
IntSize destSize = aDest->GetSize();
SkImageInfo destInfo = SkImageInfo::Make(destSize.width,
destSize.height,
kBGRA_8888_SkColorType,
kPremul_SkAlphaType);
SkBitmap destBitmap;
destBitmap.setInfo(destInfo, aDest->Stride());
destBitmap.setPixels((uint32_t*)aDest->GetData());
SkCanvas destCanvas(destBitmap);
IntSize srcSize = aSource->GetSize();
SkImageInfo srcInfo = SkImageInfo::Make(srcSize.width,
srcSize.height,
kBGRA_8888_SkColorType,
kPremul_SkAlphaType);
SkBitmap src;
src.setInfo(srcInfo, aSource->Stride());
src.setPixels((uint32_t*)aSource->GetData());
gfx3DMatrix transform = aTransform;
transform.TranslatePost(Point3D(-aDestOffset.x, -aDestOffset.y, 0));
destCanvas.setMatrix(Matrix3DToSkia(transform));
SkPaint paint;
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
paint.setAntiAlias(true);
paint.setFilterLevel(SkPaint::kLow_FilterLevel);
SkRect destRect = SkRect::MakeXYWH(0, 0, srcSize.width, srcSize.height);
destCanvas.drawBitmapRectToRect(src, nullptr, destRect, &paint);
}
示例14: switch
static void
SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, TempBitmap& aTmpBitmap,
Float aAlpha = 1.0)
{
switch (aPattern.GetType()) {
case PatternType::COLOR: {
Color color = static_cast<const ColorPattern&>(aPattern).mColor;
aPaint.setColor(ColorToSkColor(color, aAlpha));
break;
}
case PatternType::LINEAR_GRADIENT: {
const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mBegin.x), SkFloatToScalar(pat.mBegin.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mEnd.x), SkFloatToScalar(pat.mEnd.y));
SkShader* shader = SkGradientShader::CreateLinear(points,
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
mode);
if (shader) {
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
}
} else {
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
break;
}
case PatternType::RADIAL_GRADIENT: {
const RadialGradientPattern& pat = static_cast<const RadialGradientPattern&>(aPattern);
GradientStopsSkia *stops = static_cast<GradientStopsSkia*>(pat.mStops.get());
SkShader::TileMode mode = ExtendModeToTileMode(stops->mExtendMode);
if (stops->mCount >= 2) {
SkPoint points[2];
points[0] = SkPoint::Make(SkFloatToScalar(pat.mCenter1.x), SkFloatToScalar(pat.mCenter1.y));
points[1] = SkPoint::Make(SkFloatToScalar(pat.mCenter2.x), SkFloatToScalar(pat.mCenter2.y));
SkShader* shader = SkGradientShader::CreateTwoPointConical(points[0],
SkFloatToScalar(pat.mRadius1),
points[1],
SkFloatToScalar(pat.mRadius2),
&stops->mColors.front(),
&stops->mPositions.front(),
stops->mCount,
mode);
if (shader) {
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
}
} else {
aPaint.setColor(SkColorSetARGB(0, 0, 0, 0));
}
break;
}
case PatternType::SURFACE: {
const SurfacePattern& pat = static_cast<const SurfacePattern&>(aPattern);
aTmpBitmap = GetBitmapForSurface(pat.mSurface);
const SkBitmap& bitmap = aTmpBitmap.mBitmap;
SkShader::TileMode mode = ExtendModeToTileMode(pat.mExtendMode);
SkShader* shader = SkShader::CreateBitmapShader(bitmap, mode, mode);
SkMatrix mat;
GfxMatrixToSkiaMatrix(pat.mMatrix, mat);
shader->setLocalMatrix(mat);
SkSafeUnref(aPaint.setShader(shader));
if (pat.mFilter == Filter::POINT) {
aPaint.setFilterLevel(SkPaint::kNone_FilterLevel);
}
break;
}
}
}
示例15: drawPattern
//.........这里部分代码省略.........
FloatRect normSrcRect = floatSrcRect;
normSrcRect.intersect(FloatRect(0, 0, bitmap().width(), bitmap().height()));
if (destRect.isEmpty() || normSrcRect.isEmpty())
return; // nothing to draw
SkMatrix totalMatrix = context->getTotalMatrix();
SkScalar ctmScaleX = totalMatrix.getScaleX();
SkScalar ctmScaleY = totalMatrix.getScaleY();
totalMatrix.preScale(scale.width(), scale.height());
// Figure out what size the bitmap will be in the destination. The
// destination rect is the bounds of the pattern, we need to use the
// matrix to see how big it will be.
SkRect destRectTarget;
totalMatrix.mapRect(&destRectTarget, normSrcRect);
float destBitmapWidth = SkScalarToFloat(destRectTarget.width());
float destBitmapHeight = SkScalarToFloat(destRectTarget.height());
// Compute the resampling mode.
ResamplingMode resampling;
if (context->isAccelerated() || context->printing())
resampling = LinearResampling;
else
resampling = computeResamplingMode(totalMatrix, normSrcRect.width(), normSrcRect.height(), destBitmapWidth, destBitmapHeight);
resampling = limitResamplingMode(context, resampling);
SkMatrix shaderTransform;
RefPtr<SkShader> shader;
bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap());
// Bicubic filter is only applied to defer-decoded images, see
// NativeImageSkia::draw for details.
bool useBicubicFilter = resampling == AwesomeResampling && isLazyDecoded;
if (resampling == AwesomeResampling && !useBicubicFilter) {
// Do nice resampling.
float scaleX = destBitmapWidth / normSrcRect.width();
float scaleY = destBitmapHeight / normSrcRect.height();
SkRect scaledSrcRect;
// The image fragment generated here is not exactly what is
// requested. The scale factor used is approximated and image
// fragment is slightly larger to align to integer
// boundaries.
SkBitmap resampled = extractScaledImageFragment(normSrcRect, scaleX, scaleY, &scaledSrcRect);
if (repeatSpacing.isZero()) {
shader = adoptRef(SkShader::CreateBitmapShader(resampled, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
} else {
shader = adoptRef(SkShader::CreateBitmapShader(
createBitmapWithSpace(resampled, repeatSpacing.width() * ctmScaleX, repeatSpacing.height() * ctmScaleY),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
}
// Since we just resized the bitmap, we need to remove the scale
// applied to the pixels in the bitmap shader. This means we need
// CTM * shaderTransform to have identity scale. Since we
// can't modify CTM (or the rectangle will be drawn in the wrong
// place), we must set shaderTransform's scale to the inverse of
// CTM scale.
shaderTransform.setScale(ctmScaleX ? 1 / ctmScaleX : 1, ctmScaleY ? 1 / ctmScaleY : 1);
} else {
// No need to resample before drawing.
SkBitmap srcSubset;
bitmap().extractSubset(&srcSubset, enclosingIntRect(normSrcRect));
if (repeatSpacing.isZero()) {
shader = adoptRef(SkShader::CreateBitmapShader(srcSubset, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
} else {
shader = adoptRef(SkShader::CreateBitmapShader(
createBitmapWithSpace(srcSubset, repeatSpacing.width() * ctmScaleX, repeatSpacing.height() * ctmScaleY),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
}
// Because no resizing occurred, the shader transform should be
// set to the pattern's transform, which just includes scale.
shaderTransform.setScale(scale.width(), scale.height());
}
// We also need to translate it such that the origin of the pattern is the
// origin of the destination rect, which is what WebKit expects. Skia uses
// the coordinate system origin as the base for the pattern. If WebKit wants
// a shifted image, it will shift it from there using the shaderTransform.
float adjustedX = phase.x() + normSrcRect.x() * scale.width();
float adjustedY = phase.y() + normSrcRect.y() * scale.height();
shaderTransform.postTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjustedY));
shader->setLocalMatrix(shaderTransform);
SkPaint paint;
paint.setShader(shader.get());
paint.setXfermode(WebCoreCompositeToSkiaComposite(compositeOp, blendMode).get());
paint.setColorFilter(context->colorFilter());
paint.setFilterBitmap(resampling == LinearResampling);
if (useBicubicFilter)
paint.setFilterLevel(SkPaint::kHigh_FilterLevel);
if (isLazyDecoded)
PlatformInstrumentation::didDrawLazyPixelRef(bitmap().getGenerationID());
context->drawRect(destRect, paint);
}