void FatBits::drawTriangle(SkCanvas* canvas, SkPoint pts[3]) { SkPaint paint; fInverse.mapPoints(pts, 3); if (fGrid) { apply_grid(pts, 3); } SkPath path; path.moveTo(pts[0]); path.lineTo(pts[1]); path.lineTo(pts[2]); path.close(); erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); fMinSurface->getCanvas()->drawPath(path, paint); this->copyMinToMax(); SkCanvas* max = fMaxSurface->getCanvas(); fMatrix.mapPoints(pts, 3); this->drawTriangleSkeleton(max, pts); fMaxSurface->draw(canvas, 0, 0, nullptr); }
void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) { SkPaint paint; fInverse.mapPoints(pts, 2); if (fGrid) { apply_grid(pts, 2); } SkRect r; r.set(pts, 2); erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); { SkCanvas* c = fMinSurface->getCanvas(); fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint); } this->copyMinToMax(); SkCanvas* max = fMaxSurface->getCanvas(); fMatrix.mapPoints(pts, 2); r.set(pts, 2); this->drawRectSkeleton(max, r); fMaxSurface->draw(canvas, 0, 0, nullptr); }
void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { SkPaint paint; fInverse.mapPoints(pts, 2); if (fGrid) { apply_grid(pts, 2); } erase(fMinSurface.get()); this->setupPaint(&paint); paint.setColor(FAT_PIXEL_COLOR); if (fUseClip) { fMinSurface->getCanvas()->save(); SkRect r = fClipRect; r.inset(SK_Scalar1/3, SK_Scalar1/3); fMinSurface->getCanvas()->clipRect(r, kIntersect_SkClipOp, true); } fMinSurface->getCanvas()->drawLine(pts[0], pts[1], paint); if (fUseClip) { fMinSurface->getCanvas()->restore(); } this->copyMinToMax(); SkCanvas* max = fMaxSurface->getCanvas(); fMatrix.mapPoints(pts, 2); this->drawLineSkeleton(max, pts); fMaxSurface->draw(canvas, 0, 0, nullptr); }
void onDraw(int loops, SkCanvas* canvas) override { if (!fSurface) { GrContext* context = canvas->getGrContext(); if (nullptr == context) { return; } SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPremul_SkAlphaType, kSRGB_SkColorProfileType); fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); } // Clear surface once: fSurface->getCanvas()->clear(SK_ColorBLACK); SkPaint paint; paint.setFilterQuality(kMedium_SkFilterQuality); for (int i = 0; i < loops; i++) { // Touch surface so mips are dirtied fSurface->getCanvas()->drawPoint(0, 0, SK_ColorWHITE); // Draw reduced version of surface to original canvas, to trigger mip generation canvas->save(); canvas->scale(0.1f, 0.1f); canvas->drawImage(fSurface->makeImageSnapshot(SkBudgeted::kNo), 0, 0, &paint); canvas->restore(); } }
void WindowContext::presentRenderSurface(sk_sp<SkSurface> renderSurface, sk_sp<GrRenderTarget> rt, int colorBits) { if (!this->isGpuContext() || colorBits > 24 || kRGBA_F16_SkColorType == fDisplayParams.fColorType) { // We made/have an off-screen surface. Get the contents as an SkImage: SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, fDisplayParams.fColorType, kUnknown_SkAlphaType, fDisplayParams.fColorSpace); SkBitmap bm; bm.allocPixels(info); renderSurface->getCanvas()->readPixels(&bm, 0, 0); SkPixmap pm; bm.peekPixels(&pm); sk_sp<SkImage> image(SkImage::MakeTextureFromPixmap(fContext, pm, SkBudgeted::kNo)); GrTexture* texture = as_IB(image)->peekTexture(); SkASSERT(texture); // With ten-bit output, we need to manually apply the gamma of the output device // (unless we're in non-gamma correct mode, in which case our data is already // fake-sRGB, like we're expected to put in the 10-bit buffer): bool doGamma = (colorBits == 30) && SkImageInfoIsGammaCorrect(info); fContext->applyGamma(rt.get(), texture, doGamma ? 1.0f / 2.2f : 1.0f); } }
// Exercise the public API of SkSpecialSurface (e.g., getCanvas, newImageSnapshot) static void test_surface(const sk_sp<SkSpecialSurface>& surf, skiatest::Reporter* reporter, int offset) { const SkIRect surfSubset = TestingSpecialSurfaceAccess::Subset(surf.get()); REPORTER_ASSERT(reporter, offset == surfSubset.fLeft); REPORTER_ASSERT(reporter, offset == surfSubset.fTop); REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.width()); REPORTER_ASSERT(reporter, kSmallerSize == surfSubset.height()); SkCanvas* canvas = surf->getCanvas(); SkASSERT_RELEASE(canvas); canvas->clear(SK_ColorRED); sk_sp<SkSpecialImage> img(surf->makeImageSnapshot()); REPORTER_ASSERT(reporter, img); const SkIRect imgSubset = img->subset(); REPORTER_ASSERT(reporter, surfSubset == imgSubset); // the canvas was invalidated by the newImageSnapshot call REPORTER_ASSERT(reporter, !surf->getCanvas()); }
void copyMinToMax() { erase(fMaxSurface.get()); SkCanvas* canvas = fMaxSurface->getCanvas(); canvas->save(); canvas->concat(fMatrix); fMinSurface->draw(canvas, 0, 0, nullptr); canvas->restore(); SkPaint paint; paint.setBlendMode(SkBlendMode::kClear); for (int iy = 1; iy < fH; ++iy) { SkScalar y = SkIntToScalar(iy * fZoom); canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint); } for (int ix = 1; ix < fW; ++ix) { SkScalar x = SkIntToScalar(ix * fZoom); canvas->drawLine(x - SK_ScalarHalf, 0, x - SK_ScalarHalf, 999, paint); } }
Status draw(Src* src) override { auto size = src->size(); surface = SkSurface::MakeRaster(info.makeWH(size.width(), size.height())); return src->draw(surface->getCanvas()); }