Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2018 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 "GrContext.h"
      9 #include "GrCaps.h"
     10 #include "GrContextPriv.h"
     11 #include "GrContextThreadSafeProxyPriv.h"
     12 #include "GrSkSLFPFactoryCache.h"
     13 
     14 /**
     15  * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
     16  * cannot allocate any GPU resources.
     17  */
     18 class SK_API GrDDLContext : public GrContext {
     19 public:
     20     GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
     21             : INHERITED(proxy->priv().backend(), proxy->priv().contextID()) {
     22         fCaps = proxy->priv().refCaps();
     23         fFPFactoryCache = proxy->priv().fpFactoryCache();
     24         SkASSERT(fFPFactoryCache);
     25         fThreadSafeProxy = std::move(proxy);
     26     }
     27 
     28     ~GrDDLContext() override {
     29         // The GrDDLContext doesn't actually own the fRestrictedAtlasManager so don't delete it
     30     }
     31 
     32     void abandonContext() override {
     33         SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
     34         INHERITED::abandonContext();
     35     }
     36 
     37     void releaseResourcesAndAbandonContext() override {
     38         SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
     39         INHERITED::releaseResourcesAndAbandonContext();
     40     }
     41 
     42     void freeGpuResources() override {
     43         SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense
     44         INHERITED::freeGpuResources();
     45     }
     46 
     47 protected:
     48     bool init(const GrContextOptions& options) override {
     49         SkASSERT(fCaps);  // should've been set in ctor
     50         SkASSERT(fThreadSafeProxy); // should've been set in the ctor
     51 
     52         if (!INHERITED::initCommon(options)) {
     53             return false;
     54         }
     55 
     56         return true;
     57     }
     58 
     59     GrAtlasManager* onGetAtlasManager() override {
     60         SkASSERT(0);   // the DDL Recorders should never invoke this
     61         return nullptr;
     62     }
     63 
     64 private:
     65     typedef GrContext INHERITED;
     66 };
     67 
     68 sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
     69     sk_sp<GrContext> context(new GrDDLContext(proxy));
     70 
     71     // Note: we aren't creating a Gpu here. This causes the resource provider & cache to
     72     // also not be created
     73     if (!context->init(proxy->priv().contextOptions())) {
     74         return nullptr;
     75     }
     76     return context;
     77 }
     78