void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) { 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); } } }
sk_sp<GrTextureProxy> GrCopyBaseMipMapToTextureProxy(GrContext* ctx, GrTextureProxy* baseProxy) { SkASSERT(baseProxy); if (!ctx->caps()->isConfigCopyable(baseProxy->config())) { return nullptr; } GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); GrSurfaceDesc desc; desc.fFlags = kNone_GrSurfaceFlags; desc.fOrigin = baseProxy->origin(); desc.fWidth = baseProxy->width(); desc.fHeight = baseProxy->height(); desc.fConfig = baseProxy->config(); desc.fSampleCnt = 1; sk_sp<GrTextureProxy> proxy = proxyProvider->createMipMapProxy(desc, SkBudgeted::kYes); if (!proxy) { return nullptr; } // Copy the base layer to our proxy sk_sp<SkColorSpace> colorSpace; if (GrPixelConfigIsSRGB(proxy->config())) { colorSpace = SkColorSpace::MakeSRGB(); } sk_sp<GrSurfaceContext> sContext = ctx->contextPriv().makeWrappedSurfaceContext(proxy, std::move(colorSpace)); SkASSERT(sContext); SkAssertResult(sContext->copy(baseProxy)); return proxy; }
void setup_vk_attachment_description(VkAttachmentDescription* attachment, const AttachmentDesc& desc, VkImageLayout layout) { attachment->flags = 0; attachment->format = desc.fFormat; SkAssertResult(GrSampleCountToVkSampleCount(desc.fSamples, &attachment->samples)); switch (layout) { case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: attachment->loadOp = desc.fLoadStoreOps.fLoadOp; attachment->storeOp = desc.fLoadStoreOps.fStoreOp; attachment->stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment->stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: attachment->loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachment->storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; attachment->stencilLoadOp = desc.fLoadStoreOps.fLoadOp; attachment->stencilStoreOp = desc.fLoadStoreOps.fStoreOp; break; default: SkFAIL("Unexpected attachment layout"); } attachment->initialLayout = layout; attachment->finalLayout = layout; }
void GrVkGpuRTCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) { SkASSERT(!clip.hasWindowRectangles()); CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo]; GrStencilAttachment* sb = fRenderTarget->renderTargetPriv().getStencilAttachment(); // this should only be called internally when we know we have a // stencil buffer. SkASSERT(sb); int stencilBitCount = sb->bits(); // The contract with the callers does not guarantee that we preserve all bits in the stencil // during this clear. Thus we will clear the entire stencil to the desired value. VkClearDepthStencilValue vkStencilColor; memset(&vkStencilColor, 0, sizeof(VkClearDepthStencilValue)); if (insideStencilMask) { vkStencilColor.stencil = (1 << (stencilBitCount - 1)); } else { vkStencilColor.stencil = 0; } VkClearRect clearRect; // Flip rect if necessary SkIRect vkRect; if (!clip.scissorEnabled()) { vkRect.setXYWH(0, 0, fRenderTarget->width(), fRenderTarget->height()); } else if (kBottomLeft_GrSurfaceOrigin != fOrigin) { vkRect = clip.scissorRect(); } else { const SkIRect& scissor = clip.scissorRect(); vkRect.setLTRB(scissor.fLeft, fRenderTarget->height() - scissor.fBottom, scissor.fRight, fRenderTarget->height() - scissor.fTop); } clearRect.rect.offset = { vkRect.fLeft, vkRect.fTop }; clearRect.rect.extent = { (uint32_t)vkRect.width(), (uint32_t)vkRect.height() }; clearRect.baseArrayLayer = 0; clearRect.layerCount = 1; uint32_t stencilIndex; SkAssertResult(cbInfo.fRenderPass->stencilAttachmentIndex(&stencilIndex)); VkClearAttachment attachment; attachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; attachment.colorAttachment = 0; // this value shouldn't matter attachment.clearValue.depthStencil = vkStencilColor; cbInfo.currentCmdBuf()->clearAttachments(fGpu, 1, &attachment, 1, &clearRect); cbInfo.fIsEmpty = false; // Update command buffer bounds if (!clip.scissorEnabled()) { cbInfo.fBounds.join(fRenderTarget->getBoundsRect()); } else { cbInfo.fBounds.join(SkRect::Make(clip.scissorRect())); } }
GrGLPath::GrGLPath(GrGLGpu* gpu, const SkPath& origSkPath, const GrStrokeInfo& origStroke) : INHERITED(gpu, origSkPath, origStroke), fPathID(gpu->glPathRendering()->genPaths(1)) { if (origSkPath.isEmpty()) { InitPathObjectEmptyPath(gpu, fPathID); fShouldStroke = false; fShouldFill = false; } else { const SkPath* skPath = &origSkPath; SkTLazy<SkPath> tmpPath; const GrStrokeInfo* stroke = &origStroke; GrStrokeInfo tmpStroke(SkStrokeRec::kFill_InitStyle); if (stroke->isDashed()) { // Skia stroking and NVPR stroking differ with respect to dashing // pattern. // Convert a dashing to either a stroke or a fill. if (stroke->applyDashToPath(tmpPath.init(), &tmpStroke, *skPath)) { skPath = tmpPath.get(); stroke = &tmpStroke; } } bool didInit = false; if (stroke->needToApply() && stroke->getCap() != SkPaint::kButt_Cap) { // Skia stroking and NVPR stroking differ with respect to stroking // end caps of empty subpaths. // Convert stroke to fill if path contains empty subpaths. didInit = InitPathObjectPathDataCheckingDegenerates(gpu, fPathID, *skPath); if (!didInit) { if (!tmpPath.isValid()) { tmpPath.init(); } SkAssertResult(stroke->applyToPath(tmpPath.get(), *skPath)); skPath = tmpPath.get(); tmpStroke.setFillStyle(); stroke = &tmpStroke; } } if (!didInit) { InitPathObjectPathData(gpu, fPathID, *skPath); } fShouldStroke = stroke->needToApply(); fShouldFill = stroke->isFillStyle() || stroke->getStyle() == SkStrokeRec::kStrokeAndFill_Style; if (fShouldStroke) { InitPathObjectStroke(gpu, fPathID, *stroke); // FIXME: try to account for stroking, without rasterizing the stroke. fBounds.outset(stroke->getWidth(), stroke->getWidth()); } } this->registerWithCache(); }
void SkOpContour::toReversePath(SkPathWriter* path) const { const SkOpSegment* segment = fTail; do { SkAssertResult(segment->addCurveTo(segment->tail(), segment->head(), path)); } while ((segment = segment->prev())); path->finishContour(); path->assemble(); }
void SKPAnimationBench::onPerCanvasPreDraw(SkCanvas* canvas) { INHERITED::onPerCanvasPreDraw(canvas); SkIRect bounds; SkAssertResult(canvas->getClipDeviceBounds(&bounds)); fCenter.set((bounds.fRight - bounds.fLeft) / 2.0f, (bounds.fBottom - bounds.fTop) / 2.0f); }
LightingView() : fLightAngle(0.0f) , fColorFactor(0.0f) { { SkBitmap diffuseBitmap; SkAssertResult(GetResourceAsBitmap("images/brickwork-texture.jpg", &diffuseBitmap)); fRect = SkRect::MakeIWH(diffuseBitmap.width(), diffuseBitmap.height()); fDiffuseShader = diffuseBitmap.makeShader(); } { SkBitmap normalBitmap; SkAssertResult(GetResourceAsBitmap("images/brickwork_normal-map.jpg", &normalBitmap)); sk_sp<SkShader> normalMap = normalBitmap.makeShader(); fNormalSource = SkNormalSource::MakeFromNormalMap(std::move(normalMap), SkMatrix::I()); } }
void SkOpContour::toReversePath(SkPathWriter* path) const { const SkPoint& pt = fTail->pts()[0]; path->deferredMove(pt); const SkOpSegment* segment = fTail; do { SkAssertResult(segment->addCurveTo(segment->tail(), segment->head(), path)); } while ((segment = segment->prev())); path->close(); }
static const SkBitmap& not4444(const SkBitmap& input, SkBitmap* copy) { if (input.colorType() != kARGB_4444_SkColorType) { return input; } // ARGB_4444 is rarely used, so we can do a wasteful tmp copy. SkAssertResult(input.copyTo(copy, kN32_SkColorType)); copy->setImmutable(); return *copy; }
bool willUseFilterColor() const { SkXfermode::Coeff dstCoeff; SkXfermode::Coeff srcCoeff; SkAssertResult(SkXfermode::ModeAsCoeff(fMode, &srcCoeff, &dstCoeff)); if (SkXfermode::kZero_Coeff == srcCoeff) { return GrBlendCoeffRefsSrc(sk_blend_to_grblend(dstCoeff)); } return true; }
// static void SkPDFUtils::AppendTransform(const SkMatrix& matrix, SkWStream* content) { SkScalar values[6]; SkAssertResult(matrix.pdfTransform(values)); for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) { SkPDFScalar::Append(values[i], content); content->writeText(" "); } content->writeText("cm\n"); }
SkShader::Context::Context(const SkShader& shader, const ContextRec& rec) : fShader(shader), fCTM(*rec.fMatrix) { // Because the context parameters must be valid at this point, we know that the matrix is // invertible. SkAssertResult(fShader.computeTotalInverse(rec, &fTotalInverse)); fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse); fPaintAlpha = rec.fPaint->getAlpha(); }
// static SkPDFArray* SkPDFUtils::MatrixToArray(const SkMatrix& matrix) { SkScalar values[6]; SkAssertResult(matrix.pdfTransform(values)); SkPDFArray* result = new SkPDFArray; result->reserve(6); for (size_t i = 0; i < SK_ARRAY_COUNT(values); i++) { result->append(new SkPDFScalar(values[i]))->unref(); } return result; }
void SkOpContour::toPath(SkPathWriter* path) const { if (!this->count()) { return; } const SkOpSegment* segment = &fHead; do { SkAssertResult(segment->addCurveTo(segment->head(), segment->tail(), path)); } while ((segment = segment->next())); path->finishContour(); path->assemble(); }
void SkPDFStream::emitObject(SkWStream* stream, SkPDFCatalog* catalog) { if (!this->populate(catalog)) { return fSubstitute->emitObject(stream, catalog); } this->INHERITED::emitObject(stream, catalog); stream->writeText(" stream\n"); stream->writeStream(fDataStream.get(), fDataStream->getLength()); SkAssertResult(fDataStream->rewind()); stream->writeText("\nendstream"); }
/** * A test for the SkDecodingImageGenerator::Create and * SkInstallDiscardablePixelRef functions. */ DEF_TEST(ImprovedBitmapFactory, reporter) { SkString pngFilename = GetResourcePath("randPixels.png"); SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(pngFilename.c_str())); if (sk_exists(pngFilename.c_str())) { SkBitmap bm; SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1))); REPORTER_ASSERT(reporter, install_pixel_ref(&bm, stream.detach(), 1, true)); SkAutoLockPixels alp(bm); REPORTER_ASSERT(reporter, bm.getPixels()); } }
bool DecodingImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { if (NULL == pixels) { return false; } if (fInfo != info) { // The caller has specified a different info. This is an // error for this kind of SkImageGenerator. Use the Options // to change the settings. return false; } if (info.minRowBytes() > rowBytes) { // The caller has specified a bad rowBytes. return false; } SkAssertResult(fStream->rewind()); SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); if (NULL == decoder.get()) { return false; } decoder->setDitherImage(fDitherImage); decoder->setSampleSize(fSampleSize); decoder->setRequireUnpremultipliedColors( info.fAlphaType == kUnpremul_SkAlphaType); SkBitmap bitmap; TargetAllocator allocator(fInfo, pixels, rowBytes); decoder->setAllocator(&allocator); // TODO: need to be able to pass colortype directly to decoder SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); bool success = decoder->decode(fStream, &bitmap, legacyConfig, SkImageDecoder::kDecodePixels_Mode); decoder->setAllocator(NULL); if (!success) { return false; } if (allocator.isReady()) { // Did not use pixels! SkBitmap bm; SkASSERT(bitmap.canCopyTo(info.colorType())); bool copySuccess = bitmap.copyTo(&bm, info.colorType(), &allocator); if (!copySuccess || allocator.isReady()) { SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed."); // Earlier we checked canCopyto(); we expect consistency. return false; } SkASSERT(check_alpha(info.alphaType(), bm.alphaType())); } else { SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType())); } return true; }
void onOnceBeforeDraw() override { // Copyright-free file from http://openclipart.org/detail/29213/paper-plane-by-ddoo SkString pngFilename = GetResourcePath("plane.png"); SkAutoDataUnref data(SkData::NewFromFileName(pngFilename.c_str())); if (data.get()) { // Create a cache which will boot the pixels out anytime the // bitmap is unlocked. SkAutoTUnref<SkDiscardableMemoryPool> pool( SkDiscardableMemoryPool::Create(1)); SkAssertResult(SkInstallDiscardablePixelRef(SkImageGenerator::NewFromData(data), NULL, &fBitmap, pool)); } }
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = rt.width(); desc.fHeight = rt.height(); GrMockRenderTargetInfo info; SkAssertResult(rt.getMockRenderTargetInfo(&info)); desc.fConfig = info.fConfig; return sk_sp<GrRenderTarget>( new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, info)); }
// Test if invalidating unique ids prior to instantiating operates as expected static void invalidation_and_instantiation_test(GrContext* context, skiatest::Reporter* reporter) { GrProxyProvider* proxyProvider = context->priv().proxyProvider(); GrResourceProvider* resourceProvider = context->priv().resourceProvider(); GrResourceCache* cache = context->priv().getResourceCache(); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); GrUniqueKey key; GrUniqueKey::Builder builder(&key, d, 1, nullptr); builder[0] = 0; builder.finish(); // Create proxy, assign unique key sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, proxyProvider, SkBackingFit::kExact); SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get())); // Send an invalidation message, which will be sitting in the cache's inbox SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post( GrUniqueKeyInvalidatedMessage(key, context->priv().contextID())); REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); // Instantiate the proxy. This will trigger the message to be processed, so the resulting // texture should *not* have the unique key on it! SkAssertResult(proxy->instantiate(resourceProvider)); REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid()); REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid()); REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); proxy = nullptr; context->priv().testingOnly_purgeAllUnlockedResources(); REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly()); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); }
virtual void onDraw(SkCanvas* canvas) { SkBitmap bm, bm4444; SkString filename = SkOSPath::SkPathJoin(INHERITED::gResourcePath, "mandrill_512.png"); if (!SkImageDecoder::DecodeFile(filename.c_str(), &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode)) { SkDebugf("Could not decode the file. Did you forget to set the " "resourcePath?\n"); return; } canvas->drawBitmap(bm, 0, 0); SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType)); canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0); }
virtual void onDraw(SkCanvas* canvas) { SkBitmap bm, bm4444; if (!GetResourceAsBitmap("dog.jpg", &bm)) { SkDebugf("Could not decode the file. Did you forget to set the " "resourcePath?\n"); return; } canvas->drawBitmap(bm, 0, 0); // This should dither or we will see artifacts in the background of the image. SkAssertResult(sk_tool_utils::copy_to(&bm4444, kARGB_4444_SkColorType, bm)); canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0); }
// A contructor-type function that returns NULL on failure. This // prevents the returned SkImageGenerator from ever being in a bad // state. Called by both Create() functions SkImageGenerator* CreateDecodingImageGenerator( SkData* data, SkStreamRewindable* stream, const SkDecodingImageGenerator::Options& opts) { SkASSERT(stream); SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. if (opts.fUseRequestedColorType && (kIndex_8_SkColorType == opts.fRequestedColorType)) { // We do not support indexed color with SkImageGenerators, return NULL; } SkAssertResult(autoStream->rewind()); SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); if (NULL == decoder.get()) { return NULL; } SkBitmap bitmap; decoder->setSampleSize(opts.fSampleSize); decoder->setRequireUnpremultipliedColors(opts.fRequireUnpremul); if (!decoder->decode(stream, &bitmap, SkImageDecoder::kDecodeBounds_Mode)) { return NULL; } if (bitmap.config() == SkBitmap::kNo_Config) { return NULL; } SkImageInfo info = bitmap.info(); if (!opts.fUseRequestedColorType) { // Use default if (kIndex_8_SkColorType == bitmap.colorType()) { // We don't support kIndex8 because we don't support // colortables in this workflow. info.fColorType = kN32_SkColorType; } } else { if (!bitmap.canCopyTo(opts.fRequestedColorType)) { SkASSERT(bitmap.colorType() != opts.fRequestedColorType); return NULL; // Can not translate to needed config. } info.fColorType = opts.fRequestedColorType; } if (opts.fRequireUnpremul && info.fAlphaType != kOpaque_SkAlphaType) { info.fAlphaType = kUnpremul_SkAlphaType; } return SkNEW_ARGS(DecodingImageGenerator, (data, autoStream.detach(), info, opts.fSampleSize, opts.fDitherImage)); }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); static const int kWidth = 100; static const int kHeight = 90; SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight); sk_sp<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii, 1, kBottomLeft_GrSurfaceOrigin, nullptr, GrMipMapped::kNo, SkGpuDevice::kClear_InitContents)); SkBitmap bm; SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight)); // Create a gpu-backed special image from a raster-backed SkBitmap sk_sp<SkSpecialImage> special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), bm); SkASSERT(special->isTextureBacked()); SkASSERT(kWidth == special->width()); SkASSERT(kHeight == special->height()); SkASSERT(bm.getGenerationID() == special->uniqueID()); SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); // Create a gpu-backed special image from a raster-backed SkImage sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm)); special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get()); SkASSERT(special->isTextureBacked()); SkASSERT(kWidth == special->width()); SkASSERT(kHeight == special->height()); // TODO: Hmmm, this is a bit unexpected SkASSERT(image->uniqueID() != special->uniqueID()); SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); // Create a gpu-backed special image from a gpu-backed SkImage SkColorSpace* legacyColorSpace = nullptr; image = image->makeTextureImage(context, legacyColorSpace); special = DeviceTestingAccess::MakeSpecial(gpuDev.get(), image.get()); SkASSERT(special->isTextureBacked()); SkASSERT(kWidth == special->width()); SkASSERT(kHeight == special->height()); SkASSERT(image->uniqueID() == special->uniqueID()); SkASSERT(SkIRect::MakeWH(kWidth, kHeight) == special->subset()); // Snap the device as a gpu-backed special image special = DeviceTestingAccess::SnapSpecial(gpuDev.get()); SkASSERT(special->isTextureBacked()); SkASSERT(2*kWidth == special->width()); SkASSERT(2*kHeight == special->height()); SkASSERT(SkIRect::MakeWH(2*kWidth, 2*kHeight) == special->subset()); }
const char* GrGLShaderBuilder::fragmentPosition() { if (fCodeStage.inStageCode()) { const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); if (!effect->willReadFragmentPosition()) { GrDebugCrash("GrGLEffect asked for frag position but its generating GrEffect " "did not request access."); return ""; } } if (fTopLeftFragPosRead) { if (!fSetupFragPosition) { fFSInputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kIn_TypeModifier, "gl_FragCoord", GrGLShaderVar::kDefault_Precision); fSetupFragPosition = true; } return "gl_FragCoord"; } else if (fGpu->glCaps().fragCoordConventionsSupport()) { if (!fSetupFragPosition) { SkAssertResult(this->enablePrivateFeature(kFragCoordConventions_GLSLPrivateFeature)); fFSInputs.push_back().set(kVec4f_GrSLType, GrGLShaderVar::kIn_TypeModifier, "gl_FragCoord", GrGLShaderVar::kDefault_Precision, GrGLShaderVar::kUpperLeft_Origin); fSetupFragPosition = true; } return "gl_FragCoord"; } else { static const char* kCoordName = "fragCoordYDown"; if (!fSetupFragPosition) { // temporarily change the stage index because we're inserting non-stage code. CodeStage::AutoStageRestore csar(&fCodeStage, NULL); SkASSERT(!fRTHeightUniform.isValid()); const char* rtHeightName; fRTHeightUniform = this->addUniform(kFragment_Visibility, kFloat_GrSLType, "RTHeight", &rtHeightName); this->fFSCode.prependf("\tvec4 %s = vec4(gl_FragCoord.x, %s - gl_FragCoord.y, gl_FragCoord.zw);\n", kCoordName, rtHeightName); fSetupFragPosition = true; } SkASSERT(fRTHeightUniform.isValid()); return kCoordName; } }
GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path, const SkVector* offset) { if (kHairlineAA_GrProcessorEdgeType == type) { return NULL; } if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || !path.isConvex()) { return NULL; } if (path.countPoints() > kMaxEdges) { return NULL; } SkPoint pts[kMaxEdges]; SkScalar edges[3 * kMaxEdges]; SkPath::Direction dir; SkAssertResult(path.cheapComputeDirection(&dir)); SkVector t; if (NULL == offset) { t.set(0, 0); } else { t = *offset; } int count = path.getPoints(pts, kMaxEdges); int n = 0; for (int lastPt = count - 1, i = 0; i < count; lastPt = i++) { if (pts[lastPt] != pts[i]) { SkVector v = pts[i] - pts[lastPt]; v.normalize(); if (SkPath::kCCW_Direction == dir) { edges[3 * n] = v.fY; edges[3 * n + 1] = -v.fX; } else { edges[3 * n] = -v.fY; edges[3 * n + 1] = v.fX; } SkPoint p = pts[i] + t; edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); ++n; } } if (path.isInverseFillType()) { type = GrInvertProcessorEdgeType(type); } return Create(type, n, edges); }
const char* GrGLShaderBuilder::dstColor() { if (fCodeStage.inStageCode()) { const GrEffectRef& effect = *fCodeStage.effectStage()->getEffect(); if (!effect->willReadDstColor()) { SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEffect " "did not request access."); return ""; } } static const char kFBFetchColorName[] = "gl_LastFragData[0]"; GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); if (GrGLCaps::kEXT_FBFetchType == fetchType) { SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLSLPrivateFeature)); return kFBFetchColorName; } else if (GrGLCaps::kNV_FBFetchType == fetchType) { SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSLPrivateFeature)); return kFBFetchColorName; } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { return kDstCopyColorName; } else { return ""; } }
static void setup_multisample_state(int numSamples, VkPipelineMultisampleStateCreateInfo* multisampleInfo) { memset(multisampleInfo, 0, sizeof(VkPipelineMultisampleStateCreateInfo)); multisampleInfo->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleInfo->pNext = nullptr; multisampleInfo->flags = 0; SkAssertResult(GrSampleCountToVkSampleCount(numSamples, &multisampleInfo->rasterizationSamples)); multisampleInfo->sampleShadingEnable = VK_FALSE; multisampleInfo->minSampleShading = 0.0f; multisampleInfo->pSampleMask = nullptr; multisampleInfo->alphaToCoverageEnable = VK_FALSE; multisampleInfo->alphaToOneEnable = VK_FALSE; }
bool fetch(SkFILEStream& reader, TestResult* result) { char c; int i = 0; result->init(fDirNo); result->fPixelError = 0; result->fTime = 0; do { bool readOne = reader.read(&c, 1) != 0; if (!readOne) { SkASSERT(i == 0); return false; } if (c == ' ') { result->fFilename[i++] = '\0'; break; } result->fFilename[i++] = c; SkASSERT(i < kMaxLength); } while (true); do { SkAssertResult(reader.read(&c, 1) != 0); if (c == ' ') { break; } SkASSERT(c >= '0' && c <= '9'); result->fPixelError = result->fPixelError * 10 + (c - '0'); } while (true); bool minus = false; do { if (reader.read(&c, 1) == 0) { break; } if (c == '\r' && reader.read(&c, 1) == 0) { break; } if (c == '\n') { break; } if (c == '-') { minus = true; continue; } SkASSERT(c >= '0' && c <= '9'); result->fTime = result->fTime * 10 + (c - '0'); } while (true); if (minus) { result->fTime = -result->fTime; } return true; }