OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 507 |
508 ~ScopedFramebufferRestorer() | 508 ~ScopedFramebufferRestorer() |
509 { | 509 { |
510 m_context->restoreCurrentFramebuffer(); | 510 m_context->restoreCurrentFramebuffer(); |
511 } | 511 } |
512 | 512 |
513 private: | 513 private: |
514 Member<WebGLRenderingContextBase> m_context; | 514 Member<WebGLRenderingContextBase> m_context; |
515 }; | 515 }; |
516 | 516 |
| 517 class ScopedUnpackParametersResetRestore { |
| 518 STACK_ALLOCATED(); |
| 519 |
| 520 public: |
| 521 explicit ScopedUnpackParametersResetRestore(WebGLRenderingContextBase* conte
xt, bool enabled = true) |
| 522 : m_context(context) |
| 523 , m_enabled(enabled) |
| 524 { |
| 525 if (enabled) |
| 526 m_context->resetUnpackParameters(); |
| 527 } |
| 528 |
| 529 ~ScopedUnpackParametersResetRestore() |
| 530 { |
| 531 if (m_enabled) |
| 532 m_context->restoreUnpackParameters(); |
| 533 } |
| 534 |
| 535 private: |
| 536 Member<WebGLRenderingContextBase> m_context; |
| 537 bool m_enabled; |
| 538 }; |
| 539 |
517 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) | 540 static void formatWebGLStatusString(const String& glInfo, const String& infostri
ng, String& statusMessage) |
518 { | 541 { |
519 if (!infostring.isEmpty()) | 542 if (!infostring.isEmpty()) |
520 statusMessage.append(", " + glInfo + " = " + infostring); | 543 statusMessage.append(", " + glInfo + " = " + infostring); |
521 } | 544 } |
522 | 545 |
523 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) | 546 static String extractWebGLContextCreationError(const Platform::GraphicsInfo& inf
o) |
524 { | 547 { |
525 String statusMessage("Could not create a WebGL context"); | 548 String statusMessage("Could not create a WebGL context"); |
526 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i
nfo.vendorId).utf8().data() : "0xffff", statusMessage); | 549 formatWebGLStatusString("VENDOR", info.vendorId ? String::format("0x%04x", i
nfo.vendorId).utf8().data() : "0xffff", statusMessage); |
(...skipping 3490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4017 bool needConversion = true; | 4040 bool needConversion = true; |
4018 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da
taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo
thing && !flipY) { | 4041 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da
taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo
thing && !flipY) { |
4019 needConversion = false; | 4042 needConversion = false; |
4020 } else { | 4043 } else { |
4021 if (!WebGLImageConversion::packImageData(image, imagePixelData, format,
type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac
tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { | 4044 if (!WebGLImageConversion::packImageData(image, imagePixelData, format,
type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac
tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { |
4022 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error"); | 4045 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error"); |
4023 return; | 4046 return; |
4024 } | 4047 } |
4025 } | 4048 } |
4026 | 4049 |
4027 resetUnpackParameters(); | 4050 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4028 if (functionID == TexImage2D) { | 4051 if (functionID == TexImage2D) { |
4029 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(
), imageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() :
imagePixelData); | 4052 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(
), imageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() :
imagePixelData); |
4030 } else if (functionID == TexSubImage2D) { | 4053 } else if (functionID == TexSubImage2D) { |
4031 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtract
or.imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? d
ata.data() : imagePixelData); | 4054 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, imageExtract
or.imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? d
ata.data() : imagePixelData); |
4032 } else { | 4055 } else { |
4033 DCHECK_EQ(functionID, TexSubImage3D); | 4056 DCHECK_EQ(functionID, TexSubImage3D); |
4034 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima
geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon
version ? data.data() : imagePixelData); | 4057 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, ima
geExtractor.imageWidth(), imageExtractor.imageHeight(), 1, format, type, needCon
version ? data.data() : imagePixelData); |
4035 } | 4058 } |
4036 restoreUnpackParameters(); | |
4037 } | 4059 } |
4038 | 4060 |
4039 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma
geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ
et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d
epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL
int zoffset) | 4061 bool WebGLRenderingContextBase::validateTexFunc(const char* functionName, TexIma
geFunctionType functionType, TexFuncValidationSourceType sourceType, GLenum targ
et, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei d
epth, GLint border, GLenum format, GLenum type, GLint xoffset, GLint yoffset, GL
int zoffset) |
4040 { | 4062 { |
4041 if (!validateTexFuncLevel(functionName, target, level)) | 4063 if (!validateTexFuncLevel(functionName, target, level)) |
4042 return false; | 4064 return false; |
4043 | 4065 |
4044 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, depth, border, format, type)) | 4066 if (!validateTexFuncParameters(functionName, functionType, target, level, in
ternalformat, width, height, depth, border, format, type)) |
4045 return false; | 4067 return false; |
4046 | 4068 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4168 // FIXME: implement flipY and premultiplyAlpha for tex(Sub)3D. | 4190 // FIXME: implement flipY and premultiplyAlpha for tex(Sub)3D. |
4169 if (functionID == TexImage3D) { | 4191 if (functionID == TexImage3D) { |
4170 contextGL()->TexImage3D(target, level, convertTexInternalFormat(internal
format, type), width, height, depth, border, format, type, data); | 4192 contextGL()->TexImage3D(target, level, convertTexInternalFormat(internal
format, type), width, height, depth, border, format, type, data); |
4171 return; | 4193 return; |
4172 } | 4194 } |
4173 if (functionID == TexSubImage3D) { | 4195 if (functionID == TexSubImage3D) { |
4174 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, wid
th, height, depth, format, type, data); | 4196 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, wid
th, height, depth, format, type, data); |
4175 return; | 4197 return; |
4176 } | 4198 } |
4177 | 4199 |
4178 if (changeUnpackAlignment) | 4200 ScopedUnpackParametersResetRestore temporaryResetUnpack(this, changeUnpackAl
ignment); |
4179 resetUnpackParameters(); | |
4180 if (functionID == TexImage2D) | 4201 if (functionID == TexImage2D) |
4181 texImage2DBase(target, level, internalformat, width, height, border, for
mat, type, data); | 4202 texImage2DBase(target, level, internalformat, width, height, border, for
mat, type, data); |
4182 else if (functionID == TexSubImage2D) | 4203 else if (functionID == TexSubImage2D) |
4183 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); | 4204 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, heigh
t, format, type, data); |
4184 if (changeUnpackAlignment) | |
4185 restoreUnpackParameters(); | |
4186 } | 4205 } |
4187 | 4206 |
4188 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4207 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4189 GLsizei width, GLsizei height, GLint border, | 4208 GLsizei width, GLsizei height, GLint border, |
4190 GLenum format, GLenum type, DOMArrayBufferView* pixels) | 4209 GLenum format, GLenum type, DOMArrayBufferView* pixels) |
4191 { | 4210 { |
4192 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, border, format, type, 1, 0, 0, 0, pixels); | 4211 texImageHelperDOMArrayBufferView(TexImage2D, target, level, internalformat,
width, height, border, format, type, 1, 0, 0, 0, pixels); |
4193 } | 4212 } |
4194 | 4213 |
4195 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, | 4214 void WebGLRenderingContextBase::texImageHelperImageData(TexImageFunctionID funct
ionID, |
(...skipping 29 matching lines...) Expand all Loading... |
4225 } else { | 4244 } else { |
4226 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { | 4245 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { |
4227 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. | 4246 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implement
ed. |
4228 type = GL_FLOAT; | 4247 type = GL_FLOAT; |
4229 } | 4248 } |
4230 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG
LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u
npackFlipY, m_unpackPremultiplyAlpha, data)) { | 4249 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), WebG
LImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), format, type, m_u
npackFlipY, m_unpackPremultiplyAlpha, data)) { |
4231 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 4250 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
4232 return; | 4251 return; |
4233 } | 4252 } |
4234 } | 4253 } |
4235 resetUnpackParameters(); | 4254 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4236 if (functionID == TexImage2D) { | 4255 if (functionID == TexImage2D) { |
4237 texImage2DBase(target, level, internalformat, pixels->width(), pixels->h
eight(), border, format, type, needConversion ? data.data() : pixels->data()->da
ta()); | 4256 texImage2DBase(target, level, internalformat, pixels->width(), pixels->h
eight(), border, format, type, needConversion ? data.data() : pixels->data()->da
ta()); |
4238 } else if (functionID == TexSubImage2D) { | 4257 } else if (functionID == TexSubImage2D) { |
4239 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->widt
h(), pixels->height(), format, type, needConversion ? data.data() : pixels->data
()->data()); | 4258 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, pixels->widt
h(), pixels->height(), format, type, needConversion ? data.data() : pixels->data
()->data()); |
4240 } else { | 4259 } else { |
4241 DCHECK_EQ(functionID, TexSubImage3D); | 4260 DCHECK_EQ(functionID, TexSubImage3D); |
4242 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pix
els->width(), pixels->height(), depth, format, type, needConversion ? data.data(
) : pixels->data()->data()); | 4261 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, pix
els->width(), pixels->height(), depth, format, type, needConversion ? data.data(
) : pixels->data()->data()); |
4243 } | 4262 } |
4244 restoreUnpackParameters(); | |
4245 } | 4263 } |
4246 | 4264 |
4247 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4265 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4248 GLenum format, GLenum type, ImageData* pixels) | 4266 GLenum format, GLenum type, ImageData* pixels) |
4249 { | 4267 { |
4250 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format
, type, 1, 0, 0, 0, pixels); | 4268 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format
, type, 1, 0, 0, 0, pixels); |
4251 } | 4269 } |
4252 | 4270 |
4253 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(TexImageFunctionI
D functionID, | 4271 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(TexImageFunctionI
D functionID, |
4254 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, | 4272 GLenum target, GLint level, GLint internalformat, GLenum format, GLenum type
, GLint xoffset, |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4472 // This is a straight GPU-GPU copy, any necessary color spac
e conversion was handled in the paintCurrentFrameInContext() call. | 4490 // This is a straight GPU-GPU copy, any necessary color spac
e conversion was handled in the paintCurrentFrameInContext() call. |
4473 if (imageBuffer->copyToPlatformTexture(contextGL(), texture-
>object(), internalformat, type, | 4491 if (imageBuffer->copyToPlatformTexture(contextGL(), texture-
>object(), internalformat, type, |
4474 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { | 4492 level, m_unpackPremultiplyAlpha, m_unpackFlipY)) { |
4475 return; | 4493 return; |
4476 } | 4494 } |
4477 } | 4495 } |
4478 } | 4496 } |
4479 } | 4497 } |
4480 } | 4498 } |
4481 | 4499 |
| 4500 { |
| 4501 ScopedUnpackParametersResetRestore(this, m_unpackFlipY || m_unpackPremul
tiplyAlpha); |
| 4502 if (video->texImageImpl(getTexImageFunctionName(functionID), target, con
textGL(), level, internalformat, format, type, xoffset, yoffset, zoffset, |
| 4503 m_unpackFlipY, m_unpackPremultiplyAlpha && m_unpackColorspaceConvers
ion == GL_NONE)) |
| 4504 return; |
| 4505 } |
| 4506 |
4482 RefPtr<Image> image = videoFrameToImage(video); | 4507 RefPtr<Image> image = videoFrameToImage(video); |
4483 if (!image) | 4508 if (!image) |
4484 return; | 4509 return; |
4485 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); | 4510 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, zo
ffset, format, type, image.get(), WebGLImageConversion::HtmlDomVideo, m_unpackFl
ipY, m_unpackPremultiplyAlpha); |
4486 } | 4511 } |
4487 | 4512 |
4488 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, GLuint
targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targetLevel
, bool flipY) | 4513 void WebGLRenderingContextBase::texImageBitmapByGPU(ImageBitmap* bitmap, GLuint
targetTexture, GLenum targetInternalformat, GLenum targetType, GLint targetLevel
, bool flipY) |
4489 { | 4514 { |
4490 bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(), tar
getTexture, targetInternalformat, targetType, flipY); | 4515 bitmap->bitmapImage()->copyToTexture(drawingBuffer()->contextProvider(), tar
getTexture, targetInternalformat, targetType, flipY); |
4491 } | 4516 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4552 type = GL_FLOAT; | 4577 type = GL_FLOAT; |
4553 } | 4578 } |
4554 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. | 4579 // In the case of ImageBitmap, we do not need to apply flipY or premulti
plyAlpha. |
4555 bool isPixelDataBGRA = pixmap.colorType() == SkColorType::kBGRA_8888_SkC
olorType; | 4580 bool isPixelDataBGRA = pixmap.colorType() == SkColorType::kBGRA_8888_SkC
olorType; |
4556 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) | 4581 if ((isPixelDataBGRA && !WebGLImageConversion::extractImageData(pixelDat
aPtr, WebGLImageConversion::DataFormat::DataFormatBGRA8, bitmap->size(), format,
type, false, false, data)) |
4557 || (isPixelDataRGBA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { | 4582 || (isPixelDataRGBA && !WebGLImageConversion::extractImageData(pixel
DataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, bitmap->size(), form
at, type, false, false, data))) { |
4558 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); | 4583 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); |
4559 return; | 4584 return; |
4560 } | 4585 } |
4561 } | 4586 } |
4562 resetUnpackParameters(); | 4587 ScopedUnpackParametersResetRestore temporaryResetUnpack(this); |
4563 if (functionID == TexImage2D) { | 4588 if (functionID == TexImage2D) { |
4564 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); | 4589 texImage2DBase(target, level, internalformat, bitmap->width(), bitmap->h
eight(), 0, format, type, needConversion ? data.data() : pixelDataPtr); |
4565 } else if (functionID == TexSubImage2D) { | 4590 } else if (functionID == TexSubImage2D) { |
4566 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); | 4591 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, bitmap->widt
h(), bitmap->height(), format, type, needConversion ? data.data() : pixelDataPtr
); |
4567 } else { | 4592 } else { |
4568 DCHECK_EQ(functionID, TexSubImage3D); | 4593 DCHECK_EQ(functionID, TexSubImage3D); |
4569 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bit
map->width(), bitmap->height(), 1, format, type, needConversion ? data.data() :
pixelDataPtr); | 4594 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, bit
map->width(), bitmap->height(), 1, format, type, needConversion ? data.data() :
pixelDataPtr); |
4570 } | 4595 } |
4571 restoreUnpackParameters(); | |
4572 } | 4596 } |
4573 | 4597 |
4574 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, | 4598 void WebGLRenderingContextBase::texImage2D(GLenum target, GLint level, GLint int
ernalformat, |
4575 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt
ate) | 4599 GLenum format, GLenum type, ImageBitmap* bitmap, ExceptionState& exceptionSt
ate) |
4576 { | 4600 { |
4577 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format,
type, 0, 0, 0, bitmap, exceptionState); | 4601 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format,
type, 0, 0, 0, bitmap, exceptionState); |
4578 } | 4602 } |
4579 | 4603 |
4580 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) | 4604 void WebGLRenderingContextBase::texParameter(GLenum target, GLenum pname, GLfloa
t paramf, GLint parami, bool isFloat) |
4581 { | 4605 { |
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6483 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6507 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
6484 } | 6508 } |
6485 | 6509 |
6486 void WebGLRenderingContextBase::restoreUnpackParameters() | 6510 void WebGLRenderingContextBase::restoreUnpackParameters() |
6487 { | 6511 { |
6488 if (m_unpackAlignment != 1) | 6512 if (m_unpackAlignment != 1) |
6489 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6513 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
6490 } | 6514 } |
6491 | 6515 |
6492 } // namespace blink | 6516 } // namespace blink |
OLD | NEW |