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 // This define can be used to swap between the default (raster) DDL implementation and the 20 // gpu implementation. 21 #define SK_RASTER_RECORDER_IMPLEMENTATION 1 22 23 #if SK_SUPPORT_GPU 24 #include "GrContext.h" 25 26 /** \class SkSurfaceCharacterization 27 A surface characterization contains all the information Ganesh requires to makes its internal 28 rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the 29 data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of 30 those objects (the Recorder and the DisplayList) will take a ref on the 31 GrContextThreadSafeProxy and SkColorSpace objects. 32 */ 33 class SkSurfaceCharacterization { 34 public: SkSurfaceCharacterization()35 SkSurfaceCharacterization() 36 : fCacheMaxResourceCount(0) 37 , fCacheMaxResourceBytes(0) 38 , fOrigin(kBottomLeft_GrSurfaceOrigin) 39 , fWidth(0) 40 , fHeight(0) 41 , fConfig(kUnknown_GrPixelConfig) 42 , fFSAAType(GrFSAAType::kNone) 43 , fStencilCnt(0) 44 , fSurfaceProps(0, kUnknown_SkPixelGeometry) { 45 } 46 47 SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default; 48 SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default; 49 50 SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default; 51 SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default; 52 contextInfo()53 GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } cacheMaxResourceCount()54 int cacheMaxResourceCount() const { return fCacheMaxResourceCount; } cacheMaxResourceBytes()55 size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } 56 origin()57 GrSurfaceOrigin origin() const { return fOrigin; } width()58 int width() const { return fWidth; } height()59 int height() const { return fHeight; } config()60 GrPixelConfig config() const { return fConfig; } fsaaType()61 GrFSAAType fsaaType() const { return fFSAAType; } stencilCount()62 int stencilCount() const { return fStencilCnt; } colorSpace()63 SkColorSpace* colorSpace() const { return fColorSpace.get(); } refColorSpace()64 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } surfaceProps()65 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; } 66 67 private: 68 friend class SkSurface_Gpu; // for 'set' 69 set(sk_sp<GrContextThreadSafeProxy> contextInfo,int cacheMaxResourceCount,size_t cacheMaxResourceBytes,GrSurfaceOrigin origin,int width,int height,GrPixelConfig config,GrFSAAType fsaaType,int stencilCnt,sk_sp<SkColorSpace> colorSpace,const SkSurfaceProps & surfaceProps)70 void set(sk_sp<GrContextThreadSafeProxy> contextInfo, 71 int cacheMaxResourceCount, 72 size_t cacheMaxResourceBytes, 73 GrSurfaceOrigin origin, 74 int width, int height, 75 GrPixelConfig config, 76 GrFSAAType fsaaType, 77 int stencilCnt, 78 sk_sp<SkColorSpace> colorSpace, 79 const SkSurfaceProps& surfaceProps) { 80 fContextInfo = contextInfo; 81 fCacheMaxResourceCount = cacheMaxResourceCount; 82 fCacheMaxResourceBytes = cacheMaxResourceBytes; 83 84 fOrigin = origin; 85 fWidth = width; 86 fHeight = height; 87 fConfig = config; 88 fFSAAType = fsaaType; 89 fStencilCnt = stencilCnt; 90 fColorSpace = std::move(colorSpace); 91 fSurfaceProps = surfaceProps; 92 } 93 94 sk_sp<GrContextThreadSafeProxy> fContextInfo; 95 int fCacheMaxResourceCount; 96 size_t fCacheMaxResourceBytes; 97 98 GrSurfaceOrigin fOrigin; 99 int fWidth; 100 int fHeight; 101 GrPixelConfig fConfig; 102 GrFSAAType fFSAAType; 103 int fStencilCnt; 104 sk_sp<SkColorSpace> fColorSpace; 105 SkSurfaceProps fSurfaceProps; 106 }; 107 108 #else// !SK_SUPPORT_GPU 109 110 class SkSurfaceCharacterization { 111 public: SkSurfaceCharacterization()112 SkSurfaceCharacterization() 113 : fWidth(0) 114 , fHeight(0) 115 , fSurfaceProps(0, kUnknown_SkPixelGeometry) { 116 } 117 width()118 int width() const { return fWidth; } height()119 int height() const { return fHeight; } colorSpace()120 SkColorSpace* colorSpace() const { return fColorSpace.get(); } refColorSpace()121 sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } surfaceProps()122 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; } 123 124 private: 125 int fWidth; 126 int fHeight; 127 sk_sp<SkColorSpace> fColorSpace; 128 SkSurfaceProps fSurfaceProps; 129 }; 130 131 #endif 132 133 #endif 134