Bug 944866 - Pat 1: Add DrawLines to Compositor.h and implement for OGL. r=gal

This commit is contained in:
Benoit Girard 2013-12-01 15:54:46 -05:00
parent 6b2b8a9641
commit a7c936fb86
3 changed files with 70 additions and 14 deletions

View File

@ -16,6 +16,7 @@
#include "mozilla/layers/LayersTypes.h" // for LayersBackend
#include "nsTraceRefcnt.h" // for MOZ_COUNT_CTOR, etc
#include "nsRegion.h"
#include <vector>
/**
* Different elements of a web pages are rendered into separate "layers" before
@ -284,7 +285,7 @@ public:
virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) = 0;
/**
* Tell the compositor to actually draw a quad. What to do draw and how it is
* Tell the compositor to draw a quad. What to do draw and how it is
* drawn is specified by aEffectChain. aRect is the quad to draw, in user space.
* aTransform transforms from user space to screen space. If texture coords are
* required, these will be in the primary effect in the effect chain.
@ -293,6 +294,15 @@ public:
const EffectChain& aEffectChain,
gfx::Float aOpacity, const gfx::Matrix4x4 &aTransform) = 0;
/**
* Tell the compositor to draw lines connecting the points. Behaves like
* DrawQuad.
*/
virtual void DrawLines(const std::vector<gfx::Point>& aLines, const gfx::Rect& aClipRect,
const gfx::Color& aColor,
gfx::Float aOpacity, const gfx::Matrix4x4 &aTransform)
{ /* Should turn into pure virtual once implemented in D3D */ }
/**
* Start a new frame.
*

View File

@ -996,11 +996,31 @@ private:
};
void
CompositorOGL::DrawQuad(const Rect& aRect,
const Rect& aClipRect,
const EffectChain &aEffectChain,
Float aOpacity,
const gfx::Matrix4x4 &aTransform)
CompositorOGL::DrawLines(const std::vector<gfx::Point>& aLines, const gfx::Rect& aClipRect,
const gfx::Color& aColor,
gfx::Float aOpacity, const gfx::Matrix4x4 &aTransform)
{
mGLContext->fLineWidth(2.0);
EffectChain effects;
effects.mPrimaryEffect = new EffectSolidColor(aColor);
for (int32_t i = 0; i < (int32_t)aLines.size() - 1; i++) {
const gfx::Point& p1 = aLines[i];
const gfx::Point& p2 = aLines[i+1];
DrawQuadInternal(Rect(p1.x, p2.y, p2.x - p1.x, p1.y - p2.y),
aClipRect, effects, aOpacity, aTransform,
LOCAL_GL_LINE_STRIP);
}
}
void
CompositorOGL::DrawQuadInternal(const Rect& aRect,
const Rect& aClipRect,
const EffectChain &aEffectChain,
Float aOpacity,
const gfx::Matrix4x4 &aTransform,
GLuint aDrawMode)
{
PROFILER_LABEL("CompositorOGL", "DrawQuad");
MOZ_ASSERT(mFrameInProgress, "frame not started");
@ -1091,7 +1111,7 @@ CompositorOGL::DrawQuad(const Rect& aRect,
program->SetMaskLayerTransform(maskQuadTransform);
}
BindAndDrawQuad(program);
BindAndDrawQuad(program, false, aDrawMode);
}
break;
@ -1535,7 +1555,8 @@ CompositorOGL::QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex) {
void
CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
GLuint aTexCoordAttribIndex,
bool aFlipped)
bool aFlipped,
GLuint aDrawMode)
{
BindQuadVBO();
QuadVBOVerticesAttrib(aVertAttribIndex);
@ -1550,7 +1571,11 @@ CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
}
mGLContext->fEnableVertexAttribArray(aVertAttribIndex);
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
if (aDrawMode == LOCAL_GL_LINE_STRIP) {
mGLContext->fDrawArrays(aDrawMode, 1, 2);
} else {
mGLContext->fDrawArrays(aDrawMode, 0, 4);
}
mGLContext->fDisableVertexAttribArray(aVertAttribIndex);
if (aTexCoordAttribIndex != GLuint(-1)) {
@ -1560,12 +1585,13 @@ CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
void
CompositorOGL::BindAndDrawQuad(ShaderProgramOGL *aProg,
bool aFlipped)
bool aFlipped,
GLuint aDrawMode)
{
NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
BindAndDrawQuad(aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib),
aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib),
aFlipped);
aFlipped, aDrawMode);
}

View File

@ -98,7 +98,18 @@ public:
const gfx::Rect& aClipRect,
const EffectChain &aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE;
const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE
{
DrawQuadInternal(aRect, aClipRect, aEffectChain,
aOpacity, aTransform, LOCAL_GL_TRIANGLE_STRIP);
}
virtual void DrawLines(const std::vector<gfx::Point>& aLines,
const gfx::Rect& aClipRect,
const gfx::Color& aColor,
gfx::Float aOpacity,
const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE;
virtual void EndFrame() MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfxMatrix& aTransform) MOZ_OVERRIDE;
@ -171,6 +182,13 @@ public:
*/
GLuint GetTemporaryTexture(GLenum aUnit);
private:
virtual void DrawQuadInternal(const gfx::Rect& aRect,
const gfx::Rect& aClipRect,
const EffectChain &aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4 &aTransformi,
GLuint aDrawMode);
/**
* Context target, nullptr when drawing directly to our swap chain.
*/
@ -291,9 +309,11 @@ private:
void QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex);
void BindAndDrawQuad(GLuint aVertAttribIndex,
GLuint aTexCoordAttribIndex,
bool aFlipped = false);
bool aFlipped = false,
GLuint aDrawMode = LOCAL_GL_TRIANGLE_STRIP);
void BindAndDrawQuad(ShaderProgramOGL *aProg,
bool aFlipped = false);
bool aFlipped = false,
GLuint aDrawMode = LOCAL_GL_TRIANGLE_STRIP);
void BindAndDrawQuadWithTextureRect(ShaderProgramOGL *aProg,
const gfx::Rect& aTexCoordRect,
TextureSource *aTexture);