// Just draw a blurred rect at each of the four corners of a square (centered at x,y). // Use two clips to define a rectori where we want pixels to appear. void draw0x0(SkCanvas* canvas, SkScalar x, SkScalar y) { SkRect innerClip = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize }; innerClip.offset(x, y); SkRect outerClip = { -kHalfOuterClipSize-kHalfSquareSize, -kHalfOuterClipSize-kHalfSquareSize, kHalfOuterClipSize+kHalfSquareSize, kHalfOuterClipSize+kHalfSquareSize }; outerClip.offset(x, y); canvas->save(); canvas->clipRect(outerClip, SkCanvas::kIntersect_Op); canvas->clipRect(innerClip, SkCanvas::kDifference_Op); SkPaint paint; paint.setAntiAlias(true); paint.setMaskFilter(MakeBlur()); for (int i = 0; i < 4; ++i) { paint.setColor(gColors[i]); SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize }; rect.offset(gBlurOffsets[i]); rect.offset(x, y); canvas->drawRect(rect, paint); } canvas->restore(); }
static void test_strokerect(SkCanvas* canvas) { canvas->drawColor(SK_ColorWHITE); SkRect r; r.set(10, 10, 14, 14); r.offset(0.25f, 0.3333f); test_strokerect(canvas, r); canvas->translate(0, 20); r.set(10, 10, 14.5f, 14.5f); r.offset(0.25f, 0.3333f); test_strokerect(canvas, r); canvas->translate(0, 20); r.set(10, 10, 14.5f, 20); r.offset(0.25f, 0.3333f); test_strokerect(canvas, r); canvas->translate(0, 20); r.set(10, 10, 20, 14.5f); r.offset(0.25f, 0.3333f); test_strokerect(canvas, r); canvas->translate(0, 20); r.set(10, 10, 20, 20); r.offset(0.25f, 0.3333f); test_strokerect(canvas, r); canvas->translate(0, 20); }
void draw_mode(SkCanvas* canvas, SkXfermode* mode, int alpha, SkScalar x, SkScalar y) { SkPaint p; SkMaskFilter* mf = SkBlurMaskFilter::Create(5, SkBlurMaskFilter::kNormal_BlurStyle, 0); p.setMaskFilter(mf)->unref(); SkScalar ww = SkIntToScalar(W); SkScalar hh = SkIntToScalar(H); // draw a circle covering the upper // left three quarters of the canvas p.setColor(0xFFCC44FF); SkRect r; r.set(0, 0, ww*3/4, hh*3/4); r.offset(x, y); canvas->drawOval(r, p); p.setXfermode(mode); // draw a square overlapping the circle // in the lower right of the canvas p.setColor(0x00AA6633 | alpha << 24); r.set(ww/3, hh/3, ww*19/20, hh*19/20); r.offset(x, y); canvas->drawRect(r, p); }
static void show_bm(SkCanvas* canvas, int width, int height, SkColor color) { SkBitmap bm; make_bm(&bm, width, height, color); SkPaint paint; SkRect r; SkIRect ir; paint.setStyle(SkPaint::kStroke_Style); ir.set(0, 0, 128, 128); r.set(ir); canvas->save(); canvas->clipRect(r); canvas->drawBitmap(bm, 0, 0, NULL); canvas->restore(); canvas->drawRect(r, paint); r.offset(SkIntToScalar(150), 0); // exercises extract bitmap, but not shader canvas->drawBitmapRect(bm, &ir, r, NULL); canvas->drawRect(r, paint); r.offset(SkIntToScalar(150), 0); // exercises bitmapshader canvas->drawBitmapRect(bm, NULL, r, NULL); canvas->drawRect(r, paint); }
void draw_mode(SkCanvas* canvas, SkBlendMode mode, int alpha, SkScalar x, SkScalar y) { SkPaint p; p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, SkBlurMask::ConvertRadiusToSigma(5), SkBlurMaskFilter::kNone_BlurFlag)); SkScalar ww = SkIntToScalar(W); SkScalar hh = SkIntToScalar(H); // draw a circle covering the upper // left three quarters of the canvas p.setColor(0xFFCC44FF); SkRect r; r.set(0, 0, ww*3/4, hh*3/4); r.offset(x, y); canvas->drawOval(r, p); p.setBlendMode(mode); // draw a square overlapping the circle // in the lower right of the canvas p.setColor(0x00AA6633 | alpha << 24); r.set(ww/3, hh/3, ww*19/20, hh*19/20); r.offset(x, y); canvas->drawRect(r, p); }
// This draws 4 blurred shadows around a single square (centered at x, y). // Each blur is offset +/- half the square's side in x & y from the original // (so each blurred rect is centered at one of the corners of the original). // For each blur a large outer clip is centered around the blurred rect // while a difference clip stays at the location of the original rect. // Each blurred rect is drawn with a draw looper where the original (non- // blurred rect) is offset to reside outside of the large outer clip (so // it never appears) but the offset in the draw looper is used to translate // the blurred version back into the clip. void draw4x1(SkCanvas* canvas, SkScalar x, SkScalar y) { for (int i = 0; i < 4; ++i) { SkPaint loopPaint; loopPaint.setLooper(create1Looper(-kOffsetToOutsideClip, 0, gColors[i])); loopPaint.setAntiAlias(true); SkRect outerClip = { -kHalfOuterClipSize, -kHalfOuterClipSize, kHalfOuterClipSize, kHalfOuterClipSize }; outerClip.offset(x, y); // center it on the blurred rect outerClip.offset(gBlurOffsets[i]); SkRect rect = { -kHalfSquareSize, -kHalfSquareSize, kHalfSquareSize, kHalfSquareSize }; rect.offset(x, y); canvas->save(); canvas->clipRect(outerClip, SkCanvas::kIntersect_Op); canvas->clipRect(rect, SkCanvas::kDifference_Op); // move the rect to where we want the blur to appear rect.offset(gBlurOffsets[i]); // then move it outside the clip (the blur stage of the draw // looper will undo this translation) rect.offset(SkIntToScalar(kOffsetToOutsideClip), 0); canvas->drawRect(rect, loopPaint); canvas->restore(); } }
void drawClippedGeom(SkCanvas* canvas, const SkPoint& offset, bool useAA) { int count = canvas->save(); switch (fGeom) { case kRect_Geometry: canvas->clipRect(create_rect(offset), SkRegion::kReplace_Op, useAA); break; case kRRect_Geometry: canvas->clipRRect(create_rrect(offset), SkRegion::kReplace_Op, useAA); break; case kCircle_Geometry: canvas->clipRRect(create_circle(offset), SkRegion::kReplace_Op, useAA); break; case kConvexPath_Geometry: canvas->clipPath(create_convex_path(offset), SkRegion::kReplace_Op, useAA); break; case kConcavePath_Geometry: canvas->clipPath(create_concave_path(offset), SkRegion::kReplace_Op, useAA); break; case kRectAndRect_Geometry: { SkRect r = create_rect(offset); r.offset(fSign * kXlate, fSign * kXlate); canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips canvas->clipRect(create_rect(offset), SkRegion::kIntersect_Op, useAA); } break; case kRectAndRRect_Geometry: { SkRect r = create_rect(offset); r.offset(fSign * kXlate, fSign * kXlate); canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips canvas->clipRRect(create_rrect(offset), SkRegion::kIntersect_Op, useAA); } break; case kRectAndConvex_Geometry: { SkRect r = create_rect(offset); r.offset(fSign * kXlate, fSign * kXlate); canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips canvas->clipPath(create_convex_path(offset), SkRegion::kIntersect_Op, useAA); } break; case kRectAndConcave_Geometry: { SkRect r = create_rect(offset); r.offset(fSign * kXlate, fSign * kXlate); canvas->clipRect(r, SkRegion::kReplace_Op, true); // AA here forces shader clips canvas->clipPath(create_concave_path(offset), SkRegion::kIntersect_Op, useAA); } break; } SkISize size = canvas->getDeviceSize(); SkRect bigR = SkRect::MakeWH(SkIntToScalar(size.width()), SkIntToScalar(size.height())); SkPaint p; p.setColor(SK_ColorRED); canvas->drawRect(bigR, p); canvas->restoreToCount(count); }
void drawMask(SkCanvas* canvas, const SkRect& r) { SkPaint paint; paint.setAntiAlias(true); if (true) { SkBitmap mask; int w = SkScalarRound(r.width()); int h = SkScalarRound(r.height()); mask.setConfig(SkBitmap::kARGB_8888_Config, w, h); mask.allocPixels(); mask.eraseColor(0); SkCanvas c(mask); SkRect bounds = r; bounds.offset(-bounds.fLeft, -bounds.fTop); c.drawOval(bounds, paint); paint.setXfermodeMode(SkXfermode::kDstIn_Mode); canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint); } else { SkPath p; p.addOval(r); p.setFillType(SkPath::kInverseWinding_FillType); paint.setXfermodeMode(SkXfermode::kDstOut_Mode); canvas->drawPath(p, paint); } }
static std::unique_ptr<GrLegacyMeshDrawOp> Make(GrColor color, const SkMatrix& viewMatrix, const SkRect& rect, const SkStrokeRec& stroke, bool snapToPixelCenters) { if (!allowed_stroke(stroke)) { return nullptr; } NonAAStrokeRectOp* op = new NonAAStrokeRectOp(); op->fColor = color; op->fViewMatrix = viewMatrix; op->fRect = rect; // Sort the rect for hairlines op->fRect.sort(); op->fStrokeWidth = stroke.getWidth(); SkScalar rad = SkScalarHalf(op->fStrokeWidth); SkRect bounds = rect; bounds.outset(rad, rad); // If our caller snaps to pixel centers then we have to round out the bounds if (snapToPixelCenters) { viewMatrix.mapRect(&bounds); // We want to be consistent with how we snap non-aa lines. To match what we do in // GrGLSLVertexShaderBuilder, we first floor all the vertex values and then add half a // pixel to force us to pixel centers. bounds.set(SkScalarFloorToScalar(bounds.fLeft), SkScalarFloorToScalar(bounds.fTop), SkScalarFloorToScalar(bounds.fRight), SkScalarFloorToScalar(bounds.fBottom)); bounds.offset(0.5f, 0.5f); op->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo); } else { op->setTransformedBounds(bounds, op->fViewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } return std::unique_ptr<GrLegacyMeshDrawOp>(op); }
PathEffectView() { SkRandom rand; int steps = 20; SkScalar dist = SkIntToScalar(400); SkScalar x = SkIntToScalar(20); SkScalar y = SkIntToScalar(50); fPath.moveTo(x, y); for (int i = 0; i < steps; i++) { x += dist/steps; SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25); if (i == steps/2) { fPath.moveTo(x, tmpY); } else { fPath.lineTo(x, tmpY); } } { SkRect oval; oval.set(SkIntToScalar(20), SkIntToScalar(30), SkIntToScalar(100), SkIntToScalar(60)); oval.offset(x, 0); fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8)); } fClickPt.set(SkIntToScalar(200), SkIntToScalar(200)); }
SkRect LayerAndroid::subtractLayers(const SkRect& visibleRect) const { SkRect result; if (m_recordingPicture) { SkRect globalRect = bounds(); globalRect.offset(-getPosition()); // localToGlobal adds in position SkMatrix globalMatrix; localToGlobal(&globalMatrix); globalMatrix.mapRect(&globalRect); SkIRect roundedGlobal; globalRect.round(&roundedGlobal); SkIRect iVisibleRect; visibleRect.round(&iVisibleRect); SkRegion visRegion(iVisibleRect); visRegion.op(roundedGlobal, SkRegion::kDifference_Op); result.set(visRegion.getBounds()); #if DEBUG_NAV_UI SkDebugf("%s visibleRect=(%g,%g,r=%g,b=%g) globalRect=(%g,%g,r=%g,b=%g)" "result=(%g,%g,r=%g,b=%g)", __FUNCTION__, visibleRect.fLeft, visibleRect.fTop, visibleRect.fRight, visibleRect.fBottom, globalRect.fLeft, globalRect.fTop, globalRect.fRight, globalRect.fBottom, result.fLeft, result.fTop, result.fRight, result.fBottom); #endif } else result = visibleRect; for (int i = 0; i < countChildren(); i++) result = getChild(i)->subtractLayers(result); return result; }
void onOnceBeforeDraw() override { SkRandom rand; int steps = 20; SkScalar dist = SkIntToScalar(400); SkScalar x = SkIntToScalar(20); SkScalar y = SkIntToScalar(50); fPath.moveTo(x, y); for (int i = 0; i < steps; i++) { x += dist/steps; SkScalar tmpY = y + SkIntToScalar(rand.nextS() % 25); if (i == steps/2) { fPath.moveTo(x, tmpY); } else { fPath.lineTo(x, tmpY); } } { SkRect oval; oval.set(SkIntToScalar(20), SkIntToScalar(30), SkIntToScalar(100), SkIntToScalar(60)); oval.offset(x, 0); fPath.addRoundRect(oval, SkIntToScalar(8), SkIntToScalar(8)); } fClickPt.set(SkIntToScalar(200), SkIntToScalar(200)); this->setBGColor(0xFFDDDDDD); }
void onDraw(int loops, SkCanvas* canvas) override { SkPaint paint; this->setupPaint(&paint); paint.setAntiAlias(true); SkRandom rand; for (int i = 0; i < loops; i++) { SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, rand.nextUScalar1() * 400); r.offset(fRadius, fRadius); if (fRadius > 0) { sk_sp<SkImageFilter> mf; switch (fStyle) { case kDilate_MT: mf = SkDilateImageFilter::Make(SkScalarFloorToInt(fRadius), SkScalarFloorToInt(fRadius), nullptr); break; case kErode_MT: mf = SkErodeImageFilter::Make(SkScalarFloorToInt(fRadius), SkScalarFloorToInt(fRadius), nullptr); break; } paint.setImageFilter(std::move(mf)); } canvas->drawOval(r, paint); } }
void SampleWindow::onSizeChange() { this->INHERITED::onSizeChange(); SkView::F2BIter iter(this); SkView* view = iter.next(); view->setSize(this->width(), this->height()); // rebuild our clippath { const SkScalar W = this->width(); const SkScalar H = this->height(); fClipPath.reset(); #if 0 for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) { SkRect r; r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30)); for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0)) fClipPath.addRect(r); } #else SkRect r; r.set(0, 0, W, H); fClipPath.addRect(r, SkPath::kCCW_Direction); r.set(W/4, H/4, W*3/4, H*3/4); fClipPath.addRect(r, SkPath::kCW_Direction); #endif } this->updateTitle(); // to refresh our config }
void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { if (!fUseMultiPictureDraw) { return; } SkIRect bounds; SkAssertResult(canvas->getClipDeviceBounds(&bounds)); int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(FLAGS_benchTile)); int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(FLAGS_benchTile)); fSurfaces.setReserve(xTiles * yTiles); fTileRects.setReserve(xTiles * yTiles); SkImageInfo ii = canvas->imageInfo().makeWH(FLAGS_benchTile, FLAGS_benchTile); for (int y = bounds.fTop; y < bounds.fBottom; y += FLAGS_benchTile) { for (int x = bounds.fLeft; x < bounds.fRight; x += FLAGS_benchTile) { const SkIRect tileRect = SkIRect::MakeXYWH(x, y, FLAGS_benchTile, FLAGS_benchTile); *fTileRects.append() = tileRect; *fSurfaces.push() = canvas->newSurface(ii); // Never want the contents of a tile to include stuff the parent // canvas clips out SkRect clip = SkRect::Make(bounds); clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop)); fSurfaces.top()->getCanvas()->clipRect(clip); fSurfaces.top()->getCanvas()->setMatrix(canvas->getTotalMatrix()); fSurfaces.top()->getCanvas()->scale(fScale, fScale); } } }
void drawMask(SkCanvas* canvas, const SkRect& r) { SkPaint paint; paint.setAntiAlias(true); if (true) { SkBitmap mask; int w = SkScalarRoundToInt(r.width()); int h = SkScalarRoundToInt(r.height()); mask.allocN32Pixels(w, h); mask.eraseColor(SK_ColorTRANSPARENT); SkCanvas c(mask); SkRect bounds = r; bounds.offset(-bounds.fLeft, -bounds.fTop); c.drawOval(bounds, paint); paint.setBlendMode(SkBlendMode::kDstIn); canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint); } else { SkPath p; p.addOval(r); p.setFillType(SkPath::kInverseWinding_FillType); paint.setBlendMode(SkBlendMode::kDstOut); canvas->drawPath(p, paint); } }
static void add_rect_to_clip(const GrClip& clip, const SkRect& devRect, GrClip* out) { switch (clip.clipType()) { case GrClip::kClipStack_ClipType: { SkClipStack* stack = new SkClipStack; *stack = *clip.clipStack(); // The stack is actually in clip space not device space. SkRect clipRect = devRect; SkPoint origin = { SkIntToScalar(clip.origin().fX), SkIntToScalar(clip.origin().fY) }; clipRect.offset(origin); SkIRect iclipRect; clipRect.roundOut(&iclipRect); clipRect = SkRect::Make(iclipRect); stack->clipDevRect(clipRect, SkRegion::kIntersect_Op, false); out->setClipStack(stack, &clip.origin()); break; } case GrClip::kWideOpen_ClipType: *out = GrClip(devRect); break; case GrClip::kIRect_ClipType: { SkIRect intersect; devRect.roundOut(&intersect); if (intersect.intersect(clip.irect())) { *out = GrClip(intersect); } else { *out = clip; } break; } } }
virtual void onDraw(int loops, SkCanvas* canvas) { SkPaint paint; this->setupPaint(&paint); for (int i = 0; i < loops; ++i) { // jostle the clip regions each time to prevent caching fClipRect.offset((i % 2) == 0 ? SkIntToScalar(10) : SkIntToScalar(-10), 0); fClipPath.reset(); fClipPath.addRoundRect(fClipRect, SkIntToScalar(5), SkIntToScalar(5)); SkASSERT(fClipPath.isConvex()); canvas->save(); #if 1 if (fDoPath) { canvas->clipPath(fClipPath, kReplace_SkClipOp, fDoAA); } else { canvas->clipRect(fClipRect, kReplace_SkClipOp, fDoAA); } canvas->drawRect(fDrawRect, paint); #else // this path tests out directly draw the clip primitive // use it to comparing just drawing the clip vs. drawing using // the clip if (fDoPath) { canvas->drawPath(fClipPath, paint); } else { canvas->drawRect(fClipRect, paint); } #endif canvas->restore(); } }
void SkView::inval(SkRect* rect) { if (!this->isVisible()) return; SkRect bounds; this->getLocalBounds(&bounds); if (rect && !bounds.intersect(*rect)) return; rect = &bounds; SkView* view = this; for (;;) { if (view->handleInval(bounds)) break; SkRect parentR; SkView* parent = view->fParent; if (parent == NULL || !parent->isVisible()) break; bounds.offset(view->fLoc.fX, view->fLoc.fY); parent->getLocalBounds(&parentR); if (!bounds.intersect(parentR)) return; view = parent; } }
virtual void handlePath(SkCanvas* canvas, const SkPath& path, const SkPaint& paint, int N) override { SkPoint pts[2]; if (!path.isLine(pts) || pts[0].fY != pts[1].fY) { this->INHERITED::handlePath(canvas, path, paint, N); } else { SkRect rect; rect.fLeft = pts[0].fX; rect.fTop = pts[0].fY - paint.getStrokeWidth() / 2; rect.fRight = rect.fLeft + SkIntToScalar(fWidth); rect.fBottom = rect.fTop + paint.getStrokeWidth(); SkPaint p(paint); p.setStyle(SkPaint::kFill_Style); p.setPathEffect(nullptr); int count = SkScalarRoundToInt((pts[1].fX - pts[0].fX) / (2*fWidth)); SkScalar dx = SkIntToScalar(2 * fWidth); for (int i = 0; i < N*10; ++i) { SkRect r = rect; for (int j = 0; j < count; ++j) { canvas->drawRect(r, p); r.offset(dx, 0); } } } }
void onDraw(SkCanvas* canvas) override { this->drawBG(canvas); if (true) { SkRect r; r.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(220), SkIntToScalar(120)); SkPaint p; canvas->saveLayer(&r, &p); canvas->drawColor(0xFFFF0000); p.setAlpha(0); // or 0 p.setXfermodeMode(SkXfermode::kSrc_Mode); canvas->drawOval(r, p); canvas->restore(); return; } if (false) { SkRect r; r.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(220), SkIntToScalar(120)); SkPaint p; p.setAlpha(0x88); p.setAntiAlias(true); if (true) { canvas->saveLayer(&r, &p); p.setColor(0xFFFF0000); canvas->drawOval(r, p); canvas->restore(); } p.setColor(0xFF0000FF); r.offset(SkIntToScalar(20), SkIntToScalar(50)); canvas->drawOval(r, p); } if (false) { SkPaint p; p.setAlpha(0x88); p.setAntiAlias(true); canvas->translate(SkIntToScalar(300), 0); SkRect r; r.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(220), SkIntToScalar(60)); canvas->saveLayer(&r, &p); r.set(SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(220), SkIntToScalar(120)); p.setColor(SK_ColorBLUE); canvas->drawOval(r, p); canvas->restore(); return; } test_fade(canvas); }
static void lettersToBitmap2(SkBitmap* dst, const char chars[], const SkPaint& original, SkBitmap::Config config) { SkPath path; SkScalar x = 0; SkScalar width; SkPath p; for (size_t i = 0; i < strlen(chars); i++) { original.getTextPath(&chars[i], 1, x, 0, &p); path.addPath(p); original.getTextWidths(&chars[i], 1, &width); x += width; } SkRect bounds = path.getBounds(); SkScalar sw = -original.getStrokeWidth(); bounds.inset(sw, sw); path.offset(-bounds.fLeft, -bounds.fTop); bounds.offset(-bounds.fLeft, -bounds.fTop); int w = SkScalarRound(bounds.width()); int h = SkScalarRound(bounds.height()); SkPaint paint(original); paint.setAntiAlias(true); paint.setXfermodeMode(SkXfermode::kDstATop_Mode); paint.setColor(original.getColor()); paint.setStyle(SkPaint::kStroke_Style); dst->setConfig(config, w, h); dst->allocPixels(); dst->eraseColor(SK_ColorWHITE); SkCanvas canvas(*dst); canvas.drawPath(path, paint); }
virtual void onDraw(SkCanvas* canvas) { SkRect r; r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); SkISize canvas_size = canvas->getDeviceSize(); int center_x = (canvas_size.fWidth - (int)(r.width()))/2; int center_y = (canvas_size.fHeight - (int)(r.height()))/2; SkMask mask; if (!this->makeMask(&mask, r)) { SkPaint paint; r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); canvas->drawRect(r,paint); return; } SkAutoMaskFreeImage amfi(mask.fImage); SkBitmap bm; bm.installMaskPixels(mask); center_x = (canvas_size.fWidth - mask.fBounds.width())/2; center_y = (canvas_size.fHeight - mask.fBounds.height())/2; canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), NULL); }
virtual void onDraw(SkCanvas* canvas) { if (false) test_rev(canvas); // avoid bit rot, suppress warning SkRect r = { 10, 10, 100, 60 }; SkPath path; path.addRect(r); test_rev(canvas, path); canvas->translate(0, 100); path.offset(20, 20); path.addRect(r); test_rev(canvas, path); canvas->translate(0, 100); path.reset(); path.moveTo(10, 10); path.lineTo(30, 30); path.addOval(r); r.offset(50, 20); path.addOval(r); test_rev(canvas, path); SkPaint paint; paint.setTextSize(SkIntToScalar(100)); SkTypeface* hira = SkTypeface::CreateFromName("Hiragino Maru Gothic Pro", SkTypeface::kNormal); SkSafeUnref(paint.setTypeface(hira)); path.reset(); paint.getTextPath("e", 1, 50, 50, &path); canvas->translate(0, 100); test_rev(canvas, path); }
virtual void onDraw(SkCanvas* canvas) { SkPaint paint; this->setupPaint(&paint); paint.setAntiAlias(true); SkRandom rand; for (int i = 0; i < SkBENCHLOOP(3); i++) { SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, rand.nextUScalar1() * 400); r.offset(fRadius, fRadius); if (fRadius > 0) { SkMorphologyImageFilter* mf = NULL; switch (fStyle) { case kDilate_MT: mf = new SkDilateImageFilter(SkScalarFloorToInt(fRadius), SkScalarFloorToInt(fRadius)); break; case kErode_MT: mf = new SkErodeImageFilter(SkScalarFloorToInt(fRadius), SkScalarFloorToInt(fRadius)); break; } paint.setImageFilter(mf)->unref(); } canvas->drawOval(r, paint); } }
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); }
bool SkGridView::getCellRect(int index, SkRect* r) const { if (fVisibleCount.fY == 0) return false; index = this->logicalToVisualIndex(index); if (index >= 0) { SkRect bounds; int row = index / fVisibleCount.fY; int col = index % fVisibleCount.fY; bounds.set(0, 0, fCellSize.fX, fCellSize.fY); bounds.offset(col * (fCellSize.fX + SkIntToScalar(col > 0)), row * (fCellSize.fY + SkIntToScalar(row > 0))); if (bounds.fTop < this->height()) { if (r) *r = bounds; return true; } } return false; }
static FloatRect mapImageFilterRect(SkImageFilter* filter, const FloatRect& bounds) { SkRect filterBounds; filter->computeFastBounds(bounds, &filterBounds); filterBounds.offset(-bounds.x(), -bounds.y()); return filterBounds; }
void onDrawContent(SkCanvas* canvas) override { 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.setFilterQuality(1 == i ? kLow_SkFilterQuality : kNone_SkFilterQuality); canvas->drawBitmapRect(bitmap, srcR, fDstR[i], &paint, SkCanvas::kStrict_SrcRectConstraint); canvas->drawRect(fDstR[i], paint); } }
static void drawbitmaprect_proc(SkCanvas* canvas, const SkBitmap& bm, const SkPoint& pos) { SkRect r = { 0, 0, SkIntToScalar(bm.width()), SkIntToScalar(bm.height()) }; r.offset(pos.fX, pos.fY); canvas->drawBitmapRectToRect(bm, NULL, r, NULL); }