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

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

Issue 2500433003: support 3d texture sub-source uploads from ImageData (Closed)
Patch Set: use unpackImageHeight correctly and add/deduplicate validation Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4348 matching lines...) Expand 10 before | Expand all | Expand 10 after
4359 } 4359 }
4360 Vector<uint8_t> data; 4360 Vector<uint8_t> data;
4361 4361
4362 IntRect subRect = sourceImageRect; 4362 IntRect subRect = sourceImageRect;
4363 if (subRect == sentinelEmptyRect()) { 4363 if (subRect == sentinelEmptyRect()) {
4364 // Recalculate based on the size of the Image. 4364 // Recalculate based on the size of the Image.
4365 subRect = safeGetImageSize(image); 4365 subRect = safeGetImageSize(image);
4366 } 4366 }
4367 4367
4368 bool selectingSubRectangle = false; 4368 bool selectingSubRectangle = false;
4369 if (!validateTexImageSubRectangle(funcName, image, subRect, 4369 if (!validateTexImageSubRectangle(funcName, functionID, image, subRect, depth,
4370 unpackImageHeight,
4370 &selectingSubRectangle)) { 4371 &selectingSubRectangle)) {
4371 return; 4372 return;
4372 } 4373 }
4373 4374
4374 if (functionID == TexImage3D || functionID == TexSubImage3D) {
4375 DCHECK_GE(unpackImageHeight, 0);
4376
4377 // Verify that the image data can cover the required depth.
4378 CheckedNumeric<GLint> maxDepthSupported = 1;
4379 if (unpackImageHeight) {
4380 maxDepthSupported = subRect.height();
4381 maxDepthSupported /= unpackImageHeight;
4382 }
4383
4384 if (!maxDepthSupported.IsValid() ||
4385 maxDepthSupported.ValueOrDie() < depth) {
4386 synthesizeGLError(
4387 GL_INVALID_OPERATION, funcName,
4388 "Not enough data supplied to upload to a 3D texture with depth > 1");
4389 return;
4390 }
4391 } else {
4392 DCHECK_EQ(depth, 1);
4393 DCHECK_EQ(unpackImageHeight, 0);
4394 }
4395
4396 // Adjust the source image rectangle if doing a y-flip. 4375 // Adjust the source image rectangle if doing a y-flip.
4397 IntRect adjustedSourceImageRect = subRect; 4376 IntRect adjustedSourceImageRect = subRect;
4398 if (flipY) { 4377 if (flipY) {
4399 adjustedSourceImageRect.setY(image->height() - 4378 adjustedSourceImageRect.setY(image->height() -
4400 adjustedSourceImageRect.maxY()); 4379 adjustedSourceImageRect.maxY());
4401 } 4380 }
4402 4381
4403 WebGLImageConversion::ImageExtractor imageExtractor( 4382 WebGLImageConversion::ImageExtractor imageExtractor(
4404 image, domSource, premultiplyAlpha, 4383 image, domSource, premultiplyAlpha,
4405 m_unpackColorspaceConversion == GL_NONE); 4384 m_unpackColorspaceConversion == GL_NONE);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
4699 GLint level, 4678 GLint level,
4700 GLint internalformat, 4679 GLint internalformat,
4701 GLint border, 4680 GLint border,
4702 GLenum format, 4681 GLenum format,
4703 GLenum type, 4682 GLenum type,
4704 GLsizei depth, 4683 GLsizei depth,
4705 GLint xoffset, 4684 GLint xoffset,
4706 GLint yoffset, 4685 GLint yoffset,
4707 GLint zoffset, 4686 GLint zoffset,
4708 ImageData* pixels, 4687 ImageData* pixels,
4709 const IntRect& sourceImageRect) { 4688 const IntRect& sourceImageRect,
4689 GLint unpackImageHeight) {
4710 const char* funcName = getTexImageFunctionName(functionID); 4690 const char* funcName = getTexImageFunctionName(functionID);
4711 if (isContextLost()) 4691 if (isContextLost())
4712 return; 4692 return;
4713 DCHECK(pixels); 4693 DCHECK(pixels);
4714 if (pixels->data()->bufferBase()->isNeutered()) { 4694 if (pixels->data()->bufferBase()->isNeutered()) {
4715 synthesizeGLError(GL_INVALID_VALUE, funcName, 4695 synthesizeGLError(GL_INVALID_VALUE, funcName,
4716 "The source data has been neutered."); 4696 "The source data has been neutered.");
4717 return; 4697 return;
4718 } 4698 }
4719 if (!validateTexImageBinding(funcName, functionID, target)) 4699 if (!validateTexImageBinding(funcName, functionID, target))
4720 return; 4700 return;
4721 TexImageFunctionType functionType; 4701 TexImageFunctionType functionType;
4722 if (functionID == TexImage2D) 4702 if (functionID == TexImage2D)
4723 functionType = TexImage; 4703 functionType = TexImage;
4724 else 4704 else
4725 functionType = TexSubImage; 4705 functionType = TexSubImage;
4726 if (!validateTexFunc(funcName, functionType, SourceImageData, target, level, 4706 if (!validateTexFunc(funcName, functionType, SourceImageData, target, level,
4727 internalformat, pixels->width(), pixels->height(), depth, 4707 internalformat, pixels->width(), pixels->height(), depth,
4728 border, format, type, xoffset, yoffset, zoffset)) 4708 border, format, type, xoffset, yoffset, zoffset))
4729 return; 4709 return;
4730 4710
4731 bool selectingSubRectangle = false; 4711 bool selectingSubRectangle = false;
4732 if (!validateTexImageSubRectangle(funcName, pixels, sourceImageRect, 4712 if (!validateTexImageSubRectangle(funcName, functionID, pixels,
4713 sourceImageRect, depth, unpackImageHeight,
4733 &selectingSubRectangle)) { 4714 &selectingSubRectangle)) {
4734 return; 4715 return;
4735 } 4716 }
4736 // Adjust the source image rectangle if doing a y-flip. 4717 // Adjust the source image rectangle if doing a y-flip.
4737 IntRect adjustedSourceImageRect = sourceImageRect; 4718 IntRect adjustedSourceImageRect = sourceImageRect;
4738 if (m_unpackFlipY) { 4719 if (m_unpackFlipY) {
4739 adjustedSourceImageRect.setY(pixels->height() - 4720 adjustedSourceImageRect.setY(pixels->height() -
4740 adjustedSourceImageRect.maxY()); 4721 adjustedSourceImageRect.maxY());
4741 } 4722 }
4742 4723
(...skipping 13 matching lines...) Expand all
4756 if (!WebGLImageConversion::extractImageData( 4737 if (!WebGLImageConversion::extractImageData(
4757 pixels->data()->data(), 4738 pixels->data()->data(),
4758 WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(), 4739 WebGLImageConversion::DataFormat::DataFormatRGBA8, pixels->size(),
4759 adjustedSourceImageRect, format, type, m_unpackFlipY, 4740 adjustedSourceImageRect, format, type, m_unpackFlipY,
4760 m_unpackPremultiplyAlpha, data)) { 4741 m_unpackPremultiplyAlpha, data)) {
4761 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data"); 4742 synthesizeGLError(GL_INVALID_VALUE, funcName, "bad image data");
4762 return; 4743 return;
4763 } 4744 }
4764 } 4745 }
4765 resetUnpackParameters(); 4746 resetUnpackParameters();
4747 GLint uploadWidth = adjustedSourceImageRect.width();
4748 GLint uploadHeight = adjustedSourceImageRect.height();
4749 if (unpackImageHeight) {
4750 // GL_UNPACK_IMAGE_HEIGHT overrides the passed-in height.
4751 uploadHeight = unpackImageHeight;
4752 }
Ken Russell (switch to Gerrit) 2016/11/14 20:12:30 This should only be used for the 3D upload path. T
Kai Ninomiya 2016/11/14 21:23:17 Done.
4753 const uint8_t* bytes = needConversion ? data.data() : pixels->data()->data();
4766 if (functionID == TexImage2D) { 4754 if (functionID == TexImage2D) {
4767 texImage2DBase(target, level, internalformat, 4755 texImage2DBase(
4768 adjustedSourceImageRect.width(), 4756 target, level, internalformat, adjustedSourceImageRect.width(),
4769 adjustedSourceImageRect.height(), border, format, type, 4757 adjustedSourceImageRect.height(), border, format, type, bytes);
4770 needConversion ? data.data() : pixels->data()->data());
4771 } else if (functionID == TexSubImage2D) { 4758 } else if (functionID == TexSubImage2D) {
4772 contextGL()->TexSubImage2D( 4759 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, uploadWidth,
4773 target, level, xoffset, yoffset, adjustedSourceImageRect.width(), 4760 uploadHeight, format, type, bytes);
Ken Russell (switch to Gerrit) 2016/11/14 20:12:30 The 2D upload path shouldn't take into considerati
Kai Ninomiya 2016/11/14 21:23:17 Done.
4774 adjustedSourceImageRect.height(), format, type, 4761 } else if (functionID == TexImage3D) {
4775 needConversion ? data.data() : pixels->data()->data()); 4762 contextGL()->TexImage3D(target, level, internalformat, uploadWidth,
4763 uploadHeight, depth, border, format, type, bytes);
4776 } else { 4764 } else {
4777 DCHECK_EQ(functionID, TexSubImage3D); 4765 DCHECK_EQ(functionID, TexSubImage3D);
4778 contextGL()->TexSubImage3D( 4766 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset,
4779 target, level, xoffset, yoffset, zoffset, 4767 uploadWidth, uploadHeight, depth, format, type,
4780 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), 4768 bytes);
4781 depth, format, type,
4782 needConversion ? data.data() : pixels->data()->data());
4783 } 4769 }
4784 restoreUnpackParameters(); 4770 restoreUnpackParameters();
4785 } 4771 }
4786 4772
4787 void WebGLRenderingContextBase::texImage2D(GLenum target, 4773 void WebGLRenderingContextBase::texImage2D(GLenum target,
4788 GLint level, 4774 GLint level,
4789 GLint internalformat, 4775 GLint internalformat,
4790 GLenum format, 4776 GLenum format,
4791 GLenum type, 4777 GLenum type,
4792 ImageData* pixels) { 4778 ImageData* pixels) {
4793 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format, 4779 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format,
4794 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels)); 4780 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels),
4781 0);
4795 } 4782 }
4796 4783
4797 void WebGLRenderingContextBase::texImageHelperHTMLImageElement( 4784 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(
4798 TexImageFunctionID functionID, 4785 TexImageFunctionID functionID,
4799 GLenum target, 4786 GLenum target,
4800 GLint level, 4787 GLint level,
4801 GLint internalformat, 4788 GLint internalformat,
4802 GLenum format, 4789 GLenum format,
4803 GLenum type, 4790 GLenum type,
4804 GLint xoffset, 4791 GLint xoffset,
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
5385 } 5372 }
5386 5373
5387 void WebGLRenderingContextBase::texSubImage2D(GLenum target, 5374 void WebGLRenderingContextBase::texSubImage2D(GLenum target,
5388 GLint level, 5375 GLint level,
5389 GLint xoffset, 5376 GLint xoffset,
5390 GLint yoffset, 5377 GLint yoffset,
5391 GLenum format, 5378 GLenum format,
5392 GLenum type, 5379 GLenum type,
5393 ImageData* pixels) { 5380 ImageData* pixels) {
5394 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1, 5381 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1,
5395 xoffset, yoffset, 0, pixels, 5382 xoffset, yoffset, 0, pixels, getImageDataSize(pixels),
5396 getImageDataSize(pixels)); 5383 0);
5397 } 5384 }
5398 5385
5399 void WebGLRenderingContextBase::texSubImage2D(GLenum target, 5386 void WebGLRenderingContextBase::texSubImage2D(GLenum target,
5400 GLint level, 5387 GLint level,
5401 GLint xoffset, 5388 GLint xoffset,
5402 GLint yoffset, 5389 GLint yoffset,
5403 GLenum format, 5390 GLenum format,
5404 GLenum type, 5391 GLenum type,
5405 HTMLImageElement* image, 5392 HTMLImageElement* image,
5406 ExceptionState& exceptionState) { 5393 ExceptionState& exceptionState) {
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after
7668 7655
7669 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7656 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7670 HTMLCanvasElementOrOffscreenCanvas& result) const { 7657 HTMLCanvasElementOrOffscreenCanvas& result) const {
7671 if (canvas()) 7658 if (canvas())
7672 result.setHTMLCanvasElement(canvas()); 7659 result.setHTMLCanvasElement(canvas());
7673 else 7660 else
7674 result.setOffscreenCanvas(getOffscreenCanvas()); 7661 result.setOffscreenCanvas(getOffscreenCanvas());
7675 } 7662 }
7676 7663
7677 } // namespace blink 7664 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698