blob: 959059fede0cb17331cf4114da13b0565852ce8b [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 Guycaaaa662017-03-27 00:40:21 -0700123 bool needsAlloc = updateLayout(width, height, internalFormat, format, GL_TEXTURE_2D);
John Reck38e0c322015-11-10 12:19:17 -0800124 if (!mId) {
125 glGenTextures(1, &mId);
126 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800127 resetCachedParams();
John Reck38e0c322015-11-10 12:19:17 -0800128 }
129 mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
130 if (needsAlloc) {
Romain Guy253f2c22016-09-28 17:34:42 -0700131 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
John Reck38e0c322015-11-10 12:19:17 -0800132 format, type, pixels);
John Reck66f65cb2016-01-21 09:08:42 -0800133 } else if (pixels) {
Romain Guy253f2c22016-09-28 17:34:42 -0700134 glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
John Reck38e0c322015-11-10 12:19:17 -0800135 format, type, pixels);
136 }
John Reck975591a2016-01-22 16:28:07 -0800137 GL_CHECKPOINT(MODERATE);
John Reck38e0c322015-11-10 12:19:17 -0800138}
139
sergeyv694d4992016-10-27 10:23:13 -0700140void Texture::uploadHardwareBitmapToTexture(GraphicBuffer* buffer) {
141 EGLDisplay eglDisplayHandle = eglGetCurrentDisplay();
142 if (mEglImageHandle != EGL_NO_IMAGE_KHR) {
143 eglDestroyImageKHR(eglDisplayHandle, mEglImageHandle);
144 mEglImageHandle = EGL_NO_IMAGE_KHR;
145 }
146 mEglImageHandle = eglCreateImageKHR(eglDisplayHandle, EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
147 buffer->getNativeBuffer(), 0);
148 glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, mEglImageHandle);
149}
150
Romain Guy253f2c22016-09-28 17:34:42 -0700151static void uploadToTexture(bool resize, GLint internalFormat, GLenum format, GLenum type,
152 GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height, const GLvoid * data) {
John Reck38e0c322015-11-10 12:19:17 -0800153
John Reck38e0c322015-11-10 12:19:17 -0800154 const bool useStride = stride != width
155 && Caches::getInstance().extensions().hasUnpackRowLength();
156 if ((stride == width) || useStride) {
157 if (useStride) {
158 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride);
159 }
160
161 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700162 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, data);
John Reck38e0c322015-11-10 12:19:17 -0800163 } else {
164 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
165 }
166
167 if (useStride) {
168 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
169 }
170 } else {
171 // With OpenGL ES 2.0 we need to copy the bitmap in a temporary buffer
172 // if the stride doesn't match the width
173
174 GLvoid * temp = (GLvoid *) malloc(width * height * bpp);
175 if (!temp) return;
176
177 uint8_t * pDst = (uint8_t *)temp;
178 uint8_t * pSrc = (uint8_t *)data;
179 for (GLsizei i = 0; i < height; i++) {
180 memcpy(pDst, pSrc, width * bpp);
181 pDst += width * bpp;
182 pSrc += stride * bpp;
183 }
184
185 if (resize) {
Romain Guy253f2c22016-09-28 17:34:42 -0700186 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, temp);
John Reck38e0c322015-11-10 12:19:17 -0800187 } else {
188 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
189 }
190
191 free(temp);
192 }
193}
194
sergeyv694d4992016-10-27 10:23:13 -0700195void Texture::colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType,
Romain Guy253f2c22016-09-28 17:34:42 -0700196 bool needSRGB, GLint* outInternalFormat, GLint* outFormat, GLint* outType) {
John Reck38e0c322015-11-10 12:19:17 -0800197 switch (colorType) {
198 case kAlpha_8_SkColorType:
199 *outFormat = GL_ALPHA;
Romain Guy253f2c22016-09-28 17:34:42 -0700200 *outInternalFormat = GL_ALPHA;
John Reck38e0c322015-11-10 12:19:17 -0800201 *outType = GL_UNSIGNED_BYTE;
202 break;
203 case kRGB_565_SkColorType:
Romain Guy253f2c22016-09-28 17:34:42 -0700204 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 }
John Reck38e0c322015-11-10 12:19:17 -0800215 break;
216 // ARGB_4444 and Index_8 are both upconverted to RGBA_8888
217 case kARGB_4444_SkColorType:
218 case kIndex_8_SkColorType:
219 case kN32_SkColorType:
220 *outFormat = GL_RGBA;
Romain Guy253f2c22016-09-28 17:34:42 -0700221 *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
John Reck38e0c322015-11-10 12:19:17 -0800222 *outType = GL_UNSIGNED_BYTE;
223 break;
Derek Sollenberger88d842f2016-01-20 10:37:30 -0500224 case kGray_8_SkColorType:
225 *outFormat = GL_LUMINANCE;
Romain Guy253f2c22016-09-28 17:34:42 -0700226 *outInternalFormat = GL_LUMINANCE;
Derek Sollenberger88d842f2016-01-20 10:37:30 -0500227 *outType = GL_UNSIGNED_BYTE;
228 break;
Romain Guy9505a652016-12-14 09:43:50 -0800229 case kRGBA_F16_SkColorType:
Romain Guy89de2342017-04-06 12:24:29 -0700230 if (caches.extensions().getMajorGlVersion() >= 3) {
231 // This format is always linear
232 *outFormat = GL_RGBA;
233 *outInternalFormat = GL_RGBA16F;
234 *outType = GL_HALF_FLOAT;
235 } else {
236 *outFormat = GL_RGBA;
237 *outInternalFormat = caches.rgbaInternalFormat(true);
238 *outType = GL_UNSIGNED_BYTE;
239 }
Romain Guy9505a652016-12-14 09:43:50 -0800240 break;
John Reck38e0c322015-11-10 12:19:17 -0800241 default:
242 LOG_ALWAYS_FATAL("Unsupported bitmap colorType: %d", colorType);
243 break;
244 }
245}
246
Romain Guyefb4b062017-02-27 11:00:04 -0800247SkBitmap Texture::uploadToN32(const SkBitmap& bitmap, bool hasLinearBlending,
248 sk_sp<SkColorSpace> sRGB) {
sergeyv694d4992016-10-27 10:23:13 -0700249 SkBitmap rgbaBitmap;
250 rgbaBitmap.allocPixels(SkImageInfo::MakeN32(bitmap.width(), bitmap.height(),
Romain Guyefb4b062017-02-27 11:00:04 -0800251 bitmap.info().alphaType(), 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
256 bitmap.readPixels(rgbaBitmap.info()
257 .makeColorSpace(SkColorSpace::MakeSRGB()),
258 rgbaBitmap.getPixels(), rgbaBitmap.rowBytes(), 0, 0);
259 } else {
260 SkCanvas canvas(rgbaBitmap);
261 canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
262 }
263
sergeyv694d4992016-10-27 10:23:13 -0700264 return rgbaBitmap;
265}
266
Romain Guycaaaa662017-03-27 00:40:21 -0700267bool Texture::hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending) {
sergeyv694d4992016-10-27 10:23:13 -0700268 return info.colorType() == kARGB_4444_SkColorType
269 || info.colorType() == kIndex_8_SkColorType
Romain Guycaaaa662017-03-27 00:40:21 -0700270 || (info.colorType() == kRGB_565_SkColorType
271 && hasLinearBlending
Romain Guy89de2342017-04-06 12:24:29 -0700272 && info.colorSpace()->isSRGB())
273 || (info.colorType() == kRGBA_F16_SkColorType
274 && Caches::getInstance().extensions().getMajorGlVersion() < 3);
sergeyv694d4992016-10-27 10:23:13 -0700275}
276
sergeyv98fa4f92016-10-24 15:35:21 -0700277void Texture::upload(Bitmap& bitmap) {
John Reck38e0c322015-11-10 12:19:17 -0800278 if (!bitmap.readyToDraw()) {
279 ALOGE("Cannot generate texture from bitmap");
280 return;
281 }
282
283 ATRACE_FORMAT("Upload %ux%u Texture", bitmap.width(), bitmap.height());
284
285 // We could also enable mipmapping if both bitmap dimensions are powers
286 // of 2 but we'd have to deal with size changes. Let's keep this simple
287 const bool canMipMap = mCaches.extensions().hasNPot();
288
289 // If the texture had mipmap enabled but not anymore,
290 // force a glTexImage2D to discard the mipmap levels
291 bool needsAlloc = canMipMap && mipMap && !bitmap.hasHardwareMipMap();
John Reck48247a22016-01-22 10:55:32 -0800292 bool setDefaultParams = false;
John Reck38e0c322015-11-10 12:19:17 -0800293
294 if (!mId) {
295 glGenTextures(1, &mId);
296 needsAlloc = true;
John Reck48247a22016-01-22 10:55:32 -0800297 setDefaultParams = true;
John Reck38e0c322015-11-10 12:19:17 -0800298 }
299
Romain Guycaaaa662017-03-27 00:40:21 -0700300 bool hasLinearBlending = mCaches.extensions().hasLinearBlending();
301 bool needSRGB = transferFunctionCloseToSRGB(bitmap.info().colorSpace());
John Reck38e0c322015-11-10 12:19:17 -0800302
Romain Guy253f2c22016-09-28 17:34:42 -0700303 GLint internalFormat, format, type;
Romain Guycaaaa662017-03-27 00:40:21 -0700304 colorTypeToGlFormatAndType(mCaches, bitmap.colorType(),
305 needSRGB && hasLinearBlending, &internalFormat, &format, &type);
306
Romain Guy89de2342017-04-06 12:24:29 -0700307 // Some devices don't support GL_RGBA16F, so we need to compare the color type
308 // and internal GL format to decide what to do with 16 bit bitmaps
309 bool rgba16fNeedsConversion = bitmap.colorType() == kRGBA_F16_SkColorType
310 && internalFormat != GL_RGBA16F;
311
Romain Guycaaaa662017-03-27 00:40:21 -0700312 mConnector.reset();
313
314 // RGBA16F is always extended sRGB, alpha masks don't have color profiles
Romain Guy89de2342017-04-06 12:24:29 -0700315 // If an RGBA16F bitmap needs conversion, we know the target will be sRGB
316 if (internalFormat != GL_RGBA16F && internalFormat != GL_ALPHA && !rgba16fNeedsConversion) {
Romain Guycaaaa662017-03-27 00:40:21 -0700317 SkColorSpace* colorSpace = bitmap.info().colorSpace();
318 // If the bitmap is sRGB we don't need conversion
319 if (colorSpace != nullptr && !colorSpace->isSRGB()) {
320 SkMatrix44 xyzMatrix(SkMatrix44::kUninitialized_Constructor);
321 if (!colorSpace->toXYZD50(&xyzMatrix)) {
322 ALOGW("Incompatible color space!");
323 } else {
324 SkColorSpaceTransferFn fn;
325 if (!colorSpace->isNumericalTransferFn(&fn)) {
326 ALOGW("Incompatible color space, no numerical transfer function!");
327 } else {
328 float data[16];
329 xyzMatrix.asColMajorf(data);
330
331 ColorSpace::TransferParameters p =
332 {fn.fG, fn.fA, fn.fB, fn.fC, fn.fD, fn.fE, fn.fF};
333 ColorSpace src("Unnamed", mat4f((const float*) &data[0]).upperLeft(), p);
334 mConnector.reset(new ColorSpaceConnector(src, ColorSpace::sRGB()));
335
336 // A non-sRGB color space might have a transfer function close enough to sRGB
337 // that we can save shader instructions by using an sRGB sampler
338 // This is only possible if we have hardware support for sRGB textures
339 if (needSRGB && internalFormat == GL_RGBA
340 && mCaches.extensions().hasSRGB() && !bitmap.isHardware()) {
341 internalFormat = GL_SRGB8_ALPHA8;
342 }
343 }
344 }
345 }
346 }
Romain Guy253f2c22016-09-28 17:34:42 -0700347
sergeyv694d4992016-10-27 10:23:13 -0700348 GLenum target = bitmap.isHardware() ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
Romain Guycaaaa662017-03-27 00:40:21 -0700349 needsAlloc |= updateLayout(bitmap.width(), bitmap.height(), internalFormat, format, target);
John Reck38e0c322015-11-10 12:19:17 -0800350
351 blend = !bitmap.isOpaque();
sergeyv694d4992016-10-27 10:23:13 -0700352 mCaches.textureState().bindTexture(mTarget, mId);
John Reck38e0c322015-11-10 12:19:17 -0800353
Romain Guy253f2c22016-09-28 17:34:42 -0700354 // TODO: Handle sRGB gray bitmaps
Romain Guycaaaa662017-03-27 00:40:21 -0700355 if (CC_UNLIKELY(hasUnsupportedColorType(bitmap.info(), hasLinearBlending))) {
sergeyv98fa4f92016-10-24 15:35:21 -0700356 SkBitmap skBitmap;
357 bitmap.getSkBitmap(&skBitmap);
Romain Guycaaaa662017-03-27 00:40:21 -0700358 sk_sp<SkColorSpace> sRGB = SkColorSpace::MakeSRGB();
Romain Guyefb4b062017-02-27 11:00:04 -0800359 SkBitmap rgbaBitmap = uploadToN32(skBitmap, hasLinearBlending, std::move(sRGB));
sergeyv98fa4f92016-10-24 15:35:21 -0700360 uploadToTexture(needsAlloc, internalFormat, format, type, rgbaBitmap.rowBytesAsPixels(),
361 rgbaBitmap.bytesPerPixel(), rgbaBitmap.width(),
362 rgbaBitmap.height(), rgbaBitmap.getPixels());
sergeyv694d4992016-10-27 10:23:13 -0700363 } else if (bitmap.isHardware()) {
364 uploadHardwareBitmapToTexture(bitmap.graphicBuffer());
John Reck38e0c322015-11-10 12:19:17 -0800365 } else {
sergeyv98fa4f92016-10-24 15:35:21 -0700366 uploadToTexture(needsAlloc, internalFormat, format, type, bitmap.rowBytesAsPixels(),
367 bitmap.info().bytesPerPixel(), bitmap.width(), bitmap.height(), bitmap.pixels());
John Reck38e0c322015-11-10 12:19:17 -0800368 }
369
370 if (canMipMap) {
371 mipMap = bitmap.hasHardwareMipMap();
372 if (mipMap) {
373 glGenerateMipmap(GL_TEXTURE_2D);
374 }
375 }
376
John Reck48247a22016-01-22 10:55:32 -0800377 if (setDefaultParams) {
John Reck38e0c322015-11-10 12:19:17 -0800378 setFilter(GL_NEAREST);
John Reck38e0c322015-11-10 12:19:17 -0800379 setWrap(GL_CLAMP_TO_EDGE);
380 }
381}
382
sergeyv2a38c422016-10-25 15:21:50 -0700383void Texture::wrap(GLuint id, uint32_t width, uint32_t height,
384 GLint internalFormat, GLint format, GLenum target) {
John Reck38e0c322015-11-10 12:19:17 -0800385 mId = id;
386 mWidth = width;
387 mHeight = height;
388 mFormat = format;
Romain Guy253f2c22016-09-28 17:34:42 -0700389 mInternalFormat = internalFormat;
sergeyv2a38c422016-10-25 15:21:50 -0700390 mTarget = target;
Romain Guycaaaa662017-03-27 00:40:21 -0700391 mConnector.reset();
John Reck38e0c322015-11-10 12:19:17 -0800392 // We're wrapping an existing texture, so don't double count this memory
393 notifySizeChanged(0);
Romain Guybe1b1272013-06-06 14:02:54 -0700394}
395
Romain Guycaaaa662017-03-27 00:40:21 -0700396TransferFunctionType Texture::getTransferFunctionType() const {
397 if (mConnector.get() != nullptr && mInternalFormat != GL_SRGB8_ALPHA8) {
398 const ColorSpace::TransferParameters& p = mConnector->getSource().getTransferParameters();
399 if (MathUtils::isZero(p.e) && MathUtils::isZero(p.f)) {
400 if (MathUtils::areEqual(p.a, 1.0f) && MathUtils::isZero(p.b)
401 && MathUtils::isZero(p.c) && MathUtils::isZero(p.d)) {
402 if (MathUtils::areEqual(p.g, 1.0f)) {
403 return TransferFunctionType::None;
404 }
405 return TransferFunctionType::Gamma;
406 }
407 return TransferFunctionType::Limited;
408 }
409 return TransferFunctionType::Full;
410 }
411 return TransferFunctionType::None;
412}
413
Romain Guy8aa195d2013-06-04 18:00:09 -0700414}; // namespace uirenderer
415}; // namespace android