Bug 1012407 - Part 2: Use Moz2D to draw velocity graph and elminiate use of GL_LINE_STRIP (r=Bas)

This commit is contained in:
Andreas Gal 2014-05-21 23:24:16 +02:00
Родитель 202b439890
Коммит 013ca12b06
4 изменённых файлов: 41 добавлений и 75 удалений

Просмотреть файл

@ -308,15 +308,6 @@ 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 */ }
/*
* Clear aRect on current render target.
*/

Просмотреть файл

@ -36,6 +36,8 @@
namespace mozilla {
namespace layers {
using namespace gfx;
/**
* Returns a rectangle of content painted opaquely by aLayer. Very consertative;
* bails by returning an empty rect in any tricky situations.
@ -204,35 +206,46 @@ static void DrawVelGraph(const nsIntRect& aClipRect,
aManager->SetDebugOverlayWantsNextFrame(true);
const gfx::Matrix4x4& transform = aLayer->GetEffectiveTransform();
const Matrix4x4& transform = aLayer->GetEffectiveTransform();
nsIntRect bounds = aLayer->GetEffectiveVisibleRegion().GetBounds();
gfx::Rect graphBounds = gfx::Rect(bounds.x, bounds.y,
bounds.width, bounds.height);
gfx::Rect graphRect = gfx::Rect(bounds.x, bounds.y, 200, 100);
IntSize graphSize = IntSize(200, 100);
Rect graphRect = Rect(bounds.x, bounds.y, graphSize.width, graphSize.height);
float opacity = 1.0;
EffectChain effects;
effects.mPrimaryEffect = new EffectSolidColor(gfx::Color(0.2f,0,0,1));
compositor->DrawQuad(graphRect,
clipRect,
effects,
opacity,
transform);
RefPtr<DrawTarget> dt = aManager->CreateDrawTarget(graphSize, SurfaceFormat::B8G8R8A8);
dt->FillRect(Rect(0, 0, graphSize.width, graphSize.height),
ColorPattern(Color(0.2f,0,0,1)));
std::vector<gfx::Point> graph;
int yScaleFactor = 3;
Point prev = Point(0,0);
bool first = true;
for (int32_t i = (int32_t)velocityData->mData.size() - 2; i >= 0; i--) {
const gfx::Point& p1 = velocityData->mData[i+1].mPoint;
const gfx::Point& p2 = velocityData->mData[i].mPoint;
int vel = sqrt((p1.x - p2.x) * (p1.x - p2.x) +
(p1.y - p2.y) * (p1.y - p2.y));
graph.push_back(
gfx::Point(bounds.x + graphRect.width / circularBufferSize * i,
graphBounds.y + graphRect.height - vel/yScaleFactor));
Point next = Point(graphRect.width / circularBufferSize * i,
graphRect.height - vel/yScaleFactor);
if (first) {
first = false;
} else {
dt->StrokeLine(prev, next, ColorPattern(Color(0,1,0,1)));
}
prev = next;
}
compositor->DrawLines(graph, clipRect, gfx::Color(0,1,0,1),
opacity, transform);
RefPtr<DataTextureSource> textureSource = compositor->CreateDataTextureSource();
RefPtr<SourceSurface> snapshot = dt->Snapshot();
RefPtr<DataSourceSurface> data = snapshot->GetDataSurface();
textureSource->Update(data);
EffectChain effectChain;
effectChain.mPrimaryEffect = CreateTexturedEffect(SurfaceFormat::B8G8R8A8, textureSource, Filter::POINT);
compositor->DrawQuad(graphRect,
clipRect,
effectChain,
1.0f,
transform);
}
// ContainerRender is shared between RefLayer and ContainerLayer

Просмотреть файл

@ -875,25 +875,6 @@ CompositorOGL::GetShaderProgramFor(const ShaderConfigOGL &aConfig)
return shader;
}
void
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);
}
}
static bool SetBlendMode(GLContext* aGL, gfx::CompositionOp aBlendMode, bool aIsPremultiplied = true)
{
if (aBlendMode == gfx::CompositionOp::OP_OVER && aIsPremultiplied) {
@ -934,8 +915,7 @@ CompositorOGL::DrawQuadInternal(const Rect& aRect,
const Rect& aClipRect,
const EffectChain &aEffectChain,
Float aOpacity,
const gfx::Matrix4x4 &aTransform,
GLuint aDrawMode)
const gfx::Matrix4x4 &aTransform)
{
PROFILER_LABEL("CompositorOGL", "DrawQuad");
MOZ_ASSERT(mFrameInProgress, "frame not started");
@ -1044,7 +1024,7 @@ CompositorOGL::DrawQuadInternal(const Rect& aRect,
didSetBlendMode = SetBlendMode(gl(), blendMode);
BindAndDrawQuad(program, aDrawMode);
BindAndDrawQuad(program);
}
break;
@ -1483,8 +1463,7 @@ CompositorOGL::QuadVBOTexCoordsAttrib(GLuint aAttribIndex) {
void
CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
GLuint aTexCoordAttribIndex,
GLuint aDrawMode)
GLuint aTexCoordAttribIndex)
{
BindQuadVBO();
QuadVBOVerticesAttrib(aVertAttribIndex);
@ -1495,21 +1474,15 @@ CompositorOGL::BindAndDrawQuad(GLuint aVertAttribIndex,
}
mGLContext->fEnableVertexAttribArray(aVertAttribIndex);
if (aDrawMode == LOCAL_GL_LINE_STRIP) {
mGLContext->fDrawArrays(aDrawMode, 1, 2);
} else {
mGLContext->fDrawArrays(aDrawMode, 0, 4);
}
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
}
void
CompositorOGL::BindAndDrawQuad(ShaderProgramOGL *aProg,
GLuint aDrawMode)
CompositorOGL::BindAndDrawQuad(ShaderProgramOGL *aProg)
{
NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
BindAndDrawQuad(aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib),
aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib),
aDrawMode);
aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib));
}
GLuint

Просмотреть файл

@ -206,17 +206,9 @@ public:
gfx::Float aOpacity,
const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE
{
DrawQuadInternal(aRect, aClipRect, aEffectChain,
aOpacity, aTransform, LOCAL_GL_TRIANGLE_STRIP);
DrawQuadInternal(aRect, aClipRect, aEffectChain, aOpacity, aTransform);
}
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 SetFBAcquireFence(Layer* aLayer) MOZ_OVERRIDE;
virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE;
@ -289,8 +281,7 @@ private:
const gfx::Rect& aClipRect,
const EffectChain &aEffectChain,
gfx::Float aOpacity,
const gfx::Matrix4x4 &aTransformi,
GLuint aDrawMode);
const gfx::Matrix4x4 &aTransform);
virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE
{
@ -387,10 +378,8 @@ private:
void QuadVBOVerticesAttrib(GLuint aAttribIndex);
void QuadVBOTexCoordsAttrib(GLuint aAttribIndex);
void BindAndDrawQuad(GLuint aVertAttribIndex,
GLuint aTexCoordAttribIndex,
GLuint aDrawMode = LOCAL_GL_TRIANGLE_STRIP);
void BindAndDrawQuad(ShaderProgramOGL *aProg,
GLuint aDrawMode = LOCAL_GL_TRIANGLE_STRIP);
GLuint aTexCoordAttribIndex);
void BindAndDrawQuad(ShaderProgramOGL *aProg);
void BindAndDrawQuadWithTextureRect(ShaderProgramOGL *aProg,
const gfx3DMatrix& aTextureTransform,
const gfx::Rect& aTexCoordRect,