summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmo@google.com <zmo@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>2012-04-11 22:12:37 (GMT)
committerPierre-Antoine LaFayette <plafayet@codeaurora.org>2012-07-13 17:44:10 (GMT)
commit66bc9c1b9eb5151b1b236199d0eeb17df0557b47 (patch)
tree3f87d1ef3003c0d0782cba6fed7f3b14d404a6aa
parentb521df690ec8eb2c683771c6f99a2ecef9d2c643 (diff)
WebGLRenderingContext should defer caching program info
https://bugs.webkit.org/show_bug.cgi?id=83513 Reviewed by Kenneth Russell. * html/canvas/WebGLProgram.cpp: (WebCore::WebGLProgram::WebGLProgram): (WebCore::WebGLProgram::numActiveAttribLocations): call cacheInfoIfNeeded(); (WebCore::WebGLProgram::getActiveAttribLocation): Ditto. (WebCore::WebGLProgram::isUsingVertexAttrib0): Ditto. (WebCore::WebGLProgram::getLinkStatus): Ditto. (WebCore): (WebCore::WebGLProgram::cacheActiveAttribLocations): (WebCore::WebGLProgram::cacheInfoIfNeeded): Cache link status, active attire locations, etc if needed. (WebCore::WebGLProgram::increaseLinkCount): also invalidate cached info. * html/canvas/WebGLProgram.h: (WebGLProgram): * html/canvas/WebGLRenderingContext.cpp: (WebCore): (WebCore::WebGLRenderingContext::linkProgram): Do not cache program info immediately. CRs-fixed: 340203 Change-Id: I90a7b8ca91f0491df093759a0773cad968da41ab git-svn-id: http://svn.webkit.org/repository/webkit/trunk@113915 268f45cc-cd09-0410-ab3c-d52691b4dbfc
-rw-r--r--Source/WebCore/ChangeLog23
-rw-r--r--Source/WebCore/html/canvas/WebGLProgram.cpp84
-rw-r--r--Source/WebCore/html/canvas/WebGLProgram.h21
-rw-r--r--Source/WebCore/html/canvas/WebGLRenderingContext.cpp6
4 files changed, 93 insertions, 41 deletions
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 7bdb919..db8f129 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,26 @@
+2012-04-10 Zhenyao Mo <zmo@google.com>
+
+ WebGLRenderingContext should defer caching program info
+ https://bugs.webkit.org/show_bug.cgi?id=83513
+
+ Reviewed by Kenneth Russell.
+
+ * html/canvas/WebGLProgram.cpp:
+ (WebCore::WebGLProgram::WebGLProgram):
+ (WebCore::WebGLProgram::numActiveAttribLocations): call cacheInfoIfNeeded();
+ (WebCore::WebGLProgram::getActiveAttribLocation): Ditto.
+ (WebCore::WebGLProgram::isUsingVertexAttrib0): Ditto.
+ (WebCore::WebGLProgram::getLinkStatus): Ditto.
+ (WebCore):
+ (WebCore::WebGLProgram::cacheActiveAttribLocations):
+ (WebCore::WebGLProgram::cacheInfoIfNeeded): Cache link status, active attire locations, etc if needed.
+ (WebCore::WebGLProgram::increaseLinkCount): also invalidate cached info.
+ * html/canvas/WebGLProgram.h:
+ (WebGLProgram):
+ * html/canvas/WebGLRenderingContext.cpp:
+ (WebCore):
+ (WebCore::WebGLRenderingContext::linkProgram): Do not cache program info immediately.
+
2011-10-06 Dominic Cooney <dominicc@chromium.org>
Don't make virtual calls in Node::parentNode.
diff --git a/Source/WebCore/html/canvas/WebGLProgram.cpp b/Source/WebCore/html/canvas/WebGLProgram.cpp
index d3efda4..ec99dc4 100644
--- a/Source/WebCore/html/canvas/WebGLProgram.cpp
+++ b/Source/WebCore/html/canvas/WebGLProgram.cpp
@@ -42,6 +42,7 @@ WebGLProgram::WebGLProgram(WebGLRenderingContext* ctx)
: WebGLObject(ctx)
, m_linkStatus(false)
, m_linkCount(0)
+ , m_infoValid(true)
{
setObject(context()->graphicsContext3D()->createProgram());
}
@@ -59,43 +60,23 @@ void WebGLProgram::deleteObjectImpl(Platform3DObject obj)
}
}
-bool WebGLProgram::cacheActiveAttribLocations()
-{
- m_activeAttribLocations.clear();
- if (!object())
- return false;
- GraphicsContext3D* context3d = context()->graphicsContext3D();
-
- // Assume link status has already been cached.
- if (!m_linkStatus)
- return false;
-
- GC3Dint numAttribs = 0;
- context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs);
- m_activeAttribLocations.resize(static_cast<size_t>(numAttribs));
- for (int i = 0; i < numAttribs; ++i) {
- ActiveInfo info;
- context3d->getActiveAttrib(object(), i, info);
- m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info.name.charactersWithNullTermination());
- }
-
- return true;
-}
-
-unsigned WebGLProgram::numActiveAttribLocations() const
+unsigned WebGLProgram::numActiveAttribLocations()
{
+ cacheInfoIfNeeded();
return m_activeAttribLocations.size();
}
-GC3Dint WebGLProgram::getActiveAttribLocation(GC3Duint index) const
+GC3Dint WebGLProgram::getActiveAttribLocation(GC3Duint index)
{
+ cacheInfoIfNeeded();
if (index >= numActiveAttribLocations())
return -1;
return m_activeAttribLocations[index];
}
-bool WebGLProgram::isUsingVertexAttrib0() const
+bool WebGLProgram::isUsingVertexAttrib0()
{
+ cacheInfoIfNeeded();
for (unsigned ii = 0; ii < numActiveAttribLocations(); ++ii) {
if (!getActiveAttribLocation(ii))
return true;
@@ -103,6 +84,24 @@ bool WebGLProgram::isUsingVertexAttrib0() const
return false;
}
+bool WebGLProgram::getLinkStatus()
+{
+ cacheInfoIfNeeded();
+ return m_linkStatus;
+}
+
+void WebGLProgram::setLinkStatus(bool status)
+{
+ cacheInfoIfNeeded();
+ m_linkStatus = status;
+}
+
+void WebGLProgram::increaseLinkCount()
+{
+ ++m_linkCount;
+ m_infoValid = false;
+}
+
WebGLShader* WebGLProgram::getAttachedShader(GC3Denum type)
{
switch (type) {
@@ -155,6 +154,39 @@ bool WebGLProgram::detachShader(WebGLShader* shader)
}
}
+void WebGLProgram::cacheActiveAttribLocations(GraphicsContext3D* context3d)
+{
+ m_activeAttribLocations.clear();
+
+ GC3Dint numAttribs = 0;
+ context3d->getProgramiv(object(), GraphicsContext3D::ACTIVE_ATTRIBUTES, &numAttribs);
+ m_activeAttribLocations.resize(static_cast<size_t>(numAttribs));
+ for (int i = 0; i < numAttribs; ++i) {
+ ActiveInfo info;
+ context3d->getActiveAttrib(object(), i, info);
+ m_activeAttribLocations[i] = context3d->getAttribLocation(object(), info.name.charactersWithNullTermination());
+ }
+}
+
+void WebGLProgram::cacheInfoIfNeeded()
+{
+ if (m_infoValid)
+ return;
+
+ if (!object())
+ return;
+
+ GraphicsContext3D* ctx = context()->graphicsContext3D();
+ if (!ctx)
+ return;
+ GC3Dint linkStatus = 0;
+ ctx->getProgramiv(object(), GraphicsContext3D::LINK_STATUS, &linkStatus);
+ m_linkStatus = linkStatus;
+ if (m_linkStatus)
+ cacheActiveAttribLocations(ctx);
+ m_infoValid = true;
+}
+
}
#endif // ENABLE(WEBGL)
diff --git a/Source/WebCore/html/canvas/WebGLProgram.h b/Source/WebCore/html/canvas/WebGLProgram.h
index 0dd3ba0..13a5bdd 100644
--- a/Source/WebCore/html/canvas/WebGLProgram.h
+++ b/Source/WebCore/html/canvas/WebGLProgram.h
@@ -42,23 +42,21 @@ public:
static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*);
- // cacheActiveAttribLocation() is only called once after linkProgram()
- // succeeds.
- bool cacheActiveAttribLocations();
- unsigned numActiveAttribLocations() const;
- GC3Dint getActiveAttribLocation(GC3Duint index) const;
+ unsigned numActiveAttribLocations();
+ GC3Dint getActiveAttribLocation(GC3Duint index);
- bool isUsingVertexAttrib0() const;
+ bool isUsingVertexAttrib0();
- bool getLinkStatus() const { return m_linkStatus; }
- void setLinkStatus(bool status) { m_linkStatus = status; }
+ bool getLinkStatus();
+ void setLinkStatus(bool);
unsigned getLinkCount() const { return m_linkCount; }
// This is to be called everytime after the program is successfully linked.
// We don't deal with integer overflow here, assuming in reality a program
// will never be linked so many times.
- void increaseLinkCount() { ++m_linkCount; }
+ // Also, we invalidate the cached program info.
+ void increaseLinkCount();
WebGLShader* getAttachedShader(GC3Denum);
bool attachShader(WebGLShader*);
@@ -72,6 +70,9 @@ protected:
private:
virtual bool isProgram() const { return true; }
+ void cacheActiveAttribLocations(GraphicsContext3D*);
+ void cacheInfoIfNeeded();
+
Vector<GC3Dint> m_activeAttribLocations;
GC3Dint m_linkStatus;
@@ -82,6 +83,8 @@ private:
RefPtr<WebGLShader> m_vertexShader;
RefPtr<WebGLShader> m_fragmentShader;
+
+ bool m_infoValid;
};
} // namespace WebCore
diff --git a/Source/WebCore/html/canvas/WebGLRenderingContext.cpp b/Source/WebCore/html/canvas/WebGLRenderingContext.cpp
index 457a2b1..d5b9e36 100644
--- a/Source/WebCore/html/canvas/WebGLRenderingContext.cpp
+++ b/Source/WebCore/html/canvas/WebGLRenderingContext.cpp
@@ -2813,12 +2813,6 @@ void WebGLRenderingContext::linkProgram(WebGLProgram* program, ExceptionCode& ec
m_context->linkProgram(objectOrZero(program));
program->increaseLinkCount();
- // cache link status
- GC3Dint value = 0;
- m_context->getProgramiv(objectOrZero(program), GraphicsContext3D::LINK_STATUS, &value);
- program->setLinkStatus(static_cast<bool>(value));
- // Need to cache link status before caching active attribute locations.
- program->cacheActiveAttribLocations();
cleanupAfterGraphicsCall(false);
}