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

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: address comments + roll webgl (+ rebase) 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 || functionID == TexImage3D)
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();
Ken Russell (switch to Gerrit) 2016/11/14 21:27:38 Could you please just put these two definitions in
4749 const uint8_t* bytes = needConversion ? data.data() : pixels->data()->data();
4766 if (functionID == TexImage2D) { 4750 if (functionID == TexImage2D) {
4767 texImage2DBase(target, level, internalformat, 4751 DCHECK_EQ(unpackImageHeight, 0);
4768 adjustedSourceImageRect.width(), 4752 texImage2DBase(
4769 adjustedSourceImageRect.height(), border, format, type, 4753 target, level, internalformat, adjustedSourceImageRect.width(),
4770 needConversion ? data.data() : pixels->data()->data()); 4754 adjustedSourceImageRect.height(), border, format, type, bytes);
4771 } else if (functionID == TexSubImage2D) { 4755 } else if (functionID == TexSubImage2D) {
4772 contextGL()->TexSubImage2D( 4756 DCHECK_EQ(unpackImageHeight, 0);
4773 target, level, xoffset, yoffset, adjustedSourceImageRect.width(), 4757 contextGL()->TexSubImage2D(target, level, xoffset, yoffset, uploadWidth,
4774 adjustedSourceImageRect.height(), format, type, 4758 uploadHeight, format, type, bytes);
4775 needConversion ? data.data() : pixels->data()->data());
4776 } else { 4759 } else {
4777 DCHECK_EQ(functionID, TexSubImage3D); 4760 if (unpackImageHeight) {
4778 contextGL()->TexSubImage3D( 4761 // GL_UNPACK_IMAGE_HEIGHT overrides the passed-in height.
4779 target, level, xoffset, yoffset, zoffset, 4762 uploadHeight = unpackImageHeight;
4780 adjustedSourceImageRect.width(), adjustedSourceImageRect.height(), 4763 }
4781 depth, format, type, 4764 if (functionID == TexImage3D) {
4782 needConversion ? data.data() : pixels->data()->data()); 4765 contextGL()->TexImage3D(target, level, internalformat, uploadWidth,
4766 uploadHeight, depth, border, format, type, bytes);
4767 } else {
4768 DCHECK_EQ(functionID, TexSubImage3D);
4769 contextGL()->TexSubImage3D(target, level, xoffset, yoffset, zoffset,
4770 uploadWidth, uploadHeight, depth, format, type,
4771 bytes);
4772 }
4783 } 4773 }
4784 restoreUnpackParameters(); 4774 restoreUnpackParameters();
4785 } 4775 }
4786 4776
4787 void WebGLRenderingContextBase::texImage2D(GLenum target, 4777 void WebGLRenderingContextBase::texImage2D(GLenum target,
4788 GLint level, 4778 GLint level,
4789 GLint internalformat, 4779 GLint internalformat,
4790 GLenum format, 4780 GLenum format,
4791 GLenum type, 4781 GLenum type,
4792 ImageData* pixels) { 4782 ImageData* pixels) {
4793 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format, 4783 texImageHelperImageData(TexImage2D, target, level, internalformat, 0, format,
4794 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels)); 4784 type, 1, 0, 0, 0, pixels, getImageDataSize(pixels),
4785 0);
4795 } 4786 }
4796 4787
4797 void WebGLRenderingContextBase::texImageHelperHTMLImageElement( 4788 void WebGLRenderingContextBase::texImageHelperHTMLImageElement(
4798 TexImageFunctionID functionID, 4789 TexImageFunctionID functionID,
4799 GLenum target, 4790 GLenum target,
4800 GLint level, 4791 GLint level,
4801 GLint internalformat, 4792 GLint internalformat,
4802 GLenum format, 4793 GLenum format,
4803 GLenum type, 4794 GLenum type,
4804 GLint xoffset, 4795 GLint xoffset,
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
5385 } 5376 }
5386 5377
5387 void WebGLRenderingContextBase::texSubImage2D(GLenum target, 5378 void WebGLRenderingContextBase::texSubImage2D(GLenum target,
5388 GLint level, 5379 GLint level,
5389 GLint xoffset, 5380 GLint xoffset,
5390 GLint yoffset, 5381 GLint yoffset,
5391 GLenum format, 5382 GLenum format,
5392 GLenum type, 5383 GLenum type,
5393 ImageData* pixels) { 5384 ImageData* pixels) {
5394 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1, 5385 texImageHelperImageData(TexSubImage2D, target, level, 0, 0, format, type, 1,
5395 xoffset, yoffset, 0, pixels, 5386 xoffset, yoffset, 0, pixels, getImageDataSize(pixels),
5396 getImageDataSize(pixels)); 5387 0);
5397 } 5388 }
5398 5389
5399 void WebGLRenderingContextBase::texSubImage2D(GLenum target, 5390 void WebGLRenderingContextBase::texSubImage2D(GLenum target,
5400 GLint level, 5391 GLint level,
5401 GLint xoffset, 5392 GLint xoffset,
5402 GLint yoffset, 5393 GLint yoffset,
5403 GLenum format, 5394 GLenum format,
5404 GLenum type, 5395 GLenum type,
5405 HTMLImageElement* image, 5396 HTMLImageElement* image,
5406 ExceptionState& exceptionState) { 5397 ExceptionState& exceptionState) {
(...skipping 2261 matching lines...) Expand 10 before | Expand all | Expand 10 after
7668 7659
7669 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7660 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7670 HTMLCanvasElementOrOffscreenCanvas& result) const { 7661 HTMLCanvasElementOrOffscreenCanvas& result) const {
7671 if (canvas()) 7662 if (canvas())
7672 result.setHTMLCanvasElement(canvas()); 7663 result.setHTMLCanvasElement(canvas());
7673 else 7664 else
7674 result.setOffscreenCanvas(getOffscreenCanvas()); 7665 result.setOffscreenCanvas(getOffscreenCanvas());
7675 } 7666 }
7676 7667
7677 } // namespace blink 7668 } // 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