implemented getting format from texture as virtual in gpu caps

Bug: skia:
Change-Id: If6bbbd212ff472ea322d2bbed61995fe7ba85df7
Reviewed-on: https://skia-review.googlesource.com/138240
Commit-Queue: Timothy Liang <timliang@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Timothy Liang 2018-06-28 15:50:36 -04:00 committed by Skia Commit-Bot
parent be0ab883e7
commit 036fdfe5aa
14 changed files with 82 additions and 35 deletions

View File

@ -172,11 +172,6 @@ public:
// Returns true if the backend texture has been initialized.
bool isValid() const { return fIsValid; }
/**
* Create a GrBackendFormat object that matches this texture
*/
GrBackendFormat format() const;
#if GR_TEST_UTILS
GrPixelConfig testingOnly_getPixelConfig() const;
static bool TestingOnly_Equals(const GrBackendTexture& , const GrBackendTexture&);

View File

@ -221,34 +221,6 @@ bool GrBackendTexture::getMockTextureInfo(GrMockTextureInfo* outInfo) const {
return false;
}
GrBackendFormat GrBackendTexture::format() const {
if (!this->isValid()) {
return GrBackendFormat();
}
switch (this->backend()) {
#ifdef SK_VULKAN
case kVulkan_GrBackend: {
GrVkImageInfo vkInfo;
SkAssertResult(this->getVkImageInfo(&vkInfo));
return GrBackendFormat::MakeVk(vkInfo.fFormat);
}
#endif
case kOpenGL_GrBackend: {
GrGLTextureInfo glInfo;
SkAssertResult(this->getGLTextureInfo(&glInfo));
return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
}
case kMock_GrBackend: {
GrMockTextureInfo mockInfo;
SkAssertResult(this->getMockTextureInfo(&mockInfo));
return GrBackendFormat::MakeMock(mockInfo.fConfig);
}
default:
return GrBackendFormat();
}
}
#if GR_TEST_UTILS
bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBackendTexture& t1) {
if (!t0.isValid() || !t1.isValid()) {

View File

@ -262,3 +262,10 @@ bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrMipMapped mipped)
return true;
}
GrBackendFormat GrCaps::createFormatFromBackendTexture(const GrBackendTexture& backendTex) const {
if (!backendTex.isValid()) {
return GrBackendFormat();
}
return this->onCreateFormatFromBackendTexture(backendTex);
}

View File

@ -271,6 +271,14 @@ public:
virtual bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
GrPixelConfig*) const = 0;
#ifdef GR_TEST_UTILS
/**
* Creates a GrBackendFormat which matches the backend texture. If the backend texture is
* invalid, the function will return the default GrBackendFormat.
*/
GrBackendFormat createFormatFromBackendTexture(const GrBackendTexture&) const;
#endif
const GrDriverBugWorkarounds& workarounds() const { return fDriverBugWorkarounds; }
protected:
@ -279,6 +287,14 @@ protected:
expand them. */
void applyOptionsOverrides(const GrContextOptions& options);
#ifdef GR_TEST_UTILS
/**
* Subclasses implement this to actually create a GrBackendFormat to match backend texture. At
* this point, the backend texture has already been validated.
*/
virtual GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const = 0;
#endif
sk_sp<GrShaderCaps> fShaderCaps;
bool fNPOTTextureTileSupport : 1;

View File

@ -2931,4 +2931,13 @@ bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColor
return validate_sized_format(*glFormat, ct, config, fStandard);
}
#ifdef GR_TEST_UTILS
GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
GrGLTextureInfo glInfo;
SkAssertResult(backendTex.getGLTextureInfo(&glInfo));
return GrBackendFormat::MakeGL(glInfo.fFormat, glInfo.fTarget);
}
#endif

View File

@ -461,6 +461,10 @@ private:
void onApplyOptionsOverrides(const GrContextOptions& options) override;
#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
#endif
bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override;
void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&,

View File

@ -107,6 +107,15 @@ public:
}
private:
#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const override {
GrMockTextureInfo mockInfo;
SkAssertResult(backendTex.getMockTextureInfo(&mockInfo));
return GrBackendFormat::MakeMock(mockInfo.fConfig);
}
#endif
static const int kMaxSampleCnt = 16;
GrMockOptions fOptions;

View File

@ -75,6 +75,11 @@ private:
void initGrCaps(const id<MTLDevice> device);
void initShaderCaps();
#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
#endif
void initConfigTable();
struct ConfigInfo {

View File

@ -7,6 +7,7 @@
#include "GrMtlCaps.h"
#include "GrBackendSurface.h"
#include "GrShaderCaps.h"
GrMtlCaps::GrMtlCaps(const GrContextOptions& contextOptions, const id<MTLDevice> device,
@ -314,3 +315,11 @@ void GrMtlCaps::initConfigTable() {
info = &fConfigTable[kRGBA_half_GrPixelConfig];
info->fFlags = ConfigInfo::kAllFlags;
}
#ifdef GR_TEST_UTILS
GrBackendFormat GrMtlCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
return GrBackendFormat(); // Metal BackendFormat not yet implemented.
}
#endif

View File

@ -664,3 +664,12 @@ bool GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColor
return validate_image_info(*vkFormat, ct, config);
}
#ifdef GR_TEST_UTILS
GrBackendFormat GrVkCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {
GrVkImageInfo vkInfo;
SkAssertResult(backendTex.getVkImageInfo(&vkInfo));
return GrBackendFormat::MakeVk(vkInfo.fFormat);
}
#endif

View File

@ -157,6 +157,10 @@ private:
uint32_t featureFlags);
void initShaderCaps(const VkPhysicalDeviceProperties&, uint32_t featureFlags);
#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(const GrBackendTexture&) const override;
#endif
void initConfigTable(const GrVkInterface*, VkPhysicalDevice, const VkPhysicalDeviceProperties&);
void initStencilFormat(const GrVkInterface* iface, VkPhysicalDevice physDev);

View File

@ -105,7 +105,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageTest, reporter, ctxInfo) {
nullptr, kWidth, kHeight, kRGBA_8888_GrPixelConfig, true, GrMipMapped::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
GrBackendFormat backendFormat = backendTex.format();
GrBackendFormat backendFormat = gpu->caps()->createFormatFromBackendTexture(backendTex);
REPORTER_ASSERT(reporter, backendFormat.isValid());
PromiseTextureChecker promiseChecker(backendTex);

View File

@ -20,6 +20,10 @@ DDLPromiseImageHelper::PromiseImageCallbackContext::~PromiseImageCallbackContext
}
}
const GrCaps* DDLPromiseImageHelper::PromiseImageCallbackContext::caps() const {
return fContext->contextPriv().caps();
}
///////////////////////////////////////////////////////////////////////////////////////////////////
sk_sp<SkData> DDLPromiseImageHelper::deflateSKP(const SkPicture* inputPicture) {
@ -104,7 +108,9 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
}
SkASSERT(curImage.fIndex == *indexPtr);
GrBackendFormat backendFormat = curImage.fCallbackContext->backendTexture().format();
const GrCaps* caps = curImage.fCallbackContext->caps();
const GrBackendTexture& backendTex = curImage.fCallbackContext->backendTexture();
GrBackendFormat backendFormat = caps->createFormatFromBackendTexture(backendTex);
// Each DDL recorder gets its own ref on the promise callback context for the
// promise images it creates.

View File

@ -77,6 +77,8 @@ private:
const GrBackendTexture& backendTexture() const { return fBackendTexture; }
const GrCaps* caps() const;
private:
GrContext* fContext;
GrBackendTexture fBackendTexture;