void onOnceBeforeDraw() override { // Build the picture. SkPictureRecorder recorder; SkCanvas* pictureCanvas = recorder.beginRecording(fTileSize, fTileSize, NULL, 0); this->drawTile(pictureCanvas); fPicture.reset(recorder.endRecording()); // Build a reference bitmap. fBitmap.allocN32Pixels(SkScalarCeilToInt(fTileSize), SkScalarCeilToInt(fTileSize)); fBitmap.eraseColor(SK_ColorTRANSPARENT); SkCanvas bitmapCanvas(fBitmap); this->drawTile(&bitmapCanvas); }
virtual void onDraw(SkCanvas* canvas) { canvas->clear(0x00000000); SkRect srcRect = SkRect::MakeWH(96, 96); SkSize deviceSize = SkSize::Make(16, 16); draw(canvas, srcRect, deviceSize, SkPaint::kNone_FilterLevel); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); draw(canvas, srcRect, deviceSize, SkPaint::kLow_FilterLevel); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); draw(canvas, srcRect, deviceSize, SkPaint::kMedium_FilterLevel); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); draw(canvas, srcRect, deviceSize, SkPaint::kHigh_FilterLevel); SkBitmap bitmap; bitmap.allocN32Pixels(16, 16); bitmap.eraseARGB(0x00, 0x00, 0x00, 0x00); { SkBitmapDevice bitmapDevice(bitmap); SkCanvas bitmapCanvas(&bitmapDevice); SkPaint paint; paint.setColor(0xFF00FF00); SkRect ovalRect = SkRect::MakeWH(16, 16); ovalRect.inset(SkScalarDiv(2.0f, 3.0f), SkScalarDiv(2.0f, 3.0f)); bitmapCanvas.drawOval(ovalRect, paint); } SkRect inRect = SkRect::MakeXYWH(-4, -4, 20, 20); SkRect outRect = SkRect::MakeXYWH(-24, -24, 120, 120); SkAutoTUnref<SkBitmapSource> source(SkBitmapSource::Create(bitmap, inRect, outRect)); canvas->translate(srcRect.width() + SkIntToScalar(10), 0); draw(canvas, srcRect, deviceSize, SkPaint::kHigh_FilterLevel, source.get()); }
virtual void recordCanvas(SkCanvas* canvas) { const SkPoint translateDelta = getTranslateDelta(); for (int i = 0; i < M; i++) { SkColor color = SK_ColorYELLOW + (i % 255); SkIRect rect = SkIRect::MakeWH(i,i); canvas->save(); // set the clip to the given region SkRegion region; region.setRect(rect); canvas->clipRegion(region); // fill the clip with a color SkPaint paint; paint.setColor(color); canvas->drawPaint(paint); // set a matrix on the canvas SkMatrix matrix; matrix.setRotate(SkIntToScalar(i % 360)); canvas->setMatrix(matrix); // create a simple bitmap SkBitmap bitmap; bitmap.setConfig(SkBitmap::kRGB_565_Config, 10, 10); bitmap.allocPixels(); // draw a single color into the bitmap SkCanvas bitmapCanvas(bitmap); bitmapCanvas.drawColor(SkColorSetA(color, i % 255)); // draw the bitmap onto the canvas canvas->drawBitmapMatrix(bitmap, matrix); canvas->restore(); canvas->translate(translateDelta.fX, translateDelta.fY); } }