2017-08-30 16:06:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSurfaceCharacterization_DEFINED
|
|
|
|
#define SkSurfaceCharacterization_DEFINED
|
|
|
|
|
|
|
|
#include "GrTypes.h"
|
|
|
|
|
2018-02-01 14:10:04 +00:00
|
|
|
#include "SkColorSpace.h"
|
|
|
|
#include "SkRefCnt.h"
|
2017-12-13 16:50:22 +00:00
|
|
|
#include "SkSurfaceProps.h"
|
|
|
|
|
|
|
|
class SkColorSpace;
|
|
|
|
|
2018-02-01 14:10:04 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
#include "GrContext.h"
|
2017-11-30 13:46:03 +00:00
|
|
|
|
|
|
|
/** \class SkSurfaceCharacterization
|
|
|
|
A surface characterization contains all the information Ganesh requires to makes its internal
|
|
|
|
rendering decisions. When passed into a SkDeferredDisplayListRecorder it will copy the
|
|
|
|
data and pass it on to the SkDeferredDisplayList if/when it is created. Note that both of
|
|
|
|
those objects (the Recorder and the DisplayList) will take a ref on the
|
2017-12-04 17:52:46 +00:00
|
|
|
GrContextThreadSafeProxy and SkColorSpace objects.
|
2017-11-30 13:46:03 +00:00
|
|
|
*/
|
2018-04-05 13:38:50 +00:00
|
|
|
class SK_API SkSurfaceCharacterization {
|
2017-08-30 16:06:35 +00:00
|
|
|
public:
|
2018-02-04 19:33:21 +00:00
|
|
|
enum class Textureable : bool { kNo = false, kYes = true };
|
|
|
|
enum class MipMapped : bool { kNo = false, kYes = true };
|
2018-04-26 20:31:38 +00:00
|
|
|
enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
|
2018-02-04 19:33:21 +00:00
|
|
|
|
2017-08-30 16:06:35 +00:00
|
|
|
SkSurfaceCharacterization()
|
2018-02-13 22:03:00 +00:00
|
|
|
: fCacheMaxResourceBytes(0)
|
2017-12-04 18:48:14 +00:00
|
|
|
, fOrigin(kBottomLeft_GrSurfaceOrigin)
|
2017-11-30 16:22:14 +00:00
|
|
|
, fConfig(kUnknown_GrPixelConfig)
|
2017-12-04 17:52:46 +00:00
|
|
|
, fFSAAType(GrFSAAType::kNone)
|
|
|
|
, fStencilCnt(0)
|
2018-02-04 19:33:21 +00:00
|
|
|
, fIsTextureable(Textureable::kYes)
|
|
|
|
, fIsMipMapped(MipMapped::kYes)
|
2018-04-26 20:31:38 +00:00
|
|
|
, fUsesGLFBO0(UsesGLFBO0::kNo)
|
2017-11-30 16:22:14 +00:00
|
|
|
, fSurfaceProps(0, kUnknown_SkPixelGeometry) {
|
2017-08-30 16:06:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 13:46:03 +00:00
|
|
|
SkSurfaceCharacterization(SkSurfaceCharacterization&&) = default;
|
|
|
|
SkSurfaceCharacterization& operator=(SkSurfaceCharacterization&&) = default;
|
|
|
|
|
|
|
|
SkSurfaceCharacterization(const SkSurfaceCharacterization&) = default;
|
|
|
|
SkSurfaceCharacterization& operator=(const SkSurfaceCharacterization& other) = default;
|
2018-04-04 15:12:39 +00:00
|
|
|
bool operator==(const SkSurfaceCharacterization& other) const;
|
|
|
|
bool operator!=(const SkSurfaceCharacterization& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2017-11-30 13:46:03 +00:00
|
|
|
|
2018-03-06 18:41:51 +00:00
|
|
|
SkSurfaceCharacterization createResized(int width, int height) const {
|
|
|
|
const GrCaps* caps = fContextInfo->caps();
|
|
|
|
if (!caps) {
|
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width <= 0 || height <= 0 ||
|
|
|
|
width > caps->maxRenderTargetSize() || height > caps->maxRenderTargetSize()) {
|
|
|
|
return SkSurfaceCharacterization();
|
|
|
|
}
|
|
|
|
|
|
|
|
return SkSurfaceCharacterization(fContextInfo,
|
|
|
|
fCacheMaxResourceBytes,
|
2018-04-03 21:17:05 +00:00
|
|
|
fImageInfo.makeWH(width, height),
|
|
|
|
fOrigin, fConfig, fFSAAType, fStencilCnt,
|
2018-04-26 20:31:38 +00:00
|
|
|
fIsTextureable, fIsMipMapped, fUsesGLFBO0,
|
2018-03-06 18:41:51 +00:00
|
|
|
fSurfaceProps);
|
|
|
|
}
|
|
|
|
|
2017-11-30 16:22:14 +00:00
|
|
|
GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
|
2018-03-02 13:53:14 +00:00
|
|
|
sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
|
2017-12-04 18:48:14 +00:00
|
|
|
size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
|
2018-02-13 22:03:00 +00:00
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
const SkImageInfo& imageInfo() const { return fImageInfo; }
|
2017-11-30 13:46:03 +00:00
|
|
|
GrSurfaceOrigin origin() const { return fOrigin; }
|
2018-04-03 21:17:05 +00:00
|
|
|
int width() const { return fImageInfo.width(); }
|
|
|
|
int height() const { return fImageInfo.height(); }
|
|
|
|
SkColorType colorType() const { return fImageInfo.colorType(); }
|
2017-12-04 17:52:46 +00:00
|
|
|
GrFSAAType fsaaType() const { return fFSAAType; }
|
|
|
|
int stencilCount() const { return fStencilCnt; }
|
2018-02-04 19:33:21 +00:00
|
|
|
bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
|
|
|
|
bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
|
2018-04-26 20:31:38 +00:00
|
|
|
bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
|
2018-04-03 21:17:05 +00:00
|
|
|
SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
|
|
|
|
sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
|
2017-11-30 16:22:14 +00:00
|
|
|
const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
|
2017-11-30 13:46:03 +00:00
|
|
|
|
|
|
|
private:
|
2018-04-03 21:17:05 +00:00
|
|
|
friend class SkSurface_Gpu; // for 'set' & 'config'
|
2018-02-13 22:03:00 +00:00
|
|
|
friend class GrContextThreadSafeProxy; // for private ctor
|
2018-04-03 21:17:05 +00:00
|
|
|
friend class SkDeferredDisplayListRecorder; // for 'config'
|
|
|
|
friend class SkSurface; // for 'config'
|
|
|
|
|
|
|
|
GrPixelConfig config() const { return fConfig; }
|
2018-02-13 22:03:00 +00:00
|
|
|
|
|
|
|
SkSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
|
|
|
|
size_t cacheMaxResourceBytes,
|
2018-04-03 21:17:05 +00:00
|
|
|
const SkImageInfo& ii,
|
|
|
|
GrSurfaceOrigin origin,
|
|
|
|
GrPixelConfig config,
|
|
|
|
GrFSAAType FSAAType, int stencilCnt,
|
2018-02-13 22:03:00 +00:00
|
|
|
Textureable isTextureable, MipMapped isMipMapped,
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 usesGLFBO0,
|
2018-02-13 22:03:00 +00:00
|
|
|
const SkSurfaceProps& surfaceProps)
|
|
|
|
: fContextInfo(std::move(contextInfo))
|
|
|
|
, fCacheMaxResourceBytes(cacheMaxResourceBytes)
|
2018-04-03 21:17:05 +00:00
|
|
|
, fImageInfo(ii)
|
2018-02-13 22:03:00 +00:00
|
|
|
, fOrigin(origin)
|
|
|
|
, fConfig(config)
|
|
|
|
, fFSAAType(FSAAType)
|
|
|
|
, fStencilCnt(stencilCnt)
|
|
|
|
, fIsTextureable(isTextureable)
|
|
|
|
, fIsMipMapped(isMipMapped)
|
2018-04-26 20:31:38 +00:00
|
|
|
, fUsesGLFBO0(usesGLFBO0)
|
2018-02-13 22:03:00 +00:00
|
|
|
, fSurfaceProps(surfaceProps) {
|
|
|
|
}
|
2017-11-30 13:46:03 +00:00
|
|
|
|
2017-11-30 16:22:14 +00:00
|
|
|
void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
|
2017-12-04 18:48:14 +00:00
|
|
|
size_t cacheMaxResourceBytes,
|
2018-04-03 21:17:05 +00:00
|
|
|
const SkImageInfo& ii,
|
2017-11-30 16:22:14 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2017-08-30 16:06:35 +00:00
|
|
|
GrPixelConfig config,
|
2017-12-04 17:52:46 +00:00
|
|
|
GrFSAAType fsaaType,
|
|
|
|
int stencilCnt,
|
2018-02-04 19:33:21 +00:00
|
|
|
Textureable isTextureable,
|
|
|
|
MipMapped isMipMapped,
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 usesGLFBO0,
|
2017-11-30 16:22:14 +00:00
|
|
|
const SkSurfaceProps& surfaceProps) {
|
2018-02-04 19:33:21 +00:00
|
|
|
SkASSERT(MipMapped::kNo == isMipMapped || Textureable::kYes == isTextureable);
|
2018-04-26 20:31:38 +00:00
|
|
|
SkASSERT(Textureable::kNo == isTextureable || UsesGLFBO0::kNo == usesGLFBO0);
|
2018-02-04 19:33:21 +00:00
|
|
|
|
2017-11-30 16:22:14 +00:00
|
|
|
fContextInfo = contextInfo;
|
2017-12-04 18:48:14 +00:00
|
|
|
fCacheMaxResourceBytes = cacheMaxResourceBytes;
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
fImageInfo = ii;
|
2017-08-30 16:06:35 +00:00
|
|
|
fOrigin = origin;
|
|
|
|
fConfig = config;
|
2017-12-04 17:52:46 +00:00
|
|
|
fFSAAType = fsaaType;
|
|
|
|
fStencilCnt = stencilCnt;
|
2018-02-04 19:33:21 +00:00
|
|
|
fIsTextureable = isTextureable;
|
|
|
|
fIsMipMapped = isMipMapped;
|
2018-04-26 20:31:38 +00:00
|
|
|
fUsesGLFBO0 = usesGLFBO0;
|
2017-11-30 16:22:14 +00:00
|
|
|
fSurfaceProps = surfaceProps;
|
2017-08-30 16:06:35 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 16:22:14 +00:00
|
|
|
sk_sp<GrContextThreadSafeProxy> fContextInfo;
|
2017-12-04 18:48:14 +00:00
|
|
|
size_t fCacheMaxResourceBytes;
|
|
|
|
|
2018-04-03 21:17:05 +00:00
|
|
|
SkImageInfo fImageInfo;
|
2017-11-30 13:46:03 +00:00
|
|
|
GrSurfaceOrigin fOrigin;
|
|
|
|
GrPixelConfig fConfig;
|
2017-12-04 17:52:46 +00:00
|
|
|
GrFSAAType fFSAAType;
|
|
|
|
int fStencilCnt;
|
2018-02-04 19:33:21 +00:00
|
|
|
Textureable fIsTextureable;
|
|
|
|
MipMapped fIsMipMapped;
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 fUsesGLFBO0;
|
2017-11-30 16:22:14 +00:00
|
|
|
SkSurfaceProps fSurfaceProps;
|
2017-11-30 13:46:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#else// !SK_SUPPORT_GPU
|
|
|
|
|
2018-04-05 13:38:50 +00:00
|
|
|
class SK_API SkSurfaceCharacterization {
|
2017-11-30 13:46:03 +00:00
|
|
|
public:
|
2018-03-06 18:41:51 +00:00
|
|
|
SkSurfaceCharacterization() : fSurfaceProps(0, kUnknown_SkPixelGeometry) { }
|
|
|
|
|
|
|
|
SkSurfaceCharacterization createResized(int width, int height) const {
|
|
|
|
return *this;
|
2017-12-13 16:50:22 +00:00
|
|
|
}
|
2017-11-30 13:46:03 +00:00
|
|
|
|
2018-04-04 15:12:39 +00:00
|
|
|
bool operator==(const SkSurfaceCharacterization& other) const { return false; }
|
|
|
|
bool operator!=(const SkSurfaceCharacterization& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:41:51 +00:00
|
|
|
size_t cacheMaxResourceBytes() const { return 0; }
|
|
|
|
|
2018-02-13 22:03:00 +00:00
|
|
|
bool isValid() const { return false; }
|
|
|
|
|
2018-03-06 18:41:51 +00:00
|
|
|
int width() const { return 0; }
|
|
|
|
int height() const { return 0; }
|
|
|
|
int stencilCount() const { return 0; }
|
|
|
|
bool isTextureable() const { return false; }
|
|
|
|
bool isMipMapped() const { return false; }
|
2018-04-26 20:31:38 +00:00
|
|
|
bool usesGLFBO0() const { return false; }
|
2018-03-06 18:41:51 +00:00
|
|
|
SkColorSpace* colorSpace() const { return nullptr; }
|
|
|
|
sk_sp<SkColorSpace> refColorSpace() const { return nullptr; }
|
2017-12-13 16:50:22 +00:00
|
|
|
const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
|
2017-08-30 16:06:35 +00:00
|
|
|
|
|
|
|
private:
|
2018-03-06 18:41:51 +00:00
|
|
|
SkSurfaceProps fSurfaceProps;
|
2017-08-30 16:06:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2017-11-30 13:46:03 +00:00
|
|
|
|
|
|
|
#endif
|