blob: 1e90eebe3bb8439bad0416ac4a67a8d819854b3f [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 "Texture.h"
John Reck1bcacfd2017-11-03 10:12:19 -070018#include "Caches.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 Reck1bcacfd2017-11-03 10:12:19 -070035 // The wrapped-texture case, usually means a SurfaceTexture
36 case 0:
37 return 0;
38 case GL_LUMINANCE:
39 case GL_ALPHA:
40 return 1;
41 case GL_SRGB8:
42 case GL_RGB:
43 return 3;
44 case GL_SRGB8_ALPHA8:
45 case GL_RGBA:
46 return 4;
47 case GL_RGBA16F:
48 return 8;
49 default:
50 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
John Reck1bcacfd2017-11-03 10:12:19 -070095bool Texture::updateLayout(uint32_t width, uint32_t height, GLint internalFormat, GLint format,
96 GLenum target) {
97 if (mWidth == width && mHeight == height && mFormat == format &&
98 mInternalFormat == internalFormat && mTarget == target) {
John Reck38e0c322015-11-10 12:19:17 -080099 return false;
100 }
101 mWidth = width;
102 mHeight = height;
103 mFormat = format;
Romain Guy253f2c22016-09-28 17:34:42 -0700104 mInternalFormat = internalFormat;
sergeyv2a38c422016-10-25 15:21:50 -0700105 mTarget = target;
Romain Guy253f2c22016-09-28 17:34:42 -0700106 notifySizeChanged(mWidth * mHeight * bytesPerPixel(internalFormat));
John Reck38e0c322015-11-10 12:19:17 -0800107 return true;
108}
109
John Reck48247a22016-01-22 10:55:32 -0800110void Texture::resetCachedParams() {
111 mWrapS = GL_REPEAT;
112 mWrapT = GL_REPEAT;
113 mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
114 mMagFilter = GL_LINEAR;
115}
116
John Reck1bcacfd2017-11-03 10:12:19 -0700117void Texture::upload(GLint internalFormat, uint32_t width, uint32_t height, GLenum format,
118 GLenum type, const void* pixels) {
John Reck975591a2016-01-22 16:28:07 -0800119 GL_CHECKPOINT(MODERATE);
Romain Guy07ae5052017-06-13 18:25:32 -0700120
121 // We don't have color space information, we assume the data is gamma encoded
122 mIsLinear = false;
123
Romain Guycaaaa662017-03-27 00:40:21 -0700124 bool needsAlloc = updateLayout(width, height, internalFormat, format, GL_TEXTURE_2D);
John Reck38e0c322015-11-10 12:19:17 -0800125 if (!mId) {
126 glGenTextures(1, &mId);
127 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800128 resetCachedParams();
John Reck38e0c322015-11-10 12:19:17 -0800129 }
130 mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
131 if (needsAlloc) {
John Reck1bcacfd2017-11-03 10:12:19 -0700132 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, format, type, pixels);
John Reck66f65cb2016-01-21 09:08:42 -0800133 } else if (pixels) {
John Reck1bcacfd2017-11-03 10:12:19 -0700134 glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0, format, type, pixels);
John Reck38e0c322015-11-10 12:19:17 -0800135 }
John Reck975591a2016-01-22 16:28:07 -0800136 GL_CHECKPOINT(MODERATE);
John Reck38e0c322015-11-10 12:19:17 -0800137}
138
sergeyv694d4992016-10-27 10:23:13 -0700139void Texture::uploadHardwareBitmapToTexture(GraphicBuffer* buffer) {
140 EGLDisplay eglDisplayHandle = eglGetCurrentDisplay();
141 if (mEglImageHandle != EGL_NO_IMAGE_KHR) {
142 eglDestroyImageKHR(eglDisplayHandle, mEglImageHandle);
143 mEglImageHandle = EGL_NO_IMAGE_KHR;
144 }
145 mEglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
John Reck1bcacfd2017-11-03 10:12:19 -0700146 buffer->getNativeBuffer(), 0);
sergeyv694d4992016-10-27 10:23:13 -0700147 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, mEglImageHandle);
148}
149
Romain Guy253f2c22016-09-28 17:34:42 -0700150static void uploadToTexture(bool resize, GLint internalFormat, GLenum format, GLenum type,
John Reck1bcacfd2017-11-03 10:12:19 -0700151 GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height,
152 const GLvoid* data) {
153 const bool useStride =
154 stride != width && Caches::getInstance().extensions().hasUnpackRowLength();
John Reck38e0c322015-11-10 12:19:17 -0800155 if ((stride == width) || useStride) {
156 if (useStride) {
157 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
158 }
159
160 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700161 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, data);
John Reck38e0c322015-11-10 12:19:17 -0800162 } else {
163 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
164 }
165
166 if (useStride) {
167 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
168 }
169 } else {
170 // With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
171 // if the stride doesn't match the width
172
John Reck1bcacfd2017-11-03 10:12:19 -0700173 GLvoid* temp = (GLvoid*)malloc(width * height * bpp);
John Reck38e0c322015-11-10 12:19:17 -0800174 if (!temp) return;
175
John Reck1bcacfd2017-11-03 10:12:19 -0700176 uint8_t* pDst = (uint8_t*)temp;
177 uint8_t* pSrc = (uint8_t*)data;
John Reck38e0c322015-11-10 12:19:17 -0800178 for (GLsizei i = 0; i < height; i++) {
179 memcpy(pDst, pSrc, width * bpp);
180 pDst += width * bpp;
181 pSrc += stride * bpp;
182 }
183
184 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700185 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, temp);
John Reck38e0c322015-11-10 12:19:17 -0800186 } else {
187 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
188 }
189
190 free(temp);
191 }
192}
193
John Reck1bcacfd2017-11-03 10:12:19 -0700194void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType, bool needSRGB,
195 GLint* outInternalFormat, GLint* outFormat,
196 GLint* outType) {
John Reck38e0c322015-11-10 12:19:17 -0800197 switch (colorType) {
John Reck1bcacfd2017-11-03 10:12:19 -0700198 case kAlpha_8_SkColorType:
199 *outFormat = GL_ALPHA;
200 *outInternalFormat = GL_ALPHA;
Romain Guy253f2c22016-09-28 17:34:42 -0700201 *outType = GL_UNSIGNED_BYTE;
John Reck1bcacfd2017-11-03 10:12:19 -0700202 break;
203 case kRGB_565_SkColorType:
204 if (needSRGB) {
205 // We would ideally use a GL_RGB/GL_SRGB8 texture but the
206 // intermediate Skia bitmap needs to be ARGB_8888
207 *outFormat = GL_RGBA;
208 *outInternalFormat = caches.rgbaInternalFormat();
209 *outType = GL_UNSIGNED_BYTE;
210 } else {
211 *outFormat = GL_RGB;
212 *outInternalFormat = GL_RGB;
213 *outType = GL_UNSIGNED_SHORT_5_6_5;
214 }
215 break;
216 // ARGB_4444 is upconverted to RGBA_8888
217 case kARGB_4444_SkColorType:
218 case kN32_SkColorType:
Romain Guy89de2342017-04-06 12:24:29 -0700219 *outFormat = GL_RGBA;
John Reck1bcacfd2017-11-03 10:12:19 -0700220 *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
Romain Guy89de2342017-04-06 12:24:29 -0700221 *outType = GL_UNSIGNED_BYTE;
John Reck1bcacfd2017-11-03 10:12:19 -0700222 break;
223 case kGray_8_SkColorType:
224 *outFormat = GL_LUMINANCE;
225 *outInternalFormat = GL_LUMINANCE;
226 *outType = GL_UNSIGNED_BYTE;
227 break;
228 case kRGBA_F16_SkColorType:
229 if (caches.extensions().getMajorGlVersion() >= 3) {
230 // This format is always linear
231 *outFormat = GL_RGBA;
232 *outInternalFormat = GL_RGBA16F;
233 *outType = GL_HALF_FLOAT;
234 } else {
235 *outFormat = GL_RGBA;
236 *outInternalFormat = caches.rgbaInternalFormat(true);
237 *outType = GL_UNSIGNED_BYTE;
238 }
239 break;
240 default:
241 LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
242 break;
John Reck38e0c322015-11-10 12:19:17 -0800243 }
244}
245
Romain Guyefb4b062017-02-27 11:00:04 -0800246SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending,
John Reck1bcacfd2017-11-03 10:12:19 -0700247 sk_sp<SkColorSpace> sRGB) {
sergeyv694d4992016-10-27 10:23:13 -0700248 SkBitmap rgbaBitmap;
249 rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(),
John Reck1bcacfd2017-11-03 10:12:19 -0700250 bitmap.info().alphaType(),
251 hasLinearBlending ? sRGB : nullptr));
sergeyv694d4992016-10-27 10:23:13 -0700252 rgbaBitmap.eraseColor(0);
Romain Guy89de2342017-04-06 12:24:29 -0700253
254 if (bitmap.colorType() == kRGBA_F16_SkColorType) {
255 // Drawing RGBA_F16 onto ARGB_8888 is not supported
John Reck1bcacfd2017-11-03 10:12:19 -0700256 bitmap.readPixels(rgbaBitmap.info().makeColorSpace(SkColorSpace::MakeSRGB()),
257 rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
Romain Guy89de2342017-04-06 12:24:29 -0700258 } else {
259 SkCanvas canvas(rgbaBitmap);
260 canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
261 }
262
sergeyv694d4992016-10-27 10:23:13 -0700263 return rgbaBitmap;
264}
265
Romain Guycaaaa662017-03-27 00:40:21 -0700266bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending) {
John Reck1bcacfd2017-11-03 10:12:19 -0700267 return info.colorType() == kARGB_4444_SkColorType ||
268 (info.colorType() == kRGB_565_SkColorType && hasLinearBlending &&
269 info.colorSpace()->isSRGB()) ||
270 (info.colorType() == kRGBA_F16_SkColorType &&
271 Caches::getInstance().extensions().getMajorGlVersion() < 3);
sergeyv694d4992016-10-27 10:23:13 -0700272}
273
sergeyv98fa4f92016-10-24 15:35:21 -0700274void Texture::upload(Bitmap& bitmap) {
John Reck38e0c322015-11-10 12:19:17 -0800275 ATRACE_FORMAT("Upload %ux%u Texture", bitmap.width(), bitmap.height());
276
277 // We could also enable mipmapping if both bitmap dimensions are powers
278 // of 2 but we'd have to deal with size changes. Let's keep this simple
279 const bool canMipMap = mCaches.extensions().hasNPot();
280
281 // If the texture had mipmap enabled but not anymore,
282 // force a glTexImage2D to discard the mipmap levels
283 bool needsAlloc = canMipMap && mipMap && !bitmap.hasHardwareMipMap();
John Reck48247a22016-01-22 10:55:32 -0800284 bool setDefaultParams = false;
John Reck38e0c322015-11-10 12:19:17 -0800285
286 if (!mId) {
287 glGenTextures(1, &mId);
288 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800289 setDefaultParams = true;
John Reck38e0c322015-11-10 12:19:17 -0800290 }
291
Romain Guycaaaa662017-03-27 00:40:21 -0700292 bool hasLinearBlending = mCaches.extensions().hasLinearBlending();
293 bool needSRGB = transferFunctionCloseToSRGB(bitmap.info().colorSpace());
John Reck38e0c322015-11-10 12:19:17 -0800294
Romain Guy253f2c22016-09-28 17:34:42 -0700295 GLint internalFormat, format, type;
John Reck1bcacfd2017-11-03 10:12:19 -0700296 colorTypeToGlFormatAndType(mCaches, bitmap.colorType(), needSRGB && hasLinearBlending,
297 &internalFormat, &format, &type);
Romain Guycaaaa662017-03-27 00:40:21 -0700298
Romain Guy89de2342017-04-06 12:24:29 -0700299 // Some devices don't support GL_RGBA16F, so we need to compare the color type
300 // and internal GL format to decide what to do with 16 bit bitmaps
John Reck1bcacfd2017-11-03 10:12:19 -0700301 bool rgba16fNeedsConversion =
302 bitmap.colorType() == kRGBA_F16_SkColorType && internalFormat != GL_RGBA16F;
Romain Guy89de2342017-04-06 12:24:29 -0700303
Romain Guy07ae5052017-06-13 18:25:32 -0700304 // RGBA16F is always linear extended sRGB
305 if (internalFormat == GL_RGBA16F) {
306 mIsLinear = true;
307 }
308
Romain Guycaaaa662017-03-27 00:40:21 -0700309 mConnector.reset();
310
Romain Guy07ae5052017-06-13 18:25:32 -0700311 // Alpha masks don't have color profiles
Romain Guy89de2342017-04-06 12:24:29 -0700312 // If an RGBA16F bitmap needs conversion, we know the target will be sRGB
Romain Guy07ae5052017-06-13 18:25:32 -0700313 if (!mIsLinear && internalFormat != GL_ALPHA && !rgba16fNeedsConversion) {
Romain Guycaaaa662017-03-27 00:40:21 -0700314 SkColorSpace* colorSpace = bitmap.info().colorSpace();
315 // If the bitmap is sRGB we don't need conversion
316 if (colorSpace != nullptr && !colorSpace->isSRGB()) {
317 SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
318 if (!colorSpace->toXYZD50(&xyzMatrix)) {
319 ALOGW("Incompatible color space!");
320 } else {
321 SkColorSpaceTransferFn fn;
322 if (!colorSpace->isNumericalTransferFn(&fn)) {
323 ALOGW("Incompatible color space, no numerical transfer function!");
324 } else {
325 float data[16];
326 xyzMatrix.asColMajorf(data);
327
John Reck1bcacfd2017-11-03 10:12:19 -0700328 ColorSpace::TransferParameters p = {fn.fG, fn.fA, fn.fB, fn.fC,
329 fn.fD, fn.fE, fn.fF};
330 ColorSpace src("Unnamed", mat4f((const float*)&data[0]).upperLeft(), p);
Romain Guycaaaa662017-03-27 00:40:21 -0700331 mConnector.reset(new ColorSpaceConnector(src, ColorSpace::sRGB()));
332
333 // A non-sRGB color space might have a transfer function close enough to sRGB
334 // that we can save shader instructions by using an sRGB sampler
335 // This is only possible if we have hardware support for sRGB textures
John Reck1bcacfd2017-11-03 10:12:19 -0700336 if (needSRGB && internalFormat == GL_RGBA && mCaches.extensions().hasSRGB() &&
337 !bitmap.isHardware()) {
Romain Guycaaaa662017-03-27 00:40:21 -0700338 internalFormat = GL_SRGB8_ALPHA8;
339 }
340 }
341 }
342 }
343 }
Romain Guy253f2c22016-09-28 17:34:42 -0700344
sergeyv694d4992016-10-27 10:23:13 -0700345 GLenum target = bitmap.isHardware() ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
Romain Guycaaaa662017-03-27 00:40:21 -0700346 needsAlloc |= updateLayout(bitmap.width(), bitmap.height(), internalFormat, format, target);
John Reck38e0c322015-11-10 12:19:17 -0800347
348 blend = !bitmap.isOpaque();
sergeyv694d4992016-10-27 10:23:13 -0700349 mCaches.textureState().bindTexture(mTarget, mId);
John Reck38e0c322015-11-10 12:19:17 -0800350
Romain Guy253f2c22016-09-28 17:34:42 -0700351 // TODO: Handle sRGB gray bitmaps
Romain Guycaaaa662017-03-27 00:40:21 -0700352 if (CC_UNLIKELY(hasUnsupportedColorType(bitmap.info(), hasLinearBlending))) {
sergeyv98fa4f92016-10-24 15:35:21 -0700353 SkBitmap skBitmap;
354 bitmap.getSkBitmap(&skBitmap);
Romain Guycaaaa662017-03-27 00:40:21 -0700355 sk_sp<SkColorSpace> sRGB = SkColorSpace::MakeSRGB();
Romain Guyefb4b062017-02-27 11:00:04 -0800356 SkBitmap rgbaBitmap = uploadToN32(skBitmap, hasLinearBlending, std::move(sRGB));
sergeyv98fa4f92016-10-24 15:35:21 -0700357 uploadToTexture(needsAlloc, internalFormat, format, type, rgbaBitmap.rowBytesAsPixels(),
John Reck1bcacfd2017-11-03 10:12:19 -0700358 rgbaBitmap.bytesPerPixel(), rgbaBitmap.width(), rgbaBitmap.height(),
359 rgbaBitmap.getPixels());
sergeyv694d4992016-10-27 10:23:13 -0700360 } else if (bitmap.isHardware()) {
361 uploadHardwareBitmapToTexture(bitmap.graphicBuffer());
John Reck38e0c322015-11-10 12:19:17 -0800362 } else {
sergeyv98fa4f92016-10-24 15:35:21 -0700363 uploadToTexture(needsAlloc, internalFormat, format, type, bitmap.rowBytesAsPixels(),
John Reck1bcacfd2017-11-03 10:12:19 -0700364 bitmap.info().bytesPerPixel(), bitmap.width(), bitmap.height(),
365 bitmap.pixels());
John Reck38e0c322015-11-10 12:19:17 -0800366 }
367
368 if (canMipMap) {
369 mipMap = bitmap.hasHardwareMipMap();
370 if (mipMap) {
371 glGenerateMipmap(GL_TEXTURE_2D);
372 }
373 }
374
John Reck48247a22016-01-22 10:55:32 -0800375 if (setDefaultParams) {
John Reck38e0c322015-11-10 12:19:17 -0800376 setFilter(GL_NEAREST);
John Reck38e0c322015-11-10 12:19:17 -0800377 setWrap(GL_CLAMP_TO_EDGE);
378 }
379}
380
John Reck1bcacfd2017-11-03 10:12:19 -0700381void Texture::wrap(GLuint id, uint32_t width, uint32_t height, GLint internalFormat, GLint format,
382 GLenum target) {
John Reck38e0c322015-11-10 12:19:17 -0800383 mId = id;
384 mWidth = width;
385 mHeight = height;
386 mFormat = format;
Romain Guy253f2c22016-09-28 17:34:42 -0700387 mInternalFormat = internalFormat;
sergeyv2a38c422016-10-25 15:21:50 -0700388 mTarget = target;
Romain Guycaaaa662017-03-27 00:40:21 -0700389 mConnector.reset();
John Reck38e0c322015-11-10 12:19:17 -0800390 // We're wrapping an existing texture, so don't double count this memory
391 notifySizeChanged(0);
Romain Guybe1b1272013-06-06 14:02:54 -0700392}
393
Romain Guycaaaa662017-03-27 00:40:21 -0700394TransferFunctionType Texture::getTransferFunctionType() const {
395 if (mConnector.get() != nullptr && mInternalFormat != GL_SRGB8_ALPHA8) {
396 const ColorSpace::TransferParameters& p = mConnector->getSource().getTransferParameters();
397 if (MathUtils::isZero(p.e) && MathUtils::isZero(p.f)) {
John Reck1bcacfd2017-11-03 10:12:19 -0700398 if (MathUtils::areEqual(p.a, 1.0f) && MathUtils::isZero(p.b) &&
399 MathUtils::isZero(p.c) && MathUtils::isZero(p.d)) {
Romain Guycaaaa662017-03-27 00:40:21 -0700400 if (MathUtils::areEqual(p.g, 1.0f)) {
401 return TransferFunctionType::None;
402 }
403 return TransferFunctionType::Gamma;
404 }
405 return TransferFunctionType::Limited;
406 }
407 return TransferFunctionType::Full;
408 }
409 return TransferFunctionType::None;
410}
411
John Reck1bcacfd2017-11-03 10:12:19 -0700412}; // namespace uirenderer
413}; // namespace android