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

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

Issue 1300573002: WebGL 2: add readPixels API to read pixels into pixel pack buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code refactoring to fix bugs in conformance test Created 5 years, 3 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 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 case GL_DYNAMIC_DRAW: 1575 case GL_DYNAMIC_DRAW:
1576 break; 1576 break;
1577 default: 1577 default:
1578 synthesizeGLError(GL_INVALID_ENUM, "bufferData", "invalid usage"); 1578 synthesizeGLError(GL_INVALID_ENUM, "bufferData", "invalid usage");
1579 return; 1579 return;
1580 } 1580 }
1581 1581
1582 if (!validateValueFitNonNegInt32("bufferData", "size", size)) 1582 if (!validateValueFitNonNegInt32("bufferData", "size", size))
1583 return; 1583 return;
1584 1584
1585 buffer->setSize(size);
1586
1585 webContext()->bufferData(target, static_cast<GLsizeiptr>(size), data, usage) ; 1587 webContext()->bufferData(target, static_cast<GLsizeiptr>(size), data, usage) ;
1586 } 1588 }
1587 1589
1588 void WebGLRenderingContextBase::bufferData(GLenum target, long long size, GLenum usage) 1590 void WebGLRenderingContextBase::bufferData(GLenum target, long long size, GLenum usage)
1589 { 1591 {
1590 if (isContextLost()) 1592 if (isContextLost())
1591 return; 1593 return;
1592 if (!size) { 1594 if (!size) {
1593 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0"); 1595 synthesizeGLError(GL_INVALID_VALUE, "bufferData", "size == 0");
1594 return; 1596 return;
(...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after
3671 case GL_FLOAT: 3673 case GL_FLOAT:
3672 return DOMArrayBufferView::TypeFloat32; 3674 return DOMArrayBufferView::TypeFloat32;
3673 case GL_HALF_FLOAT_OES: 3675 case GL_HALF_FLOAT_OES:
3674 return DOMArrayBufferView::TypeUint16; 3676 return DOMArrayBufferView::TypeUint16;
3675 default: 3677 default:
3676 ASSERT_NOT_REACHED(); 3678 ASSERT_NOT_REACHED();
3677 return DOMArrayBufferView::TypeUint8; 3679 return DOMArrayBufferView::TypeUint8;
3678 } 3680 }
3679 } 3681 }
3680 3682
3683 bool WebGLRenderingContextBase::validateReadPixelsFuncParameters(GLsizei width, GLsizei height, GLenum format, GLenum type, long long bufferSize)
3684 {
3685 if (!validateReadPixelsFormatAndType(format, type))
3686 return false;
3687 WebGLFramebuffer* readFramebufferBinding = nullptr;
3688 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3689 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3690 return false;
3691 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3692 return false;
3693
3694 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3695 unsigned totalBytesRequired = 0;
3696 unsigned padding = 0;
3697 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
3698 if (error != GL_NO_ERROR) {
3699 synthesizeGLError(error, "readPixels", "invalid dimensions");
3700 return false;
3701 }
3702 if (bufferSize < static_cast<long long>(totalBytesRequired)) {
3703 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "buffer is not lar ge enough for dimensions");
3704 return false;
3705 }
3706 return true;
3707 }
3708
3681 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels) 3709 void WebGLRenderingContextBase::readPixels(GLint x, GLint y, GLsizei width, GLsi zei height, GLenum format, GLenum type, DOMArrayBufferView* pixels)
3682 { 3710 {
3683 if (isContextLost()) 3711 if (isContextLost())
3684 return; 3712 return;
3685 // Due to WebGL's same-origin restrictions, it is not possible to 3713 // Due to WebGL's same-origin restrictions, it is not possible to
3686 // taint the origin using the WebGL API. 3714 // taint the origin using the WebGL API.
3687 ASSERT(canvas()->originClean()); 3715 ASSERT(canvas()->originClean());
3688 // Validate input parameters. 3716 // Validate input parameters.
3689 if (!pixels) { 3717 if (!pixels) {
3690 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView"); 3718 synthesizeGLError(GL_INVALID_VALUE, "readPixels", "no destination ArrayB ufferView");
3691 return; 3719 return;
3692 } 3720 }
3693 if (!validateReadPixelsFormatAndType(format, type)) 3721
3694 return; 3722 if (!validateReadPixelsFuncParameters(width, height, format, type, static_ca st<long long>(pixels->byteLength())))
3695 GLenum readBufferInternalFormat = 0, readBufferType = 0;
3696 WebGLFramebuffer* readFramebufferBinding = nullptr;
3697 if (!validateReadBufferAndGetInfo("readPixels", readFramebufferBinding, &rea dBufferInternalFormat, &readBufferType))
3698 return;
3699 if (!validateReadPixelsFormatTypeCombination(format, type, readBufferInterna lFormat, readBufferType))
3700 return; 3723 return;
3701 3724
3702 DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBuffe rViewType(type); 3725 DOMArrayBufferView::ViewType expectedViewType = readPixelsExpectedArrayBuffe rViewType(type);
3703 // Validate array type against pixel type. 3726 // Validate array type against pixel type.
3704 if (pixels->type() != expectedViewType) { 3727 if (pixels->type() != expectedViewType) {
3705 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format"); 3728 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView w as the wrong type for the pixel format");
3706 return; 3729 return;
3707 } 3730 }
3708 3731
3709 // Calculate array size, taking into consideration of PACK_ALIGNMENT.
3710 unsigned totalBytesRequired = 0;
3711 unsigned padding = 0;
3712 GLenum error = WebGLImageConversion::computeImageSizeInBytes(format, type, w idth, height, m_packAlignment, &totalBytesRequired, &padding);
3713 if (error != GL_NO_ERROR) {
3714 synthesizeGLError(error, "readPixels", "invalid dimensions");
3715 return;
3716 }
3717 if (pixels->byteLength() < totalBytesRequired) {
3718 synthesizeGLError(GL_INVALID_OPERATION, "readPixels", "ArrayBufferView n ot large enough for dimensions");
3719 return;
3720 }
3721
3722 clearIfComposited(); 3732 clearIfComposited();
3723 void* data = pixels->baseAddress(); 3733 void* data = pixels->baseAddress();
3724 3734
3735 GLenum target = isWebGL2OrHigher() ? GL_READ_FRAMEBUFFER : GL_FRAMEBUFFER;
3736 WebGLFramebuffer* readFramebufferBinding = getFramebufferBinding(target);
3725 { 3737 {
3726 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding ); 3738 ScopedDrawingBufferBinder binder(drawingBuffer(), readFramebufferBinding );
3727 webContext()->readPixels(x, y, width, height, format, type, data); 3739 webContext()->readPixels(x, y, width, height, format, type, data);
3728 } 3740 }
3729 } 3741 }
3730 3742
3731 void WebGLRenderingContextBase::renderbufferStorageImpl( 3743 void WebGLRenderingContextBase::renderbufferStorageImpl(
3732 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height, 3744 GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsize i height,
3733 const char* functionName) 3745 const char* functionName)
3734 { 3746 {
(...skipping 2948 matching lines...) Expand 10 before | Expand all | Expand 10 after
6683 6695
6684 return totalBytesPerPixel; 6696 return totalBytesPerPixel;
6685 } 6697 }
6686 6698
6687 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6699 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6688 { 6700 {
6689 return m_drawingBuffer.get(); 6701 return m_drawingBuffer.get();
6690 } 6702 }
6691 6703
6692 } // namespace blink 6704 } // 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