void test_copy_to_surface(skiatest::Reporter* reporter, GrProxyProvider* proxyProvider, GrSurfaceContext* dstContext, const char* testName) { int pixelCnt = dstContext->width() * dstContext->height(); SkAutoTMalloc<uint32_t> pixels(pixelCnt); for (int y = 0; y < dstContext->width(); ++y) { for (int x = 0; x < dstContext->height(); ++x) { pixels.get()[y * dstContext->width() + x] = GrPremulColor(GrColorPackRGBA(y, x, x * y, 2*y)); } } GrSurfaceDesc copySrcDesc; copySrcDesc.fWidth = dstContext->width(); copySrcDesc.fHeight = dstContext->height(); copySrcDesc.fConfig = kRGBA_8888_GrPixelConfig; for (auto flags : { kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag }) { copySrcDesc.fFlags = flags; copySrcDesc.fOrigin = (kNone_GrSurfaceFlags == flags) ? kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; sk_sp<GrTextureProxy> src = proxyProvider->createTextureProxy(copySrcDesc, SkBudgeted::kYes, pixels.get(), 0); dstContext->copy(src.get()); test_read_pixels(reporter, dstContext, pixels.get(), testName); } }
const GrFragmentProcessor* SkModeColorFilter::asFragmentProcessor(GrContext*) const { if (SkXfermode::kDst_Mode == fMode) { return nullptr; } SkAutoTUnref<const GrFragmentProcessor> constFP( GrConstColorProcessor::Create(SkColorToPremulGrColor(fColor), GrConstColorProcessor::kIgnore_InputMode)); const GrFragmentProcessor* fp = GrXfermodeFragmentProcessor::CreateFromSrcProcessor(constFP, fMode); if (!fp) { return nullptr; } #ifdef SK_DEBUG // With a solid color input this should always be able to compute the blended color // (at least for coeff modes) if (fMode <= SkXfermode::kLastCoeffMode) { static SkRandom gRand; GrInvariantOutput io(GrPremulColor(gRand.nextU()), kRGBA_GrColorComponentFlags, false); fp->computeInvariantOutput(&io); SkASSERT(io.validFlags() == kRGBA_GrColorComponentFlags); } #endif return fp; }
void test_write_pixels(skiatest::Reporter* reporter, GrSurfaceContext* dstContext, bool expectedToWork, const char* testName) { int pixelCnt = dstContext->width() * dstContext->height(); SkAutoTMalloc<uint32_t> pixels(pixelCnt); for (int y = 0; y < dstContext->width(); ++y) { for (int x = 0; x < dstContext->height(); ++x) { pixels.get()[y * dstContext->width() + x] = GrPremulColor(GrColorPackRGBA(x, y, x + y, 2*y)); } } SkImageInfo ii = SkImageInfo::Make(dstContext->width(), dstContext->height(), kRGBA_8888_SkColorType, kPremul_SkAlphaType); bool write = dstContext->writePixels(ii, pixels.get(), 0, 0, 0); if (!write) { if (expectedToWork) { ERRORF(reporter, "%s: Error writing to texture.", testName); } return; } if (write && !expectedToWork) { ERRORF(reporter, "%s: writePixels succeeded when it wasn't supposed to.", testName); return; } test_read_pixels(reporter, dstContext, pixels.get(), testName); }