Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2017 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "GrOnFlushResourceProvider.h"
      9 #include "GrContext.h"
     10 #include "GrContextPriv.h"
     11 #include "GrDrawingManager.h"
     12 #include "GrProxyProvider.h"
     13 #include "GrRenderTargetContext.h"
     14 #include "GrSurfaceProxy.h"
     15 
     16 sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
     17                                                         sk_sp<GrSurfaceProxy> proxy,
     18                                                         sk_sp<SkColorSpace> colorSpace,
     19                                                         const SkSurfaceProps* props) {
     20     // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator
     21     // we have to manually ensure it is allocated here. The proxy had best have been created
     22     // with the kNoPendingIO flag!
     23     if (!this->instatiateProxy(proxy.get())) {
     24         return nullptr;
     25     }
     26 
     27     sk_sp<GrRenderTargetContext> renderTargetContext(
     28         fDrawingMgr->makeRenderTargetContext(std::move(proxy),
     29                                              std::move(colorSpace),
     30                                              props, false));
     31 
     32     if (!renderTargetContext) {
     33         return nullptr;
     34     }
     35 
     36     renderTargetContext->discard();
     37 
     38     return renderTargetContext;
     39 }
     40 
     41 bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key,
     42                                                        GrTextureProxy* proxy) {
     43     auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
     44     return proxyProvider->assignUniqueKeyToProxy(key, proxy);
     45 }
     46 
     47 void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
     48     auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
     49     proxyProvider->removeUniqueKeyFromProxy(proxy);
     50 }
     51 
     52 void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) {
     53     auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
     54     proxyProvider->processInvalidUniqueKey(key, nullptr,
     55                                            GrProxyProvider::InvalidateGPUResource::kYes);
     56 }
     57 
     58 sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
     59         const GrUniqueKey& key, GrSurfaceOrigin origin) {
     60     auto proxyProvider = fDrawingMgr->getContext()->contextPriv().proxyProvider();
     61     return proxyProvider->findOrCreateProxyByUniqueKey(key, origin);
     62 }
     63 
     64 bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
     65     auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
     66 
     67     if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
     68         // DDL TODO: Decide if we ever plan to have these proxies use the GrDeinstantiateTracker
     69         // to support unistantiating them at the end of a flush.
     70         return proxy->priv().doLazyInstantiation(resourceProvider);
     71     }
     72 
     73     return proxy->instantiate(resourceProvider);
     74 }
     75 
     76 sk_sp<GrBuffer> GrOnFlushResourceProvider::makeBuffer(GrBufferType intendedType, size_t size,
     77                                                       const void* data) {
     78     auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
     79     return sk_sp<GrBuffer>(resourceProvider->createBuffer(size, intendedType,
     80                                                           kDynamic_GrAccessPattern,
     81                                                           GrResourceProvider::Flags::kNone,
     82                                                           data));
     83 }
     84 
     85 sk_sp<const GrBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(GrBufferType intendedType,
     86                                                                         size_t size,
     87                                                                         const void* data,
     88                                                                         const GrUniqueKey& key) {
     89     auto resourceProvider = fDrawingMgr->getContext()->contextPriv().resourceProvider();
     90     sk_sp<const GrBuffer> buffer = resourceProvider->findOrMakeStaticBuffer(intendedType, size,
     91                                                                             data, key);
     92     // Static buffers should never have pending IO.
     93     SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
     94     return buffer;
     95 }
     96 
     97 uint32_t GrOnFlushResourceProvider::contextID() const {
     98     return fDrawingMgr->getContext()->contextPriv().contextID();
     99 }
    100 
    101 const GrCaps* GrOnFlushResourceProvider::caps() const {
    102     return fDrawingMgr->getContext()->contextPriv().caps();
    103 }
    104