blob: b7c1e290370fc812f18849e9cf5f7a2b179d7a35 [file] [log] [blame]
Romain Guy8aa195d2013-06-04 18:00:09 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Romain Guy8aa195d2013-06-04 18:00:09 -070017#include "Caches.h"
18#include "Texture.h"
John Reck9372ac32016-01-19 11:46:52 -080019#include "utils/GLUtils.h"
Romain Guycaaaa662017-03-27 00:40:21 -070020#include "utils/MathUtils.h"
John Reck38e0c322015-11-10 12:19:17 -080021#include "utils/TraceUtils.h"
22
23#include <utils/Log.h>
24
Romain Guycaaaa662017-03-27 00:40:21 -070025#include <math/mat4.h>
26
John Reck38e0c322015-11-10 12:19:17 -080027#include <SkCanvas.h>
Romain Guy8aa195d2013-06-04 18:00:09 -070028
29namespace android {
30namespace uirenderer {
31
Romain Guy253f2c22016-09-28 17:34:42 -070032// Number of bytes used by a texture in the given format
John Reck38e0c322015-11-10 12:19:17 -080033static int bytesPerPixel(GLint glFormat) {
34 switch (glFormat) {
John Reck623d2232016-02-12 08:08:29 -080035 // The wrapped-texture case, usually means a SurfaceTexture
36 case 0:
37 return 0;
Romain Guy253f2c22016-09-28 17:34:42 -070038 case GL_LUMINANCE:
John Reck38e0c322015-11-10 12:19:17 -080039 case GL_ALPHA:
40 return 1;
Romain Guy253f2c22016-09-28 17:34:42 -070041 case GL_SRGB8:
John Reck38e0c322015-11-10 12:19:17 -080042 case GL_RGB:
43 return 3;
Romain Guy253f2c22016-09-28 17:34:42 -070044 case GL_SRGB8_ALPHA8:
John Reck38e0c322015-11-10 12:19:17 -080045 case GL_RGBA:
John Reck38e0c322015-11-10 12:19:17 -080046 return 4;
John Reck1d4e6a02016-02-11 13:22:25 -080047 case GL_RGBA16F:
Romain Guy253f2c22016-09-28 17:34:42 -070048 return 8;
John Reck1d4e6a02016-02-11 13:22:25 -080049 default:
Romain Guy9fe7e162017-02-03 16:16:07 -080050 LOG_ALWAYS_FATAL("UNKNOWN FORMAT 0x%x", glFormat);
John Reck38e0c322015-11-10 12:19:17 -080051 }
52}
53
sergeyv2a38c422016-10-25 15:21:50 -070054void Texture::setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture, bool force) {
John Reck48247a22016-01-22 10:55:32 -080055 if (force || wrapS != mWrapS || wrapT != mWrapT) {
Romain Guy8aa195d2013-06-04 18:00:09 -070056 mWrapS = wrapS;
57 mWrapT = wrapT;
58
59 if (bindTexture) {
sergeyv2a38c422016-10-25 15:21:50 -070060 mCaches.textureState().bindTexture(mTarget, mId);
Romain Guy8aa195d2013-06-04 18:00:09 -070061 }
62
sergeyv2a38c422016-10-25 15:21:50 -070063 glTexParameteri(mTarget, GL_TEXTURE_WRAP_S, wrapS);
64 glTexParameteri(mTarget, GL_TEXTURE_WRAP_T, wrapT);
Romain Guy8aa195d2013-06-04 18:00:09 -070065 }
66}
67
sergeyv2a38c422016-10-25 15:21:50 -070068void Texture::setFilterMinMag(GLenum min, GLenum mag, bool bindTexture, bool force) {
John Reck48247a22016-01-22 10:55:32 -080069 if (force || min != mMinFilter || mag != mMagFilter) {
Romain Guy8aa195d2013-06-04 18:00:09 -070070 mMinFilter = min;
71 mMagFilter = mag;
72
73 if (bindTexture) {
sergeyv2a38c422016-10-25 15:21:50 -070074 mCaches.textureState().bindTexture(mTarget, mId);
Romain Guy8aa195d2013-06-04 18:00:09 -070075 }
76
77 if (mipMap && min == GL_LINEAR) min = GL_LINEAR_MIPMAP_LINEAR;
78
sergeyv2a38c422016-10-25 15:21:50 -070079 glTexParameteri(mTarget, GL_TEXTURE_MIN_FILTER, min);
80 glTexParameteri(mTarget, GL_TEXTURE_MAG_FILTER, mag);
Romain Guy8aa195d2013-06-04 18:00:09 -070081 }
82}
83
John Reck38e0c322015-11-10 12:19:17 -080084void Texture::deleteTexture() {
85 mCaches.textureState().deleteTexture(mId);
86 mId = 0;
sergeyv694d4992016-10-27 10:23:13 -070087 mTarget = GL_NONE;
88 if (mEglImageHandle != EGL_NO_IMAGE_KHR) {
89 EGLDisplay eglDisplayHandle = eglGetCurrentDisplay();
90 eglDestroyImageKHR(eglDisplayHandle, mEglImageHandle);
91 mEglImageHandle = EGL_NO_IMAGE_KHR;
92 }
John Reck38e0c322015-11-10 12:19:17 -080093}
94
Romain Guycaaaa662017-03-27 00:40:21 -070095bool Texture::updateLayout(uint32_t width, uint32_t height, GLint internalFormat,
sergeyv2a38c422016-10-25 15:21:50 -070096 GLint format, GLenum target) {
97 if (mWidth == width
98 && mHeight == height
99 && mFormat == format
100 && mInternalFormat == internalFormat
101 && mTarget == target) {
John Reck38e0c322015-11-10 12:19:17 -0800102 return false;
103 }
104 mWidth = width;
105 mHeight = height;
106 mFormat = format;
Romain Guy253f2c22016-09-28 17:34:42 -0700107 mInternalFormat = internalFormat;
sergeyv2a38c422016-10-25 15:21:50 -0700108 mTarget = target;
Romain Guy253f2c22016-09-28 17:34:42 -0700109 notifySizeChanged(mWidth * mHeight * bytesPerPixel(internalFormat));
John Reck38e0c322015-11-10 12:19:17 -0800110 return true;
111}
112
John Reck48247a22016-01-22 10:55:32 -0800113void Texture::resetCachedParams() {
114 mWrapS = GL_REPEAT;
115 mWrapT = GL_REPEAT;
116 mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
117 mMagFilter = GL_LINEAR;
118}
119
Romain Guy253f2c22016-09-28 17:34:42 -0700120void Texture::upload(GLint internalFormat, uint32_t width, uint32_t height,
John Reck38e0c322015-11-10 12:19:17 -0800121 GLenum format, GLenum type, const void* pixels) {
John Reck975591a2016-01-22 16:28:07 -0800122 GL_CHECKPOINT(MODERATE);
Romain Guy07ae5052017-06-13 18:25:32 -0700123
124 // We don't have color space information, we assume the data is gamma encoded
125 mIsLinear = false;
126
Romain Guycaaaa662017-03-27 00:40:21 -0700127 bool needsAlloc = updateLayout(width, height, internalFormat, format, GL_TEXTURE_2D);
John Reck38e0c322015-11-10 12:19:17 -0800128 if (!mId) {
129 glGenTextures(1, &mId);
130 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800131 resetCachedParams();
John Reck38e0c322015-11-10 12:19:17 -0800132 }
133 mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
134 if (needsAlloc) {
Romain Guy253f2c22016-09-28 17:34:42 -0700135 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
John Reck38e0c322015-11-10 12:19:17 -0800136 format, type, pixels);
John Reck66f65cb2016-01-21 09:08:42 -0800137 } else if (pixels) {
Romain Guy253f2c22016-09-28 17:34:42 -0700138 glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
John Reck38e0c322015-11-10 12:19:17 -0800139 format, type, pixels);
140 }
John Reck975591a2016-01-22 16:28:07 -0800141 GL_CHECKPOINT(MODERATE);
John Reck38e0c322015-11-10 12:19:17 -0800142}
143
sergeyv694d4992016-10-27 10:23:13 -0700144void Texture::uploadHardwareBitmapToTexture(GraphicBuffer* buffer) {
145 EGLDisplay eglDisplayHandle = eglGetCurrentDisplay();
146 if (mEglImageHandle != EGL_NO_IMAGE_KHR) {
147 eglDestroyImageKHR(eglDisplayHandle, mEglImageHandle);
148 mEglImageHandle = EGL_NO_IMAGE_KHR;
149 }
150 mEglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
151 buffer->getNativeBuffer(), 0);
152 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, mEglImageHandle);
153}
154
Romain Guy253f2c22016-09-28 17:34:42 -0700155static void uploadToTexture(bool resize, GLint internalFormat, GLenum format, GLenum type,
156 GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height, const GLvoid * data) {
John Reck38e0c322015-11-10 12:19:17 -0800157
John Reck38e0c322015-11-10 12:19:17 -0800158 const bool useStride = stride != width
159 && Caches::getInstance().extensions().hasUnpackRowLength();
160 if ((stride == width) || useStride) {
161 if (useStride) {
162 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
163 }
164
165 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700166 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, data);
John Reck38e0c322015-11-10 12:19:17 -0800167 } else {
168 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
169 }
170
171 if (useStride) {
172 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
173 }
174 } else {
175 // With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
176 // if the stride doesn't match the width
177
178 GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
179 if (!temp) return;
180
181 uint8_t * pDst = (uint8_t *)temp;
182 uint8_t * pSrc = (uint8_t *)data;
183 for (GLsizei i = 0; i < height; i++) {
184 memcpy(pDst, pSrc, width * bpp);
185 pDst += width * bpp;
186 pSrc += stride * bpp;
187 }
188
189 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700190 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, temp);
John Reck38e0c322015-11-10 12:19:17 -0800191 } else {
192 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
193 }
194
195 free(temp);
196 }
197}
198
sergeyv694d4992016-10-27 10:23:13 -0700199void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType,
Romain Guy253f2c22016-09-28 17:34:42 -0700200 bool needSRGB, GLint* outInternalFormat, GLint* outFormat, GLint* outType) {
John Reck38e0c322015-11-10 12:19:17 -0800201 switch (colorType) {
202 case kAlpha_8_SkColorType:
203 *outFormat = GL_ALPHA;
Romain Guy253f2c22016-09-28 17:34:42 -0700204 *outInternalFormat = GL_ALPHA;
John Reck38e0c322015-11-10 12:19:17 -0800205 *outType = GL_UNSIGNED_BYTE;
206 break;
207 case kRGB_565_SkColorType:
Romain Guy253f2c22016-09-28 17:34:42 -0700208 if (needSRGB) {
209 // We would ideally use a GL_RGB/GL_SRGB8 texture but the
210 // intermediate Skia bitmap needs to be ARGB_8888
211 *outFormat = GL_RGBA;
212 *outInternalFormat = caches.rgbaInternalFormat();
213 *outType = GL_UNSIGNED_BYTE;
214 } else {
215 *outFormat = GL_RGB;
216 *outInternalFormat = GL_RGB;
217 *outType = GL_UNSIGNED_SHORT_5_6_5;
218 }
John Reck38e0c322015-11-10 12:19:17 -0800219 break;
Leon Scroggins IIIf51a80d2017-07-12 10:46:35 -0400220 // ARGB_4444 is upconverted to RGBA_8888
John Reck38e0c322015-11-10 12:19:17 -0800221 case kARGB_4444_SkColorType:
John Reck38e0c322015-11-10 12:19:17 -0800222 case kN32_SkColorType:
223 *outFormat = GL_RGBA;
Romain Guy253f2c22016-09-28 17:34:42 -0700224 *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
John Reck38e0c322015-11-10 12:19:17 -0800225 *outType = GL_UNSIGNED_BYTE;
226 break;
Derek Sollenberger88d842f2016-01-20 10:37:30 -0500227 case kGray_8_SkColorType:
228 *outFormat = GL_LUMINANCE;
Romain Guy253f2c22016-09-28 17:34:42 -0700229 *outInternalFormat = GL_LUMINANCE;
Derek Sollenberger88d842f2016-01-20 10:37:30 -0500230 *outType = GL_UNSIGNED_BYTE;
231 break;
Romain Guy9505a652016-12-14 09:43:50 -0800232 case kRGBA_F16_SkColorType:
Romain Guy89de2342017-04-06 12:24:29 -0700233 if (caches.extensions().getMajorGlVersion() >= 3) {
234 // This format is always linear
235 *outFormat = GL_RGBA;
236 *outInternalFormat = GL_RGBA16F;
237 *outType = GL_HALF_FLOAT;
238 } else {
239 *outFormat = GL_RGBA;
240 *outInternalFormat = caches.rgbaInternalFormat(true);
241 *outType = GL_UNSIGNED_BYTE;
242 }
Romain Guy9505a652016-12-14 09:43:50 -0800243 break;
John Reck38e0c322015-11-10 12:19:17 -0800244 default:
245 LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
246 break;
247 }
248}
249
Romain Guyefb4b062017-02-27 11:00:04 -0800250SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending,
251 sk_sp<SkColorSpace> sRGB) {
sergeyv694d4992016-10-27 10:23:13 -0700252 SkBitmap rgbaBitmap;
253 rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(),
Romain Guyefb4b062017-02-27 11:00:04 -0800254 bitmap.info().alphaType(), hasLinearBlending ? sRGB : nullptr));
sergeyv694d4992016-10-27 10:23:13 -0700255 rgbaBitmap.eraseColor(0);
Romain Guy89de2342017-04-06 12:24:29 -0700256
257 if (bitmap.colorType() == kRGBA_F16_SkColorType) {
258 // Drawing RGBA_F16 onto ARGB_8888 is not supported
259 bitmap.readPixels(rgbaBitmap.info()
260 .makeColorSpace(SkColorSpace::MakeSRGB()),
261 rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
262 } else {
263 SkCanvas canvas(rgbaBitmap);
264 canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
265 }
266
sergeyv694d4992016-10-27 10:23:13 -0700267 return rgbaBitmap;
268}
269
Romain Guycaaaa662017-03-27 00:40:21 -0700270bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending) {
sergeyv694d4992016-10-27 10:23:13 -0700271 return info.colorType() == kARGB_4444_SkColorType
Romain Guycaaaa662017-03-27 00:40:21 -0700272 || (info.colorType() == kRGB_565_SkColorType
273 && hasLinearBlending
Romain Guy89de2342017-04-06 12:24:29 -0700274 && info.colorSpace()->isSRGB())
275 || (info.colorType() == kRGBA_F16_SkColorType
276 && Caches::getInstance().extensions().getMajorGlVersion() < 3);
sergeyv694d4992016-10-27 10:23:13 -0700277}
278
sergeyv98fa4f92016-10-24 15:35:21 -0700279void Texture::upload(Bitmap& bitmap) {
John Reck38e0c322015-11-10 12:19:17 -0800280 ATRACE_FORMAT("Upload %ux%u Texture", bitmap.width(), bitmap.height());
281
282 // We could also enable mipmapping if both bitmap dimensions are powers
283 // of 2 but we'd have to deal with size changes. Let's keep this simple
284 const bool canMipMap = mCaches.extensions().hasNPot();
285
286 // If the texture had mipmap enabled but not anymore,
287 // force a glTexImage2D to discard the mipmap levels
288 bool needsAlloc = canMipMap && mipMap && !bitmap.hasHardwareMipMap();
John Reck48247a22016-01-22 10:55:32 -0800289 bool setDefaultParams = false;
John Reck38e0c322015-11-10 12:19:17 -0800290
291 if (!mId) {
292 glGenTextures(1, &mId);
293 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800294 setDefaultParams = true;
John Reck38e0c322015-11-10 12:19:17 -0800295 }
296
Romain Guycaaaa662017-03-27 00:40:21 -0700297 bool hasLinearBlending = mCaches.extensions().hasLinearBlending();
298 bool needSRGB = transferFunctionCloseToSRGB(bitmap.info().colorSpace());
John Reck38e0c322015-11-10 12:19:17 -0800299
Romain Guy253f2c22016-09-28 17:34:42 -0700300 GLint internalFormat, format, type;
Romain Guycaaaa662017-03-27 00:40:21 -0700301 colorTypeToGlFormatAndType(mCaches, bitmap.colorType(),
302 needSRGB && hasLinearBlending, &internalFormat, &format, &type);
303
Romain Guy89de2342017-04-06 12:24:29 -0700304 // Some devices don't support GL_RGBA16F, so we need to compare the color type
305 // and internal GL format to decide what to do with 16 bit bitmaps
306 bool rgba16fNeedsConversion = bitmap.colorType() == kRGBA_F16_SkColorType
307 && internalFormat != GL_RGBA16F;
308
Romain Guy07ae5052017-06-13 18:25:32 -0700309 // RGBA16F is always linear extended sRGB
310 if (internalFormat == GL_RGBA16F) {
311 mIsLinear = true;
312 }
313
Romain Guycaaaa662017-03-27 00:40:21 -0700314 mConnector.reset();
315
Romain Guy07ae5052017-06-13 18:25:32 -0700316 // Alpha masks don't have color profiles
Romain Guy89de2342017-04-06 12:24:29 -0700317 // If an RGBA16F bitmap needs conversion, we know the target will be sRGB
Romain Guy07ae5052017-06-13 18:25:32 -0700318 if (!mIsLinear && internalFormat != GL_ALPHA && !rgba16fNeedsConversion) {
Romain Guycaaaa662017-03-27 00:40:21 -0700319 SkColorSpace* colorSpace = bitmap.info().colorSpace();
320 // If the bitmap is sRGB we don't need conversion
321 if (colorSpace != nullptr && !colorSpace->isSRGB()) {
322 SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
323 if (!colorSpace->toXYZD50(&xyzMatrix)) {
324 ALOGW("Incompatible color space!");
325 } else {
326 SkColorSpaceTransferFn fn;
327 if (!colorSpace->isNumericalTransferFn(&fn)) {
328 ALOGW("Incompatible color space, no numerical transfer function!");
329 } else {
330 float data[16];
331 xyzMatrix.asColMajorf(data);
332
333 ColorSpace::TransferParameters p =
334 {fn.fG, fn.fA, fn.fB, fn.fC, fn.fD, fn.fE, fn.fF};
335 ColorSpace src("Unnamed", mat4f((const float*) &data[0]).upperLeft(), p);
336 mConnector.reset(new ColorSpaceConnector(src, ColorSpace::sRGB()));
337
338 // A non-sRGB color space might have a transfer function close enough to sRGB
339 // that we can save shader instructions by using an sRGB sampler
340 // This is only possible if we have hardware support for sRGB textures
341 if (needSRGB && internalFormat == GL_RGBA
342 && mCaches.extensions().hasSRGB() && !bitmap.isHardware()) {
343 internalFormat = GL_SRGB8_ALPHA8;
344 }
345 }
346 }
347 }
348 }
Romain Guy253f2c22016-09-28 17:34:42 -0700349
sergeyv694d4992016-10-27 10:23:13 -0700350 GLenum target = bitmap.isHardware() ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
Romain Guycaaaa662017-03-27 00:40:21 -0700351 needsAlloc |= updateLayout(bitmap.width(), bitmap.height(), internalFormat, format, target);
John Reck38e0c322015-11-10 12:19:17 -0800352
353 blend = !bitmap.isOpaque();
sergeyv694d4992016-10-27 10:23:13 -0700354 mCaches.textureState().bindTexture(mTarget, mId);
John Reck38e0c322015-11-10 12:19:17 -0800355
Romain Guy253f2c22016-09-28 17:34:42 -0700356 // TODO: Handle sRGB gray bitmaps
Romain Guycaaaa662017-03-27 00:40:21 -0700357 if (CC_UNLIKELY(hasUnsupportedColorType(bitmap.info(), hasLinearBlending))) {
sergeyv98fa4f92016-10-24 15:35:21 -0700358 SkBitmap skBitmap;
359 bitmap.getSkBitmap(&skBitmap);
Romain Guycaaaa662017-03-27 00:40:21 -0700360 sk_sp<SkColorSpace> sRGB = SkColorSpace::MakeSRGB();
Romain Guyefb4b062017-02-27 11:00:04 -0800361 SkBitmap rgbaBitmap = uploadToN32(skBitmap, hasLinearBlending, std::move(sRGB));
sergeyv98fa4f92016-10-24 15:35:21 -0700362 uploadToTexture(needsAlloc, internalFormat, format, type, rgbaBitmap.rowBytesAsPixels(),
363 rgbaBitmap.bytesPerPixel(), rgbaBitmap.width(),
364 rgbaBitmap.height(), rgbaBitmap.getPixels());
sergeyv694d4992016-10-27 10:23:13 -0700365 } else if (bitmap.isHardware()) {
366 uploadHardwareBitmapToTexture(bitmap.graphicBuffer());
John Reck38e0c322015-11-10 12:19:17 -0800367 } else {
sergeyv98fa4f92016-10-24 15:35:21 -0700368 uploadToTexture(needsAlloc, internalFormat, format, type, bitmap.rowBytesAsPixels(),
369 bitmap.info().bytesPerPixel(), bitmap.width(), bitmap.height(), bitmap.pixels());
John Reck38e0c322015-11-10 12:19:17 -0800370 }
371
372 if (canMipMap) {
373 mipMap = bitmap.hasHardwareMipMap();
374 if (mipMap) {
375 glGenerateMipmap(GL_TEXTURE_2D);
376 }
377 }
378
John Reck48247a22016-01-22 10:55:32 -0800379 if (setDefaultParams) {
John Reck38e0c322015-11-10 12:19:17 -0800380 setFilter(GL_NEAREST);
John Reck38e0c322015-11-10 12:19:17 -0800381 setWrap(GL_CLAMP_TO_EDGE);
382 }
383}
384
sergeyv2a38c422016-10-25 15:21:50 -0700385void Texture::wrap(GLuint id, uint32_t width, uint32_t height,
386 GLint internalFormat, GLint format, GLenum target) {
John Reck38e0c322015-11-10 12:19:17 -0800387 mId = id;
388 mWidth = width;
389 mHeight = height;
390 mFormat = format;
Romain Guy253f2c22016-09-28 17:34:42 -0700391 mInternalFormat = internalFormat;
sergeyv2a38c422016-10-25 15:21:50 -0700392 mTarget = target;
Romain Guycaaaa662017-03-27 00:40:21 -0700393 mConnector.reset();
John Reck38e0c322015-11-10 12:19:17 -0800394 // We're wrapping an existing texture, so don't double count this memory
395 notifySizeChanged(0);
Romain Guybe1b1272013-06-06 14:02:54 -0700396}
397
Romain Guycaaaa662017-03-27 00:40:21 -0700398TransferFunctionType Texture::getTransferFunctionType() const {
399 if (mConnector.get() != nullptr && mInternalFormat != GL_SRGB8_ALPHA8) {
400 const ColorSpace::TransferParameters& p = mConnector->getSource().getTransferParameters();
401 if (MathUtils::isZero(p.e) && MathUtils::isZero(p.f)) {
402 if (MathUtils::areEqual(p.a, 1.0f) && MathUtils::isZero(p.b)
403 && MathUtils::isZero(p.c) && MathUtils::isZero(p.d)) {
404 if (MathUtils::areEqual(p.g, 1.0f)) {
405 return TransferFunctionType::None;
406 }
407 return TransferFunctionType::Gamma;
408 }
409 return TransferFunctionType::Limited;
410 }
411 return TransferFunctionType::Full;
412 }
413 return TransferFunctionType::None;
414}
415
Romain Guy8aa195d2013-06-04 18:00:09 -0700416}; // namespace uirenderer
417}; // namespace android