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

Side by Side Diff: Source/core/html/canvas/WebGL2RenderingContextBase.cpp

Issue 1210673002: Improving support for WebGL2 Query objects (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 6 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 // 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 "config.h" 5 #include "config.h"
6 #include "core/html/canvas/WebGL2RenderingContextBase.h" 6 #include "core/html/canvas/WebGL2RenderingContextBase.h"
7 7
8 #include "bindings/core/v8/WebGLAny.h" 8 #include "bindings/core/v8/WebGLAny.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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 WebGL2RenderingContextBase::~WebGL2RenderingContextBase() 48 WebGL2RenderingContextBase::~WebGL2RenderingContextBase()
49 { 49 {
50 m_readFramebufferBinding = nullptr; 50 m_readFramebufferBinding = nullptr;
51 51
52 m_boundCopyReadBuffer = nullptr; 52 m_boundCopyReadBuffer = nullptr;
53 m_boundCopyWriteBuffer = nullptr; 53 m_boundCopyWriteBuffer = nullptr;
54 m_boundPixelPackBuffer = nullptr; 54 m_boundPixelPackBuffer = nullptr;
55 m_boundPixelUnpackBuffer = nullptr; 55 m_boundPixelUnpackBuffer = nullptr;
56 m_boundTransformFeedbackBuffer = nullptr; 56 m_boundTransformFeedbackBuffer = nullptr;
57 m_boundUniformBuffer = nullptr; 57 m_boundUniformBuffer = nullptr;
58
59 m_currentBooleanOcclusionQuery = nullptr;
60 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
58 } 61 }
59 62
60 void WebGL2RenderingContextBase::initializeNewContext() 63 void WebGL2RenderingContextBase::initializeNewContext()
61 { 64 {
62 ASSERT(!isContextLost()); 65 ASSERT(!isContextLost());
63 ASSERT(drawingBuffer()); 66 ASSERT(drawingBuffer());
64 67
65 m_readFramebufferBinding = nullptr; 68 m_readFramebufferBinding = nullptr;
66 69
67 m_boundCopyReadBuffer = nullptr; 70 m_boundCopyReadBuffer = nullptr;
68 m_boundCopyWriteBuffer = nullptr; 71 m_boundCopyWriteBuffer = nullptr;
69 m_boundPixelPackBuffer = nullptr; 72 m_boundPixelPackBuffer = nullptr;
70 m_boundPixelUnpackBuffer = nullptr; 73 m_boundPixelUnpackBuffer = nullptr;
71 m_boundTransformFeedbackBuffer = nullptr; 74 m_boundTransformFeedbackBuffer = nullptr;
72 m_boundUniformBuffer = nullptr; 75 m_boundUniformBuffer = nullptr;
73 76
77 m_currentBooleanOcclusionQuery = nullptr;
78 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
79
74 m_max3DTextureSize = 0; 80 m_max3DTextureSize = 0;
75 webContext()->getIntegerv(GL_MAX_3D_TEXTURE_SIZE, &m_max3DTextureSize); 81 webContext()->getIntegerv(GL_MAX_3D_TEXTURE_SIZE, &m_max3DTextureSize);
76 m_max3DTextureLevel = WebGLTexture::computeLevelCount(m_max3DTextureSize, m_ max3DTextureSize, m_max3DTextureSize); 82 m_max3DTextureLevel = WebGLTexture::computeLevelCount(m_max3DTextureSize, m_ max3DTextureSize, m_max3DTextureSize);
77 83
78 WebGLRenderingContextBase::initializeNewContext(); 84 WebGLRenderingContextBase::initializeNewContext();
79 } 85 }
80 86
81 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) 87 void WebGL2RenderingContextBase::copyBufferSubData(GLenum readTarget, GLenum wri teTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
82 { 88 {
83 if (isContextLost()) 89 if (isContextLost())
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 { 1042 {
1037 if (isContextLost()) 1043 if (isContextLost())
1038 return nullptr; 1044 return nullptr;
1039 RefPtrWillBeRawPtr<WebGLQuery> o = WebGLQuery::create(this); 1045 RefPtrWillBeRawPtr<WebGLQuery> o = WebGLQuery::create(this);
1040 addSharedObject(o.get()); 1046 addSharedObject(o.get());
1041 return o; 1047 return o;
1042 } 1048 }
1043 1049
1044 void WebGL2RenderingContextBase::deleteQuery(WebGLQuery* query) 1050 void WebGL2RenderingContextBase::deleteQuery(WebGLQuery* query)
1045 { 1051 {
1052 if (m_currentBooleanOcclusionQuery == query) {
1053 webContext()->endQueryEXT(m_currentBooleanOcclusionQuery->getTarget());
1054 m_currentBooleanOcclusionQuery = nullptr;
1055 }
1056
1057 if (m_currentTransformFeedbackPrimitivesWrittenQuery == query) {
1058 webContext()->endQueryEXT(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
1059 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
1060 }
1061
1046 deleteObject(query); 1062 deleteObject(query);
1047 } 1063 }
1048 1064
1049 GLboolean WebGL2RenderingContextBase::isQuery(WebGLQuery* query) 1065 GLboolean WebGL2RenderingContextBase::isQuery(WebGLQuery* query)
1050 { 1066 {
1051 if (isContextLost() || !query) 1067 if (isContextLost() || !query)
1052 return 0; 1068 return 0;
1053 1069
1054 return webContext()->isQueryEXT(query->object()); 1070 return webContext()->isQueryEXT(query->object());
1055 } 1071 }
1056 1072
1057 void WebGL2RenderingContextBase::beginQuery(GLenum target, WebGLQuery* query) 1073 void WebGL2RenderingContextBase::beginQuery(GLenum target, WebGLQuery* query)
1058 { 1074 {
1059 if (isContextLost() || !validateWebGLObject("beginQuery", query)) 1075 bool deleted;
1076 if (!checkObjectToBeBound("beginQuery", query, deleted))
1060 return; 1077 return;
1078 if (deleted) {
1079 synthesizeGLError(GL_INVALID_OPERATION, "beginQuery", "attempted to begi n a deleted query object");
1080 return;
1081 }
1082
1083 if (!query->compatibleTarget(target)) {
1084 synthesizeGLError(GL_INVALID_OPERATION, "beginQuery", "query type does n ot match target");
1085 return;
1086 }
1087
1088 switch (target) {
1089 case GL_ANY_SAMPLES_PASSED:
1090 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
1091 {
1092 if (m_currentBooleanOcclusionQuery) {
1093 synthesizeGLError(GL_INVALID_OPERATION, "beginQuery", "a query i s already active for target");
1094 return;
1095 }
1096 m_currentBooleanOcclusionQuery = query;
1097 }
1098 break;
1099 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1100 {
1101 if (m_currentTransformFeedbackPrimitivesWrittenQuery) {
1102 synthesizeGLError(GL_INVALID_OPERATION, "beginQuery", "a query i s already active for target");
1103 return;
1104 }
1105 m_currentTransformFeedbackPrimitivesWrittenQuery = query;
1106 }
1107 break;
1108 default:
1109 synthesizeGLError(GL_INVALID_ENUM, "beginQuery", "invalid target");
1110 return;
1111 }
1112
1113 query->setTarget(target);
1061 1114
1062 webContext()->beginQueryEXT(target, query->object()); 1115 webContext()->beginQueryEXT(target, query->object());
1063 } 1116 }
1064 1117
1065 void WebGL2RenderingContextBase::endQuery(GLenum target) 1118 void WebGL2RenderingContextBase::endQuery(GLenum target)
1066 { 1119 {
1067 if (isContextLost()) 1120 if (isContextLost())
1068 return; 1121 return;
1069 1122
1123 switch (target) {
1124 case GL_ANY_SAMPLES_PASSED:
1125 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
1126 {
1127 if (m_currentBooleanOcclusionQuery && m_currentBooleanOcclusionQuery ->getTarget() == target) {
1128 m_currentBooleanOcclusionQuery = nullptr;
1129 } else {
1130 synthesizeGLError(GL_INVALID_OPERATION, "endQuery", "target quer y is not active");
1131 return;
1132 }
1133 }
1134 break;
1135 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1136 {
1137 if (m_currentTransformFeedbackPrimitivesWrittenQuery) {
1138 m_currentTransformFeedbackPrimitivesWrittenQuery = nullptr;
1139 } else {
1140 synthesizeGLError(GL_INVALID_OPERATION, "endQuery", "target quer y is not active");
1141 return;
1142 }
1143 }
1144 break;
1145 default:
1146 synthesizeGLError(GL_INVALID_ENUM, "endQuery", "invalid target");
1147 return;
1148 }
1149
1070 webContext()->endQueryEXT(target); 1150 webContext()->endQueryEXT(target);
1071 } 1151 }
1072 1152
1073 PassRefPtrWillBeRawPtr<WebGLQuery> WebGL2RenderingContextBase::getQuery(GLenum t arget, GLenum pname) 1153 PassRefPtrWillBeRawPtr<WebGLQuery> WebGL2RenderingContextBase::getQuery(GLenum t arget, GLenum pname)
Ken Russell (switch to Gerrit) 2015/06/24 21:07:22 I think that we might have made a mistake when ori
1074 { 1154 {
1075 if (isContextLost()) 1155 if (isContextLost())
1076 return nullptr; 1156 return nullptr;
1077 1157
1078 notImplemented(); 1158 if (pname != GL_CURRENT_QUERY) {
1159 synthesizeGLError(GL_INVALID_ENUM, "getQuery", "invalid parameter name") ;
1160 return nullptr;
1161 }
1162
1163 switch (target) {
1164 case GL_ANY_SAMPLES_PASSED:
1165 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
1166 if (m_currentBooleanOcclusionQuery && m_currentBooleanOcclusionQuery->ge tTarget() == target)
1167 return PassRefPtrWillBeRawPtr<WebGLQuery>(m_currentBooleanOcclusionQ uery.get());
1168 break;
1169 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
1170 return PassRefPtrWillBeRawPtr<WebGLQuery>(m_currentTransformFeedbackPrim itivesWrittenQuery.get());
1171 default:
1172 synthesizeGLError(GL_INVALID_ENUM, "getQuery", "invalid target");
1173 return nullptr;
1174 }
1079 return nullptr; 1175 return nullptr;
1080 } 1176 }
1081 1177
1082 ScriptValue WebGL2RenderingContextBase::getQueryParameter(ScriptState* scriptSta te, WebGLQuery* query, GLenum pname) 1178 ScriptValue WebGL2RenderingContextBase::getQueryParameter(ScriptState* scriptSta te, WebGLQuery* query, GLenum pname)
1083 { 1179 {
1084 if (isContextLost() || !validateWebGLObject("getQueryParameter", query)) 1180 if (isContextLost() || !validateWebGLObject("getQueryParameter", query))
1085 return ScriptValue::createNull(scriptState); 1181 return ScriptValue::createNull(scriptState);
1086 1182
1087 switch (pname) { 1183 switch (pname) {
1088 case GL_QUERY_RESULT: 1184 case GL_QUERY_RESULT:
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 DEFINE_TRACE(WebGL2RenderingContextBase) 2074 DEFINE_TRACE(WebGL2RenderingContextBase)
1979 { 2075 {
1980 visitor->trace(m_readFramebufferBinding); 2076 visitor->trace(m_readFramebufferBinding);
1981 visitor->trace(m_transformFeedbackBinding); 2077 visitor->trace(m_transformFeedbackBinding);
1982 visitor->trace(m_boundCopyReadBuffer); 2078 visitor->trace(m_boundCopyReadBuffer);
1983 visitor->trace(m_boundCopyWriteBuffer); 2079 visitor->trace(m_boundCopyWriteBuffer);
1984 visitor->trace(m_boundPixelPackBuffer); 2080 visitor->trace(m_boundPixelPackBuffer);
1985 visitor->trace(m_boundPixelUnpackBuffer); 2081 visitor->trace(m_boundPixelUnpackBuffer);
1986 visitor->trace(m_boundTransformFeedbackBuffer); 2082 visitor->trace(m_boundTransformFeedbackBuffer);
1987 visitor->trace(m_boundUniformBuffer); 2083 visitor->trace(m_boundUniformBuffer);
2084 visitor->trace(m_currentBooleanOcclusionQuery);
2085 visitor->trace(m_currentTransformFeedbackPrimitivesWrittenQuery);
1988 WebGLRenderingContextBase::trace(visitor); 2086 WebGLRenderingContextBase::trace(visitor);
1989 } 2087 }
1990 2088
1991 WebGLTexture* WebGL2RenderingContextBase::validateTextureBinding(const char* fun ctionName, GLenum target, bool useSixEnumsForCubeMap) 2089 WebGLTexture* WebGL2RenderingContextBase::validateTextureBinding(const char* fun ctionName, GLenum target, bool useSixEnumsForCubeMap)
1992 { 2090 {
1993 WebGLTexture* tex = nullptr; 2091 WebGLTexture* tex = nullptr;
1994 switch (target) { 2092 switch (target) {
1995 case GL_TEXTURE_2D_ARRAY: 2093 case GL_TEXTURE_2D_ARRAY:
1996 tex = m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding.get(); 2094 tex = m_textureUnits[m_activeTextureUnit].m_texture2DArrayBinding.get();
1997 if (!tex) 2095 if (!tex)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2125 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat() 2223 GLenum WebGL2RenderingContextBase::boundFramebufferColorFormat()
2126 { 2224 {
2127 if (m_readFramebufferBinding && m_readFramebufferBinding->object()) 2225 if (m_readFramebufferBinding && m_readFramebufferBinding->object())
2128 return m_readFramebufferBinding->colorBufferFormat(); 2226 return m_readFramebufferBinding->colorBufferFormat();
2129 if (m_requestedAttributes.alpha()) 2227 if (m_requestedAttributes.alpha())
2130 return GL_RGBA; 2228 return GL_RGBA;
2131 return GL_RGB; 2229 return GL_RGB;
2132 } 2230 }
2133 2231
2134 } // namespace blink 2232 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698