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

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

Issue 1288303002: WebGL 2: add types into glReadPixels (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: nits Created 5 years, 4 months 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 | « 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 3691 matching lines...) Expand 10 before | Expand all | Expand 10 after
3702 webContext()->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &implForm at); 3702 webContext()->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &implForm at);
3703 webContext()->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &implType); 3703 webContext()->getIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &implType);
3704 if (!implFormat || !implType || format != static_cast<GLenum>(implFormat ) || type != static_cast<GLenum>(implType)) { 3704 if (!implFormat || !implType || format != static_cast<GLenum>(implFormat ) || type != static_cast<GLenum>(implType)) {
3705 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "invalid forma t/type combination"); 3705 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "invalid forma t/type combination");
3706 return false; 3706 return false;
3707 } 3707 }
3708 } 3708 }
3709 return true; 3709 return true;
3710 } 3710 }
3711 3711
3712 DOMArrayBufferView::ViewType WebGLRenderingContextBase::readPixelsExpectedArrayB ufferViewType(GLenum type)
3713 {
3714 switch (type) {
3715 case GL_UNSIGNED_BYTE:
3716 return DOMArrayBufferView::TypeUint8;
3717 case GL_UNSIGNED_SHORT_5_6_5:
3718 case GL_UNSIGNED_SHORT_4_4_4_4:
3719 case GL_UNSIGNED_SHORT_5_5_5_1:
3720 return DOMArrayBufferView::TypeUint16;
3721 case GL_FLOAT:
3722 return DOMArrayBufferView::TypeFloat32;
3723 case GL_HALF_FLOAT_OES:
3724 return DOMArrayBufferView::TypeUint16;
3725 default:
3726 ASSERT_NOT_REACHED();
3727 return DOMArrayBufferView::TypeUint8;
3728 }
3729 }
3730
3712 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 3731 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
3713 { 3732 {
3714 if (isContextLost()) 3733 if (isContextLost())
3715 return; 3734 return;
3716 // Due to WebGL's same-origin restrictions, it is not possible to 3735 // Due to WebGL's same-origin restrictions, it is not possible to
3717 // taint the origin using the WebGL API. 3736 // taint the origin using the WebGL API.
3718 ASSERT(canvas()->originClean()); 3737 ASSERT(canvas()->originClean());
3719 // Validate input parameters. 3738 // Validate input parameters.
3720 if (!pixels) { 3739 if (!pixels) {
3721 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView"); 3740 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView");
3722 return; 3741 return;
3723 } 3742 }
3724 if (!validateReadPixelsFormatAndType(format, type)) 3743 if (!validateReadPixelsFormatAndType(format, type))
3725 return; 3744 return;
3726 GLenum readBufferInternalFormat = 0, readBufferType = 0; 3745 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3727 WebGLFramebuffer* readFramebufferBinding = nullptr; 3746 WebGLFramebuffer* readFramebufferBinding = nullptr;
3728 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType)) 3747 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3729 return; 3748 return;
3730 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType)) 3749 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3731 return; 3750 return;
3732 3751
3733 DOMArrayBufferView::ViewType expectedViewType; 3752 DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBuffe rViewType(type);
3734 switch (type) {
3735 case GL_UNSIGNED_BYTE:
3736 expectedViewType = DOMArrayBufferView::TypeUint8;
3737 break;
3738 case GL_BYTE:
3739 expectedViewType = DOMArrayBufferView::TypeInt8;
3740 break;
3741 case GL_UNSIGNED_SHORT_5_6_5:
3742 case GL_UNSIGNED_SHORT_4_4_4_4:
3743 case GL_UNSIGNED_SHORT_5_5_5_1:
3744 expectedViewType = DOMArrayBufferView::TypeUint16;
3745 break;
3746 case GL_FLOAT:
3747 expectedViewType = DOMArrayBufferView::TypeFloat32;
3748 break;
3749 case GL_HALF_FLOAT:
3750 case GL_HALF_FLOAT_OES:
3751 expectedViewType = DOMArrayBufferView::TypeUint16;
3752 break;
3753 case GL_UNSIGNED_INT:
3754 case GL_UNSIGNED_INT_2_10_10_10_REV:
3755 case GL_UNSIGNED_INT_10F_11F_11F_REV:
3756 case GL_UNSIGNED_INT_5_9_9_9_REV:
3757 expectedViewType = DOMArrayBufferView::TypeUint32;
3758 break;
3759 case GL_INT:
3760 expectedViewType = DOMArrayBufferView::TypeInt32;
3761 break;
3762 default:
3763 ASSERT_NOT_REACHED();
3764 expectedViewType = DOMArrayBufferView::TypeUint8;
3765 break;
3766 }
3767 // Validate array type against pixel type. 3753 // Validate array type against pixel type.
3768 if (pixels->type() != expectedViewType) { 3754 if (pixels->type() != expectedViewType) {
3769 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format"); 3755 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format");
3770 return; 3756 return;
3771 } 3757 }
3772 3758
3773 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3759 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3774 unsigned totalBytesRequired = 0; 3760 unsigned totalBytesRequired = 0;
3775 unsigned padding = 0; 3761 unsigned padding = 0;
3776 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); 3762 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
(...skipping 2864 matching lines...) Expand 10 before | Expand all | Expand 10 after
6641 6627
6642 return totalBytesPerPixel; 6628 return totalBytesPerPixel;
6643 } 6629 }
6644 6630
6645 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6631 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6646 { 6632 {
6647 return m_drawingBuffer.get(); 6633 return m_drawingBuffer.get();
6648 } 6634 }
6649 6635
6650 } // namespace blink 6636 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/webgl/WebGLRenderingContextBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698