diff --git a/gfx/layers/Compositor.h b/gfx/layers/Compositor.h index 69fbf908b966..d9de13d761fd 100644 --- a/gfx/layers/Compositor.h +++ b/gfx/layers/Compositor.h @@ -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& 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. */ diff --git a/gfx/layers/composite/ContainerLayerComposite.cpp b/gfx/layers/composite/ContainerLayerComposite.cpp index a90e99f65e9a..f0c9f1dd2f89 100644 --- a/gfx/layers/composite/ContainerLayerComposite.cpp +++ b/gfx/layers/composite/ContainerLayerComposite.cpp @@ -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 dt = aManager->CreateDrawTarget(graphSize, SurfaceFormat::B8G8R8A8); + dt->FillRect(Rect(0, 0, graphSize.width, graphSize.height), + ColorPattern(Color(0.2f,0,0,1))); - std::vector 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 textureSource = compositor->CreateDataTextureSource(); + RefPtr snapshot = dt->Snapshot(); + RefPtr 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 diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp index c9caf84fc02f..0310797d6610 100644 --- a/gfx/layers/opengl/CompositorOGL.cpp +++ b/gfx/layers/opengl/CompositorOGL.cpp @@ -875,25 +875,6 @@ CompositorOGL::GetShaderProgramFor(const ShaderConfigOGL &aConfig) return shader; } -void -CompositorOGL::DrawLines(const std::vector& 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 diff --git a/gfx/layers/opengl/CompositorOGL.h b/gfx/layers/opengl/CompositorOGL.h index d65313af0b3f..5ff67cf3c743 100644 --- a/gfx/layers/opengl/CompositorOGL.h +++ b/gfx/layers/opengl/CompositorOGL.h @@ -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& 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,