Format the world (or just HWUI)
Test: No code changes, just ran through clang-format
Change-Id: Id23aa4ec7eebc0446fe3a30260f33e7fd455bb8c
diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp
index b7c1e29..1e90eeb 100644
--- a/libs/hwui/Texture.cpp
+++ b/libs/hwui/Texture.cpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include "Caches.h"
#include "Texture.h"
+#include "Caches.h"
#include "utils/GLUtils.h"
#include "utils/MathUtils.h"
#include "utils/TraceUtils.h"
@@ -32,22 +32,22 @@
// Number of bytes used by a texture in the given format
static int bytesPerPixel(GLint glFormat) {
switch (glFormat) {
- // The wrapped-texture case, usually means a SurfaceTexture
- case 0:
- return 0;
- case GL_LUMINANCE:
- case GL_ALPHA:
- return 1;
- case GL_SRGB8:
- case GL_RGB:
- return 3;
- case GL_SRGB8_ALPHA8:
- case GL_RGBA:
- return 4;
- case GL_RGBA16F:
- return 8;
- default:
- LOG_ALWAYS_FATAL("UNKNOWN FORMAT 0x%x", glFormat);
+ // The wrapped-texture case, usually means a SurfaceTexture
+ case 0:
+ return 0;
+ case GL_LUMINANCE:
+ case GL_ALPHA:
+ return 1;
+ case GL_SRGB8:
+ case GL_RGB:
+ return 3;
+ case GL_SRGB8_ALPHA8:
+ case GL_RGBA:
+ return 4;
+ case GL_RGBA16F:
+ return 8;
+ default:
+ LOG_ALWAYS_FATAL("UNKNOWN FORMAT 0x%x", glFormat);
}
}
@@ -92,13 +92,10 @@
}
}
-bool Texture::updateLayout(uint32_t width, uint32_t height, GLint internalFormat,
- GLint format, GLenum target) {
- if (mWidth == width
- && mHeight == height
- && mFormat == format
- && mInternalFormat == internalFormat
- && mTarget == target) {
+bool Texture::updateLayout(uint32_t width, uint32_t height, GLint internalFormat, GLint format,
+ GLenum target) {
+ if (mWidth == width && mHeight == height && mFormat == format &&
+ mInternalFormat == internalFormat && mTarget == target) {
return false;
}
mWidth = width;
@@ -117,8 +114,8 @@
mMagFilter = GL_LINEAR;
}
-void Texture::upload(GLint internalFormat, uint32_t width, uint32_t height,
- GLenum format, GLenum type, const void* pixels) {
+void Texture::upload(GLint internalFormat, uint32_t width, uint32_t height, GLenum format,
+ GLenum type, const void* pixels) {
GL_CHECKPOINT(MODERATE);
// We don't have color space information, we assume the data is gamma encoded
@@ -132,11 +129,9 @@
}
mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
if (needsAlloc) {
- glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
- format, type, pixels);
+ glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, format, type, pixels);
} else if (pixels) {
- glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
- format, type, pixels);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, format, type, pixels);
}
GL_CHECKPOINT(MODERATE);
}
@@ -148,15 +143,15 @@
mEglImageHandle = EGL_NO_IMAGE_KHR;
}
mEglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
- buffer->getNativeBuffer(), 0);
+ buffer->getNativeBuffer(), 0);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, mEglImageHandle);
}
static void uploadToTexture(bool resize, GLint internalFormat, GLenum format, GLenum type,
- GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height, const GLvoid * data) {
-
- const bool useStride = stride != width
- && Caches::getInstance().extensions().hasUnpackRowLength();
+ GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height,
+ const GLvoid* data) {
+ const bool useStride =
+ stride != width && Caches::getInstance().extensions().hasUnpackRowLength();
if ((stride == width) || useStride) {
if (useStride) {
glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
@@ -175,11 +170,11 @@
// With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
// if the stride doesn't match the width
- GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
+ GLvoid* temp = (GLvoid*)malloc(width * height * bpp);
if (!temp) return;
- uint8_t * pDst = (uint8_t *)temp;
- uint8_t * pSrc = (uint8_t *)data;
+ uint8_t* pDst = (uint8_t*)temp;
+ uint8_t* pSrc = (uint8_t*)data;
for (GLsizei i = 0; i < height; i++) {
memcpy(pDst, pSrc, width * bpp);
pDst += width * bpp;
@@ -196,69 +191,70 @@
}
}
-void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType,
- bool needSRGB, GLint* outInternalFormat, GLint* outFormat, GLint* outType) {
+void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType, bool needSRGB,
+ GLint* outInternalFormat, GLint* outFormat,
+ GLint* outType) {
switch (colorType) {
- case kAlpha_8_SkColorType:
- *outFormat = GL_ALPHA;
- *outInternalFormat = GL_ALPHA;
- *outType = GL_UNSIGNED_BYTE;
- break;
- case kRGB_565_SkColorType:
- if (needSRGB) {
- // We would ideally use a GL_RGB/GL_SRGB8 texture but the
- // intermediate Skia bitmap needs to be ARGB_8888
- *outFormat = GL_RGBA;
- *outInternalFormat = caches.rgbaInternalFormat();
+ case kAlpha_8_SkColorType:
+ *outFormat = GL_ALPHA;
+ *outInternalFormat = GL_ALPHA;
*outType = GL_UNSIGNED_BYTE;
- } else {
- *outFormat = GL_RGB;
- *outInternalFormat = GL_RGB;
- *outType = GL_UNSIGNED_SHORT_5_6_5;
- }
- break;
- // ARGB_4444 is upconverted to RGBA_8888
- case kARGB_4444_SkColorType:
- case kN32_SkColorType:
- *outFormat = GL_RGBA;
- *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
- *outType = GL_UNSIGNED_BYTE;
- break;
- case kGray_8_SkColorType:
- *outFormat = GL_LUMINANCE;
- *outInternalFormat = GL_LUMINANCE;
- *outType = GL_UNSIGNED_BYTE;
- break;
- case kRGBA_F16_SkColorType:
- if (caches.extensions().getMajorGlVersion() >= 3) {
- // This format is always linear
+ break;
+ case kRGB_565_SkColorType:
+ if (needSRGB) {
+ // We would ideally use a GL_RGB/GL_SRGB8 texture but the
+ // intermediate Skia bitmap needs to be ARGB_8888
+ *outFormat = GL_RGBA;
+ *outInternalFormat = caches.rgbaInternalFormat();
+ *outType = GL_UNSIGNED_BYTE;
+ } else {
+ *outFormat = GL_RGB;
+ *outInternalFormat = GL_RGB;
+ *outType = GL_UNSIGNED_SHORT_5_6_5;
+ }
+ break;
+ // ARGB_4444 is upconverted to RGBA_8888
+ case kARGB_4444_SkColorType:
+ case kN32_SkColorType:
*outFormat = GL_RGBA;
- *outInternalFormat = GL_RGBA16F;
- *outType = GL_HALF_FLOAT;
- } else {
- *outFormat = GL_RGBA;
- *outInternalFormat = caches.rgbaInternalFormat(true);
+ *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
*outType = GL_UNSIGNED_BYTE;
- }
- break;
- default:
- LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
- break;
+ break;
+ case kGray_8_SkColorType:
+ *outFormat = GL_LUMINANCE;
+ *outInternalFormat = GL_LUMINANCE;
+ *outType = GL_UNSIGNED_BYTE;
+ break;
+ case kRGBA_F16_SkColorType:
+ if (caches.extensions().getMajorGlVersion() >= 3) {
+ // This format is always linear
+ *outFormat = GL_RGBA;
+ *outInternalFormat = GL_RGBA16F;
+ *outType = GL_HALF_FLOAT;
+ } else {
+ *outFormat = GL_RGBA;
+ *outInternalFormat = caches.rgbaInternalFormat(true);
+ *outType = GL_UNSIGNED_BYTE;
+ }
+ break;
+ default:
+ LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
+ break;
}
}
SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending,
- sk_sp<SkColorSpace> sRGB) {
+ sk_sp<SkColorSpace> sRGB) {
SkBitmap rgbaBitmap;
rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(),
- bitmap.info().alphaType(), hasLinearBlending ? sRGB : nullptr));
+ bitmap.info().alphaType(),
+ hasLinearBlending ? sRGB : nullptr));
rgbaBitmap.eraseColor(0);
if (bitmap.colorType() == kRGBA_F16_SkColorType) {
// Drawing RGBA_F16 onto ARGB_8888 is not supported
- bitmap.readPixels(rgbaBitmap.info()
- .makeColorSpace(SkColorSpace::MakeSRGB()),
- rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
+ bitmap.readPixels(rgbaBitmap.info().makeColorSpace(SkColorSpace::MakeSRGB()),
+ rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
} else {
SkCanvas canvas(rgbaBitmap);
canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
@@ -268,12 +264,11 @@
}
bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending) {
- return info.colorType() == kARGB_4444_SkColorType
- || (info.colorType() == kRGB_565_SkColorType
- && hasLinearBlending
- && info.colorSpace()->isSRGB())
- || (info.colorType() == kRGBA_F16_SkColorType
- && Caches::getInstance().extensions().getMajorGlVersion() < 3);
+ return info.colorType() == kARGB_4444_SkColorType ||
+ (info.colorType() == kRGB_565_SkColorType && hasLinearBlending &&
+ info.colorSpace()->isSRGB()) ||
+ (info.colorType() == kRGBA_F16_SkColorType &&
+ Caches::getInstance().extensions().getMajorGlVersion() < 3);
}
void Texture::upload(Bitmap& bitmap) {
@@ -298,13 +293,13 @@
bool needSRGB = transferFunctionCloseToSRGB(bitmap.info().colorSpace());
GLint internalFormat, format, type;
- colorTypeToGlFormatAndType(mCaches, bitmap.colorType(),
- needSRGB && hasLinearBlending, &internalFormat, &format, &type);
+ colorTypeToGlFormatAndType(mCaches, bitmap.colorType(), needSRGB && hasLinearBlending,
+ &internalFormat, &format, &type);
// Some devices don't support GL_RGBA16F, so we need to compare the color type
// and internal GL format to decide what to do with 16 bit bitmaps
- bool rgba16fNeedsConversion = bitmap.colorType() == kRGBA_F16_SkColorType
- && internalFormat != GL_RGBA16F;
+ bool rgba16fNeedsConversion =
+ bitmap.colorType() == kRGBA_F16_SkColorType && internalFormat != GL_RGBA16F;
// RGBA16F is always linear extended sRGB
if (internalFormat == GL_RGBA16F) {
@@ -330,16 +325,16 @@
float data[16];
xyzMatrix.asColMajorf(data);
- ColorSpace::TransferParameters p =
- {fn.fG, fn.fA, fn.fB, fn.fC, fn.fD, fn.fE, fn.fF};
- ColorSpace src("Unnamed", mat4f((const float*) &data[0]).upperLeft(), p);
+ ColorSpace::TransferParameters p = {fn.fG, fn.fA, fn.fB, fn.fC,
+ fn.fD, fn.fE, fn.fF};
+ ColorSpace src("Unnamed", mat4f((const float*)&data[0]).upperLeft(), p);
mConnector.reset(new ColorSpaceConnector(src, ColorSpace::sRGB()));
// A non-sRGB color space might have a transfer function close enough to sRGB
// that we can save shader instructions by using an sRGB sampler
// This is only possible if we have hardware support for sRGB textures
- if (needSRGB && internalFormat == GL_RGBA
- && mCaches.extensions().hasSRGB() && !bitmap.isHardware()) {
+ if (needSRGB && internalFormat == GL_RGBA && mCaches.extensions().hasSRGB() &&
+ !bitmap.isHardware()) {
internalFormat = GL_SRGB8_ALPHA8;
}
}
@@ -360,13 +355,14 @@
sk_sp<SkColorSpace> sRGB = SkColorSpace::MakeSRGB();
SkBitmap rgbaBitmap = uploadToN32(skBitmap, hasLinearBlending, std::move(sRGB));
uploadToTexture(needsAlloc, internalFormat, format, type, rgbaBitmap.rowBytesAsPixels(),
- rgbaBitmap.bytesPerPixel(), rgbaBitmap.width(),
- rgbaBitmap.height(), rgbaBitmap.getPixels());
+ rgbaBitmap.bytesPerPixel(), rgbaBitmap.width(), rgbaBitmap.height(),
+ rgbaBitmap.getPixels());
} else if (bitmap.isHardware()) {
uploadHardwareBitmapToTexture(bitmap.graphicBuffer());
} else {
uploadToTexture(needsAlloc, internalFormat, format, type, bitmap.rowBytesAsPixels(),
- bitmap.info().bytesPerPixel(), bitmap.width(), bitmap.height(), bitmap.pixels());
+ bitmap.info().bytesPerPixel(), bitmap.width(), bitmap.height(),
+ bitmap.pixels());
}
if (canMipMap) {
@@ -382,8 +378,8 @@
}
}
-void Texture::wrap(GLuint id, uint32_t width, uint32_t height,
- GLint internalFormat, GLint format, GLenum target) {
+void Texture::wrap(GLuint id, uint32_t width, uint32_t height, GLint internalFormat, GLint format,
+ GLenum target) {
mId = id;
mWidth = width;
mHeight = height;
@@ -399,8 +395,8 @@
if (mConnector.get() != nullptr && mInternalFormat != GL_SRGB8_ALPHA8) {
const ColorSpace::TransferParameters& p = mConnector->getSource().getTransferParameters();
if (MathUtils::isZero(p.e) && MathUtils::isZero(p.f)) {
- if (MathUtils::areEqual(p.a, 1.0f) && MathUtils::isZero(p.b)
- && MathUtils::isZero(p.c) && MathUtils::isZero(p.d)) {
+ if (MathUtils::areEqual(p.a, 1.0f) && MathUtils::isZero(p.b) &&
+ MathUtils::isZero(p.c) && MathUtils::isZero(p.d)) {
if (MathUtils::areEqual(p.g, 1.0f)) {
return TransferFunctionType::None;
}
@@ -413,5 +409,5 @@
return TransferFunctionType::None;
}
-}; // namespace uirenderer
-}; // namespace android
+}; // namespace uirenderer
+}; // namespace android