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

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

Issue 1361043003: Revert of Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if (position != WTF::kNotFound) 196 if (position != WTF::kNotFound)
197 forciblyEvictedContexts().remove(position); 197 forciblyEvictedContexts().remove(position);
198 } 198 }
199 199
200 void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co ntext) 200 void WebGLRenderingContextBase::willDestroyContext(WebGLRenderingContextBase* co ntext)
201 { 201 {
202 removeFromEvictedList(context); 202 removeFromEvictedList(context);
203 deactivateContext(context); 203 deactivateContext(context);
204 204
205 // Try to re-enable the oldest inactive contexts. 205 // Try to re-enable the oldest inactive contexts.
206 while (activeContexts().size() < maxGLActiveContexts && forciblyEvictedConte xts().size()) { 206 while(activeContexts().size() < maxGLActiveContexts && forciblyEvictedContex ts().size()) {
207 WebGLRenderingContextBase* evictedContext = forciblyEvictedContexts().fi rst(); 207 WebGLRenderingContextBase* evictedContext = forciblyEvictedContexts().fi rst();
208 if (!evictedContext->m_restoreAllowed) { 208 if (!evictedContext->m_restoreAllowed) {
209 forciblyEvictedContexts().remove(0); 209 forciblyEvictedContexts().remove(0);
210 continue; 210 continue;
211 } 211 }
212 212
213 IntSize desiredSize = DrawingBuffer::adjustSize(evictedContext->clampedC anvasSize(), IntSize(), evictedContext->m_maxTextureSize); 213 IntSize desiredSize = DrawingBuffer::adjustSize(evictedContext->clampedC anvasSize(), IntSize(), evictedContext->m_maxTextureSize);
214 214
215 // If there's room in the pixel budget for this context, restore it. 215 // If there's room in the pixel budget for this context, restore it.
216 if (!desiredSize.isEmpty()) { 216 if (!desiredSize.isEmpty()) {
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 { GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT }, 859 { GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT },
860 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT }, 860 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT },
861 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, 861 { GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT },
862 { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT }, 862 { GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT },
863 { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT }, 863 { GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT },
864 { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 }, 864 { GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 },
865 }; 865 };
866 866
867 } // namespace anonymous 867 } // namespace anonymous
868 868
869 #define ADD_VALUES_TO_SET(set, values) \
870 for (size_t i = 0; i < arraysize(values); ++i) { \
871 set.insert(values[i]); \
872 }
873
869 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes) 874 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes)
870 : CanvasRenderingContext(passedCanvas) 875 : CanvasRenderingContext(passedCanvas)
871 , m_contextLostMode(NotLostContext) 876 , m_contextLostMode(NotLostContext)
872 , m_autoRecoveryMethod(Manual) 877 , m_autoRecoveryMethod(Manual)
873 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 878 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
874 , m_restoreAllowed(false) 879 , m_restoreAllowed(false)
875 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 880 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
876 , m_generatedImageCache(4) 881 , m_generatedImageCache(4)
877 , m_requestedAttributes(requestedAttributes) 882 , m_requestedAttributes(requestedAttributes)
878 , m_synthesizedErrorsToConsole(true) 883 , m_synthesizedErrorsToConsole(true)
(...skipping 18 matching lines...) Expand all
897 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context); 902 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context);
898 if (!buffer) { 903 if (!buffer) {
899 m_contextLostMode = SyntheticLostContext; 904 m_contextLostMode = SyntheticLostContext;
900 return; 905 return;
901 } 906 }
902 907
903 m_drawingBuffer = buffer.release(); 908 m_drawingBuffer = buffer.release();
904 909
905 drawingBuffer()->bind(GL_FRAMEBUFFER); 910 drawingBuffer()->bind(GL_FRAMEBUFFER);
906 setupFlags(); 911 setupFlags();
907
908 #define ADD_VALUES_TO_SET(set, values) \
909 for (size_t i = 0; i < arraysize(values); ++i) { \
910 set.insert(values[i]); \
911 }
912 912
913 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2); 913 ADD_VALUES_TO_SET(m_supportedInternalFormats, kSupportedInternalFormatsES2);
914 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2); 914 ADD_VALUES_TO_SET(m_supportedFormats, kSupportedFormatsES2);
915 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2); 915 ADD_VALUES_TO_SET(m_supportedTypes, kSupportedTypesES2);
916 ADD_VALUES_TO_SET(m_supportedFormatTypeCombinations, kSupportedFormatTypesES 2); 916 ADD_VALUES_TO_SET(m_supportedFormatTypeCombinations, kSupportedFormatTypesES 2);
917 } 917 }
918 918
919 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3D> context) 919 PassRefPtr<DrawingBuffer> WebGLRenderingContextBase::createDrawingBuffer(PassOwn Ptr<WebGraphicsContext3D> context)
920 { 920 {
921 WebGraphicsContext3D::Attributes attrs; 921 WebGraphicsContext3D::Attributes attrs;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 tracker->loseExtension(true); 1100 tracker->loseExtension(true);
1101 } 1101 }
1102 m_extensions.clear(); 1102 m_extensions.clear();
1103 1103
1104 // Context must be removed from the group prior to the destruction of the 1104 // Context must be removed from the group prior to the destruction of the
1105 // WebGraphicsContext3D, otherwise shared objects may not be properly delete d. 1105 // WebGraphicsContext3D, otherwise shared objects may not be properly delete d.
1106 m_contextGroup->removeContext(this); 1106 m_contextGroup->removeContext(this);
1107 1107
1108 destroyContext(); 1108 destroyContext();
1109 1109
1110 if (m_multisamplingObserverRegistered) { 1110 if (m_multisamplingObserverRegistered)
1111 if (Page* page = canvas()->document().page()) 1111 if (Page* page = canvas()->document().page())
1112 page->removeMultisamplingChangedObserver(this); 1112 page->removeMultisamplingChangedObserver(this);
1113 }
1114 1113
1115 willDestroyContext(this); 1114 willDestroyContext(this);
1116 } 1115 }
1117 1116
1118 void WebGLRenderingContextBase::destroyContext() 1117 void WebGLRenderingContextBase::destroyContext()
1119 { 1118 {
1120 if (!drawingBuffer()) 1119 if (!drawingBuffer())
1121 return; 1120 return;
1122 1121
1123 m_extensionsUtil.clear(); 1122 m_extensionsUtil.clear();
(...skipping 2902 matching lines...) Expand 10 before | Expand all | Expand 10 after
4026 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 4025 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
4027 if (!imageExtractor.extractSucceeded()) { 4026 if (!imageExtractor.extractSucceeded()) {
4028 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4027 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4029 return; 4028 return;
4030 } 4029 }
4031 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 4030 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
4032 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 4031 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
4033 const void* imagePixelData = imageExtractor.imagePixelData(); 4032 const void* imagePixelData = imageExtractor.imagePixelData();
4034 4033
4035 bool needConversion = true; 4034 bool needConversion = true;
4036 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 4035 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
4037 needConversion = false; 4036 needConversion = false;
4038 } else { 4037 else {
4039 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4038 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4040 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 4039 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
4041 return; 4040 return;
4042 } 4041 }
4043 } 4042 }
4044 4043
4045 if (m_unpackAlignment != 1) 4044 if (m_unpackAlignment != 1)
4046 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4045 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4047 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); 4046 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData);
4048 if (m_unpackAlignment != 1) 4047 if (m_unpackAlignment != 1)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0)) 4180 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0))
4182 return; 4181 return;
4183 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4182 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4184 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4183 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4185 type = GL_FLOAT; 4184 type = GL_FLOAT;
4186 } 4185 }
4187 Vector<uint8_t> data; 4186 Vector<uint8_t> data;
4188 bool needConversion = true; 4187 bool needConversion = true;
4189 // The data from ImageData is always of format RGBA8. 4188 // The data from ImageData is always of format RGBA8.
4190 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4189 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4191 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) { 4190 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE)
4192 needConversion = false; 4191 needConversion = false;
4193 } else { 4192 else {
4194 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4193 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4195 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4194 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4196 return; 4195 return;
4197 } 4196 }
4198 } 4197 }
4199 if (m_unpackAlignment != 1) 4198 if (m_unpackAlignment != 1)
4200 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4199 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4201 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data()); 4200 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data());
4202 if (m_unpackAlignment != 1) 4201 if (m_unpackAlignment != 1)
4203 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4202 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
4291 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0)) 4290 if (isContextLost() || !validateHTMLCanvasElement("texImage2D", canvas, exce ptionState) || !validateTexFunc("texImage2D", NotTexSubImage2D, SourceHTMLCanvas Element, target, level, internalformat, canvas->width(), canvas->height(), 0, fo rmat, type, 0, 0))
4292 return; 4291 return;
4293 4292
4294 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4293 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4295 ASSERT(texture); 4294 ASSERT(texture);
4296 4295
4297 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float type. 4296 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float type.
4298 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4297 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES;
4299 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4298 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) {
4300 // 2D canvas has only FrontBuffer. 4299 // 2D canvas has only FrontBuffer.
4301 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(), 4300 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer).get(),
4302 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4301 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4303 return; 4302 return;
4304 } 4303 }
4305 4304
4306 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas); 4305 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas);
4307 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type); 4306 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type);
4308 } 4307 }
4309 4308
4310 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video) 4309 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video)
4311 { 4310 {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 4441 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
4443 if (!imageExtractor.extractSucceeded()) { 4442 if (!imageExtractor.extractSucceeded()) {
4444 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image"); 4443 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image");
4445 return; 4444 return;
4446 } 4445 }
4447 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 4446 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
4448 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 4447 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
4449 const void* imagePixelData = imageExtractor.imagePixelData(); 4448 const void* imagePixelData = imageExtractor.imagePixelData();
4450 4449
4451 bool needConversion = true; 4450 bool needConversion = true;
4452 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) { 4451 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY)
4453 needConversion = false; 4452 needConversion = false;
4454 } else { 4453 else {
4455 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4454 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4456 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4455 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4457 return; 4456 return;
4458 } 4457 }
4459 } 4458 }
4460 4459
4461 if (m_unpackAlignment != 1) 4460 if (m_unpackAlignment != 1)
4462 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4461 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4463 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData); 4462 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData);
4464 if (m_unpackAlignment != 1) 4463 if (m_unpackAlignment != 1)
4465 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4464 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4466 } 4465 }
4467 4466
4468 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4467 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4469 GLsizei width, GLsizei height, 4468 GLsizei width, GLsizei height,
4470 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4469 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4471 { 4470 {
4472 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) 4471 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset)
4473 || !validateTexFuncData("texSubImage2D", level, width, height, format, t ype, pixels, NullNotAllowed)) 4472 || !validateTexFuncData("texSubImage2D", level, width, height, format, t ype, pixels, NullNotAllowed))
4474 return; 4473 return;
4475 void* data = pixels->baseAddress(); 4474 void* data = pixels->baseAddress();
4476 Vector<uint8_t> tempData; 4475 Vector<uint8_t> tempData;
4477 bool changeUnpackAlignment = false; 4476 bool changeUnpackAlignment = false;
4478 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4477 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4479 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 4478 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
4480 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData)) 4479 m_unpackAlignment,
4480 m_unpackFlipY, m_unpackPremultiplyAlp ha,
4481 data,
4482 tempData))
4481 return; 4483 return;
4482 data = tempData.data(); 4484 data = tempData.data();
4483 changeUnpackAlignment = true; 4485 changeUnpackAlignment = true;
4484 } 4486 }
4485 if (changeUnpackAlignment) 4487 if (changeUnpackAlignment)
4486 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4488 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4487 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data); 4489 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
4488 if (changeUnpackAlignment) 4490 if (changeUnpackAlignment)
4489 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4491 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4490 } 4492 }
4491 4493
4492 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4494 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4493 GLenum format, GLenum type, ImageData* pixels) 4495 GLenum format, GLenum type, ImageData* pixels)
4494 { 4496 {
4495 if (!pixels) { 4497 if (!pixels) {
4496 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); 4498 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data");
4497 return; 4499 return;
4498 } 4500 }
4499 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset)) 4501 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset))
4500 return; 4502 return;
4501 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4503 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4502 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4504 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4503 type = GL_FLOAT; 4505 type = GL_FLOAT;
4504 } 4506 }
4505 Vector<uint8_t> data; 4507 Vector<uint8_t> data;
4506 bool needConversion = true; 4508 bool needConversion = true;
4507 // The data from ImageData is always of format RGBA8. 4509 // The data from ImageData is always of format RGBA8.
4508 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4510 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4509 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) { 4511 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha)
4510 needConversion = false; 4512 needConversion = false;
4511 } else { 4513 else {
4512 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4514 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4513 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4515 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4514 return; 4516 return;
4515 } 4517 }
4516 } 4518 }
4517 if (m_unpackAlignment != 1) 4519 if (m_unpackAlignment != 1)
4518 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4520 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4519 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data()); 4521 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data());
4520 if (m_unpackAlignment != 1) 4522 if (m_unpackAlignment != 1)
4521 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4523 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
(...skipping 26 matching lines...) Expand all
4548 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 4550 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
4549 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset)) 4551 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset))
4550 return; 4552 return;
4551 4553
4552 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); 4554 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4553 ASSERT(texture); 4555 ASSERT(texture);
4554 4556
4555 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4557 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES;
4556 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4558 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) {
4557 // 2D canvas has only FrontBuffer. 4559 // 2D canvas has only FrontBuffer.
4558 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(), 4560 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer).get(),
4559 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4561 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4560 return; 4562 return;
4561 } 4563 }
4562 4564
4563 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); 4565 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas);
4564 } 4566 }
4565 4567
4566 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4568 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4567 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4569 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4568 { 4570 {
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
6547 6549
6548 } // namespace anonymous 6550 } // namespace anonymous
6549 6551
6550 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display) 6552 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display)
6551 { 6553 {
6552 String errorType = GetErrorString(error); 6554 String errorType = GetErrorString(error);
6553 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) { 6555 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
6554 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description); 6556 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description);
6555 printGLErrorToConsole(message); 6557 printGLErrorToConsole(message);
6556 } 6558 }
6557 if (!isContextLost()) { 6559 if (!isContextLost())
6558 webContext()->synthesizeGLError(error); 6560 webContext()->synthesizeGLError(error);
6559 } else { 6561 else {
6560 if (m_lostContextErrors.find(error) == WTF::kNotFound) 6562 if (m_lostContextErrors.find(error) == WTF::kNotFound)
6561 m_lostContextErrors.append(error); 6563 m_lostContextErrors.append(error);
6562 } 6564 }
6563 InspectorInstrumentation::didFireWebGLError(canvas(), errorType); 6565 InspectorInstrumentation::didFireWebGLError(canvas(), errorType);
6564 } 6566 }
6565 6567
6566 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description) 6568 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description)
6567 { 6569 {
6568 if (m_synthesizedErrorsToConsole) { 6570 if (m_synthesizedErrorsToConsole) {
6569 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description); 6571 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description);
6570 printGLErrorToConsole(message); 6572 printGLErrorToConsole(message);
6571 } 6573 }
6572 InspectorInstrumentation::didFireWebGLWarning(canvas()); 6574 InspectorInstrumentation::didFireWebGLWarning(canvas());
6573 } 6575 }
6574 6576
6575 void WebGLRenderingContextBase::applyStencilTest() 6577 void WebGLRenderingContextBase::applyStencilTest()
6576 { 6578 {
6577 bool haveStencilBuffer = false; 6579 bool haveStencilBuffer = false;
6578 6580
6579 if (m_framebufferBinding) { 6581 if (m_framebufferBinding)
6580 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer(); 6582 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
6581 } else { 6583 else {
6582 Nullable<WebGLContextAttributes> attributes; 6584 Nullable<WebGLContextAttributes> attributes;
6583 getContextAttributes(attributes); 6585 getContextAttributes(attributes);
6584 haveStencilBuffer = !attributes.isNull() && attributes.get().stencil(); 6586 haveStencilBuffer = !attributes.isNull() && attributes.get().stencil();
6585 } 6587 }
6586 enableOrDisable(GL_STENCIL_TEST, m_stencilEnabled && haveStencilBuffer); 6588 enableOrDisable(GL_STENCIL_TEST,
6589 m_stencilEnabled && haveStencilBuffer);
6587 } 6590 }
6588 6591
6589 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable) 6592 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
6590 { 6593 {
6591 if (isContextLost()) 6594 if (isContextLost())
6592 return; 6595 return;
6593 if (enable) 6596 if (enable)
6594 webContext()->enable(capability); 6597 webContext()->enable(capability);
6595 else 6598 else
6596 webContext()->disable(capability); 6599 webContext()->disable(capability);
6597 } 6600 }
6598 6601
6599 IntSize WebGLRenderingContextBase::clampedCanvasSize() 6602 IntSize WebGLRenderingContextBase::clampedCanvasSize()
6600 { 6603 {
6601 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 6604 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
6602 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 6605 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
6603 } 6606 }
6604 6607
6605 GLint WebGLRenderingContextBase::maxDrawBuffers() 6608 GLint WebGLRenderingContextBase::maxDrawBuffers()
6606 { 6609 {
6607 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) 6610 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher()))
6608 return 0; 6611 return 0;
6609 if (!m_maxDrawBuffers) 6612 if (!m_maxDrawBuffers)
6610 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 6613 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
6611 if (!m_maxColorAttachments) 6614 if (!m_maxColorAttachments)
6612 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments); 6615 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
6732 6735
6733 return totalBytesPerPixel; 6736 return totalBytesPerPixel;
6734 } 6737 }
6735 6738
6736 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6739 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6737 { 6740 {
6738 return m_drawingBuffer.get(); 6741 return m_drawingBuffer.get();
6739 } 6742 }
6740 6743
6741 } // namespace blink 6744 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698