Home | History | Annotate | Download | only in core
      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 #ifndef SkSurfaceCharacterization_DEFINED
      9 #define SkSurfaceCharacterization_DEFINED
     10 
     11 #include "GrTypes.h"
     12 
     13 #include "SkColorSpace.h"
     14 #include "SkRefCnt.h"
     15 #include "SkSurfaceProps.h"
     16 
     17 class SkColorSpace;
     18 
     19 #if SK_SUPPORT_GPU
     20 // TODO: remove the GrContext.h include once Flutter is updated
     21 #include "GrContext.h"
     22 #include "GrContextThreadSafeProxy.h"
     23 
     24 /** \class SkSurfaceCharacterization
     25     A surface characterization contains all the information Ganesh requires to makes its internal
     26     rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
     27     data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
     28     those objects (the Recorder and the DisplayList) will take a ref on the
     29     GrContextThreadSafeProxy and SkColorSpace objects.
     30 */
     31 class SK_API SkSurfaceCharacterization {
     32 public:
     33     enum class Textureable : bool { kNo = false, kYes = true };
     34     enum class MipMapped : bool { kNo = false, kYes = true };
     35     enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
     36     // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
     37     enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
     38 
     39     SkSurfaceCharacterization()
     40             : fCacheMaxResourceBytes(0)
     41             , fOrigin(kBottomLeft_GrSurfaceOrigin)
     42             , fConfig(kUnknown_GrPixelConfig)
     43             , fFSAAType(GrFSAAType::kNone)
     44             , fStencilCnt(0)
     45             , fIsTextureable(Textureable::kYes)
     46             , fIsMipMapped(MipMapped::kYes)
     47             , fUsesGLFBO0(UsesGLFBO0::kNo)
     48             , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
     49             , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
     50     }
     51 
     52     SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
     53     SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
     54 
     55     SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
     56     SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
     57     bool operator==(const SkSurfaceCharacterization& other) const;
     58     bool operator!=(const SkSurfaceCharacterization& other) const {
     59         return !(*this == other);
     60     }
     61 
     62     SkSurfaceCharacterization createResized(int width, int height) const;
     63 
     64     GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
     65     sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
     66     size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
     67 
     68     bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
     69 
     70     const SkImageInfo& imageInfo() const { return fImageInfo; }
     71     GrSurfaceOrigin origin() const { return fOrigin; }
     72     int width() const { return fImageInfo.width(); }
     73     int height() const { return fImageInfo.height(); }
     74     SkColorType colorType() const { return fImageInfo.colorType(); }
     75     GrFSAAType fsaaType() const { return fFSAAType; }
     76     int stencilCount() const { return fStencilCnt; }
     77     bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
     78     bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
     79     bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
     80     bool vulkanSecondaryCBCompatible() const {
     81         return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
     82     }
     83     SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
     84     sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
     85     const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
     86 
     87 private:
     88     friend class SkSurface_Gpu; // for 'set' & 'config'
     89     friend class GrContextThreadSafeProxy; // for private ctor
     90     friend class SkDeferredDisplayListRecorder; // for 'config'
     91     friend class SkSurface; // for 'config'
     92 
     93     GrPixelConfig config() const { return fConfig; }
     94 
     95     SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
     96                               size_t cacheMaxResourceBytes,
     97                               const SkImageInfo& ii,
     98                               GrSurfaceOrigin origin,
     99                               GrPixelConfig config,
    100                               GrFSAAType FSAAType, int stencilCnt,
    101                               Textureable isTextureable, MipMapped isMipMapped,
    102                               UsesGLFBO0 usesGLFBO0,
    103                               VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
    104                               const SkSurfaceProps& surfaceProps)
    105             : fContextInfo(std::move(contextInfo))
    106             , fCacheMaxResourceBytes(cacheMaxResourceBytes)
    107             , fImageInfo(ii)
    108             , fOrigin(origin)
    109             , fConfig(config)
    110             , fFSAAType(FSAAType)
    111             , fStencilCnt(stencilCnt)
    112             , fIsTextureable(isTextureable)
    113             , fIsMipMapped(isMipMapped)
    114             , fUsesGLFBO0(usesGLFBO0)
    115             , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
    116             , fSurfaceProps(surfaceProps) {
    117     }
    118 
    119     void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
    120              size_t cacheMaxResourceBytes,
    121              const SkImageInfo& ii,
    122              GrSurfaceOrigin origin,
    123              GrPixelConfig config,
    124              GrFSAAType fsaaType,
    125              int stencilCnt,
    126              Textureable isTextureable,
    127              MipMapped isMipMapped,
    128              UsesGLFBO0 usesGLFBO0,
    129              VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
    130              const SkSurfaceProps& surfaceProps) {
    131         SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
    132         SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0);
    133 
    134         SkASSERT(VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible ||
    135                  UsesGLFBO0::kNo == usesGLFBO0);
    136         SkASSERT(Textureable::kNo == isTextureable ||
    137                  VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible);
    138 
    139         fContextInfo = contextInfo;
    140         fCacheMaxResourceBytes = cacheMaxResourceBytes;
    141 
    142         fImageInfo = ii;
    143         fOrigin = origin;
    144         fConfig = config;
    145         fFSAAType = fsaaType;
    146         fStencilCnt = stencilCnt;
    147         fIsTextureable = isTextureable;
    148         fIsMipMapped = isMipMapped;
    149         fUsesGLFBO0 = usesGLFBO0;
    150         fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
    151         fSurfaceProps = surfaceProps;
    152     }
    153 
    154     sk_sp<GrContextThreadSafeProxy> fContextInfo;
    155     size_t                          fCacheMaxResourceBytes;
    156 
    157     SkImageInfo                     fImageInfo;
    158     GrSurfaceOrigin                 fOrigin;
    159     GrPixelConfig                   fConfig;
    160     GrFSAAType                      fFSAAType;
    161     int                             fStencilCnt;
    162     Textureable                     fIsTextureable;
    163     MipMapped                       fIsMipMapped;
    164     UsesGLFBO0                      fUsesGLFBO0;
    165     VulkanSecondaryCBCompatible     fVulkanSecondaryCBCompatible;
    166     SkSurfaceProps                  fSurfaceProps;
    167 };
    168 
    169 #else// !SK_SUPPORT_GPU
    170 
    171 class SK_API SkSurfaceCharacterization {
    172 public:
    173     SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { }
    174 
    175     SkSurfaceCharacterization createResized(int width, int height) const {
    176         return *this;
    177     }
    178 
    179     bool operator==(const SkSurfaceCharacterization& other) const { return false; }
    180     bool operator!=(const SkSurfaceCharacterization& other) const {
    181         return !(*this == other);
    182     }
    183 
    184     size_t cacheMaxResourceBytes() const { return 0; }
    185 
    186     bool isValid() const { return false; }
    187 
    188     int width() const { return 0; }
    189     int height() const { return 0; }
    190     int stencilCount() const { return 0; }
    191     bool isTextureable() const { return false; }
    192     bool isMipMapped() const { return false; }
    193     bool usesGLFBO0() const { return false; }
    194     bool vulkanSecondaryCBCompatible() const { return false; }
    195     SkColorSpace* colorSpace() const { return nullptr; }
    196     sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
    197     const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
    198 
    199 private:
    200     SkSurfaceProps fSurfaceProps;
    201 };
    202 
    203 #endif
    204 
    205 #endif
    206