Remove some uses of GrBytesPerPixel
GrPixelConfig needs to go away. Towards that end, switch the Vk and GL backends over to using their native formats. Change-Id: I92c80eb27e5d639097a40745429721208fe26836 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/213428 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
2b8b06e793
commit
13f02be291
@ -35,11 +35,11 @@ void GrDrawOpAtlas::instantiate(GrOnFlushResourceProvider* onFlushResourceProvid
|
||||
|
||||
std::unique_ptr<GrDrawOpAtlas> GrDrawOpAtlas::Make(GrProxyProvider* proxyProvider,
|
||||
const GrBackendFormat& format,
|
||||
GrPixelConfig config, int width,
|
||||
GrColorType colorType, int width,
|
||||
int height, int plotWidth, int plotHeight,
|
||||
AllowMultitexturing allowMultitexturing,
|
||||
GrDrawOpAtlas::EvictionFunc func, void* data) {
|
||||
std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, format, config, width,
|
||||
std::unique_ptr<GrDrawOpAtlas> atlas(new GrDrawOpAtlas(proxyProvider, format, colorType, width,
|
||||
height, plotWidth, plotHeight,
|
||||
allowMultitexturing));
|
||||
if (!atlas->getProxies()[0]) {
|
||||
@ -56,7 +56,7 @@ static bool gDumpAtlasData = false;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY,
|
||||
int width, int height, GrPixelConfig config)
|
||||
int width, int height, GrColorType colorType)
|
||||
: fLastUpload(GrDeferredUploadToken::AlreadyFlushedToken())
|
||||
, fLastUse(GrDeferredUploadToken::AlreadyFlushedToken())
|
||||
, fFlushesSinceLastUse(0)
|
||||
@ -71,8 +71,8 @@ GrDrawOpAtlas::Plot::Plot(int pageIndex, int plotIndex, uint64_t genID, int offX
|
||||
, fY(offY)
|
||||
, fRects(nullptr)
|
||||
, fOffset(SkIPoint16::Make(fX * fWidth, fY * fHeight))
|
||||
, fConfig(config)
|
||||
, fBytesPerPixel(GrBytesPerPixel(config))
|
||||
, fColorType(colorType)
|
||||
, fBytesPerPixel(GrColorTypeBytesPerPixel(colorType))
|
||||
#ifdef SK_DEBUG
|
||||
, fDirty(false)
|
||||
#endif
|
||||
@ -150,10 +150,9 @@ void GrDrawOpAtlas::Plot::uploadToTexture(GrDeferredTextureUploadWritePixelsFn&
|
||||
// Set up dataPtr
|
||||
dataPtr += rowBytes * fDirtyRect.fTop;
|
||||
dataPtr += fBytesPerPixel * fDirtyRect.fLeft;
|
||||
// TODO: Make GrDrawOpAtlas store a GrColorType rather than GrPixelConfig.
|
||||
auto colorType = GrPixelConfigToColorType(fConfig);
|
||||
|
||||
writePixels(proxy, fOffset.fX + fDirtyRect.fLeft, fOffset.fY + fDirtyRect.fTop,
|
||||
fDirtyRect.width(), fDirtyRect.height(), colorType, dataPtr, rowBytes);
|
||||
fDirtyRect.width(), fDirtyRect.height(), fColorType, dataPtr, rowBytes);
|
||||
fDirtyRect.setEmpty();
|
||||
SkDEBUGCODE(fDirty = false;)
|
||||
}
|
||||
@ -180,10 +179,10 @@ void GrDrawOpAtlas::Plot::resetRects() {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GrDrawOpAtlas::GrDrawOpAtlas(GrProxyProvider* proxyProvider, const GrBackendFormat& format,
|
||||
GrPixelConfig config, int width, int height,
|
||||
GrColorType colorType, int width, int height,
|
||||
int plotWidth, int plotHeight, AllowMultitexturing allowMultitexturing)
|
||||
: fFormat(format)
|
||||
, fPixelConfig(config)
|
||||
, fColorType(colorType)
|
||||
, fTextureWidth(width)
|
||||
, fTextureHeight(height)
|
||||
, fPlotWidth(plotWidth)
|
||||
@ -524,7 +523,7 @@ bool GrDrawOpAtlas::createPages(GrProxyProvider* proxyProvider) {
|
||||
}
|
||||
desc.fWidth = fTextureWidth;
|
||||
desc.fHeight = fTextureHeight;
|
||||
desc.fConfig = fPixelConfig;
|
||||
desc.fConfig = GrColorTypeToPixelConfig(fColorType, GrSRGBEncoded::kNo);
|
||||
|
||||
int numPlotsX = fTextureWidth/fPlotWidth;
|
||||
int numPlotsY = fTextureHeight/fPlotHeight;
|
||||
@ -546,7 +545,7 @@ bool GrDrawOpAtlas::createPages(GrProxyProvider* proxyProvider) {
|
||||
for (int x = numPlotsX - 1, c = 0; x >= 0; --x, ++c) {
|
||||
uint32_t plotIndex = r * numPlotsX + c;
|
||||
currPlot->reset(new Plot(i, plotIndex, 1, x, y, fPlotWidth, fPlotHeight,
|
||||
fPixelConfig));
|
||||
fColorType));
|
||||
|
||||
// build LRU list
|
||||
fPages[i].fPlotList.addToHead(currPlot->get());
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
/**
|
||||
* Returns a GrDrawOpAtlas. This function can be called anywhere, but the returned atlas
|
||||
* should only be used inside of GrMeshDrawOp::onPrepareDraws.
|
||||
* @param GrPixelConfig The pixel config which this atlas will store
|
||||
* @param GrColorType The colorType which this atlas will store
|
||||
* @param width width in pixels of the atlas
|
||||
* @param height height in pixels of the atlas
|
||||
* @param numPlotsX The number of plots the atlas should be broken up into in the X
|
||||
@ -93,7 +93,7 @@ public:
|
||||
*/
|
||||
static std::unique_ptr<GrDrawOpAtlas> Make(GrProxyProvider*,
|
||||
const GrBackendFormat& format,
|
||||
GrPixelConfig,
|
||||
GrColorType,
|
||||
int width, int height,
|
||||
int plotWidth, int plotHeight,
|
||||
AllowMultitexturing allowMultitexturing,
|
||||
@ -246,7 +246,7 @@ public:
|
||||
void setMaxPages_TestingOnly(uint32_t maxPages);
|
||||
|
||||
private:
|
||||
GrDrawOpAtlas(GrProxyProvider*, const GrBackendFormat& format, GrPixelConfig, int width,
|
||||
GrDrawOpAtlas(GrProxyProvider*, const GrBackendFormat& format, GrColorType, int width,
|
||||
int height, int plotWidth, int plotHeight,
|
||||
AllowMultitexturing allowMultitexturing);
|
||||
|
||||
@ -296,8 +296,8 @@ private:
|
||||
void incFlushesSinceLastUsed() { fFlushesSinceLastUse++; }
|
||||
|
||||
private:
|
||||
Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY, int width, int height,
|
||||
GrPixelConfig config);
|
||||
Plot(int pageIndex, int plotIndex, uint64_t genID, int offX, int offY,
|
||||
int width, int height, GrColorType colorType);
|
||||
|
||||
~Plot() override;
|
||||
|
||||
@ -306,7 +306,8 @@ private:
|
||||
* the atlas
|
||||
*/
|
||||
Plot* clone() const {
|
||||
return new Plot(fPageIndex, fPlotIndex, fGenID + 1, fX, fY, fWidth, fHeight, fConfig);
|
||||
return new Plot(fPageIndex, fPlotIndex, fGenID + 1, fX, fY, fWidth, fHeight,
|
||||
fColorType);
|
||||
}
|
||||
|
||||
static GrDrawOpAtlas::AtlasID CreateId(uint32_t pageIdx, uint32_t plotIdx,
|
||||
@ -336,7 +337,7 @@ private:
|
||||
const int fY;
|
||||
GrRectanizer* fRects;
|
||||
const SkIPoint16 fOffset; // the offset of the plot in the backing texture
|
||||
const GrPixelConfig fConfig;
|
||||
const GrColorType fColorType;
|
||||
const size_t fBytesPerPixel;
|
||||
SkIRect fDirtyRect;
|
||||
SkDEBUGCODE(bool fDirty);
|
||||
@ -385,7 +386,7 @@ private:
|
||||
}
|
||||
|
||||
GrBackendFormat fFormat;
|
||||
GrPixelConfig fPixelConfig;
|
||||
GrColorType fColorType;
|
||||
int fTextureWidth;
|
||||
int fTextureHeight;
|
||||
int fPlotWidth;
|
||||
|
@ -1573,6 +1573,43 @@ static GrGLTexture::SamplerParams set_initial_texture_params(const GrGLInterface
|
||||
return params;
|
||||
}
|
||||
|
||||
size_t GLBytesPerPixel(GrGLenum glFormat) {
|
||||
switch (glFormat) {
|
||||
case GR_GL_LUMINANCE8:
|
||||
case GR_GL_ALPHA8:
|
||||
case GR_GL_R8:
|
||||
return 1;
|
||||
|
||||
case GR_GL_RGB565:
|
||||
case GR_GL_RGBA4:
|
||||
case GR_GL_RG8:
|
||||
case GR_GL_R16F:
|
||||
return 2;
|
||||
|
||||
case GR_GL_RGB8:
|
||||
return 3;
|
||||
|
||||
case GR_GL_RGBA8:
|
||||
case GR_GL_SRGB8_ALPHA8:
|
||||
case GR_GL_BGRA8:
|
||||
case GR_GL_RGB10_A2:
|
||||
return 4;
|
||||
|
||||
case GR_GL_RGBA16F:
|
||||
case GR_GL_RG32F:
|
||||
return 8;
|
||||
|
||||
case GR_GL_RGBA32F:
|
||||
return 16;
|
||||
|
||||
case GR_GL_COMPRESSED_RGB8_ETC2:
|
||||
return 0;
|
||||
}
|
||||
|
||||
SK_ABORT("Invalid GL format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sk_sp<GrTexture> GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
||||
SkBudgeted budgeted,
|
||||
const GrMipLevel texels[],
|
||||
@ -1583,6 +1620,8 @@ sk_sp<GrTexture> GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
||||
return return_null_texture();
|
||||
}
|
||||
|
||||
GrGLenum glFormat = this->glCaps().configSizedInternalFormat(desc.fConfig);
|
||||
|
||||
bool performClear = (desc.fFlags & kPerformInitialClear_GrSurfaceFlag) &&
|
||||
!GrPixelConfigIsCompressed(desc.fConfig);
|
||||
|
||||
@ -1590,7 +1629,7 @@ sk_sp<GrTexture> GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc,
|
||||
std::unique_ptr<uint8_t[]> zeros;
|
||||
if (performClear && !this->glCaps().clearTextureSupport() &&
|
||||
!this->glCaps().canConfigBeFBOColorAttachment(desc.fConfig)) {
|
||||
size_t rowSize = GrBytesPerPixel(desc.fConfig) * desc.fWidth;
|
||||
size_t rowSize = GLBytesPerPixel(glFormat) * desc.fWidth;
|
||||
size_t size = rowSize * desc.fHeight;
|
||||
zeros.reset(new uint8_t[size]);
|
||||
memset(zeros.get(), 0, size);
|
||||
|
@ -877,7 +877,7 @@ bool GrSmallPathRenderer::onDrawPath(const DrawPathArgs& args) {
|
||||
kAlpha_8_SkColorType);
|
||||
fAtlas = GrDrawOpAtlas::Make(args.fContext->priv().proxyProvider(),
|
||||
format,
|
||||
kAlpha_8_GrPixelConfig,
|
||||
GrColorType::kAlpha_8,
|
||||
ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_HEIGHT,
|
||||
PLOT_WIDTH, PLOT_HEIGHT,
|
||||
GrDrawOpAtlas::AllowMultitexturing::kYes,
|
||||
@ -966,7 +966,7 @@ GR_DRAW_OP_TEST_DEFINE(SmallPathOp) {
|
||||
const GrBackendFormat format =
|
||||
context->priv().caps()->getBackendFormatFromColorType(kAlpha_8_SkColorType);
|
||||
gTestStruct.fAtlas = GrDrawOpAtlas::Make(context->priv().proxyProvider(),
|
||||
format, kAlpha_8_GrPixelConfig,
|
||||
format, GrColorType::kAlpha_8,
|
||||
ATLAS_TEXTURE_WIDTH, ATLAS_TEXTURE_HEIGHT,
|
||||
PLOT_WIDTH, PLOT_HEIGHT,
|
||||
GrDrawOpAtlas::AllowMultitexturing::kYes,
|
||||
|
@ -21,35 +21,20 @@ GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, GrStrikeCache* gl
|
||||
|
||||
GrAtlasManager::~GrAtlasManager() = default;
|
||||
|
||||
static GrPixelConfig mask_format_to_pixel_config(GrMaskFormat format) {
|
||||
static GrColorType mask_format_to_gr_color_type(GrMaskFormat format) {
|
||||
switch (format) {
|
||||
case kA8_GrMaskFormat:
|
||||
return kAlpha_8_GrPixelConfig;
|
||||
return GrColorType::kAlpha_8;
|
||||
case kA565_GrMaskFormat:
|
||||
return kRGB_565_GrPixelConfig;
|
||||
return GrColorType::kRGB_565;
|
||||
case kARGB_GrMaskFormat:
|
||||
return kRGBA_8888_GrPixelConfig;
|
||||
return GrColorType::kRGBA_8888;
|
||||
default:
|
||||
SkDEBUGFAIL("unsupported GrMaskFormat");
|
||||
return kAlpha_8_GrPixelConfig;
|
||||
return GrColorType::kAlpha_8;
|
||||
}
|
||||
}
|
||||
|
||||
static SkColorType mask_format_to_color_type(GrMaskFormat format) {
|
||||
switch (format) {
|
||||
case kA8_GrMaskFormat:
|
||||
return kAlpha_8_SkColorType;
|
||||
case kA565_GrMaskFormat:
|
||||
return kRGB_565_SkColorType;
|
||||
case kARGB_GrMaskFormat:
|
||||
return kRGBA_8888_SkColorType;
|
||||
default:
|
||||
SkDEBUGFAIL("unsupported GrMaskFormat");
|
||||
return kAlpha_8_SkColorType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void GrAtlasManager::freeAll() {
|
||||
for (int i = 0; i < kMaskFormatCount; ++i) {
|
||||
fAtlases[i] = nullptr;
|
||||
@ -175,17 +160,18 @@ void GrAtlasManager::setAtlasSizesToMinimum_ForTesting() {
|
||||
bool GrAtlasManager::initAtlas(GrMaskFormat format) {
|
||||
int index = MaskFormatToAtlasIndex(format);
|
||||
if (fAtlases[index] == nullptr) {
|
||||
GrPixelConfig config = mask_format_to_pixel_config(format);
|
||||
SkColorType colorType = mask_format_to_color_type(format);
|
||||
GrColorType grColorType = mask_format_to_gr_color_type(format);
|
||||
SkISize atlasDimensions = fAtlasConfig.atlasDimensions(format);
|
||||
SkISize plotDimensions = fAtlasConfig.plotDimensions(format);
|
||||
|
||||
const GrBackendFormat format = fCaps->getBackendFormatFromColorType(colorType);
|
||||
const GrBackendFormat format = fCaps->getBackendFormatFromGrColorType(grColorType,
|
||||
GrSRGBEncoded::kNo);
|
||||
|
||||
fAtlases[index] = GrDrawOpAtlas::Make(
|
||||
fProxyProvider, format, config, atlasDimensions.width(), atlasDimensions.height(),
|
||||
plotDimensions.width(), plotDimensions.height(), fAllowMultitexturing,
|
||||
&GrStrikeCache::HandleEviction, fGlyphCache);
|
||||
fProxyProvider, format, grColorType,
|
||||
atlasDimensions.width(), atlasDimensions.height(),
|
||||
plotDimensions.width(), plotDimensions.height(),
|
||||
fAllowMultitexturing, &GrStrikeCache::HandleEviction, fGlyphCache);
|
||||
if (!fAtlases[index]) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1445,6 +1445,45 @@ bool copy_testing_data(GrVkGpu* gpu, const void* srcData, const GrVkAlloc& alloc
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t VkBytesPerPixel(VkFormat vkFormat) {
|
||||
switch (vkFormat) {
|
||||
case VK_FORMAT_R8_UNORM:
|
||||
return 1;
|
||||
|
||||
case VK_FORMAT_R5G6B5_UNORM_PACK16:
|
||||
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
|
||||
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
|
||||
case VK_FORMAT_R8G8_UNORM:
|
||||
case VK_FORMAT_R16_SFLOAT:
|
||||
return 2;
|
||||
|
||||
case VK_FORMAT_R8G8B8_UNORM:
|
||||
return 3;
|
||||
|
||||
case VK_FORMAT_R8G8B8A8_UNORM:
|
||||
case VK_FORMAT_R8G8B8A8_SRGB:
|
||||
case VK_FORMAT_B8G8R8A8_UNORM:
|
||||
case VK_FORMAT_B8G8R8A8_SRGB:
|
||||
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
|
||||
return 4;
|
||||
|
||||
case VK_FORMAT_R16G16B16A16_SFLOAT:
|
||||
case VK_FORMAT_R32G32_SFLOAT:
|
||||
return 8;
|
||||
|
||||
case VK_FORMAT_R32G32B32A32_SFLOAT:
|
||||
return 16;
|
||||
|
||||
case VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK:
|
||||
default:
|
||||
SK_ABORT("Invalid Vk format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SK_ABORT("Invalid Vk format");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool texturable,
|
||||
bool renderable, GrMipMapped mipMapped, const void* srcData,
|
||||
@ -1454,8 +1493,8 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool
|
||||
SkASSERT(GrMipMapped::kNo == mipMapped);
|
||||
SkASSERT(!srcData);
|
||||
}
|
||||
VkFormat pixelFormat;
|
||||
if (!GrPixelConfigToVkFormat(config, &pixelFormat)) {
|
||||
VkFormat vkFormat;
|
||||
if (!GrPixelConfigToVkFormat(config, &vkFormat)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1503,7 +1542,7 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool
|
||||
nullptr, // pNext
|
||||
0, // VkImageCreateFlags
|
||||
VK_IMAGE_TYPE_2D, // VkImageType
|
||||
pixelFormat, // VkFormat
|
||||
vkFormat, // VkFormat
|
||||
{(uint32_t)w, (uint32_t)h, 1}, // VkExtent3D
|
||||
mipLevels, // mipLevels
|
||||
1, // arrayLayers
|
||||
@ -1555,7 +1594,7 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool
|
||||
err = VK_CALL(BeginCommandBuffer(cmdBuffer, &cmdBufferBeginInfo));
|
||||
SkASSERT(!err);
|
||||
|
||||
size_t bpp = GrBytesPerPixel(config);
|
||||
size_t bpp = VkBytesPerPixel(vkFormat);
|
||||
SkASSERT(w && h);
|
||||
|
||||
const size_t trimRowBytes = w * bpp;
|
||||
@ -1769,7 +1808,7 @@ bool GrVkGpu::createTestingOnlyVkImage(GrPixelConfig config, int w, int h, bool
|
||||
info->fAlloc = alloc;
|
||||
info->fImageTiling = VK_IMAGE_TILING_OPTIMAL;
|
||||
info->fImageLayout = initialLayout;
|
||||
info->fFormat = pixelFormat;
|
||||
info->fFormat = vkFormat;
|
||||
info->fLevelCount = mipLevels;
|
||||
|
||||
return true;
|
||||
|
@ -144,7 +144,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BasicDrawOpAtlas, reporter, ctxInfo) {
|
||||
std::unique_ptr<GrDrawOpAtlas> atlas = GrDrawOpAtlas::Make(
|
||||
proxyProvider,
|
||||
format,
|
||||
kAlpha_8_GrPixelConfig,
|
||||
GrColorType::kAlpha_8,
|
||||
kAtlasSize, kAtlasSize,
|
||||
kAtlasSize/kNumPlots, kAtlasSize/kNumPlots,
|
||||
GrDrawOpAtlas::AllowMultitexturing::kYes,
|
||||
|
Loading…
Reference in New Issue
Block a user