blob: 2abd5b6555b353e3c6c0da0f31c805dce7934807 [file] [log] [blame]
Robert Phillipsad8a43f2017-08-30 12:06:35 -04001/*
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
Robert Phillips62000362018-02-01 09:10:04 -050013#include "SkColorSpace.h"
14#include "SkRefCnt.h"
Robert Phillips61e51012017-11-30 11:22:14 -050015#include "SkSurfaceProps.h"
Robert Phillipsad8a43f2017-08-30 12:06:35 -040016
Robert Phillips61e51012017-11-30 11:22:14 -050017class SkColorSpace;
Robert Phillips8def8bf2017-11-30 08:46:03 -050018
Robert Phillips62000362018-02-01 09:10:04 -050019#if SK_SUPPORT_GPU
20#include "GrContext.h"
Robert Phillipse42edcc2017-12-13 11:50:22 -050021
Robert Phillips8def8bf2017-11-30 08:46:03 -050022/** \class SkSurfaceCharacterization
23 A surface characterization contains all the information Ganesh requires to makes its internal
24 rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
25 data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
26 those objects (the Recorder and the DisplayList) will take a ref on the
Robert Phillips7ffbcf92017-12-04 12:52:46 -050027 GrContextThreadSafeProxy and SkColorSpace objects.
Robert Phillips8def8bf2017-11-30 08:46:03 -050028*/
Robert Phillips91749c82018-04-05 09:38:50 -040029class SK_API SkSurfaceCharacterization {
Robert Phillipsad8a43f2017-08-30 12:06:35 -040030public:
Robert Phillipse8fabb22018-02-04 14:33:21 -050031 enum class Textureable : bool { kNo = false, kYes = true };
32 enum class MipMapped : bool { kNo = false, kYes = true };
Greg Daniela070ed72018-04-26 16:31:38 -040033 enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
Robert Phillipse8fabb22018-02-04 14:33:21 -050034
Robert Phillipsad8a43f2017-08-30 12:06:35 -040035 SkSurfaceCharacterization()
Robert Phillipsfc711a22018-02-13 17:03:00 -050036 : fCacheMaxResourceBytes(0)
Robert Phillips8d1e67e2017-12-04 13:48:14 -050037 , fOrigin(kBottomLeft_GrSurfaceOrigin)
Robert Phillips61e51012017-11-30 11:22:14 -050038 , fConfig(kUnknown_GrPixelConfig)
Robert Phillips7ffbcf92017-12-04 12:52:46 -050039 , fFSAAType(GrFSAAType::kNone)
40 , fStencilCnt(0)
Robert Phillipse8fabb22018-02-04 14:33:21 -050041 , fIsTextureable(Textureable::kYes)
42 , fIsMipMapped(MipMapped::kYes)
Greg Daniela070ed72018-04-26 16:31:38 -040043 , fUsesGLFBO0(UsesGLFBO0::kNo)
Robert Phillips61e51012017-11-30 11:22:14 -050044 , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
Robert Phillipsad8a43f2017-08-30 12:06:35 -040045 }
46
Robert Phillips8def8bf2017-11-30 08:46:03 -050047 SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
48 SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
49
50 SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
51 SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
Robert Phillipsc1267c62018-04-04 11:12:39 -040052 bool operator==(const SkSurfaceCharacterization& other) const;
53 bool operator!=(const SkSurfaceCharacterization& other) const {
54 return !(*this == other);
55 }
Robert Phillipsad8a43f2017-08-30 12:06:35 -040056
Brian Salomon52aacd62018-05-10 12:57:17 -040057 SkSurfaceCharacterization createResized(int width, int height) const;
Robert Phillips94458ee2018-03-06 13:41:51 -050058
Robert Phillips61e51012017-11-30 11:22:14 -050059 GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
Robert Phillipsfde6fa02018-03-02 08:53:14 -050060 sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
Robert Phillips8d1e67e2017-12-04 13:48:14 -050061 size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
62
Robert Phillipsbe77a022018-04-03 17:17:05 -040063 bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
Robert Phillipsfc711a22018-02-13 17:03:00 -050064
Robert Phillipsbe77a022018-04-03 17:17:05 -040065 const SkImageInfo& imageInfo() const { return fImageInfo; }
Robert Phillipsad8a43f2017-08-30 12:06:35 -040066 GrSurfaceOrigin origin() const { return fOrigin; }
Robert Phillipsbe77a022018-04-03 17:17:05 -040067 int width() const { return fImageInfo.width(); }
68 int height() const { return fImageInfo.height(); }
69 SkColorType colorType() const { return fImageInfo.colorType(); }
Robert Phillips7ffbcf92017-12-04 12:52:46 -050070 GrFSAAType fsaaType() const { return fFSAAType; }
71 int stencilCount() const { return fStencilCnt; }
Robert Phillipse8fabb22018-02-04 14:33:21 -050072 bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
73 bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
Greg Daniela070ed72018-04-26 16:31:38 -040074 bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
Robert Phillipsbe77a022018-04-03 17:17:05 -040075 SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
76 sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
Robert Phillips61e51012017-11-30 11:22:14 -050077 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
Robert Phillipsad8a43f2017-08-30 12:06:35 -040078
79private:
Robert Phillipsbe77a022018-04-03 17:17:05 -040080 friend class SkSurface_Gpu; // for 'set' & 'config'
Robert Phillipsfc711a22018-02-13 17:03:00 -050081 friend class GrContextThreadSafeProxy; // for private ctor
Robert Phillipsbe77a022018-04-03 17:17:05 -040082 friend class SkDeferredDisplayListRecorder; // for 'config'
83 friend class SkSurface; // for 'config'
84
85 GrPixelConfig config() const { return fConfig; }
Robert Phillipsfc711a22018-02-13 17:03:00 -050086
87 SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
88 size_t cacheMaxResourceBytes,
Robert Phillipsbe77a022018-04-03 17:17:05 -040089 const SkImageInfo& ii,
90 GrSurfaceOrigin origin,
91 GrPixelConfig config,
92 GrFSAAType FSAAType, int stencilCnt,
Robert Phillipsfc711a22018-02-13 17:03:00 -050093 Textureable isTextureable, MipMapped isMipMapped,
Greg Daniela070ed72018-04-26 16:31:38 -040094 UsesGLFBO0 usesGLFBO0,
Robert Phillipsfc711a22018-02-13 17:03:00 -050095 const SkSurfaceProps& surfaceProps)
96 : fContextInfo(std::move(contextInfo))
97 , fCacheMaxResourceBytes(cacheMaxResourceBytes)
Robert Phillipsbe77a022018-04-03 17:17:05 -040098 , fImageInfo(ii)
Robert Phillipsfc711a22018-02-13 17:03:00 -050099 , fOrigin(origin)
Robert Phillipsfc711a22018-02-13 17:03:00 -0500100 , fConfig(config)
101 , fFSAAType(FSAAType)
102 , fStencilCnt(stencilCnt)
103 , fIsTextureable(isTextureable)
104 , fIsMipMapped(isMipMapped)
Greg Daniela070ed72018-04-26 16:31:38 -0400105 , fUsesGLFBO0(usesGLFBO0)
Robert Phillipsfc711a22018-02-13 17:03:00 -0500106 , fSurfaceProps(surfaceProps) {
107 }
Robert Phillips8def8bf2017-11-30 08:46:03 -0500108
Robert Phillips61e51012017-11-30 11:22:14 -0500109 void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500110 size_t cacheMaxResourceBytes,
Robert Phillipsbe77a022018-04-03 17:17:05 -0400111 const SkImageInfo& ii,
Robert Phillips61e51012017-11-30 11:22:14 -0500112 GrSurfaceOrigin origin,
Robert Phillips8def8bf2017-11-30 08:46:03 -0500113 GrPixelConfig config,
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500114 GrFSAAType fsaaType,
115 int stencilCnt,
Robert Phillipse8fabb22018-02-04 14:33:21 -0500116 Textureable isTextureable,
117 MipMapped isMipMapped,
Greg Daniela070ed72018-04-26 16:31:38 -0400118 UsesGLFBO0 usesGLFBO0,
Robert Phillips61e51012017-11-30 11:22:14 -0500119 const SkSurfaceProps& surfaceProps) {
Robert Phillipse8fabb22018-02-04 14:33:21 -0500120 SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
Greg Daniela070ed72018-04-26 16:31:38 -0400121 SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0);
Robert Phillipse8fabb22018-02-04 14:33:21 -0500122
Robert Phillips61e51012017-11-30 11:22:14 -0500123 fContextInfo = contextInfo;
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500124 fCacheMaxResourceBytes = cacheMaxResourceBytes;
125
Robert Phillipsbe77a022018-04-03 17:17:05 -0400126 fImageInfo = ii;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500127 fOrigin = origin;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500128 fConfig = config;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500129 fFSAAType = fsaaType;
130 fStencilCnt = stencilCnt;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500131 fIsTextureable = isTextureable;
132 fIsMipMapped = isMipMapped;
Greg Daniela070ed72018-04-26 16:31:38 -0400133 fUsesGLFBO0 = usesGLFBO0;
Robert Phillips61e51012017-11-30 11:22:14 -0500134 fSurfaceProps = surfaceProps;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500135 }
136
Robert Phillips61e51012017-11-30 11:22:14 -0500137 sk_sp<GrContextThreadSafeProxy> fContextInfo;
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500138 size_t fCacheMaxResourceBytes;
139
Robert Phillipsbe77a022018-04-03 17:17:05 -0400140 SkImageInfo fImageInfo;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500141 GrSurfaceOrigin fOrigin;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500142 GrPixelConfig fConfig;
Robert Phillips7ffbcf92017-12-04 12:52:46 -0500143 GrFSAAType fFSAAType;
144 int fStencilCnt;
Robert Phillipse8fabb22018-02-04 14:33:21 -0500145 Textureable fIsTextureable;
146 MipMapped fIsMipMapped;
Greg Daniela070ed72018-04-26 16:31:38 -0400147 UsesGLFBO0 fUsesGLFBO0;
Robert Phillips61e51012017-11-30 11:22:14 -0500148 SkSurfaceProps fSurfaceProps;
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400149};
150
Robert Phillips8def8bf2017-11-30 08:46:03 -0500151#else// !SK_SUPPORT_GPU
152
Robert Phillips91749c82018-04-05 09:38:50 -0400153class SK_API SkSurfaceCharacterization {
Robert Phillips8def8bf2017-11-30 08:46:03 -0500154public:
Robert Phillips94458ee2018-03-06 13:41:51 -0500155 SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { }
156
157 SkSurfaceCharacterization createResized(int width, int height) const {
158 return *this;
Robert Phillipse42edcc2017-12-13 11:50:22 -0500159 }
Robert Phillips8def8bf2017-11-30 08:46:03 -0500160
Robert Phillipsc1267c62018-04-04 11:12:39 -0400161 bool operator==(const SkSurfaceCharacterization& other) const { return false; }
162 bool operator!=(const SkSurfaceCharacterization& other) const {
163 return !(*this == other);
164 }
165
Robert Phillips94458ee2018-03-06 13:41:51 -0500166 size_t cacheMaxResourceBytes() const { return 0; }
167
Robert Phillipsfc711a22018-02-13 17:03:00 -0500168 bool isValid() const { return false; }
169
Robert Phillips94458ee2018-03-06 13:41:51 -0500170 int width() const { return 0; }
171 int height() const { return 0; }
172 int stencilCount() const { return 0; }
173 bool isTextureable() const { return false; }
174 bool isMipMapped() const { return false; }
Greg Daniela070ed72018-04-26 16:31:38 -0400175 bool usesGLFBO0() const { return false; }
Robert Phillips94458ee2018-03-06 13:41:51 -0500176 SkColorSpace* colorSpace() const { return nullptr; }
177 sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
Robert Phillipse42edcc2017-12-13 11:50:22 -0500178 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
Robert Phillips8def8bf2017-11-30 08:46:03 -0500179
180private:
Robert Phillips94458ee2018-03-06 13:41:51 -0500181 SkSurfaceProps fSurfaceProps;
Robert Phillips8def8bf2017-11-30 08:46:03 -0500182};
183
184#endif
185
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400186#endif