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

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

Issue 1367683002: 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: added nullptr check + fixed style check errors Created 5 years, 2 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 && forciblyEvictedContex ts().size()) { 206 while (activeContexts().size() < maxGLActiveContexts && forciblyEvictedConte xts().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
874 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes) 869 WebGLRenderingContextBase::WebGLRenderingContextBase(HTMLCanvasElement* passedCa nvas, PassOwnPtr<WebGraphicsContext3D> context, const WebGLContextAttributes& re questedAttributes)
875 : CanvasRenderingContext(passedCanvas) 870 : CanvasRenderingContext(passedCanvas)
876 , m_contextLostMode(NotLostContext) 871 , m_contextLostMode(NotLostContext)
877 , m_autoRecoveryMethod(Manual) 872 , m_autoRecoveryMethod(Manual)
878 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent) 873 , m_dispatchContextLostEventTimer(this, &WebGLRenderingContextBase::dispatch ContextLostEvent)
879 , m_restoreAllowed(false) 874 , m_restoreAllowed(false)
880 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext) 875 , m_restoreTimer(this, &WebGLRenderingContextBase::maybeRestoreContext)
881 , m_generatedImageCache(4) 876 , m_generatedImageCache(4)
882 , m_requestedAttributes(requestedAttributes) 877 , m_requestedAttributes(requestedAttributes)
883 , m_synthesizedErrorsToConsole(true) 878 , m_synthesizedErrorsToConsole(true)
(...skipping 18 matching lines...) Expand all
902 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context); 897 RefPtr<DrawingBuffer> buffer = createDrawingBuffer(context);
903 if (!buffer) { 898 if (!buffer) {
904 m_contextLostMode = SyntheticLostContext; 899 m_contextLostMode = SyntheticLostContext;
905 return; 900 return;
906 } 901 }
907 902
908 m_drawingBuffer = buffer.release(); 903 m_drawingBuffer = buffer.release();
909 904
910 drawingBuffer()->bind(GL_FRAMEBUFFER); 905 drawingBuffer()->bind(GL_FRAMEBUFFER);
911 setupFlags(); 906 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 }
1113 1114
1114 willDestroyContext(this); 1115 willDestroyContext(this);
1115 } 1116 }
1116 1117
1117 void WebGLRenderingContextBase::destroyContext() 1118 void WebGLRenderingContextBase::destroyContext()
1118 { 1119 {
1119 if (!drawingBuffer()) 1120 if (!drawingBuffer())
1120 return; 1121 return;
1121 1122
1122 m_extensionsUtil.clear(); 1123 m_extensionsUtil.clear();
(...skipping 2902 matching lines...) Expand 10 before | Expand all | Expand 10 after
4025 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 4026 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
4026 if (!imageExtractor.extractSucceeded()) { 4027 if (!imageExtractor.extractSucceeded()) {
4027 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4028 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4028 return; 4029 return;
4029 } 4030 }
4030 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 4031 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
4031 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 4032 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
4032 const void* imagePixelData = imageExtractor.imagePixelData(); 4033 const void* imagePixelData = imageExtractor.imagePixelData();
4033 4034
4034 bool needConversion = true; 4035 bool needConversion = true;
4035 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 4036 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
4036 needConversion = false; 4037 needConversion = false;
4037 else { 4038 } else {
4038 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4039 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4039 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ; 4040 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "packImage error") ;
4040 return; 4041 return;
4041 } 4042 }
4042 } 4043 }
4043 4044
4044 if (m_unpackAlignment != 1) 4045 if (m_unpackAlignment != 1)
4045 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4046 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4046 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData); 4047 texImage2DBase(target, level, internalformat, imageExtractor.imageWidth(), i mageExtractor.imageHeight(), 0, format, type, needConversion ? data.data() : ima gePixelData);
4047 if (m_unpackAlignment != 1) 4048 if (m_unpackAlignment != 1)
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4180 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0)) 4181 if (isContextLost() || !validateTexFunc("texImage2D", NotTexSubImage2D, Sour ceImageData, target, level, internalformat, pixels->width(), pixels->height(), 0 , format, type, 0, 0))
4181 return; 4182 return;
4182 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4183 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4183 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4184 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4184 type = GL_FLOAT; 4185 type = GL_FLOAT;
4185 } 4186 }
4186 Vector<uint8_t> data; 4187 Vector<uint8_t> data;
4187 bool needConversion = true; 4188 bool needConversion = true;
4188 // The data from ImageData is always of format RGBA8. 4189 // The data from ImageData is always of format RGBA8.
4189 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4190 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4190 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) 4191 if (!m_unpackFlipY && !m_unpackPremultiplyAlpha && format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
4191 needConversion = false; 4192 needConversion = false;
4192 else { 4193 } else {
4193 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4194 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4194 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data"); 4195 synthesizeGLError(GL_INVALID_VALUE, "texImage2D", "bad image data");
4195 return; 4196 return;
4196 } 4197 }
4197 } 4198 }
4198 if (m_unpackAlignment != 1) 4199 if (m_unpackAlignment != 1)
4199 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4200 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4200 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data()); 4201 texImage2DBase(target, level, internalformat, pixels->width(), pixels->heigh t(), 0, format, type, needConversion ? data.data() : pixels->data()->data());
4201 if (m_unpackAlignment != 1) 4202 if (m_unpackAlignment != 1)
4202 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4203 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
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)) 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))
4291 return; 4292 return;
4292 4293
4293 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true); 4294 WebGLTexture* texture = validateTextureBinding("texImage2D", target, true);
4294 ASSERT(texture); 4295 ASSERT(texture);
4295 4296
4296 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float type. 4297 // texImage2DCanvasByGPU relies on copyTextureCHROMIUM which doesn't support float type.
4297 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4298 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES;
4298 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4299 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) {
4299 // 2D canvas has only FrontBuffer. 4300 // 2D canvas has only FrontBuffer.
4300 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer).get(), 4301 texImage2DImpl(target, level, internalformat, format, type, canvas->copi edImage(FrontBuffer, PreferAcceleration).get(),
4301 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4302 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4302 return; 4303 return;
4303 } 4304 }
4304 4305
4305 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas); 4306 texImage2DCanvasByGPU(NotTexSubImage2D, texture, target, level, internalform at, type, 0, 0, canvas);
4306 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type); 4307 texture->setLevelInfo(target, level, internalformat, canvas->width(), canvas ->height(), 1, type);
4307 } 4308 }
4308 4309
4309 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video) 4310 PassRefPtr<Image> WebGLRenderingContextBase::videoFrameToImage(HTMLVideoElement* video)
4310 { 4311 {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
4441 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE); 4442 WebGLImageConversion::ImageExtractor imageExtractor(image, domSource, premul tiplyAlpha, m_unpackColorspaceConversion == GL_NONE);
4442 if (!imageExtractor.extractSucceeded()) { 4443 if (!imageExtractor.extractSucceeded()) {
4443 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image"); 4444 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image");
4444 return; 4445 return;
4445 } 4446 }
4446 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat(); 4447 WebGLImageConversion::DataFormat sourceDataFormat = imageExtractor.imageSour ceFormat();
4447 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp(); 4448 WebGLImageConversion::AlphaOp alphaOp = imageExtractor.imageAlphaOp();
4448 const void* imagePixelData = imageExtractor.imagePixelData(); 4449 const void* imagePixelData = imageExtractor.imagePixelData();
4449 4450
4450 bool needConversion = true; 4451 bool needConversion = true;
4451 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) 4452 if (type == GL_UNSIGNED_BYTE && sourceDataFormat == WebGLImageConversion::Da taFormatRGBA8 && format == GL_RGBA && alphaOp == WebGLImageConversion::AlphaDoNo thing && !flipY) {
4452 needConversion = false; 4453 needConversion = false;
4453 else { 4454 } else {
4454 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) { 4455 if (!WebGLImageConversion::packImageData(image, imagePixelData, format, type, flipY, alphaOp, sourceDataFormat, imageExtractor.imageWidth(), imageExtrac tor.imageHeight(), imageExtractor.imageSourceUnpackAlignment(), data)) {
4455 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4456 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4456 return; 4457 return;
4457 } 4458 }
4458 } 4459 }
4459 4460
4460 if (m_unpackAlignment != 1) 4461 if (m_unpackAlignment != 1)
4461 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4462 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4462 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData); 4463 webContext()->texSubImage2D(target, level, xoffset, yoffset, imageExtractor. imageWidth(), imageExtractor.imageHeight(), format, type, needConversion ? data .data() : imagePixelData);
4463 if (m_unpackAlignment != 1) 4464 if (m_unpackAlignment != 1)
4464 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4465 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4465 } 4466 }
4466 4467
4467 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4468 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4468 GLsizei width, GLsizei height, 4469 GLsizei width, GLsizei height,
4469 GLenum format, GLenum type, DOMArrayBufferView* pixels) 4470 GLenum format, GLenum type, DOMArrayBufferView* pixels)
4470 { 4471 {
4471 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset) 4472 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceArrayBufferView, target, level, 0, width, height, 0, format, type, xoffset, yo ffset)
4472 || !validateTexFuncData("texSubImage2D", level, width, height, format, t ype, pixels, NullNotAllowed)) 4473 || !validateTexFuncData("texSubImage2D", level, width, height, format, t ype, pixels, NullNotAllowed))
4473 return; 4474 return;
4474 void* data = pixels->baseAddress(); 4475 void* data = pixels->baseAddress();
4475 Vector<uint8_t> tempData; 4476 Vector<uint8_t> tempData;
4476 bool changeUnpackAlignment = false; 4477 bool changeUnpackAlignment = false;
4477 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) { 4478 if (data && (m_unpackFlipY || m_unpackPremultiplyAlpha)) {
4478 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e, 4479 if (!WebGLImageConversion::extractTextureData(width, height, format, typ e,
4479 m_unpackAlignment, 4480 m_unpackAlignment, m_unpackFlipY, m_unpackPremultiplyAlpha, data, te mpData))
4480 m_unpackFlipY, m_unpackPremultiplyAlp ha,
4481 data,
4482 tempData))
4483 return; 4481 return;
4484 data = tempData.data(); 4482 data = tempData.data();
4485 changeUnpackAlignment = true; 4483 changeUnpackAlignment = true;
4486 } 4484 }
4487 if (changeUnpackAlignment) 4485 if (changeUnpackAlignment)
4488 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4486 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4489 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data); 4487 webContext()->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, data);
4490 if (changeUnpackAlignment) 4488 if (changeUnpackAlignment)
4491 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4489 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
4492 } 4490 }
4493 4491
4494 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4492 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4495 GLenum format, GLenum type, ImageData* pixels) 4493 GLenum format, GLenum type, ImageData* pixels)
4496 { 4494 {
4497 if (!pixels) { 4495 if (!pixels) {
4498 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data"); 4496 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "no image data");
4499 return; 4497 return;
4500 } 4498 }
4501 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset)) 4499 if (isContextLost() || !validateTexFunc("texSubImage2D", TexSubImage2D, Sour ceImageData, target, level, 0, pixels->width(), pixels->height(), 0, format, ty pe, xoffset, yoffset))
4502 return; 4500 return;
4503 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) { 4501 if (type == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4504 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented. 4502 // The UNSIGNED_INT_10F_11F_11F_REV type pack/unpack isn't implemented.
4505 type = GL_FLOAT; 4503 type = GL_FLOAT;
4506 } 4504 }
4507 Vector<uint8_t> data; 4505 Vector<uint8_t> data;
4508 bool needConversion = true; 4506 bool needConversion = true;
4509 // The data from ImageData is always of format RGBA8. 4507 // The data from ImageData is always of format RGBA8.
4510 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required. 4508 // No conversion is needed if destination format is RGBA and type is USIGNED _BYTE and no Flip or Premultiply operation is required.
4511 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) 4509 if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !m_unpackFlipY && !m_un packPremultiplyAlpha) {
4512 needConversion = false; 4510 needConversion = false;
4513 else { 4511 } else {
4514 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) { 4512 if (!WebGLImageConversion::extractImageData(pixels->data()->data(), pixe ls->size(), format, type, m_unpackFlipY, m_unpackPremultiplyAlpha, data)) {
4515 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data "); 4513 synthesizeGLError(GL_INVALID_VALUE, "texSubImage2D", "bad image data ");
4516 return; 4514 return;
4517 } 4515 }
4518 } 4516 }
4519 if (m_unpackAlignment != 1) 4517 if (m_unpackAlignment != 1)
4520 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1); 4518 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, 1);
4521 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data()); 4519 webContext()->texSubImage2D(target, level, xoffset, yoffset, pixels->width() , pixels->height(), format, type, needConversion ? data.data() : pixels->data()- >data());
4522 if (m_unpackAlignment != 1) 4520 if (m_unpackAlignment != 1)
4523 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); 4521 webContext()->pixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment);
(...skipping 26 matching lines...) Expand all
4550 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState) 4548 if (isContextLost() || !validateHTMLCanvasElement("texSubImage2D", canvas, e xceptionState)
4551 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset)) 4549 || !validateTexFunc("texSubImage2D", TexSubImage2D, SourceHTMLCanvasElem ent, target, level, 0, canvas->width(), canvas->height(), 0, format, type, xoffs et, yoffset))
4552 return; 4550 return;
4553 4551
4554 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true ); 4552 WebGLTexture* texture = validateTextureBinding("texSubImage2D", target, true );
4555 ASSERT(texture); 4553 ASSERT(texture);
4556 4554
4557 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES; 4555 bool isFloatType = type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_H ALF_FLOAT_OES;
4558 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) { 4556 if (!canvas->renderingContext() || !canvas->renderingContext()->isAccelerate d() || isFloatType) {
4559 // 2D canvas has only FrontBuffer. 4557 // 2D canvas has only FrontBuffer.
4560 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer).get(), 4558 texSubImage2DImpl(target, level, xoffset, yoffset, format, type, canvas- >copiedImage(FrontBuffer, PreferAcceleration).get(),
4561 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha); 4559 WebGLImageConversion::HtmlDomCanvas, m_unpackFlipY, m_unpackPremulti plyAlpha);
4562 return; 4560 return;
4563 } 4561 }
4564 4562
4565 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas); 4563 texImage2DCanvasByGPU(TexSubImage2D, texture, target, level, GL_RGBA, type, xoffset, yoffset, canvas);
4566 } 4564 }
4567 4565
4568 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, 4566 void WebGLRenderingContextBase::texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
4569 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState) 4567 GLenum format, GLenum type, HTMLVideoElement* video, ExceptionState& excepti onState)
4570 { 4568 {
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
6549 6547
6550 } // namespace anonymous 6548 } // namespace anonymous
6551 6549
6552 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display) 6550 void WebGLRenderingContextBase::synthesizeGLError(GLenum error, const char* func tionName, const char* description, ConsoleDisplayPreference display)
6553 { 6551 {
6554 String errorType = GetErrorString(error); 6552 String errorType = GetErrorString(error);
6555 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) { 6553 if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
6556 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description); 6554 String message = String("WebGL: ") + errorType + ": " + String(function Name) + ": " + String(description);
6557 printGLErrorToConsole(message); 6555 printGLErrorToConsole(message);
6558 } 6556 }
6559 if (!isContextLost()) 6557 if (!isContextLost()) {
6560 webContext()->synthesizeGLError(error); 6558 webContext()->synthesizeGLError(error);
6561 else { 6559 } else {
6562 if (m_lostContextErrors.find(error) == WTF::kNotFound) 6560 if (m_lostContextErrors.find(error) == WTF::kNotFound)
6563 m_lostContextErrors.append(error); 6561 m_lostContextErrors.append(error);
6564 } 6562 }
6565 InspectorInstrumentation::didFireWebGLError(canvas(), errorType); 6563 InspectorInstrumentation::didFireWebGLError(canvas(), errorType);
6566 } 6564 }
6567 6565
6568 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description) 6566 void WebGLRenderingContextBase::emitGLWarning(const char* functionName, const ch ar* description)
6569 { 6567 {
6570 if (m_synthesizedErrorsToConsole) { 6568 if (m_synthesizedErrorsToConsole) {
6571 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description); 6569 String message = String("WebGL: ") + String(functionName) + ": " + Strin g(description);
6572 printGLErrorToConsole(message); 6570 printGLErrorToConsole(message);
6573 } 6571 }
6574 InspectorInstrumentation::didFireWebGLWarning(canvas()); 6572 InspectorInstrumentation::didFireWebGLWarning(canvas());
6575 } 6573 }
6576 6574
6577 void WebGLRenderingContextBase::applyStencilTest() 6575 void WebGLRenderingContextBase::applyStencilTest()
6578 { 6576 {
6579 bool haveStencilBuffer = false; 6577 bool haveStencilBuffer = false;
6580 6578
6581 if (m_framebufferBinding) 6579 if (m_framebufferBinding) {
6582 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer(); 6580 haveStencilBuffer = m_framebufferBinding->hasStencilBuffer();
6583 else { 6581 } else {
6584 Nullable<WebGLContextAttributes> attributes; 6582 Nullable<WebGLContextAttributes> attributes;
6585 getContextAttributes(attributes); 6583 getContextAttributes(attributes);
6586 haveStencilBuffer = !attributes.isNull() && attributes.get().stencil(); 6584 haveStencilBuffer = !attributes.isNull() && attributes.get().stencil();
6587 } 6585 }
6588 enableOrDisable(GL_STENCIL_TEST, 6586 enableOrDisable(GL_STENCIL_TEST, m_stencilEnabled && haveStencilBuffer);
6589 m_stencilEnabled && haveStencilBuffer);
6590 } 6587 }
6591 6588
6592 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable) 6589 void WebGLRenderingContextBase::enableOrDisable(GLenum capability, bool enable)
6593 { 6590 {
6594 if (isContextLost()) 6591 if (isContextLost())
6595 return; 6592 return;
6596 if (enable) 6593 if (enable)
6597 webContext()->enable(capability); 6594 webContext()->enable(capability);
6598 else 6595 else
6599 webContext()->disable(capability); 6596 webContext()->disable(capability);
6600 } 6597 }
6601 6598
6602 IntSize WebGLRenderingContextBase::clampedCanvasSize() 6599 IntSize WebGLRenderingContextBase::clampedCanvasSize()
6603 { 6600 {
6604 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]), 6601 return IntSize(clamp(canvas()->width(), 1, m_maxViewportDims[0]),
6605 clamp(canvas()->height(), 1, m_maxViewportDims[1])); 6602 clamp(canvas()->height(), 1, m_maxViewportDims[1]));
6606 } 6603 }
6607 6604
6608 GLint WebGLRenderingContextBase::maxDrawBuffers() 6605 GLint WebGLRenderingContextBase::maxDrawBuffers()
6609 { 6606 {
6610 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher())) 6607 if (isContextLost() || !(extensionEnabled(WebGLDrawBuffersName) || isWebGL2O rHigher()))
6611 return 0; 6608 return 0;
6612 if (!m_maxDrawBuffers) 6609 if (!m_maxDrawBuffers)
6613 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers); 6610 webContext()->getIntegerv(GL_MAX_DRAW_BUFFERS_EXT, &m_maxDrawBuffers);
6614 if (!m_maxColorAttachments) 6611 if (!m_maxColorAttachments)
6615 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments); 6612 webContext()->getIntegerv(GL_MAX_COLOR_ATTACHMENTS_EXT, &m_maxColorAttac hments);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
6735 6732
6736 return totalBytesPerPixel; 6733 return totalBytesPerPixel;
6737 } 6734 }
6738 6735
6739 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const 6736 DrawingBuffer* WebGLRenderingContextBase::drawingBuffer() const
6740 { 6737 {
6741 return m_drawingBuffer.get(); 6738 return m_drawingBuffer.get();
6742 } 6739 }
6743 6740
6744 } // namespace blink 6741 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698