aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-03-22 10:01:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-22 14:49:44 +0000
commit5fba7ad39a96d02c8a23cc20e47c5021b6a85baa (patch)
tree17840b99fbcec0957762a06f3952552466e74ddc /include
parent9eded2c211773133b86a964b357404ae6b021d7d (diff)
Support GL_RGB textures and render targets.
Bug= skia:7533 Change-Id: Iba30e90dbf2574368b773bb5cf2ebd5219559717 Reviewed-on: https://skia-review.googlesource.com/108188 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'include')
-rw-r--r--include/gpu/GrTypes.h41
-rw-r--r--include/private/GrTypesPriv.h70
-rw-r--r--include/private/SkImageInfoPriv.h220
3 files changed, 276 insertions, 55 deletions
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 3fec742907..979014cca4 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -286,58 +286,29 @@ static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
}
/**
- * Pixel configurations.
+ * Pixel configurations. This type conflates texture formats, CPU pixel formats, and
+ * premultipliedness. We are moving away from it towards SkColorType and backend API (GL, Vulkan)
+ * texture formats in the pulbic API. Right now this mostly refers to texture formats as we're
+ * migrating.
*/
enum GrPixelConfig {
kUnknown_GrPixelConfig,
kAlpha_8_GrPixelConfig,
kGray_8_GrPixelConfig,
kRGB_565_GrPixelConfig,
- /**
- * Premultiplied
- */
kRGBA_4444_GrPixelConfig,
- /**
- * Premultiplied. Byte order is r,g,b,a.
- */
kRGBA_8888_GrPixelConfig,
- /**
- * Premultiplied. Byte order is b,g,r,a.
- */
+ kRGB_888_GrPixelConfig,
kBGRA_8888_GrPixelConfig,
- /**
- * Premultiplied and sRGB. Byte order is r,g,b,a.
- */
kSRGBA_8888_GrPixelConfig,
- /**
- * Premultiplied and sRGB. Byte order is b,g,r,a.
- */
kSBGRA_8888_GrPixelConfig,
-
- /**
- * Premultiplied.
- */
kRGBA_1010102_GrPixelConfig,
-
- /**
- * Byte order is r, g, b, a. This color format is 32 bits per channel
- */
kRGBA_float_GrPixelConfig,
- /**
- * Byte order is r, g. This color format is 32 bits per channel
- */
kRG_float_GrPixelConfig,
-
- /**
- * This color format is a single 16 bit float channel
- */
kAlpha_half_GrPixelConfig,
-
- /**
- * Byte order is r, g, b, a. This color format is 16 bits per channel
- */
kRGBA_half_GrPixelConfig,
+ /** For internal usage. */
kPrivateConfig1_GrPixelConfig,
kPrivateConfig2_GrPixelConfig,
kPrivateConfig3_GrPixelConfig,
diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h
index 69c79ab042..74b2425c14 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -12,6 +12,8 @@
#include "GrSharedEnums.h"
#include "GrTypes.h"
#include "SkImageInfo.h"
+#include "SkImageInfoPriv.h"
+#include "SkRefCnt.h"
#include "SkWeakRefCnt.h"
class GrCaps;
@@ -814,6 +816,7 @@ static inline GrSRGBEncoded GrPixelConfigIsSRGBEncoded(GrPixelConfig config) {
case kGray_8_as_Red_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kRGBA_1010102_GrPixelConfig:
@@ -852,6 +855,7 @@ static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
case kGray_8_as_Red_GrPixelConfig:
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kRGBA_1010102_GrPixelConfig:
case kRGBA_float_GrPixelConfig:
case kRG_float_GrPixelConfig:
@@ -879,6 +883,7 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
case kAlpha_half_as_Red_GrPixelConfig:
return 2;
case kRGBA_8888_GrPixelConfig:
+ case kRGB_888_GrPixelConfig: // Assuming GPUs store this 4-byte aligned.
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
@@ -900,6 +905,7 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) {
static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
switch (config) {
case kRGB_565_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kGray_8_GrPixelConfig:
case kGray_8_as_Lum_GrPixelConfig:
case kGray_8_as_Red_GrPixelConfig:
@@ -940,6 +946,7 @@ static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
@@ -971,6 +978,7 @@ static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
@@ -992,6 +1000,7 @@ static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
@@ -1024,6 +1033,7 @@ static inline GrSLPrecision GrSLSamplerPrecision(GrPixelConfig config) {
case kRGB_565_GrPixelConfig:
case kRGBA_4444_GrPixelConfig:
case kRGBA_8888_GrPixelConfig:
+ case kRGB_888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
@@ -1059,6 +1069,7 @@ enum class GrColorType {
kRGB_565,
kABGR_4444, // This name differs from SkColorType. kARGB_4444_SkColorType is misnamed.
kRGBA_8888,
+ kRGB_888x,
kBGRA_8888,
kRGBA_1010102,
kGray_8,
@@ -1075,6 +1086,7 @@ static inline SkColorType GrColorTypeToSkColorType(GrColorType ct) {
case GrColorType::kRGB_565: return kRGB_565_SkColorType;
case GrColorType::kABGR_4444: return kARGB_4444_SkColorType;
case GrColorType::kRGBA_8888: return kRGBA_8888_SkColorType;
+ case GrColorType::kRGB_888x: return kRGB_888x_SkColorType;
case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType;
case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType;
case GrColorType::kGray_8: return kGray_8_SkColorType;
@@ -1094,8 +1106,8 @@ static inline GrColorType SkColorTypeToGrColorType(SkColorType ct) {
case kRGB_565_SkColorType: return GrColorType::kRGB_565;
case kARGB_4444_SkColorType: return GrColorType::kABGR_4444;
case kRGBA_8888_SkColorType: return GrColorType::kRGBA_8888;
+ case kRGB_888x_SkColorType: return GrColorType::kRGB_888x;
case kBGRA_8888_SkColorType: return GrColorType::kBGRA_8888;
- case kRGB_888x_SkColorType: return GrColorType::kUnknown;
case kGray_8_SkColorType: return GrColorType::kGray_8;
case kRGBA_F16_SkColorType: return GrColorType::kRGBA_F16;
case kRGBA_1010102_SkColorType: return GrColorType::kRGBA_1010102;
@@ -1105,6 +1117,35 @@ static inline GrColorType SkColorTypeToGrColorType(SkColorType ct) {
return GrColorType::kUnknown;
}
+static inline uint32_t GrColorTypeComponentFlags(GrColorType ct) {
+ switch (ct) {
+ case GrColorType::kUnknown: return 0;
+ case GrColorType::kAlpha_8: return kAlpha_SkColorTypeComponentFlag;
+ case GrColorType::kRGB_565: return kRGB_SkColorTypeComponentFlags;
+ case GrColorType::kABGR_4444: return kRGBA_SkColorTypeComponentFlags;
+ case GrColorType::kRGBA_8888: return kRGBA_SkColorTypeComponentFlags;
+ case GrColorType::kRGB_888x: return kRGB_SkColorTypeComponentFlags;
+ case GrColorType::kBGRA_8888: return kRGBA_SkColorTypeComponentFlags;
+ case GrColorType::kRGBA_1010102: return kRGBA_SkColorTypeComponentFlags;
+ case GrColorType::kGray_8: return kGray_SkColorTypeComponentFlag;
+ case GrColorType::kAlpha_F16: return kAlpha_SkColorTypeComponentFlag;
+ case GrColorType::kRGBA_F16: return kRGBA_SkColorTypeComponentFlags;
+ case GrColorType::kRG_F32: return kRed_SkColorTypeComponentFlag |
+ kGreen_SkColorTypeComponentFlag;
+ case GrColorType::kRGBA_F32: return kRGBA_SkColorTypeComponentFlags;
+ }
+ SK_ABORT("Invalid GrColorType");
+ return kUnknown_SkColorType;
+}
+
+static inline bool GrColorTypeIsAlphaOnly(GrColorType ct) {
+ return kAlpha_SkColorTypeComponentFlag == GrColorTypeComponentFlags(ct);
+}
+
+static inline bool GrColorTypeHasAlpha(GrColorType ct) {
+ return kAlpha_SkColorTypeComponentFlag & GrColorTypeComponentFlags(ct);
+}
+
static inline int GrColorTypeBytesPerPixel(GrColorType ct) {
switch (ct) {
case GrColorType::kUnknown: return 0;
@@ -1112,6 +1153,7 @@ static inline int GrColorTypeBytesPerPixel(GrColorType ct) {
case GrColorType::kRGB_565: return 2;
case GrColorType::kABGR_4444: return 2;
case GrColorType::kRGBA_8888: return 4;
+ case GrColorType::kRGB_888x: return 4;
case GrColorType::kBGRA_8888: return 4;
case GrColorType::kRGBA_1010102: return 4;
case GrColorType::kGray_8: return 1;
@@ -1124,25 +1166,6 @@ static inline int GrColorTypeBytesPerPixel(GrColorType ct) {
return 0;
}
-static inline int GrColorTypeIsAlphaOnly(GrColorType ct) {
- switch (ct) {
- case GrColorType::kUnknown: return false;
- case GrColorType::kAlpha_8: return true;
- case GrColorType::kRGB_565: return false;
- case GrColorType::kABGR_4444: return false;
- case GrColorType::kRGBA_8888: return false;
- case GrColorType::kBGRA_8888: return false;
- case GrColorType::kRGBA_1010102: return false;
- case GrColorType::kGray_8: return false;
- case GrColorType::kAlpha_F16: return true;
- case GrColorType::kRGBA_F16: return false;
- case GrColorType::kRG_F32: return false;
- case GrColorType::kRGBA_F32: return false;
- }
- SK_ABORT("Invalid GrColorType");
- return false;
-}
-
static inline GrColorType GrPixelConfigToColorTypeAndEncoding(GrPixelConfig config,
GrSRGBEncoded* srgbEncoded) {
SkASSERT(srgbEncoded);
@@ -1164,6 +1187,9 @@ static inline GrColorType GrPixelConfigToColorTypeAndEncoding(GrPixelConfig conf
case kRGBA_8888_GrPixelConfig:
*srgbEncoded = GrSRGBEncoded::kNo;
return GrColorType::kRGBA_8888;
+ case kRGB_888_GrPixelConfig:
+ *srgbEncoded = GrSRGBEncoded::kNo;
+ return GrColorType::kRGB_888x;
case kBGRA_8888_GrPixelConfig:
*srgbEncoded = GrSRGBEncoded::kNo;
return GrColorType::kBGRA_8888;
@@ -1238,6 +1264,10 @@ static inline GrPixelConfig GrColorTypeToPixelConfig(GrColorType config,
return (GrSRGBEncoded::kYes == srgbEncoded) ? kSRGBA_8888_GrPixelConfig
: kRGBA_8888_GrPixelConfig;
+ case GrColorType::kRGB_888x:
+ return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig
+ : kRGB_888_GrPixelConfig;
+
case GrColorType::kBGRA_8888:
return (GrSRGBEncoded::kYes == srgbEncoded) ? kSBGRA_8888_GrPixelConfig
: kBGRA_8888_GrPixelConfig;
diff --git a/include/private/SkImageInfoPriv.h b/include/private/SkImageInfoPriv.h
new file mode 100644
index 0000000000..597906af29
--- /dev/null
+++ b/include/private/SkImageInfoPriv.h
@@ -0,0 +1,220 @@
+/*
+ * 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 SkImageInfoPriv_DEFINED
+#define SkImageInfoPriv_DEFINED
+
+#include "SkImageInfo.h"
+
+enum class SkDestinationSurfaceColorMode {
+ kLegacy,
+ kGammaAndColorSpaceAware,
+};
+
+enum SkColorTypeComponentFlag {
+ kRed_SkColorTypeComponentFlag = 0x1,
+ kGreen_SkColorTypeComponentFlag = 0x2,
+ kBlue_SkColorTypeComponentFlag = 0x4,
+ kAlpha_SkColorTypeComponentFlag = 0x8,
+ kGray_SkColorTypeComponentFlag = 0x10,
+ kRGB_SkColorTypeComponentFlags = kRed_SkColorTypeComponentFlag |
+ kGreen_SkColorTypeComponentFlag |
+ kBlue_SkColorTypeComponentFlag,
+ kRGBA_SkColorTypeComponentFlags = kRGB_SkColorTypeComponentFlags |
+ kAlpha_SkColorTypeComponentFlag,
+};
+
+static inline uint32_t SkColorTypeComponentFlags(SkColorType ct) {
+ switch (ct) {
+ case kUnknown_SkColorType: return 0;
+ case kAlpha_8_SkColorType: return kAlpha_SkColorTypeComponentFlag;
+ case kRGB_565_SkColorType: return kRGB_SkColorTypeComponentFlags;
+ case kARGB_4444_SkColorType: return kRGBA_SkColorTypeComponentFlags;
+ case kRGBA_8888_SkColorType: return kRGBA_SkColorTypeComponentFlags;
+ case kRGB_888x_SkColorType: return kRGB_SkColorTypeComponentFlags;
+ case kBGRA_8888_SkColorType: return kRGBA_SkColorTypeComponentFlags;
+ case kRGBA_1010102_SkColorType: return kRGBA_SkColorTypeComponentFlags;
+ case kRGB_101010x_SkColorType: return kRGB_SkColorTypeComponentFlags;
+ case kGray_8_SkColorType: return kGray_SkColorTypeComponentFlag;
+ case kRGBA_F16_SkColorType: return kRGBA_SkColorTypeComponentFlags;
+ }
+ return 0;
+}
+
+static inline bool SkColorTypeIsAlphaOnly(SkColorType ct) {
+ return kAlpha_SkColorTypeComponentFlag == SkColorTypeComponentFlags(ct);
+}
+
+static inline bool SkAlphaTypeIsValid(unsigned value) {
+ return value <= kLastEnum_SkAlphaType;
+}
+
+static inline bool SkColorTypeIsGray(SkColorType ct) {
+ auto flags = SkColorTypeComponentFlags(ct);
+ // Currently assuming that a color type has only gray or does not have gray.
+ SkASSERT(!(kGray_SkColorTypeComponentFlag & flags) || kGray_SkColorTypeComponentFlag == flags);
+ return kGray_SkColorTypeComponentFlag == flags;
+}
+
+static int SkColorTypeShiftPerPixel(SkColorType ct) {
+ switch (ct) {
+ case kUnknown_SkColorType: return 0;
+ case kAlpha_8_SkColorType: return 0;
+ case kRGB_565_SkColorType: return 1;
+ case kARGB_4444_SkColorType: return 1;
+ case kRGBA_8888_SkColorType: return 2;
+ case kRGB_888x_SkColorType: return 2;
+ case kBGRA_8888_SkColorType: return 2;
+ case kRGBA_1010102_SkColorType: return 2;
+ case kRGB_101010x_SkColorType: return 2;
+ case kGray_8_SkColorType: return 0;
+ case kRGBA_F16_SkColorType: return 3;
+ }
+ return 0;
+}
+
+static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
+ return width * SkColorTypeBytesPerPixel(ct);
+}
+
+static inline bool SkColorTypeIsValid(unsigned value) {
+ return value <= kLastEnum_SkColorType;
+}
+
+static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) {
+ if (kUnknown_SkColorType == ct) {
+ return 0;
+ }
+ return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
+}
+
+/**
+ * This contains shared checks on SkImageInfo. Depending on the desired color space behavior,
+ * the caller should choose one of the two versions below.
+ */
+static inline bool SkImageInfoIsValidCommon(const SkImageInfo& info) {
+ if (info.width() <= 0 || info.height() <= 0) {
+ return false;
+ }
+
+ const int kMaxDimension = SK_MaxS32 >> 2;
+ if (info.width() > kMaxDimension || info.height() > kMaxDimension) {
+ return false;
+ }
+
+ if (kUnknown_SkColorType == info.colorType() || kUnknown_SkAlphaType == info.alphaType()) {
+ return false;
+ }
+
+ if (kOpaque_SkAlphaType != info.alphaType() &&
+ (kRGB_565_SkColorType == info.colorType() || kGray_8_SkColorType == info.colorType())) {
+ return false;
+ }
+
+ if (kRGBA_F16_SkColorType == info.colorType() &&
+ (info.colorSpace() && (!info.colorSpace()->gammaIsLinear()))) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
+ * colorSpace. Allows numerical color spaces. Returns false otherwise.
+ */
+static inline bool SkImageInfoIsValidAllowNumericalCS(const SkImageInfo& info) {
+ if (!SkImageInfoIsValidCommon(info)) {
+ return false;
+ }
+
+ SkColorSpaceTransferFn fn;
+ if (info.colorSpace() && !info.colorSpace()->isNumericalTransferFn(&fn)) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
+ * colorSpace. Only supports rendering color spaces. Returns false otherwise.
+ */
+static inline bool SkImageInfoIsValidRenderingCS(const SkImageInfo& info) {
+ if (!SkImageInfoIsValidCommon(info)) {
+ return false;
+ }
+
+ if (info.colorSpace() &&
+ (!info.colorSpace()->gammaCloseToSRGB() && !info.colorSpace()->gammaIsLinear())) {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Returns true if |info| contains a valid combination of width, height, colorType, alphaType,
+ * colorSpace. Uses |colorMode| to decide how to treat color spaces.
+ */
+static inline bool SkImageInfoIsValid(const SkImageInfo& info,
+ SkDestinationSurfaceColorMode colorMode) {
+ if (SkDestinationSurfaceColorMode::kGammaAndColorSpaceAware == colorMode) {
+ return SkImageInfoIsValidRenderingCS(info);
+ }
+
+ return SkImageInfoIsValidAllowNumericalCS(info);
+}
+
+/**
+ * Returns true if Skia has defined a pixel conversion from the |src| to the |dst|.
+ * Returns false otherwise. Some discussion of false cases:
+ * We will not convert to kIndex8 unless it exactly matches the src, since color tables
+ * are immutable.
+ * We do not convert to kGray8 when the |src| is not kGray8 in the same color space.
+ * We may add this feature - it just requires some work to convert to luminance while
+ * handling color spaces correctly. Currently no one is asking for this.
+ * We will not convert from kAlpha8 when the |dst| is not kAlpha8. This would require
+ * inventing color information.
+ * We will not convert to kOpaque when the |src| is not kOpaque. This could be
+ * implemented to set all the alpha values to 1, but there is still some ambiguity -
+ * should we use kPremul or kUnpremul color values with the opaque alphas? Or should
+ * we just use whatever the |src| alpha is? In the future, we could choose to clearly
+ * define this, but currently no one is asking for this feature.
+ * We will not convert to a particular color space if |src| is nullptr. The color space
+ * conversion is not well-defined.
+ */
+static inline bool SkImageInfoValidConversion(const SkImageInfo& dst, const SkImageInfo& src) {
+ if (!SkImageInfoIsValidAllowNumericalCS(dst) || !SkImageInfoIsValidAllowNumericalCS(src)) {
+ return false;
+ }
+
+ if (SkColorTypeIsGray(dst.colorType())) {
+ if (!SkColorTypeIsGray(src.colorType())) {
+ return false;
+ }
+
+ if (dst.colorSpace() && !SkColorSpace::Equals(dst.colorSpace(), src.colorSpace())) {
+ return false;
+ }
+ }
+
+ if (!SkColorTypeIsAlphaOnly(dst.colorType()) && SkColorTypeIsAlphaOnly(src.colorType())) {
+ return false;
+ }
+
+ if (kOpaque_SkAlphaType == dst.alphaType() && kOpaque_SkAlphaType != src.alphaType()) {
+ return false;
+ }
+
+ if (dst.colorSpace() && !src.colorSpace()) {
+ return false;
+ }
+
+ return true;
+}
+#endif // SkImageInfoPriv_DEFINED