OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webgl/WebGL2RenderingContextBase.h" | 5 #include "modules/webgl/WebGL2RenderingContextBase.h" |
6 | 6 |
7 #include "bindings/modules/v8/WebGLAny.h" | 7 #include "bindings/modules/v8/WebGLAny.h" |
8 #include "core/frame/ImageBitmap.h" | 8 #include "core/frame/ImageBitmap.h" |
9 #include "core/html/HTMLCanvasElement.h" | 9 #include "core/html/HTMLCanvasElement.h" |
10 #include "core/html/HTMLImageElement.h" | 10 #include "core/html/HTMLImageElement.h" |
11 #include "core/html/HTMLVideoElement.h" | 11 #include "core/html/HTMLVideoElement.h" |
12 #include "core/html/ImageData.h" | 12 #include "core/html/ImageData.h" |
13 #include "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
14 #include "modules/webgl/WebGLActiveInfo.h" | 14 #include "modules/webgl/WebGLActiveInfo.h" |
15 #include "modules/webgl/WebGLBuffer.h" | 15 #include "modules/webgl/WebGLBuffer.h" |
16 #include "modules/webgl/WebGLFenceSync.h" | 16 #include "modules/webgl/WebGLFenceSync.h" |
17 #include "modules/webgl/WebGLFramebuffer.h" | 17 #include "modules/webgl/WebGLFramebuffer.h" |
18 #include "modules/webgl/WebGLProgram.h" | 18 #include "modules/webgl/WebGLProgram.h" |
19 #include "modules/webgl/WebGLQuery.h" | 19 #include "modules/webgl/WebGLQuery.h" |
20 #include "modules/webgl/WebGLRenderbuffer.h" | 20 #include "modules/webgl/WebGLRenderbuffer.h" |
21 #include "modules/webgl/WebGLSampler.h" | 21 #include "modules/webgl/WebGLSampler.h" |
22 #include "modules/webgl/WebGLSync.h" | 22 #include "modules/webgl/WebGLSync.h" |
23 #include "modules/webgl/WebGLTexture.h" | 23 #include "modules/webgl/WebGLTexture.h" |
24 #include "modules/webgl/WebGLTransformFeedback.h" | 24 #include "modules/webgl/WebGLTransformFeedback.h" |
25 #include "modules/webgl/WebGLUniformLocation.h" | 25 #include "modules/webgl/WebGLUniformLocation.h" |
26 #include "modules/webgl/WebGLVertexArrayObject.h" | 26 #include "modules/webgl/WebGLVertexArrayObject.h" |
27 #include "platform/CheckedInt.h" | 27 #include "platform/CheckedInt.h" |
28 #include "public/platform/WebGraphicsContext3DProvider.h" | 28 #include "public/platform/WebGraphicsContext3DProvider.h" |
29 #include "wtf/PtrUtil.h" | 29 #include "wtf/OwnPtr.h" |
| 30 #include "wtf/PassOwnPtr.h" |
30 #include "wtf/text/WTFString.h" | 31 #include "wtf/text/WTFString.h" |
31 #include <memory> | |
32 | 32 |
33 using WTF::String; | 33 using WTF::String; |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 GLsync syncObjectOrZero(const WebGLSync* object) | 39 GLsync syncObjectOrZero(const WebGLSync* object) |
40 { | 40 { |
41 return object ? object->object() : nullptr; | 41 return object ? object->object() : nullptr; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 GL_COMPRESSED_RG11_EAC, | 107 GL_COMPRESSED_RG11_EAC, |
108 GL_COMPRESSED_SIGNED_RG11_EAC, | 108 GL_COMPRESSED_SIGNED_RG11_EAC, |
109 GL_COMPRESSED_RGB8_ETC2, | 109 GL_COMPRESSED_RGB8_ETC2, |
110 GL_COMPRESSED_SRGB8_ETC2, | 110 GL_COMPRESSED_SRGB8_ETC2, |
111 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, | 111 GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, |
112 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, | 112 GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, |
113 GL_COMPRESSED_RGBA8_ETC2_EAC, | 113 GL_COMPRESSED_RGBA8_ETC2_EAC, |
114 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, | 114 GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, |
115 }; | 115 }; |
116 | 116 |
117 WebGL2RenderingContextBase::WebGL2RenderingContextBase(HTMLCanvasElement* passed
Canvas, std::unique_ptr<WebGraphicsContext3DProvider> contextProvider, const Web
GLContextAttributes& requestedAttributes) | 117 WebGL2RenderingContextBase::WebGL2RenderingContextBase(HTMLCanvasElement* passed
Canvas, PassOwnPtr<WebGraphicsContext3DProvider> contextProvider, const WebGLCon
textAttributes& requestedAttributes) |
118 : WebGLRenderingContextBase(passedCanvas, std::move(contextProvider), reques
tedAttributes) | 118 : WebGLRenderingContextBase(passedCanvas, std::move(contextProvider), reques
tedAttributes) |
119 { | 119 { |
120 m_supportedInternalFormatsStorage.insert(kSupportedInternalFormatsStorage, k
SupportedInternalFormatsStorage + WTF_ARRAY_LENGTH(kSupportedInternalFormatsStor
age)); | 120 m_supportedInternalFormatsStorage.insert(kSupportedInternalFormatsStorage, k
SupportedInternalFormatsStorage + WTF_ARRAY_LENGTH(kSupportedInternalFormatsStor
age)); |
121 m_supportedInternalFormatsStorage.insert(kCompressedTextureFormatsETC2EAC, k
CompressedTextureFormatsETC2EAC + WTF_ARRAY_LENGTH(kCompressedTextureFormatsETC2
EAC)); | 121 m_supportedInternalFormatsStorage.insert(kCompressedTextureFormatsETC2EAC, k
CompressedTextureFormatsETC2EAC + WTF_ARRAY_LENGTH(kCompressedTextureFormatsETC2
EAC)); |
122 m_compressedTextureFormatsETC2EAC.insert(kCompressedTextureFormatsETC2EAC, k
CompressedTextureFormatsETC2EAC + WTF_ARRAY_LENGTH(kCompressedTextureFormatsETC2
EAC)); | 122 m_compressedTextureFormatsETC2EAC.insert(kCompressedTextureFormatsETC2EAC, k
CompressedTextureFormatsETC2EAC + WTF_ARRAY_LENGTH(kCompressedTextureFormatsETC2
EAC)); |
123 m_compressedTextureFormats.append(kCompressedTextureFormatsETC2EAC, WTF_ARRA
Y_LENGTH(kCompressedTextureFormatsETC2EAC)); | 123 m_compressedTextureFormats.append(kCompressedTextureFormatsETC2EAC, WTF_ARRA
Y_LENGTH(kCompressedTextureFormatsETC2EAC)); |
124 } | 124 } |
125 | 125 |
126 WebGL2RenderingContextBase::~WebGL2RenderingContextBase() | 126 WebGL2RenderingContextBase::~WebGL2RenderingContextBase() |
127 { | 127 { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 floatType = true; | 398 floatType = true; |
399 break; | 399 break; |
400 default: | 400 default: |
401 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d internalformat"); | 401 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d internalformat"); |
402 return ScriptValue::createNull(scriptState); | 402 return ScriptValue::createNull(scriptState); |
403 } | 403 } |
404 | 404 |
405 switch (pname) { | 405 switch (pname) { |
406 case GL_SAMPLES: | 406 case GL_SAMPLES: |
407 { | 407 { |
408 std::unique_ptr<GLint[]> values; | 408 OwnPtr<GLint[]> values; |
409 GLint length = -1; | 409 GLint length = -1; |
410 if (!floatType) { | 410 if (!floatType) { |
411 contextGL()->GetInternalformativ(target, internalformat, GL_NUM_
SAMPLE_COUNTS, 1, &length); | 411 contextGL()->GetInternalformativ(target, internalformat, GL_NUM_
SAMPLE_COUNTS, 1, &length); |
412 if (length <= 0) | 412 if (length <= 0) |
413 return WebGLAny(scriptState, DOMInt32Array::create(0)); | 413 return WebGLAny(scriptState, DOMInt32Array::create(0)); |
414 | 414 |
415 values = wrapArrayUnique(new GLint[length]); | 415 values = adoptArrayPtr(new GLint[length]); |
416 for (GLint ii = 0; ii < length; ++ii) | 416 for (GLint ii = 0; ii < length; ++ii) |
417 values[ii] = 0; | 417 values[ii] = 0; |
418 contextGL()->GetInternalformativ(target, internalformat, GL_SAMP
LES, length, values.get()); | 418 contextGL()->GetInternalformativ(target, internalformat, GL_SAMP
LES, length, values.get()); |
419 } else { | 419 } else { |
420 length = 1; | 420 length = 1; |
421 values = wrapArrayUnique(new GLint[1]); | 421 values = adoptArrayPtr(new GLint[1]); |
422 values[0] = 1; | 422 values[0] = 1; |
423 } | 423 } |
424 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len
gth)); | 424 return WebGLAny(scriptState, DOMInt32Array::create(values.get(), len
gth)); |
425 } | 425 } |
426 default: | 426 default: |
427 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d parameter name"); | 427 synthesizeGLError(GL_INVALID_ENUM, "getInternalformatParameter", "invali
d parameter name"); |
428 return ScriptValue::createNull(scriptState); | 428 return ScriptValue::createNull(scriptState); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
(...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2109 if (index >= static_cast<GLuint>(maxIndex)) { | 2109 if (index >= static_cast<GLuint>(maxIndex)) { |
2110 synthesizeGLError(GL_INVALID_VALUE, "getTransformFeedbackVarying", "inva
lid index"); | 2110 synthesizeGLError(GL_INVALID_VALUE, "getTransformFeedbackVarying", "inva
lid index"); |
2111 return nullptr; | 2111 return nullptr; |
2112 } | 2112 } |
2113 | 2113 |
2114 GLint maxNameLength = -1; | 2114 GLint maxNameLength = -1; |
2115 contextGL()->GetProgramiv(objectOrZero(program), GL_TRANSFORM_FEEDBACK_VARYI
NG_MAX_LENGTH, &maxNameLength); | 2115 contextGL()->GetProgramiv(objectOrZero(program), GL_TRANSFORM_FEEDBACK_VARYI
NG_MAX_LENGTH, &maxNameLength); |
2116 if (maxNameLength <= 0) { | 2116 if (maxNameLength <= 0) { |
2117 return nullptr; | 2117 return nullptr; |
2118 } | 2118 } |
2119 std::unique_ptr<GLchar[]> name = wrapArrayUnique(new GLchar[maxNameLength]); | 2119 OwnPtr<GLchar[]> name = adoptArrayPtr(new GLchar[maxNameLength]); |
2120 GLsizei length = 0; | 2120 GLsizei length = 0; |
2121 GLsizei size = 0; | 2121 GLsizei size = 0; |
2122 GLenum type = 0; | 2122 GLenum type = 0; |
2123 contextGL()->GetTransformFeedbackVarying(objectOrZero(program), index, maxNa
meLength, &length, &size, &type, name.get()); | 2123 contextGL()->GetTransformFeedbackVarying(objectOrZero(program), index, maxNa
meLength, &length, &size, &type, name.get()); |
2124 | 2124 |
2125 if (length == 0 || size == 0 || type == 0) { | 2125 if (length == 0 || size == 0 || type == 0) { |
2126 return nullptr; | 2126 return nullptr; |
2127 } | 2127 } |
2128 | 2128 |
2129 return WebGLActiveInfo::create(String(name.get(), length), type, size); | 2129 return WebGLActiveInfo::create(String(name.get(), length), type, size); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2402 if (!validateUniformBlockIndex("getActiveUniformBlockName", program, uniform
BlockIndex)) | 2402 if (!validateUniformBlockIndex("getActiveUniformBlockName", program, uniform
BlockIndex)) |
2403 return String(); | 2403 return String(); |
2404 | 2404 |
2405 GLint maxNameLength = -1; | 2405 GLint maxNameLength = -1; |
2406 contextGL()->GetProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORM_BLOCK_MAX
_NAME_LENGTH, &maxNameLength); | 2406 contextGL()->GetProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORM_BLOCK_MAX
_NAME_LENGTH, &maxNameLength); |
2407 if (maxNameLength <= 0) { | 2407 if (maxNameLength <= 0) { |
2408 // This state indicates that there are no active uniform blocks | 2408 // This state indicates that there are no active uniform blocks |
2409 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniformBlockName", "invali
d uniform block index"); | 2409 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniformBlockName", "invali
d uniform block index"); |
2410 return String(); | 2410 return String(); |
2411 } | 2411 } |
2412 std::unique_ptr<GLchar[]> name = wrapArrayUnique(new GLchar[maxNameLength]); | 2412 OwnPtr<GLchar[]> name = adoptArrayPtr(new GLchar[maxNameLength]); |
2413 | 2413 |
2414 GLsizei length = 0; | 2414 GLsizei length = 0; |
2415 contextGL()->GetActiveUniformBlockName(objectOrZero(program), uniformBlockIn
dex, maxNameLength, &length, name.get()); | 2415 contextGL()->GetActiveUniformBlockName(objectOrZero(program), uniformBlockIn
dex, maxNameLength, &length, name.get()); |
2416 | 2416 |
2417 return String(name.get(), length); | 2417 return String(name.get(), length); |
2418 } | 2418 } |
2419 | 2419 |
2420 void WebGL2RenderingContextBase::uniformBlockBinding(WebGLProgram* program, GLui
nt uniformBlockIndex, GLuint uniformBlockBinding) | 2420 void WebGL2RenderingContextBase::uniformBlockBinding(WebGLProgram* program, GLui
nt uniformBlockIndex, GLuint uniformBlockBinding) |
2421 { | 2421 { |
2422 if (isContextLost() || !validateWebGLObject("uniformBlockBinding", program)) | 2422 if (isContextLost() || !validateWebGLObject("uniformBlockBinding", program)) |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3369 params.skipPixels = m_unpackSkipPixels; | 3369 params.skipPixels = m_unpackSkipPixels; |
3370 params.skipRows = m_unpackSkipRows; | 3370 params.skipRows = m_unpackSkipRows; |
3371 if (dimension == Tex3D) { | 3371 if (dimension == Tex3D) { |
3372 params.imageHeight = m_unpackImageHeight; | 3372 params.imageHeight = m_unpackImageHeight; |
3373 params.skipImages = m_unpackSkipImages; | 3373 params.skipImages = m_unpackSkipImages; |
3374 } | 3374 } |
3375 return params; | 3375 return params; |
3376 } | 3376 } |
3377 | 3377 |
3378 } // namespace blink | 3378 } // namespace blink |
OLD | NEW |