bool GrGpu::copySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) { GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "copySurface", fContext); SkASSERT(dst && src); this->handleDirtyContext(); return this->onCopySurface(dst, dstOrigin, src, srcOrigin, srcRect, dstPoint, canDiscardOutsideDstRect); }
sk_sp<GrTexture> GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budgeted, const GrMipLevel texels[], int mipLevelCount) { GR_CREATE_TRACE_MARKER_CONTEXT("GrGpu", "createTexture", fContext); GrSurfaceDesc desc = origDesc; GrMipMapped mipMapped = mipLevelCount > 1 ? GrMipMapped::kYes : GrMipMapped::kNo; if (!this->caps()->validateSurfaceDesc(desc, mipMapped)) { return nullptr; } bool isRT = desc.fFlags & kRenderTarget_GrSurfaceFlag; if (isRT) { desc.fSampleCnt = this->caps()->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig); } // Attempt to catch un- or wrongly initialized sample counts. SkASSERT(desc.fSampleCnt > 0 && desc.fSampleCnt <= 64); if (mipLevelCount && (desc.fFlags & kPerformInitialClear_GrSurfaceFlag)) { return nullptr; } this->handleDirtyContext(); sk_sp<GrTexture> tex = this->onCreateTexture(desc, budgeted, texels, mipLevelCount); if (tex) { if (!this->caps()->reuseScratchTextures() && !isRT) { tex->resourcePriv().removeScratchKey(); } fStats.incTextureCreates(); if (mipLevelCount) { if (texels[0].fPixels) { fStats.incTextureUploads(); } } } return tex; }
// MDB TODO: make use of the 'proxy' parameter. GrSemaphoresSubmitted GrDrawingManager::internalFlush(GrSurfaceProxy*, GrResourceCache::FlushType type, int numSemaphores, GrBackendSemaphore backendSemaphores[]) { GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "internalFlush", fContext); if (fFlushing || this->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; } GrGpu* gpu = fContext->contextPriv().getGpu(); if (!gpu) { return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording } fFlushing = true; for (int i = 0; i < fOpLists.count(); ++i) { // Semi-usually the GrOpLists are already closed at this point, but sometimes Ganesh // needs to flush mid-draw. In that case, the SkGpuDevice's GrOpLists won't be closed // but need to be flushed anyway. Closing such GrOpLists here will mean new // GrOpLists will be created to replace them if the SkGpuDevice(s) write to them again. fOpLists[i]->makeClosed(*fContext->caps()); } #ifdef SK_DEBUG // This block checks for any unnecessary splits in the opLists. If two sequential opLists // share the same backing GrSurfaceProxy it means the opList was artificially split. if (fOpLists.count()) { GrRenderTargetOpList* prevOpList = fOpLists[0]->asRenderTargetOpList(); for (int i = 1; i < fOpLists.count(); ++i) { GrRenderTargetOpList* curOpList = fOpLists[i]->asRenderTargetOpList(); if (prevOpList && curOpList) { SkASSERT(prevOpList->fTarget.get() != curOpList->fTarget.get()); } prevOpList = curOpList; } } #endif if (fSortRenderTargets) { SkDEBUGCODE(bool result =) SkTTopoSort<GrOpList, GrOpList::TopoSortTraits>(&fOpLists); SkASSERT(result); } GrOpFlushState flushState(gpu, fContext->contextPriv().resourceProvider(), &fTokenTracker); GrOnFlushResourceProvider onFlushProvider(this); // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the // stack here is to preserve the flush tokens. // Prepare any onFlush op lists (e.g. atlases). if (!fOnFlushCBObjects.empty()) { fFlushingOpListIDs.reset(fOpLists.count()); for (int i = 0; i < fOpLists.count(); ++i) { fFlushingOpListIDs[i] = fOpLists[i]->uniqueID(); } SkSTArray<4, sk_sp<GrRenderTargetContext>> renderTargetContexts; for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { onFlushCBObject->preFlush(&onFlushProvider, fFlushingOpListIDs.begin(), fFlushingOpListIDs.count(), &renderTargetContexts); for (const sk_sp<GrRenderTargetContext>& rtc : renderTargetContexts) { sk_sp<GrRenderTargetOpList> onFlushOpList = sk_ref_sp(rtc->getRTOpList()); if (!onFlushOpList) { continue; // Odd - but not a big deal } #ifdef SK_DEBUG // OnFlush callbacks are already invoked during flush, and are therefore expected to // handle resource allocation & usage on their own. (No deferred or lazy proxies!) onFlushOpList->visitProxies_debugOnly([](GrSurfaceProxy* p) { SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred()); SkASSERT(GrSurfaceProxy::LazyState::kNot == p->lazyInstantiationState()); }); #endif onFlushOpList->makeClosed(*fContext->caps()); onFlushOpList->prepare(&flushState); fOnFlushCBOpLists.push_back(std::move(onFlushOpList)); } renderTargetContexts.reset(); } } #if 0 // Enable this to print out verbose GrOp information for (int i = 0; i < fOpLists.count(); ++i) { SkDEBUGCODE(fOpLists[i]->dump();) } #endif int startIndex, stopIndex; bool flushed = false; { GrResourceAllocator alloc(fContext->contextPriv().resourceProvider()); for (int i = 0; i < fOpLists.count(); ++i) { fOpLists[i]->gatherProxyIntervals(&alloc); alloc.markEndOfOpList(i); } GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError; while (alloc.assign(&startIndex, &stopIndex, flushState.uninstantiateProxyTracker(), &error)) { if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) { for (int i = startIndex; i < stopIndex; ++i) { fOpLists[i]->purgeOpsWithUninstantiatedProxies(); } } if (this->executeOpLists(startIndex, stopIndex, &flushState)) { flushed = true; } } } fOpLists.reset(); GrSemaphoresSubmitted result = gpu->finishFlush(numSemaphores, backendSemaphores); flushState.uninstantiateProxyTracker()->uninstantiateAllProxies(); // We always have to notify the cache when it requested a flush so it can reset its state. if (flushed || type == GrResourceCache::FlushType::kCacheRequested) { fContext->contextPriv().getResourceCache()->notifyFlushOccurred(type); } for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingOpListIDs.begin(), fFlushingOpListIDs.count()); } fFlushingOpListIDs.reset(); fFlushing = false; return result; }