aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2018-02-13 10:20:13 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-13 16:03:50 +0000
commitd76e56d93c27856b10d6636882a5ffcd79a9d967 (patch)
treee20c54f11793cfbc57fa4b878d95931ae80a020d /src
parent366093f2124c38fa5c590c9ed2d1811817fed8ee (diff)
Add SkCharacterization creation helper to GrContextThreadSafeProxy
Change-Id: I8ad7cf335f2b586cf501eaa70573690fbbd53efa Reviewed-on: https://skia-review.googlesource.com/106105 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkDeferredDisplayListRecorder.cpp4
-rw-r--r--src/gpu/GrBackendSurface.cpp49
-rw-r--r--src/gpu/GrContext.cpp37
-rw-r--r--src/gpu/GrOnFlushResourceProvider.h3
-rw-r--r--src/gpu/gl/GrGLCaps.cpp10
-rw-r--r--src/gpu/gl/GrGLCaps.h3
-rw-r--r--src/gpu/mock/GrMockCaps.h20
-rw-r--r--src/gpu/mock/GrMockGpu.cpp2
-rw-r--r--src/gpu/mtl/GrMtlCaps.h5
-rw-r--r--src/gpu/vk/GrVkCaps.cpp29
-rw-r--r--src/gpu/vk/GrVkCaps.h3
-rw-r--r--src/image/SkSurface_Gpu.cpp10
12 files changed, 160 insertions, 15 deletions
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp
index 14e5926637..b3c0679724 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -41,6 +41,10 @@ SkDeferredDisplayListRecorder::~SkDeferredDisplayListRecorder() {
bool SkDeferredDisplayListRecorder::init() {
SkASSERT(!fSurface);
+ if (!fCharacterization.isValid()) {
+ return false;
+ }
+
#ifdef SK_RASTER_RECORDER_IMPLEMENTATION
// Use raster right now to allow threading
const SkImageInfo ii = SkImageInfo::Make(fCharacterization.width(), fCharacterization.height(),
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 16fa793d25..dcfbe3b5a5 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -14,6 +14,55 @@
#include "vk/GrVkUtil.h"
#endif
+GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
+ : fBackend(kOpenGL_GrBackend)
+ , fValid(true)
+ , fGLTarget(target)
+ , fGLFormat(format) {
+}
+
+const GrGLenum* GrBackendFormat::getGLFormat() const {
+ if (this->isValid() && kOpenGL_GrBackend == fBackend) {
+ return &fGLFormat;
+ }
+ return nullptr;
+}
+
+const GrGLenum* GrBackendFormat::getGLTarget() const {
+ if (this->isValid() && kOpenGL_GrBackend == fBackend) {
+ return &fGLTarget;
+ }
+ return nullptr;
+}
+
+#ifdef SK_VULKAN
+GrBackendFormat::GrBackendFormat(VkFormat vkFormat)
+ : fBackend(kVulkan_GrBackend)
+ , fValid(true)
+ , fVkFormat(vkFormat) {
+}
+
+const VkFormat* GrBackendFormat::getVkFormat() const {
+ if (this->isValid() && kVulkan_GrBackend == fBackend) {
+ return &fVkFormat;
+ }
+ return nullptr;
+}
+#endif
+
+GrBackendFormat::GrBackendFormat(GrPixelConfig config)
+ : fBackend(kMock_GrBackend)
+ , fValid(true)
+ , fMockFormat(config) {
+}
+
+const GrPixelConfig* GrBackendFormat::getMockFormat() const {
+ if (this->isValid() && kMock_GrBackend == fBackend) {
+ return &fMockFormat;
+ }
+ return nullptr;
+}
+
#ifdef SK_VULKAN
GrBackendTexture::GrBackendTexture(int width,
int height,
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 1700c1be1d..8a5417ed17 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -334,6 +334,42 @@ sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
return fThreadSafeProxy;
}
+SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
+ size_t cacheMaxResourceBytes,
+ const SkImageInfo& ii, const GrBackendFormat& backendFormat,
+ int sampleCnt, GrSurfaceOrigin origin,
+ const SkSurfaceProps& surfaceProps,
+ bool isMipMapped) {
+ if (!backendFormat.isValid()) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ // We're assuming GrFSAAType::kMixedSamples will never be specified via this code path
+ GrFSAAType FSAAType = sampleCnt > 1 ? GrFSAAType::kUnifiedMSAA : GrFSAAType::kNone;
+
+ if (!fCaps->mipMapSupport()) {
+ isMipMapped = false;
+ }
+
+ GrPixelConfig config = kUnknown_GrPixelConfig;
+ if (!fCaps->getConfigFromBackendFormat(backendFormat, ii.colorType(), &config)) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ // This surface characterization factory assumes that the resulting characterization is
+ // textureable.
+ if (!fCaps->isConfigTexturable(config)) {
+ return SkSurfaceCharacterization(); // return an invalid characterization
+ }
+
+ return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
+ cacheMaxResourceBytes,
+ origin, ii.width(), ii.height(), config, FSAAType, sampleCnt,
+ SkSurfaceCharacterization::Textureable(true),
+ SkSurfaceCharacterization::MipMapped(isMipMapped),
+ ii.refColorSpace(), surfaceProps);
+}
+
void GrContext::abandonContext() {
ASSERT_SINGLE_OWNER
@@ -1081,6 +1117,7 @@ bool GrContext::validPMUPMConversionExists() {
//////////////////////////////////////////////////////////////////////////////
+// DDL TODO: remove 'maxResources'
void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
ASSERT_SINGLE_OWNER
if (maxResources) {
diff --git a/src/gpu/GrOnFlushResourceProvider.h b/src/gpu/GrOnFlushResourceProvider.h
index 633abe1411..224160de5f 100644
--- a/src/gpu/GrOnFlushResourceProvider.h
+++ b/src/gpu/GrOnFlushResourceProvider.h
@@ -57,9 +57,6 @@ public:
* Any OnFlushCallbackObject associated with a path renderer will need to be deleted.
*/
virtual bool retainOnFreeGpuResources() { return false; }
-
-private:
- typedef SkRefCnt INHERITED;
};
/*
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 0b2e57067f..56f25ea4cc 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2539,3 +2539,13 @@ bool GrGLCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkCo
return validate_sized_format(fbInfo->fFormat, ct, config, fStandard);
}
+bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
+ GrPixelConfig* config) const {
+ const GrGLenum* glFormat = format.getGLFormat();
+ if (!glFormat) {
+ return false;
+ }
+ return validate_sized_format(*glFormat, ct, config, fStandard);
+}
+
+
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index c7812be20e..6c8fe5ccd9 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -407,6 +407,9 @@ public:
bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
GrPixelConfig*) const override;
+ bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
+ GrPixelConfig*) const override;
+
private:
enum ExternalFormatUsage {
kTexImage_ExternalFormatUsage,
diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h
index 1e448516d7..d96a690b31 100644
--- a/src/gpu/mock/GrMockCaps.h
+++ b/src/gpu/mock/GrMockCaps.h
@@ -72,8 +72,14 @@ public:
}
bool validateBackendTexture(const GrBackendTexture& tex, SkColorType,
- GrPixelConfig*) const override {
- return SkToBool(tex.getMockTextureInfo());
+ GrPixelConfig* config) const override {
+ const GrMockTextureInfo* texInfo = tex.getMockTextureInfo();
+ if (!texInfo) {
+ return false;
+ }
+
+ *config = texInfo->fConfig;
+ return true;
}
bool validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType,
@@ -81,6 +87,16 @@ public:
return false;
}
+ bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
+ GrPixelConfig* config) const override {
+ const GrPixelConfig* mockFormat = format.getMockFormat();
+ if (!mockFormat) {
+ return false;
+ }
+ *config = *mockFormat;
+ return true;
+ }
+
private:
static const int kMaxSampleCnt = 16;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index da6b21aea0..9d1661be44 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -69,6 +69,7 @@ sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgete
GrMipMapsStatus mipMapsStatus = mipLevelCount > 1 ? GrMipMapsStatus::kValid
: GrMipMapsStatus::kNotAllocated;
GrMockTextureInfo info;
+ info.fConfig = desc.fConfig;
info.fID = NextInternalTextureID();
if (desc.fFlags & kRenderTarget_GrSurfaceFlag) {
return sk_sp<GrTexture>(
@@ -94,6 +95,7 @@ GrBackendTexture GrMockGpu::createTestingOnlyBackendTexture(void* pixels, int w,
GrPixelConfig config, bool isRT,
GrMipMapped) {
GrMockTextureInfo info;
+ info.fConfig = config;
info.fID = NextExternalTextureID();
fOutstandingTestingOnlyTextureIDs.add(info.fID);
return GrBackendTexture(w, h, config, info);
diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h
index 935cb07822..c23a9028ca 100644
--- a/src/gpu/mtl/GrMtlCaps.h
+++ b/src/gpu/mtl/GrMtlCaps.h
@@ -57,6 +57,11 @@ public:
return false;
}
+ bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
+ GrPixelConfig*) const override {
+ return false;
+ }
+
private:
void initFeatureSet(MTLFeatureSet featureSet);
diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp
index 8af81190af..3fc5a08acb 100644
--- a/src/gpu/vk/GrVkCaps.cpp
+++ b/src/gpu/vk/GrVkCaps.cpp
@@ -416,11 +416,7 @@ int GrVkCaps::maxRenderTargetSampleCount(GrPixelConfig config) const {
return table[table.count() - 1];
}
-bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixelConfig* config) {
- if (!imageInfo) {
- return false;
- }
- VkFormat format = imageInfo->fFormat;
+bool validate_image_info(VkFormat format, SkColorType ct, GrPixelConfig* config) {
*config = kUnknown_GrPixelConfig;
switch (ct) {
@@ -478,11 +474,30 @@ bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixel
bool GrVkCaps::validateBackendTexture(const GrBackendTexture& tex, SkColorType ct,
GrPixelConfig* config) const {
- return validate_image_info(tex.getVkImageInfo(), ct, config);
+ const GrVkImageInfo* imageInfo = tex.getVkImageInfo();
+ if (!imageInfo) {
+ return false;
+ }
+
+ return validate_image_info(imageInfo->fFormat, ct, config);
}
bool GrVkCaps::validateBackendRenderTarget(const GrBackendRenderTarget& rt, SkColorType ct,
GrPixelConfig* config) const {
- return validate_image_info(rt.getVkImageInfo(), ct, config);
+ const GrVkImageInfo* imageInfo = rt.getVkImageInfo();
+ if (!imageInfo) {
+ return false;
+ }
+
+ return validate_image_info(imageInfo->fFormat, ct, config);
+}
+
+bool GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
+ GrPixelConfig* config) const {
+ const VkFormat* vkFormat = format.getVkFormat();
+ if (!vkFormat) {
+ return false;
+ }
+ return validate_image_info(*vkFormat, ct, config);
}
diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h
index 3449dd2ccc..b6c8bebdc9 100644
--- a/src/gpu/vk/GrVkCaps.h
+++ b/src/gpu/vk/GrVkCaps.h
@@ -113,6 +113,9 @@ public:
bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType,
GrPixelConfig*) const override;
+ bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
+ GrPixelConfig*) const override;
+
private:
enum VkVendor {
kAMD_VkVendor = 4098,
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 04333ae508..bb748b8d7e 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -174,7 +174,7 @@ bool SkSurface_Gpu::onCharacterize(SkSurfaceCharacterization* data) const {
bool mipmapped = rtc->asTextureProxy() ? GrMipMapped::kYes == rtc->asTextureProxy()->mipMapped()
: false;
- data->set(ctx->threadSafeProxy(), maxResourceCount, maxResourceBytes,
+ data->set(ctx->threadSafeProxy(), maxResourceBytes,
rtc->origin(), rtc->width(), rtc->height(),
rtc->colorSpaceInfo().config(), rtc->fsaaType(), rtc->numStencilSamples(),
SkSurfaceCharacterization::Textureable(SkToBool(rtc->asTextureProxy())),
@@ -188,8 +188,13 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const {
GrRenderTargetContext* rtc = fDevice->accessRenderTargetContext();
GrContext* ctx = fDevice->context();
+ if (!data.isValid()) {
+ return false;
+ }
+
// As long as the current state if the context allows for greater or equal resources,
// we allow the DDL to be replayed.
+ // DDL TODO: should we just remove the resource check and ignore the cache limits on playback?
int maxResourceCount;
size_t maxResourceBytes;
ctx->getResourceCacheLimits(&maxResourceCount, &maxResourceBytes);
@@ -210,7 +215,6 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const {
}
return data.contextInfo() && data.contextInfo()->matches(ctx) &&
- data.cacheMaxResourceCount() <= maxResourceCount &&
data.cacheMaxResourceBytes() <= maxResourceBytes &&
data.origin() == rtc->origin() && data.width() == rtc->width() &&
data.height() == rtc->height() && data.config() == rtc->colorSpaceInfo().config() &&
@@ -220,7 +224,7 @@ bool SkSurface_Gpu::isCompatible(const SkSurfaceCharacterization& data) const {
}
bool SkSurface_Gpu::onDraw(const SkDeferredDisplayList* ddl) {
- if (!this->isCompatible(ddl->characterization())) {
+ if (!ddl || !this->isCompatible(ddl->characterization())) {
return false;
}