本文整理汇总了C++中SkMatrix::postScale方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMatrix::postScale方法的具体用法?C++ SkMatrix::postScale怎么用?C++ SkMatrix::postScale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMatrix
的用法示例。
在下文中一共展示了SkMatrix::postScale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make_bmp
static SkBitmap make_bmp(int w, int h) {
SkBitmap bmp;
bmp.allocN32Pixels(w, h, true);
SkCanvas canvas(bmp);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
SkPoint pt = { wScalar / 2, hScalar / 2 };
SkScalar radius = 3 * SkMaxScalar(wScalar, hScalar);
SkColor colors[] = { SK_ColorDKGRAY, 0xFF222255,
0xFF331133, 0xFF884422,
0xFF000022, SK_ColorWHITE,
0xFFAABBCC};
SkScalar pos[] = {0,
SK_Scalar1 / 6,
2 * SK_Scalar1 / 6,
3 * SK_Scalar1 / 6,
4 * SK_Scalar1 / 6,
5 * SK_Scalar1 / 6,
SK_Scalar1};
SkPaint paint;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
paint.setShader(SkGradientShader::CreateRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
0, &mat))->unref();
canvas.drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.preTranslate(6 * wScalar, 6 * hScalar);
mat.postScale(SK_Scalar1 / 3, SK_Scalar1 / 3);
}
paint.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&paint);
paint.setTextSize(wScalar / 2.2f);
paint.setShader(0);
paint.setColor(SK_ColorLTGRAY);
static const char kTxt[] = "Skia";
SkPoint texPos = { wScalar / 17, hScalar / 2 + paint.getTextSize() / 2.5f };
canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint);
paint.setColor(SK_ColorBLACK);
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(SK_Scalar1);
canvas.drawText(kTxt, SK_ARRAY_COUNT(kTxt)-1, texPos.fX, texPos.fY, paint);
return bmp;
}
示例2: surface
// Creates a bitmap and a matching image.
static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) {
SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
auto surface(sk_tool_utils::makeSurface(origCanvas, info));
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorTRANSPARENT);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
SkPoint pt = { wScalar / 2, hScalar / 2 };
SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
SK_ColorGREEN, SK_ColorMAGENTA,
SK_ColorBLUE, SK_ColorCYAN,
SK_ColorRED};
SkScalar pos[] = {0,
SK_Scalar1 / 6,
2 * SK_Scalar1 / 6,
3 * SK_Scalar1 / 6,
4 * SK_Scalar1 / 6,
5 * SK_Scalar1 / 6,
SK_Scalar1};
SkPaint paint;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
paint.setShader(SkGradientShader::MakeRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
0, &mat));
canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
}
auto image = surface->makeImageSnapshot();
SkBitmap tempBM;
image->asLegacyBitmap(&tempBM);
// Let backends know we won't change this, so they don't have to deep copy it defensively.
tempBM.setImmutable();
*resultBM = tempBM;
return image;
}
示例3: pts_to_unit_matrix
static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) {
SkVector vec = pts[1] - pts[0];
SkScalar mag = vec.length();
SkScalar inv = mag ? SkScalarInvert(mag) : 0;
vec.scale(inv);
SkMatrix matrix;
matrix.setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
matrix.postTranslate(-pts[0].fX, -pts[0].fY);
matrix.postScale(inv, inv);
return matrix;
}
示例4: setupGLPaintShader
SkGLDevice::TexCache* SkGLDevice::setupGLPaintShader(const SkPaint& paint) {
SkGL::SetPaint(paint);
SkShader* shader = paint.getShader();
if (NULL == shader) {
return NULL;
}
if (!shader->setContext(this->accessBitmap(false), paint, this->matrix())) {
return NULL;
}
SkBitmap bitmap;
SkMatrix matrix;
SkShader::TileMode tileModes[2];
if (!shader->asABitmap(&bitmap, &matrix, tileModes)) {
return NULL;
}
bitmap.lockPixels();
if (!bitmap.readyToDraw()) {
return NULL;
}
// see if we've already cached the bitmap from the shader
SkPoint max;
GLuint name;
TexCache* cache = SkGLDevice::LockTexCache(bitmap, &name, &max);
// the lock has already called glBindTexture for us
SkGL::SetTexParams(paint.isFilterBitmap(), tileModes[0], tileModes[1]);
// since our texture coords will be in local space, we wack the texture
// matrix to map them back into 0...1 before we load it
SkMatrix localM;
if (shader->getLocalMatrix(&localM)) {
SkMatrix inverse;
if (localM.invert(&inverse)) {
matrix.preConcat(inverse);
}
}
matrix.postScale(max.fX / bitmap.width(), max.fY / bitmap.height());
glMatrixMode(GL_TEXTURE);
SkGL::LoadMatrix(matrix);
glMatrixMode(GL_MODELVIEW);
// since we're going to use a shader/texture, we don't want the color,
// just its alpha
SkGL::SetAlpha(paint.getAlpha());
// report that we have setup the texture
return cache;
}
示例5: Make
std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
const SkMatrix& origTextureMatrix,
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
const GrSamplerState::Filter* filterOrNullForBicubic,
SkColorSpace* dstColorSpace) {
SkMatrix textureMatrix = origTextureMatrix;
SkRect domain;
GrSamplerState samplerState;
if (filterOrNullForBicubic) {
samplerState.setFilterMode(*filterOrNullForBicubic);
}
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
sk_sp<GrTextureProxy> proxy(
this->refTextureProxySafeForParams(samplerState, scaleAdjust));
if (!proxy) {
return nullptr;
}
// If we made a copy then we only copied the contentArea, in which case the new texture is all
// content.
if (proxy.get() != this->originalProxy()) {
textureMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
}
DomainMode domainMode =
DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
proxy.get(), filterOrNullForBicubic, &domain);
if (kTightCopy_DomainMode == domainMode) {
// TODO: Copy the texture and adjust the texture matrix (both parts need to consider
// non-int constraint rect)
// For now: treat as bilerp and ignore what goes on above level 0.
// We only expect MIP maps to require a tight copy.
SkASSERT(filterOrNullForBicubic &&
GrSamplerState::Filter::kMipMap == *filterOrNullForBicubic);
static const GrSamplerState::Filter kBilerp = GrSamplerState::Filter::kBilerp;
domainMode =
DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
proxy.get(), &kBilerp, &domain);
SkASSERT(kTightCopy_DomainMode != domainMode);
}
SkASSERT(kNoDomain_DomainMode == domainMode ||
(domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
GrPixelConfig config = proxy->config();
auto fp = CreateFragmentProcessorForDomainAndFilter(std::move(proxy), textureMatrix,
domainMode, domain, filterOrNullForBicubic);
return GrColorSpaceXformEffect::Make(std::move(fp), fColorSpace, config, dstColorSpace);
}
示例6: samplerState
std::unique_ptr<GrFragmentProcessor> SkImageShader::asFragmentProcessor(
const GrFPArgs& args) const {
const auto lm = this->totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix);
SkMatrix lmInverse;
if (!lm->invert(&lmInverse)) {
return nullptr;
}
GrSamplerState::WrapMode wrapModes[] = {tile_mode_to_wrap_mode(fTileModeX),
tile_mode_to_wrap_mode(fTileModeY)};
// Must set wrap and filter on the sampler before requesting a texture. In two places below
// we check the matrix scale factors to determine how to interpret the filter quality setting.
// This completely ignores the complexity of the drawVertices case where explicit local coords
// are provided by the caller.
bool doBicubic;
GrSamplerState::Filter textureFilterMode = GrSkFilterQualityToGrFilterMode(
args.fFilterQuality, *args.fViewMatrix, *lm,
args.fContext->contextPriv().sharpenMipmappedTextures(), &doBicubic);
GrSamplerState samplerState(wrapModes, textureFilterMode);
sk_sp<SkColorSpace> texColorSpace;
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
sk_sp<GrTextureProxy> proxy(as_IB(fImage)->asTextureProxyRef(
args.fContext, samplerState, args.fDstColorSpaceInfo->colorSpace(), &texColorSpace,
scaleAdjust));
if (!proxy) {
return nullptr;
}
GrPixelConfig config = proxy->config();
bool isAlphaOnly = GrPixelConfigIsAlphaOnly(config);
lmInverse.postScale(scaleAdjust[0], scaleAdjust[1]);
std::unique_ptr<GrFragmentProcessor> inner;
if (doBicubic) {
inner = GrBicubicEffect::Make(std::move(proxy), lmInverse, wrapModes);
} else {
inner = GrSimpleTextureEffect::Make(std::move(proxy), lmInverse, samplerState);
}
inner = GrColorSpaceXformEffect::Make(std::move(inner), texColorSpace.get(), config,
args.fDstColorSpaceInfo->colorSpace());
if (isAlphaOnly) {
return inner;
}
return GrFragmentProcessor::MulChildByInputAlpha(std::move(inner));
}
示例7: makebm
static SkImage* makebm(SkBitmap* bm, int w, int h) {
bm->allocN32Pixels(w, h);
bm->eraseColor(SK_ColorTRANSPARENT);
SkCanvas canvas(*bm);
SkScalar wScalar = SkIntToScalar(w);
SkScalar hScalar = SkIntToScalar(h);
SkPoint pt = { wScalar / 2, hScalar / 2 };
SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
SK_ColorGREEN, SK_ColorMAGENTA,
SK_ColorBLUE, SK_ColorCYAN,
SK_ColorRED};
SkScalar pos[] = {0,
SK_Scalar1 / 6,
2 * SK_Scalar1 / 6,
3 * SK_Scalar1 / 6,
4 * SK_Scalar1 / 6,
5 * SK_Scalar1 / 6,
SK_Scalar1};
SkPaint paint;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
paint.setShader(SkGradientShader::CreateRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
0, &mat))->unref();
canvas.drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
}
// Let backends know we won't change this, so they don't have to deep copy it defensively.
bm->setImmutable();
return image_from_bitmap(*bm);
}
示例8: makebm
static SkImage* makebm(SkCanvas* caller, int w, int h) {
SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
SkAutoTUnref<SkSurface> surface(caller->newSurface(info));
if (nullptr == surface) {
surface.reset(SkSurface::NewRaster(info));
}
SkCanvas* canvas = surface->getCanvas();
const SkScalar wScalar = SkIntToScalar(w);
const SkScalar hScalar = SkIntToScalar(h);
const SkPoint pt = { wScalar / 2, hScalar / 2 };
const SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
static const SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
SK_ColorGREEN, SK_ColorMAGENTA,
SK_ColorBLUE, SK_ColorCYAN,
SK_ColorRED};
static const SkScalar pos[] = {0,
SK_Scalar1 / 6,
2 * SK_Scalar1 / 6,
3 * SK_Scalar1 / 6,
4 * SK_Scalar1 / 6,
5 * SK_Scalar1 / 6,
SK_Scalar1};
SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(pos));
SkPaint paint;
SkRect rect = SkRect::MakeWH(wScalar, hScalar);
SkMatrix mat = SkMatrix::I();
for (int i = 0; i < 4; ++i) {
paint.setShader(SkGradientShader::CreateRadial(
pt, radius,
colors, pos,
SK_ARRAY_COUNT(colors),
SkShader::kRepeat_TileMode,
0, &mat))->unref();
canvas->drawRect(rect, paint);
rect.inset(wScalar / 8, hScalar / 8);
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
}
return surface->newImageSnapshot();
}
示例9: computeMatrix
SkMatrix Viewer::computeMatrix() {
SkMatrix m;
m.reset();
if (fZoomLevel) {
SkPoint center;
//m = this->getLocalMatrix();//.invert(&m);
m.mapXY(fZoomCenterX, fZoomCenterY, ¢er);
SkScalar cx = center.fX;
SkScalar cy = center.fY;
m.setTranslate(-cx, -cy);
m.postScale(fZoomScale, fZoomScale);
m.postTranslate(cx, cy);
}
m.preConcat(fGesture.localM());
m.preConcat(fGesture.globalM());
return m;
}
示例10: onOnceBeforeDraw
void onOnceBeforeDraw() override {
SkPictureRecorder recorder;
SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
draw_scene(pictureCanvas, kPictureSize);
SkAutoTUnref<SkPicture> picture(recorder.endRecording());
SkPoint offset = SkPoint::Make(100, 100);
pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
kPictureSize, kPictureSize));
pictureCanvas->translate(offset.x(), offset.y());
draw_scene(pictureCanvas, kPictureSize);
SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());
for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
tiles[i].y * kPictureSize,
tiles[i].w * kPictureSize,
tiles[i].h * kPictureSize);
SkMatrix localMatrix;
localMatrix.setTranslate(tiles[i].offsetX * kPictureSize,
tiles[i].offsetY * kPictureSize);
localMatrix.postScale(kFillSize / (2 * kPictureSize),
kFillSize / (2 * kPictureSize));
SkPicture* picturePtr = picture.get();
SkRect* tilePtr = &tile;
if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
// When the tile == picture bounds, exercise the picture + offset path.
picturePtr = offsetPicture.get();
tilePtr = NULL;
}
fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode,
&localMatrix,
tilePtr));
}
}
示例11: onDraw
void onDraw(SkCanvas* canvas) override {
SkIRect rects[2];
rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300);
rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT);
SkRegion region;
region.setRects(rects, 2);
SkMatrix matrix;
matrix.reset();
matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f);
matrix.postScale(.8f, .8f);
canvas->concat(matrix);
SkPaint paint;
paint.setImageFilter(
SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref();
canvas->saveLayer(nullptr, &paint);
paint.setAntiAlias(true);
SkPaint rect_paint;
rect_paint.setColor(0xFF0000FF);
canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2),
rect_paint);
rect_paint.setColor(0xBFFF0000);
canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2),
rect_paint);
rect_paint.setColor(0x3F00FF00);
canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
rect_paint);
rect_paint.setColor(0x00000000);
canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2),
rect_paint);
canvas->restore();
}
示例12: test_matrix_is_similarity
//.........这里部分代码省略.........
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// scale with different size at a pivot point
mat.reset();
mat.setScale(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with same size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(15),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// skew with different size at a pivot point
mat.reset();
mat.setSkew(SkIntToScalar(15), SkIntToScalar(20),
SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective x
mat.reset();
mat.setPerspX(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// perspective y
mat.reset();
mat.setPerspY(SkScalarToPersp(SK_Scalar1 / 2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#ifdef SK_SCALAR_IS_FLOAT
/* We bypass the following tests for SK_SCALAR_IS_FIXED build.
* The long discussion can be found in this issue:
* http://codereview.appspot.com/5999050/
* In short, we haven't found a perfect way to fix the precision
* issue, i.e. the way we use tolerance in isSimilarityTransformation
* is incorrect. The situation becomes worse in fixed build, so
* we disabled rotation related tests for fixed build.
*/
// rotate
for (int angle = 0; angle < 360; ++angle) {
mat.reset();
mat.setRotate(SkIntToScalar(angle));
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
// see if there are any accumulated precision issues
mat.reset();
for (int i = 1; i < 360; i++) {
mat.postRotate(SkIntToScalar(1));
}
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + translate
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postTranslate(SkIntToScalar(10), SkIntToScalar(20));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(2), SkIntToScalar(2));
REPORTER_ASSERT(reporter, mat.isSimilarity());
// rotate + non-uniform scale
mat.reset();
mat.setRotate(SkIntToScalar(30));
mat.postScale(SkIntToScalar(3), SkIntToScalar(2));
REPORTER_ASSERT(reporter, !mat.isSimilarity());
#endif
// all zero
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, 0);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// all zero except perspective
mat.setAll(0, 0, 0, 0, 0, 0, 0, 0, SK_Scalar1);
REPORTER_ASSERT(reporter, !mat.isSimilarity());
// scales zero, only skews
mat.setAll(0, SK_Scalar1, 0,
SK_Scalar1, 0, 0,
0, 0, SkMatrix::I()[8]);
REPORTER_ASSERT(reporter, mat.isSimilarity());
}
示例13: init
void GrStencilAndCoverTextContext::init(GrRenderTarget* rt,
const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint,
size_t textByteLength,
RenderMode renderMode,
const SkMatrix& viewMatrix,
const SkIRect& regionClipBounds) {
GrTextContext::init(rt, clip, paint, skPaint, regionClipBounds);
fContextInitialMatrix = viewMatrix;
fViewMatrix = viewMatrix;
fLocalMatrix = SkMatrix::I();
const bool otherBackendsWillDrawAsPaths =
SkDraw::ShouldDrawTextAsPaths(skPaint, fContextInitialMatrix);
fUsingDeviceSpaceGlyphs = !otherBackendsWillDrawAsPaths &&
kMaxAccuracy_RenderMode == renderMode &&
SkToBool(fContextInitialMatrix.getType() &
(SkMatrix::kScale_Mask | SkMatrix::kAffine_Mask));
if (fUsingDeviceSpaceGlyphs) {
// SkDraw::ShouldDrawTextAsPaths takes care of perspective transforms.
SkASSERT(!fContextInitialMatrix.hasPerspective());
// The whole shape (including stroke) will be baked into the glyph outlines. Make
// NVPR just fill the baked shapes.
fStroke = GrStrokeInfo(SkStrokeRec::kFill_InitStyle);
fTextRatio = fTextInverseRatio = 1.0f;
// Glyphs loaded by GPU path rendering have an inverted y-direction.
SkMatrix m;
m.setScale(1, -1);
fViewMatrix = m;
// Post-flip the initial matrix so we're left with just the flip after
// the paint preConcats the inverse.
m = fContextInitialMatrix;
m.postScale(1, -1);
if (!m.invert(&fLocalMatrix)) {
SkDebugf("Not invertible!\n");
return;
}
fGlyphCache = fSkPaint.detachCache(&fDeviceProperties, &fContextInitialMatrix,
true /*ignoreGamma*/);
fGlyphs = get_gr_glyphs(fContext, fGlyphCache->getScalerContext()->getTypeface(),
&fGlyphCache->getDescriptor(), fStroke);
} else {
// Don't bake strokes into the glyph outlines. We will stroke the glyphs
// using the GPU instead. This is the fast path.
fStroke = GrStrokeInfo(fSkPaint);
fSkPaint.setStyle(SkPaint::kFill_Style);
if (fStroke.isHairlineStyle()) {
// Approximate hairline stroke.
SkScalar strokeWidth = SK_Scalar1 /
(SkVector::Make(fContextInitialMatrix.getScaleX(),
fContextInitialMatrix.getSkewY()).length());
fStroke.setStrokeStyle(strokeWidth, false /*strokeAndFill*/);
} else if (fSkPaint.isFakeBoldText() &&
#ifdef SK_USE_FREETYPE_EMBOLDEN
kMaxPerformance_RenderMode == renderMode &&
#endif
SkStrokeRec::kStroke_Style != fStroke.getStyle()) {
// Instead of baking fake bold into the glyph outlines, do it with the GPU stroke.
SkScalar fakeBoldScale = SkScalarInterpFunc(fSkPaint.getTextSize(),
kStdFakeBoldInterpKeys,
kStdFakeBoldInterpValues,
kStdFakeBoldInterpLength);
SkScalar extra = SkScalarMul(fSkPaint.getTextSize(), fakeBoldScale);
fStroke.setStrokeStyle(fStroke.needToApply() ? fStroke.getWidth() + extra : extra,
true /*strokeAndFill*/);
fSkPaint.setFakeBoldText(false);
}
bool canUseRawPaths;
if (!fStroke.isDashed() && (otherBackendsWillDrawAsPaths ||
kMaxPerformance_RenderMode == renderMode)) {
// We can draw the glyphs from canonically sized paths.
fTextRatio = fSkPaint.getTextSize() / SkPaint::kCanonicalTextSizeForPaths;
fTextInverseRatio = SkPaint::kCanonicalTextSizeForPaths / fSkPaint.getTextSize();
// Compensate for the glyphs being scaled by fTextRatio.
if (!fStroke.isFillStyle()) {
fStroke.setStrokeStyle(fStroke.getWidth() / fTextRatio,
SkStrokeRec::kStrokeAndFill_Style == fStroke.getStyle());
}
fSkPaint.setLinearText(true);
fSkPaint.setLCDRenderText(false);
fSkPaint.setAutohinted(false);
fSkPaint.setHinting(SkPaint::kNo_Hinting);
fSkPaint.setSubpixelText(true);
fSkPaint.setTextSize(SkIntToScalar(SkPaint::kCanonicalTextSizeForPaths));
//.........这里部分代码省略.........
示例14: generateMask
static void generateMask(const SkMask& mask, const SkPath& path) {
SkBitmap::Config config;
SkPaint paint;
int srcW = mask.fBounds.width();
int srcH = mask.fBounds.height();
int dstW = srcW;
int dstH = srcH;
int dstRB = mask.fRowBytes;
SkMatrix matrix;
matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft),
-SkIntToScalar(mask.fBounds.fTop));
if (SkMask::kBW_Format == mask.fFormat) {
config = SkBitmap::kA1_Config;
paint.setAntiAlias(false);
} else {
config = SkBitmap::kA8_Config;
paint.setAntiAlias(true);
switch (mask.fFormat) {
case SkMask::kA8_Format:
break;
case SkMask::kLCD16_Format:
case SkMask::kLCD32_Format:
// TODO: trigger off LCD orientation
dstW *= 3;
matrix.postScale(SkIntToScalar(3), SK_Scalar1);
dstRB = 0; // signals we need a copy
break;
default:
SkDEBUGFAIL("unexpected mask format");
}
}
SkRasterClip clip;
clip.setRect(SkIRect::MakeWH(dstW, dstH));
SkBitmap bm;
bm.setConfig(config, dstW, dstH, dstRB);
if (0 == dstRB) {
bm.allocPixels();
bm.lockPixels();
} else {
bm.setPixels(mask.fImage);
}
sk_bzero(bm.getPixels(), bm.getSafeSize());
SkDraw draw;
sk_bzero(&draw, sizeof(draw));
draw.fRC = &clip;
draw.fClip = &clip.bwRgn();
draw.fMatrix = &matrix;
draw.fBitmap = &bm;
draw.drawPath(path, paint);
if (0 == dstRB) {
switch (mask.fFormat) {
case SkMask::kLCD16_Format:
pack3xHToLCD16(bm, mask);
break;
case SkMask::kLCD32_Format:
pack3xHToLCD32(bm, mask);
break;
default:
SkDEBUGFAIL("bad format for copyback");
}
}
}
示例15: pattern
//.........这里部分代码省略.........
if (!rect.isEmpty()) {
paint.setColor(image->getColor(width - 1, 0));
canvas.drawRect(rect, paint);
}
rect = SkRect::MakeLTRB(width, height, surfaceBBox.fRight,
surfaceBBox.fBottom);
if (!rect.isEmpty()) {
paint.setColor(image->getColor(width - 1, height - 1));
canvas.drawRect(rect, paint);
}
rect = SkRect::MakeLTRB(surfaceBBox.fLeft, height, 0,
surfaceBBox.fBottom);
if (!rect.isEmpty()) {
paint.setColor(image->getColor(0, height - 1));
canvas.drawRect(rect, paint);
}
}
// Then expand the left, right, top, then bottom.
if (tileModes[0] == SkShader::kClamp_TileMode) {
SkIRect subset = SkIRect::MakeXYWH(0, 0, 1, height);
if (surfaceBBox.fLeft < 0) {
SkBitmap left;
SkAssertResult(image->extractSubset(&left, subset));
SkMatrix leftMatrix;
leftMatrix.setScale(-surfaceBBox.fLeft, 1);
leftMatrix.postTranslate(surfaceBBox.fLeft, 0);
canvas.drawBitmapMatrix(left, leftMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
leftMatrix.postScale(SK_Scalar1, -SK_Scalar1);
leftMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(left, leftMatrix);
}
patternBBox.fLeft = 0;
}
if (surfaceBBox.fRight > width) {
SkBitmap right;
subset.offset(width - 1, 0);
SkAssertResult(image->extractSubset(&right, subset));
SkMatrix rightMatrix;
rightMatrix.setScale(surfaceBBox.fRight - width, 1);
rightMatrix.postTranslate(width, 0);
canvas.drawBitmapMatrix(right, rightMatrix);
if (tileModes[1] == SkShader::kMirror_TileMode) {
rightMatrix.postScale(SK_Scalar1, -SK_Scalar1);
rightMatrix.postTranslate(0, 2 * height);
canvas.drawBitmapMatrix(right, rightMatrix);
}
patternBBox.fRight = surfaceBBox.width();
}
}
if (tileModes[1] == SkShader::kClamp_TileMode) {
SkIRect subset = SkIRect::MakeXYWH(0, 0, width, 1);
if (surfaceBBox.fTop < 0) {
SkBitmap top;
SkAssertResult(image->extractSubset(&top, subset));
SkMatrix topMatrix;