Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2476693002: WebGL & 16-bit video stream: upload to FLOAT texture. (Closed)
Patch Set: Nits. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 public: 494 public:
495 explicit ScopedFramebufferRestorer(WebGLRenderingContextBase* context) 495 explicit ScopedFramebufferRestorer(WebGLRenderingContextBase* context)
496 : m_context(context) {} 496 : m_context(context) {}
497 497
498 ~ScopedFramebufferRestorer() { m_context->restoreCurrentFramebuffer(); } 498 ~ScopedFramebufferRestorer() { m_context->restoreCurrentFramebuffer(); }
499 499
500 private: 500 private:
501 Member<WebGLRenderingContextBase> m_context; 501 Member<WebGLRenderingContextBase> m_context;
502 }; 502 };
503 503
504 class ScopedUnpackParametersResetRestore {
505 STACK_ALLOCATED();
506
507 public:
508 explicit ScopedUnpackParametersResetRestore(
509 WebGLRenderingContextBase* context,
510 bool enabled = true)
511 : m_context(context), m_enabled(enabled) {
512 if (enabled)
513 m_context->resetUnpackParameters();
514 }
515
516 ~ScopedUnpackParametersResetRestore() {
517 if (m_enabled)
518 m_context->restoreUnpackParameters();
519 }
520
521 private:
522 Member<WebGLRenderingContextBase> m_context;
523 bool m_enabled;
524 };
525
504 static void formatWebGLStatusString(const StringView& glInfo, 526 static void formatWebGLStatusString(const StringView& glInfo,
505 const StringView& infoString, 527 const StringView& infoString,
506 StringBuilder& builder) { 528 StringBuilder& builder) {
507 if (infoString.isEmpty()) 529 if (infoString.isEmpty())
508 return; 530 return;
509 builder.append(", "); 531 builder.append(", ");
510 builder.append(glInfo); 532 builder.append(glInfo);
511 builder.append(" = "); 533 builder.append(" = ");
512 builder.append(infoString); 534 builder.append(infoString);
513 } 535 }
(...skipping 3896 matching lines...) Expand 10 before | Expand all | Expand 10 after
4410 image, imagePixelData, format, type, flipY, alphaOp, 4432 image, imagePixelData, format, type, flipY, alphaOp,
4411 sourceDataFormat, imageExtractor.imageWidth(), 4433 sourceDataFormat, imageExtractor.imageWidth(),
4412 imageExtractor.imageHeight(), adjustedSourceImageRect, depth, 4434 imageExtractor.imageHeight(), adjustedSourceImageRect, depth,
4413 imageExtractor.imageSourceUnpackAlignment(), unpackImageHeight, 4435 imageExtractor.imageSourceUnpackAlignment(), unpackImageHeight,
4414 data)) { 4436 data)) {
4415 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error"); 4437 synthesizeGLError(GL_INVALID_VALUE, funcName, "packImage error");
4416 return; 4438 return;
4417 } 4439 }
4418 } 4440 }
4419 4441
4420 resetUnpackParameters(); 4442 ScopedUnpackParametersResetRestore temporaryResetUnpack(this);
4421 if (functionID == TexImage2D) { 4443 if (functionID == TexImage2D) {
4422 texImage2DBase(target, level, internalformat, 4444 texImage2DBase(target, level, internalformat,
4423 adjustedSourceImageRect.width(), 4445 adjustedSourceImageRect.width(),
4424 adjustedSourceImageRect.height(), 0, format, type, 4446 adjustedSourceImageRect.height(), 0, format, type,
4425 needConversion ? data.data() : imagePixelData); 4447 needConversion ? data.data() : imagePixelData);
4426 } else if (functionID == TexSubImage2D) { 4448 } else if (functionID == TexSubImage2D) {
4427 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, 4449 contextGL()->TexSubImage2D(target, level, xoffset, yoffset,
4428 adjustedSourceImageRect.width(), 4450 adjustedSourceImageRect.width(),
4429 adjustedSourceImageRect.height(), format, type, 4451 adjustedSourceImageRect.height(), format, type,
4430 needConversion ? data.data() : imagePixelData); 4452 needConversion ? data.data() : imagePixelData);
4431 } else { 4453 } else {
4432 // 3D functions. 4454 // 3D functions.
4433 if (functionID == TexImage3D) { 4455 if (functionID == TexImage3D) {
4434 contextGL()->TexImage3D( 4456 contextGL()->TexImage3D(
4435 target, level, internalformat, adjustedSourceImageRect.width(), 4457 target, level, internalformat, adjustedSourceImageRect.width(),
4436 adjustedSourceImageRect.height(), depth, 0, format, type, 4458 adjustedSourceImageRect.height(), depth, 0, format, type,
4437 needConversion ? data.data() : imagePixelData); 4459 needConversion ? data.data() : imagePixelData);
4438 } else { 4460 } else {
4439 DCHECK_EQ(functionID, TexSubImage3D); 4461 DCHECK_EQ(functionID, TexSubImage3D);
4440 contextGL()->TexSubImage3D( 4462 contextGL()->TexSubImage3D(
4441 target, level, xoffset, yoffset, zoffset, 4463 target, level, xoffset, yoffset, zoffset,
4442 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), 4464 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(),
4443 depth, format, type, needConversion ? data.data() : imagePixelData); 4465 depth, format, type, needConversion ? data.data() : imagePixelData);
4444 } 4466 }
4445 } 4467 }
4446 restoreUnpackParameters();
4447 } 4468 }
4448 4469
4449 bool WebGLRenderingContextBase::validateTexFunc( 4470 bool WebGLRenderingContextBase::validateTexFunc(
4450 const char* functionName, 4471 const char* functionName,
4451 TexImageFunctionType functionType, 4472 TexImageFunctionType functionType,
4452 TexFuncValidationSourceType sourceType, 4473 TexFuncValidationSourceType sourceType,
4453 GLenum target, 4474 GLenum target,
4454 GLint level, 4475 GLint level,
4455 GLenum internalformat, 4476 GLenum internalformat,
4456 GLsizei width, 4477 GLsizei width,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
4643 convertTexInternalFormat(internalformat, type), 4664 convertTexInternalFormat(internalformat, type),
4644 width, height, depth, border, format, type, data); 4665 width, height, depth, border, format, type, data);
4645 return; 4666 return;
4646 } 4667 }
4647 if (functionID == TexSubImage3D) { 4668 if (functionID == TexSubImage3D) {
4648 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, 4669 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, width,
4649 height, depth, format, type, data); 4670 height, depth, format, type, data);
4650 return; 4671 return;
4651 } 4672 }
4652 4673
4653 if (changeUnpackAlignment) 4674 ScopedUnpackParametersResetRestore temporaryResetUnpack(
4654 resetUnpackParameters(); 4675 this, changeUnpackAlignment);
4655 if (functionID == TexImage2D) 4676 if (functionID == TexImage2D)
4656 texImage2DBase(target, level, internalformat, width, height, border, format, 4677 texImage2DBase(target, level, internalformat, width, height, border, format,
4657 type, data); 4678 type, data);
4658 else if (functionID == TexSubImage2D) 4679 else if (functionID == TexSubImage2D)
4659 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height, 4680 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height,
4660 format, type, data); 4681 format, type, data);
4661 if (changeUnpackAlignment)
4662 restoreUnpackParameters();
4663 } 4682 }
4664 4683
4665 void WebGLRenderingContextBase::texImage2D(GLenum target, 4684 void WebGLRenderingContextBase::texImage2D(GLenum target,
4666 GLint level, 4685 GLint level,
4667 GLint internalformat, 4686 GLint internalformat,
4668 GLsizei width, 4687 GLsizei width,
4669 GLsizei height, 4688 GLsizei height,
4670 GLint border, 4689 GLint border,
4671 GLenum format, 4690 GLenum format,
4672 GLenum type, 4691 GLenum type,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 } 4759 }
4741 if (!WebGLImageConversion::extractImageData( 4760 if (!WebGLImageConversion::extractImageData(
4742 pixels->data()->data(), 4761 pixels->data()->data(),
4743 WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), 4762 WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(),
4744 adjustedSourceImageRect, depth, unpackImageHeight, format, type, 4763 adjustedSourceImageRect, depth, unpackImageHeight, format, type,
4745 m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4764 m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4746 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); 4765 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data");
4747 return; 4766 return;
4748 } 4767 }
4749 } 4768 }
4750 resetUnpackParameters(); 4769 ScopedUnpackParametersResetRestore temporaryResetUnpack(this);
4751 const uint8_t* bytes = needConversion ? data.data() : pixels->data()->data(); 4770 const uint8_t* bytes = needConversion ? data.data() : pixels->data()->data();
4752 if (functionID == TexImage2D) { 4771 if (functionID == TexImage2D) {
4753 DCHECK_EQ(unpackImageHeight, 0); 4772 DCHECK_EQ(unpackImageHeight, 0);
4754 texImage2DBase( 4773 texImage2DBase(
4755 target, level, internalformat, adjustedSourceImageRect.width(), 4774 target, level, internalformat, adjustedSourceImageRect.width(),
4756 adjustedSourceImageRect.height(), border, format, type, bytes); 4775 adjustedSourceImageRect.height(), border, format, type, bytes);
4757 } else if (functionID == TexSubImage2D) { 4776 } else if (functionID == TexSubImage2D) {
4758 DCHECK_EQ(unpackImageHeight, 0); 4777 DCHECK_EQ(unpackImageHeight, 0);
4759 contextGL()->TexSubImage2D( 4778 contextGL()->TexSubImage2D(
4760 target, level, xoffset, yoffset, adjustedSourceImageRect.width(), 4779 target, level, xoffset, yoffset, adjustedSourceImageRect.width(),
4761 adjustedSourceImageRect.height(), format, type, bytes); 4780 adjustedSourceImageRect.height(), format, type, bytes);
4762 } else { 4781 } else {
4763 GLint uploadHeight = adjustedSourceImageRect.height(); 4782 GLint uploadHeight = adjustedSourceImageRect.height();
4764 if (unpackImageHeight) { 4783 if (unpackImageHeight) {
4765 // GL_UNPACK_IMAGE_HEIGHT overrides the passed-in height. 4784 // GL_UNPACK_IMAGE_HEIGHT overrides the passed-in height.
4766 uploadHeight = unpackImageHeight; 4785 uploadHeight = unpackImageHeight;
4767 } 4786 }
4768 if (functionID == TexImage3D) { 4787 if (functionID == TexImage3D) {
4769 contextGL()->TexImage3D(target, level, internalformat, 4788 contextGL()->TexImage3D(target, level, internalformat,
4770 adjustedSourceImageRect.width(), uploadHeight, 4789 adjustedSourceImageRect.width(), uploadHeight,
4771 depth, border, format, type, bytes); 4790 depth, border, format, type, bytes);
4772 } else { 4791 } else {
4773 DCHECK_EQ(functionID, TexSubImage3D); 4792 DCHECK_EQ(functionID, TexSubImage3D);
4774 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, 4793 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset,
4775 adjustedSourceImageRect.width(), uploadHeight, 4794 adjustedSourceImageRect.width(), uploadHeight,
4776 depth, format, type, bytes); 4795 depth, format, type, bytes);
4777 } 4796 }
4778 } 4797 }
4779 restoreUnpackParameters();
4780 } 4798 }
4781 4799
4782 void WebGLRenderingContextBase::texImage2D(GLenum target, 4800 void WebGLRenderingContextBase::texImage2D(GLenum target,
4783 GLint level, 4801 GLint level,
4784 GLint internalformat, 4802 GLint internalformat,
4785 GLenum format, 4803 GLenum format,
4786 GLenum type, 4804 GLenum type,
4787 ImageData* pixels) { 4805 ImageData* pixels) {
4788 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format, 4806 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format,
4789 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels), 4807 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels),
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
5157 // Try using an accelerated image buffer, this allows YUV conversion to be 5175 // Try using an accelerated image buffer, this allows YUV conversion to be
5158 // done on the GPU. 5176 // done on the GPU.
5159 std::unique_ptr<ImageBufferSurface> surface = 5177 std::unique_ptr<ImageBufferSurface> surface =
5160 wrapUnique(new AcceleratedImageBufferSurface( 5178 wrapUnique(new AcceleratedImageBufferSurface(
5161 IntSize(video->videoWidth(), video->videoHeight()))); 5179 IntSize(video->videoWidth(), video->videoHeight())));
5162 if (surface->isValid()) { 5180 if (surface->isValid()) {
5163 std::unique_ptr<ImageBuffer> imageBuffer( 5181 std::unique_ptr<ImageBuffer> imageBuffer(
5164 ImageBuffer::create(std::move(surface))); 5182 ImageBuffer::create(std::move(surface)));
5165 if (imageBuffer) { 5183 if (imageBuffer) {
5166 // The video element paints an RGBA frame into our surface here. By 5184 // The video element paints an RGBA frame into our surface here. By
5167 // using an AcceleratedImageBufferSurface, we enable the 5185 // using an AcceleratedImageBufferSurface, we enable the WebMediaPlayer
5168 // WebMediaPlayer implementation to do any necessary color space 5186 // implementation to do any necessary color space conversion on the GPU
5169 // conversion on the GPU (though it 5187 // (though it may still do a CPU conversion and upload the results).
5170 // may still do a CPU conversion and upload the results).
5171 video->paintCurrentFrame( 5188 video->paintCurrentFrame(
5172 imageBuffer->canvas(), 5189 imageBuffer->canvas(),
5173 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr); 5190 IntRect(0, 0, video->videoWidth(), video->videoHeight()), nullptr);
5174 5191
5175 // This is a straight GPU-GPU copy, any necessary color space 5192 // This is a straight GPU-GPU copy, any necessary color space conversion
5176 // conversion was handled in the paintCurrentFrameInContext() call. 5193 // was handled in the paintCurrentFrameInContext() call.
5177 5194
5178 // Note that copyToPlatformTexture no longer allocates the 5195 // Note that copyToPlatformTexture no longer allocates the destination
5179 // destination texture. 5196 // texture.
5180 texImage2DBase(target, level, internalformat, video->videoWidth(), 5197 texImage2DBase(target, level, internalformat, video->videoWidth(),
5181 video->videoHeight(), 0, format, type, nullptr); 5198 video->videoHeight(), 0, format, type, nullptr);
5182 5199
5183 if (imageBuffer->copyToPlatformTexture( 5200 if (imageBuffer->copyToPlatformTexture(
5184 contextGL(), texture->object(), internalformat, type, level, 5201 contextGL(), texture->object(), internalformat, type, level,
5185 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0), 5202 m_unpackPremultiplyAlpha, m_unpackFlipY, IntPoint(0, 0),
5186 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) { 5203 IntRect(0, 0, video->videoWidth(), video->videoHeight()))) {
5187 return; 5204 return;
5188 } 5205 }
5189 } 5206 }
5190 } 5207 }
5191 } 5208 }
5192 5209
5210 if (sourceImageRectIsDefault) {
5211 // Try using optimized CPU-GPU path for some formats: e.g. Y16 and Y8. It
5212 // leaves early for other formats or if frame is stored on GPU.
5213 ScopedUnpackParametersResetRestore(
5214 this, m_unpackFlipY || m_unpackPremultiplyAlpha);
5215 if (video->texImageImpl(
5216 static_cast<WebMediaPlayer::TexImageFunctionID>(functionID), target,
5217 contextGL(), level, convertTexInternalFormat(internalformat, type),
5218 format, type, xoffset, yoffset, zoffset, m_unpackFlipY,
5219 m_unpackPremultiplyAlpha &&
5220 m_unpackColorspaceConversion == GL_NONE))
5221 return;
5222 }
5223
5193 RefPtr<Image> image = videoFrameToImage(video); 5224 RefPtr<Image> image = videoFrameToImage(video);
5194 if (!image) 5225 if (!image)
5195 return; 5226 return;
5196 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset, 5227 texImageImpl(functionID, target, level, internalformat, xoffset, yoffset,
5197 zoffset, format, type, image.get(), 5228 zoffset, format, type, image.get(),
5198 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY, 5229 WebGLImageConversion::HtmlDomVideo, m_unpackFlipY,
5199 m_unpackPremultiplyAlpha, sourceImageRect, depth, 5230 m_unpackPremultiplyAlpha, sourceImageRect, depth,
5200 unpackImageHeight); 5231 unpackImageHeight);
5201 } 5232 }
5202 5233
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
5324 type, false, false, data)) || 5355 type, false, false, data)) ||
5325 (isPixelDataRGBA && 5356 (isPixelDataRGBA &&
5326 !WebGLImageConversion::extractImageData( 5357 !WebGLImageConversion::extractImageData(
5327 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8, 5358 pixelDataPtr, WebGLImageConversion::DataFormat::DataFormatRGBA8,
5328 bitmap->size(), sourceSubRect, depth, unpackImageHeight, format, 5359 bitmap->size(), sourceSubRect, depth, unpackImageHeight, format,
5329 type, false, false, data))) { 5360 type, false, false, data))) {
5330 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); 5361 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data");
5331 return; 5362 return;
5332 } 5363 }
5333 } 5364 }
5334 resetUnpackParameters(); 5365 ScopedUnpackParametersResetRestore temporaryResetUnpack(this);
5335 if (functionID == TexImage2D) { 5366 if (functionID == TexImage2D) {
5336 texImage2DBase(target, level, internalformat, width, height, 0, format, 5367 texImage2DBase(target, level, internalformat, width, height, 0, format,
5337 type, needConversion ? data.data() : pixelDataPtr); 5368 type, needConversion ? data.data() : pixelDataPtr);
5338 } else if (functionID == TexSubImage2D) { 5369 } else if (functionID == TexSubImage2D) {
5339 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height, 5370 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, width, height,
5340 format, type, 5371 format, type,
5341 needConversion ? data.data() : pixelDataPtr); 5372 needConversion ? data.data() : pixelDataPtr);
5342 } else if (functionID == TexImage3D) { 5373 } else if (functionID == TexImage3D) {
5343 contextGL()->TexImage3D(target, level, internalformat, width, height, depth, 5374 contextGL()->TexImage3D(target, level, internalformat, width, height, depth,
5344 0, format, type, 5375 0, format, type,
5345 needConversion ? data.data() : pixelDataPtr); 5376 needConversion ? data.data() : pixelDataPtr);
5346 } else { 5377 } else {
5347 DCHECK_EQ(functionID, TexSubImage3D); 5378 DCHECK_EQ(functionID, TexSubImage3D);
5348 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, width, 5379 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset, width,
5349 height, depth, format, type, 5380 height, depth, format, type,
5350 needConversion ? data.data() : pixelDataPtr); 5381 needConversion ? data.data() : pixelDataPtr);
5351 } 5382 }
5352 restoreUnpackParameters();
5353 } 5383 }
5354 5384
5355 void WebGLRenderingContextBase::texImage2D(GLenum target, 5385 void WebGLRenderingContextBase::texImage2D(GLenum target,
5356 GLint level, 5386 GLint level,
5357 GLint internalformat, 5387 GLint internalformat,
5358 GLenum format, 5388 GLenum format,
5359 GLenum type, 5389 GLenum type,
5360 ImageBitmap* bitmap, 5390 ImageBitmap* bitmap,
5361 ExceptionState& exceptionState) { 5391 ExceptionState& exceptionState) {
5362 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format, 5392 texImageHelperImageBitmap(TexImage2D, target, level, internalformat, format,
(...skipping 2398 matching lines...) Expand 10 before | Expand all | Expand 10 after
7761 7791
7762 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7792 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7763 HTMLCanvasElementOrOffscreenCanvas& result) const { 7793 HTMLCanvasElementOrOffscreenCanvas& result) const {
7764 if (canvas()) 7794 if (canvas())
7765 result.setHTMLCanvasElement(canvas()); 7795 result.setHTMLCanvasElement(canvas());
7766 else 7796 else
7767 result.setOffscreenCanvas(getOffscreenCanvas()); 7797 result.setOffscreenCanvas(getOffscreenCanvas());
7768 } 7798 }
7769 7799
7770 } // namespace blink 7800 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698