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

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: To make the code snippet clearer, override the part of getting ArrayBuffer ViewType in readPixels f… 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
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 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 3712 DOMArrayBufferView::ViewType WebGLRenderingContextBase::readPixelsExpectedArrayB ufferViewType(GLenum type)
3713 { 3713 {
3714 if (isContextLost())
3715 return;
3716 // Due to WebGL's same-origin restrictions, it is not possible to
3717 // taint the origin using the WebGL API.
3718 ASSERT(canvas()->originClean());
3719 // Validate input parameters.
3720 if (!pixels) {
3721 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView");
3722 return;
3723 }
3724 if (!validateReadPixelsFormatAndType(format, type))
3725 return;
3726 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3727 WebGLFramebuffer* readFramebufferBinding = nullptr;
3728 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3729 return;
3730 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3731 return;
3732
3733 DOMArrayBufferView::ViewType expectedViewType; 3714 DOMArrayBufferView::ViewType expectedViewType;
Zhenyao Mo 2015/08/14 16:07:42 nit: you don't need this expectedViewType. You ca
3734 switch (type) { 3715 switch (type) {
3735 case GL_UNSIGNED_BYTE: 3716 case GL_UNSIGNED_BYTE:
3736 expectedViewType = DOMArrayBufferView::TypeUint8; 3717 expectedViewType = DOMArrayBufferView::TypeUint8;
3737 break; 3718 break;
3738 case GL_BYTE:
3739 expectedViewType = DOMArrayBufferView::TypeInt8;
3740 break;
3741 case GL_UNSIGNED_SHORT_5_6_5: 3719 case GL_UNSIGNED_SHORT_5_6_5:
3742 case GL_UNSIGNED_SHORT_4_4_4_4: 3720 case GL_UNSIGNED_SHORT_4_4_4_4:
3743 case GL_UNSIGNED_SHORT_5_5_5_1: 3721 case GL_UNSIGNED_SHORT_5_5_5_1:
3744 expectedViewType = DOMArrayBufferView::TypeUint16; 3722 expectedViewType = DOMArrayBufferView::TypeUint16;
3745 break; 3723 break;
3746 case GL_FLOAT: 3724 case GL_FLOAT:
3747 expectedViewType = DOMArrayBufferView::TypeFloat32; 3725 expectedViewType = DOMArrayBufferView::TypeFloat32;
3748 break; 3726 break;
3749 case GL_HALF_FLOAT:
3750 case GL_HALF_FLOAT_OES: 3727 case GL_HALF_FLOAT_OES:
3751 expectedViewType = DOMArrayBufferView::TypeUint16; 3728 expectedViewType = DOMArrayBufferView::TypeUint16;
3752 break; 3729 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: 3730 default:
3763 ASSERT_NOT_REACHED(); 3731 ASSERT_NOT_REACHED();
3764 expectedViewType = DOMArrayBufferView::TypeUint8; 3732 expectedViewType = DOMArrayBufferView::TypeUint8;
3765 break; 3733 break;
3766 } 3734 }
3735 return expectedViewType;
3736 }
3737
3738 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
3739 {
3740 if (isContextLost())
3741 return;
3742 // Due to WebGL's same-origin restrictions, it is not possible to
3743 // taint the origin using the WebGL API.
3744 ASSERT(canvas()->originClean());
3745 // Validate input parameters.
3746 if (!pixels) {
3747 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView");
3748 return;
3749 }
3750 if (!validateReadPixelsFormatAndType(format, type))
3751 return;
3752 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3753 WebGLFramebuffer* readFramebufferBinding = nullptr;
3754 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3755 return;
3756 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3757 return;
3758
3759 DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBuffe rViewType(type);
3767 // Validate array type against pixel type. 3760 // Validate array type against pixel type.
3768 if (pixels->type() != expectedViewType) { 3761 if (pixels->type() != expectedViewType) {
3769 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format"); 3762 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format");
3770 return; 3763 return;
3771 } 3764 }
3772 3765
3773 // Calculate array size, taking into consideration of PACK_ALIGNMENT. 3766 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3774 unsigned totalBytesRequired = 0; 3767 unsigned totalBytesRequired = 0;
3775 unsigned padding = 0; 3768 unsigned padding = 0;
3776 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding); 3769 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 6634
6642 return totalBytesPerPixel; 6635 return totalBytesPerPixel;
6643 } 6636 }
6644 6637
6645 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6638 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6646 { 6639 {
6647 return m_drawingBuffer.get(); 6640 return m_drawingBuffer.get();
6648 } 6641 }
6649 6642
6650 } // namespace blink 6643 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698