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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTypes.h"
|
2017-08-30 16:06:35 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorSpace.h"
|
2020-02-13 18:24:47 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkSurfaceProps.h"
|
2017-12-13 16:50:22 +00:00
|
|
|
|
|
|
|
class SkColorSpace;
|
|
|
|
|
2019-07-02 20:33:05 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-02-13 18:24:47 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrContextThreadSafeProxy.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 };
|
2019-01-02 19:51:29 +00:00
|
|
|
// This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
|
|
|
|
enum class VulkanSecondaryCBCompatible : 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)
|
2019-06-24 00:07:38 +00:00
|
|
|
, fSampleCnt(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)
|
2019-01-02 19:51:29 +00:00
|
|
|
, fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
|
2019-07-10 13:28:59 +00:00
|
|
|
, fIsProtected(GrProtected::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
|
|
|
|
2019-10-03 15:09:17 +00:00
|
|
|
/*
|
|
|
|
* Return a new surface characterization with the only difference being a different width
|
|
|
|
* and height
|
|
|
|
*/
|
2018-05-10 16:57:17 +00:00
|
|
|
SkSurfaceCharacterization createResized(int width, int height) const;
|
2018-03-06 18:41:51 +00:00
|
|
|
|
2019-10-03 15:09:17 +00:00
|
|
|
/*
|
|
|
|
* Return a new surface characterization with only a replaced color space
|
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const;
|
|
|
|
|
2020-02-13 18:24:47 +00:00
|
|
|
/*
|
|
|
|
* Return a new surface characterization with the backend format replaced. A colorType
|
|
|
|
* must also be supplied to indicate the interpretation of the new format.
|
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createBackendFormat(SkColorType colorType,
|
|
|
|
const GrBackendFormat& backendFormat) const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a new surface characterization with just a different use of FBO0 (in GL)
|
|
|
|
*/
|
|
|
|
SkSurfaceCharacterization createFBO0(bool usesGLFBO0) const;
|
|
|
|
|
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; }
|
2019-07-02 20:33:05 +00:00
|
|
|
const GrBackendFormat& backendFormat() const { return fBackendFormat; }
|
2017-11-30 13:46:03 +00:00
|
|
|
GrSurfaceOrigin origin() const { return fOrigin; }
|
2020-02-07 19:17:25 +00:00
|
|
|
SkISize dimensions() const { return fImageInfo.dimensions(); }
|
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(); }
|
2019-06-24 00:07:38 +00:00
|
|
|
int sampleCount() const { return fSampleCnt; }
|
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; }
|
2019-01-02 19:51:29 +00:00
|
|
|
bool vulkanSecondaryCBCompatible() const {
|
|
|
|
return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
|
|
|
|
}
|
2019-07-10 13:28:59 +00:00
|
|
|
GrProtected isProtected() const { return fIsProtected; }
|
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
|
|
|
|
2019-07-01 14:34:03 +00:00
|
|
|
// Is the provided backend texture compatible with this surface characterization?
|
|
|
|
bool isCompatible(const GrBackendTexture&) const;
|
|
|
|
|
2017-11-30 13:46:03 +00:00
|
|
|
private:
|
2018-04-03 21:17:05 +00:00
|
|
|
friend class SkSurface_Gpu; // for 'set' & 'config'
|
2019-03-05 21:55:12 +00:00
|
|
|
friend class GrVkSecondaryCBDrawContext; // 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'
|
|
|
|
|
2019-07-02 20:33:05 +00:00
|
|
|
SkDEBUGCODE(void validate() const;)
|
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,
|
2019-07-02 20:33:05 +00:00
|
|
|
const GrBackendFormat& backendFormat,
|
2018-04-03 21:17:05 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2019-06-24 00:07:38 +00:00
|
|
|
int sampleCnt,
|
2019-07-02 20:33:05 +00:00
|
|
|
Textureable isTextureable,
|
|
|
|
MipMapped isMipMapped,
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 usesGLFBO0,
|
2019-01-02 19:51:29 +00:00
|
|
|
VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
|
2019-07-10 13:28:59 +00:00
|
|
|
GrProtected isProtected,
|
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)
|
2019-07-02 20:33:05 +00:00
|
|
|
, fBackendFormat(backendFormat)
|
2018-02-13 22:03:00 +00:00
|
|
|
, fOrigin(origin)
|
2019-06-24 00:07:38 +00:00
|
|
|
, fSampleCnt(sampleCnt)
|
2018-02-13 22:03:00 +00:00
|
|
|
, fIsTextureable(isTextureable)
|
|
|
|
, fIsMipMapped(isMipMapped)
|
2018-04-26 20:31:38 +00:00
|
|
|
, fUsesGLFBO0(usesGLFBO0)
|
2019-01-02 19:51:29 +00:00
|
|
|
, fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
|
2019-07-10 13:28:59 +00:00
|
|
|
, fIsProtected(isProtected)
|
2018-02-13 22:03:00 +00:00
|
|
|
, fSurfaceProps(surfaceProps) {
|
2019-07-02 20:33:05 +00:00
|
|
|
SkDEBUGCODE(this->validate());
|
2018-02-13 22:03:00 +00:00
|
|
|
}
|
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,
|
2019-07-02 20:33:05 +00:00
|
|
|
const GrBackendFormat& backendFormat,
|
2017-11-30 16:22:14 +00:00
|
|
|
GrSurfaceOrigin origin,
|
2019-06-24 00:07:38 +00:00
|
|
|
int sampleCnt,
|
2018-02-04 19:33:21 +00:00
|
|
|
Textureable isTextureable,
|
|
|
|
MipMapped isMipMapped,
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 usesGLFBO0,
|
2019-01-02 19:51:29 +00:00
|
|
|
VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
|
2019-07-10 13:28:59 +00:00
|
|
|
GrProtected isProtected,
|
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
|
|
|
|
2019-01-02 19:51:29 +00:00
|
|
|
SkASSERT(VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible ||
|
|
|
|
UsesGLFBO0::kNo == usesGLFBO0);
|
|
|
|
SkASSERT(Textureable::kNo == isTextureable ||
|
|
|
|
VulkanSecondaryCBCompatible::kNo == vulkanSecondaryCBCompatible);
|
|
|
|
|
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;
|
2019-07-02 20:33:05 +00:00
|
|
|
fBackendFormat = backendFormat;
|
2017-08-30 16:06:35 +00:00
|
|
|
fOrigin = origin;
|
2019-06-24 00:07:38 +00:00
|
|
|
fSampleCnt = sampleCnt;
|
2018-02-04 19:33:21 +00:00
|
|
|
fIsTextureable = isTextureable;
|
|
|
|
fIsMipMapped = isMipMapped;
|
2018-04-26 20:31:38 +00:00
|
|
|
fUsesGLFBO0 = usesGLFBO0;
|
2019-01-02 19:51:29 +00:00
|
|
|
fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
|
2019-07-10 13:28:59 +00:00
|
|
|
fIsProtected = isProtected;
|
2017-11-30 16:22:14 +00:00
|
|
|
fSurfaceProps = surfaceProps;
|
2019-07-02 20:33:05 +00:00
|
|
|
|
|
|
|
SkDEBUGCODE(this->validate());
|
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;
|
2019-07-02 20:33:05 +00:00
|
|
|
GrBackendFormat fBackendFormat;
|
2017-11-30 13:46:03 +00:00
|
|
|
GrSurfaceOrigin fOrigin;
|
2019-06-24 00:07:38 +00:00
|
|
|
int fSampleCnt;
|
2018-02-04 19:33:21 +00:00
|
|
|
Textureable fIsTextureable;
|
|
|
|
MipMapped fIsMipMapped;
|
2018-04-26 20:31:38 +00:00
|
|
|
UsesGLFBO0 fUsesGLFBO0;
|
2019-01-02 19:51:29 +00:00
|
|
|
VulkanSecondaryCBCompatible fVulkanSecondaryCBCompatible;
|
2019-07-10 13:28:59 +00:00
|
|
|
GrProtected fIsProtected;
|
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
|
|
|
|
2019-10-03 15:09:17 +00:00
|
|
|
SkSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2020-02-13 18:24:47 +00:00
|
|
|
SkSurfaceCharacterization createBackendFormat(SkColorType, const GrBackendFormat&) const {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkSurfaceCharacterization createFBO0(bool usesGLFBO0) const {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
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; }
|
2019-01-02 19:51:29 +00:00
|
|
|
bool vulkanSecondaryCBCompatible() 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
|