Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2019 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 "GrContextThreadSafeProxy.h"
      9 #include "GrContextThreadSafeProxyPriv.h"
     10 
     11 #include "GrBaseContextPriv.h"
     12 #include "GrCaps.h"
     13 #include "GrContext.h"
     14 #include "GrSkSLFPFactoryCache.h"
     15 #include "SkSurface_Gpu.h"
     16 #include "SkSurfaceCharacterization.h"
     17 
     18 GrContextThreadSafeProxy::GrContextThreadSafeProxy(GrBackendApi backend,
     19                                                    const GrContextOptions& options,
     20                                                    uint32_t contextID)
     21         : INHERITED(backend, options, contextID) {
     22 }
     23 
     24 GrContextThreadSafeProxy::~GrContextThreadSafeProxy() = default;
     25 
     26 bool GrContextThreadSafeProxy::init(sk_sp<const GrCaps> caps,
     27                                     sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
     28     return INHERITED::init(std::move(caps), std::move(FPFactoryCache));
     29 }
     30 
     31 SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
     32                                      size_t cacheMaxResourceBytes,
     33                                      const SkImageInfo& ii, const GrBackendFormat& backendFormat,
     34                                      int sampleCnt, GrSurfaceOrigin origin,
     35                                      const SkSurfaceProps& surfaceProps,
     36                                      bool isMipMapped, bool willUseGLFBO0, bool isTextureable) {
     37     if (!backendFormat.isValid()) {
     38         return SkSurfaceCharacterization(); // return an invalid characterization
     39     }
     40 
     41     if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
     42         // The willUseGLFBO0 flags can only be used for a GL backend.
     43         return SkSurfaceCharacterization(); // return an invalid characterization
     44     }
     45 
     46     if (!this->caps()->mipMapSupport()) {
     47         isMipMapped = false;
     48     }
     49 
     50     GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType());
     51     if (config == kUnknown_GrPixelConfig) {
     52         return SkSurfaceCharacterization(); // return an invalid characterization
     53     }
     54 
     55     if (!SkSurface_Gpu::Valid(this->caps(), config, ii.colorSpace())) {
     56         return SkSurfaceCharacterization(); // return an invalid characterization
     57     }
     58 
     59     sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, config);
     60     if (!sampleCnt) {
     61         return SkSurfaceCharacterization(); // return an invalid characterization
     62     }
     63 
     64     GrFSAAType FSAAType = GrFSAAType::kNone;
     65     if (sampleCnt > 1) {
     66         FSAAType = this->caps()->usesMixedSamples() ? GrFSAAType::kMixedSamples
     67                                                     : GrFSAAType::kUnifiedMSAA;
     68     }
     69 
     70     if (willUseGLFBO0 && isTextureable) {
     71         return SkSurfaceCharacterization(); // return an invalid characterization
     72     }
     73 
     74     if (isTextureable && !this->caps()->isConfigTexturable(config)) {
     75         // Skia doesn't agree that this is textureable.
     76         return SkSurfaceCharacterization(); // return an invalid characterization
     77     }
     78 
     79     return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
     80                                      cacheMaxResourceBytes, ii,
     81                                      origin, config, FSAAType, sampleCnt,
     82                                      SkSurfaceCharacterization::Textureable(isTextureable),
     83                                      SkSurfaceCharacterization::MipMapped(isMipMapped),
     84                                      SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
     85                                      SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
     86                                      surfaceProps);
     87 }
     88 
     89 ////////////////////////////////////////////////////////////////////////////////
     90 sk_sp<GrSkSLFPFactoryCache> GrContextThreadSafeProxyPriv::fpFactoryCache() {
     91     return fProxy->fpFactoryCache();
     92 }
     93 
     94 sk_sp<GrContextThreadSafeProxy> GrContextThreadSafeProxyPriv::Make(
     95                              GrBackendApi backend,
     96                              const GrContextOptions& options,
     97                              uint32_t contextID,
     98                              sk_sp<const GrCaps> caps,
     99                              sk_sp<GrSkSLFPFactoryCache> cache) {
    100     sk_sp<GrContextThreadSafeProxy> proxy(new GrContextThreadSafeProxy(backend, options,
    101                                                                        contextID));
    102 
    103     if (!proxy->init(std::move(caps), std::move(cache))) {
    104         return nullptr;
    105     }
    106     return proxy;
    107 }
    108 
    109