Bug 486936 - image-rendering style should apply to canvas element. r=vladimir

This commit is contained in:
Robert Longson 2009-06-17 21:31:18 +01:00
parent 6a8d60b403
commit 8a18a5a87c
10 changed files with 74 additions and 16 deletions

View File

@ -39,14 +39,15 @@
#define nsICanvasElement_h___
#include "nsISupports.h"
#include "gfxPattern.h"
class gfxContext;
class nsIFrame;
struct gfxRect;
// {C234660C-BD06-493e-8583-939A5A158B37}
// {D31B3CCF-DDA3-49a8-AEF6-B95AF8E09159}
#define NS_ICANVASELEMENT_IID \
{ 0xc234660c, 0xbd06, 0x493e, { 0x85, 0x83, 0x93, 0x9a, 0x5a, 0x15, 0x8b, 0x37 } }
{ 0xd31b3ccf, 0xdda3, 0x49a8, { 0xae, 0xf6, 0xb9, 0x5a, 0xf8, 0xe0, 0x91, 0x59 } }
class nsIRenderingContext;
@ -72,7 +73,7 @@ public:
* Ask the canvas element to tell the contexts to render themselves
* to the given gfxContext at the origin of its coordinate space.
*/
NS_IMETHOD RenderContexts (gfxContext *ctx) = 0;
NS_IMETHOD RenderContexts (gfxContext *ctx, gfxPattern::GraphicsFilter aFilter) = 0;
/**
* Determine whether the canvas is write-only.

View File

@ -41,10 +41,11 @@
#include "nsISupports.h"
#include "nsICanvasElement.h"
#include "nsIInputStream.h"
#include "gfxPattern.h"
// {eab854fd-aa5e-44bb-8cc5-8d02f84b0216}
// {ed741c16-4039-469b-91da-dca742c51a9f}
#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
{ 0xeab854fd, 0xaa5e, 0x44bb, { 0x8c, 0xc5, 0x8d, 0x02, 0xf8, 0x4b, 0x02, 0x16 } }
{ 0xed741c16, 0x4039, 0x469b, { 0x91, 0xda, 0xdc, 0xa7, 0x42, 0xc5, 0x1a, 0x9f } }
class gfxContext;
class gfxASurface;
@ -62,7 +63,7 @@ public:
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height) = 0;
// Render the canvas at the origin of the given gfxContext
NS_IMETHOD Render(gfxContext *ctx) = 0;
NS_IMETHOD Render(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter) = 0;
// Gives you a stream containing the image represented by this context.
// The format is given in aMimeTime, for example "image/png".

View File

@ -324,7 +324,7 @@ public:
// nsICanvasRenderingContextInternal
NS_IMETHOD SetCanvasElement(nsICanvasElement* aParentCanvas);
NS_IMETHOD SetDimensions(PRInt32 width, PRInt32 height);
NS_IMETHOD Render(gfxContext *ctx);
NS_IMETHOD Render(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter);
NS_IMETHOD GetInputStream(const char* aMimeType,
const PRUnichar* aEncoderOptions,
nsIInputStream **aStream);
@ -984,7 +984,7 @@ nsCanvasRenderingContext2D::SetIsOpaque(PRBool isOpaque)
}
NS_IMETHODIMP
nsCanvasRenderingContext2D::Render(gfxContext *ctx)
nsCanvasRenderingContext2D::Render(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter)
{
nsresult rv = NS_OK;
@ -998,6 +998,8 @@ nsCanvasRenderingContext2D::Render(gfxContext *ctx)
nsRefPtr<gfxPattern> pat = new gfxPattern(mSurface);
pat->SetFilter(aFilter);
gfxContext::GraphicsOperator op = ctx->CurrentOperator();
if (mOpaque)
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
@ -3305,7 +3307,7 @@ nsCanvasRenderingContext2D::ThebesSurfaceFromElement(nsIDOMElement *imgElt,
gfxPlatform::GetPlatform()->CreateOffscreenSurface
(gfxIntSize(w, h), gfxASurface::ImageFormatARGB32);
nsRefPtr<gfxContext> ctx = new gfxContext(surf);
rv = canvas->RenderContexts(ctx);
rv = canvas->RenderContexts(ctx, gfxPattern::FILTER_NEAREST);
if (NS_FAILED(rv))
return rv;
sourceSurface = surf;
@ -3345,7 +3347,7 @@ nsCanvasRenderingContext2D::ThebesSurfaceFromElement(nsIDOMElement *imgElt,
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
video->Paint(ctx, gfxPattern::FILTER_GOOD, gfxRect(0, 0, videoWidth, videoHeight));
video->Paint(ctx, gfxPattern::FILTER_NEAREST, gfxRect(0, 0, videoWidth, videoHeight));
*aSurface = surf.forget().get();
*widthOut = videoWidth;

View File

@ -88,7 +88,7 @@ public:
// nsICanvasElement
NS_IMETHOD GetPrimaryCanvasFrame(nsIFrame **aFrame);
NS_IMETHOD GetSize(PRUint32 *width, PRUint32 *height);
NS_IMETHOD RenderContexts(gfxContext *ctx);
NS_IMETHOD RenderContexts(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter);
virtual PRBool IsWriteOnly();
virtual void SetWriteOnly();
NS_IMETHOD InvalidateFrame ();
@ -521,12 +521,12 @@ nsHTMLCanvasElement::GetSize(PRUint32 *width, PRUint32 *height)
}
NS_IMETHODIMP
nsHTMLCanvasElement::RenderContexts(gfxContext *ctx)
nsHTMLCanvasElement::RenderContexts(gfxContext *ctx, gfxPattern::GraphicsFilter aFilter)
{
if (!mCurrentContext)
return NS_OK;
return mCurrentContext->Render(ctx);
return mCurrentContext->Render(ctx, aFilter);
}
PRBool

View File

@ -598,7 +598,7 @@ CanvasToImageSurface(nsIDOMHTMLCanvasElement *canvas)
ctx->Paint();
ctx->SetOperator(gfxContext::OPERATOR_OVER);
rv = elt->RenderContexts(ctx);
rv = elt->RenderContexts(ctx, gfxPattern::FILTER_NEAREST);
if (NS_FAILED(rv))
return nsnull;

View File

@ -249,7 +249,7 @@ nsHTMLCanvasFrame::PaintCanvas(nsIRenderingContext& aRenderingContext,
ctx->Translate(devInner.pos);
ctx->Scale(sx, sy);
canvas->RenderContexts(ctx);
canvas->RenderContexts(ctx, nsLayoutUtils::GetGraphicsFilterForFrame(this));
ctx->Restore();
}

View File

@ -0,0 +1,26 @@
?<!DOCTYPE HTML>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<html>
<head>
<title>reference image-rendering</title>
<style>
canvas { position:absolute;left:0px;top:0px; }
</style>
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(255,0,0)";
ctx.fillRect(50,50,200,200);
ctx.fillStyle = "rgb(0,255,0)";
ctx.fillRect(50,50,100,100);
}
</script>
</head>
<body onload="draw();">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>

View File

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<html reftest-zoom="2">
<head>
<title>test image-rendering</title>
<style>
canvas { position:absolute;left:0px;top:0px; }
</style>
<script type="text/javascript">
function draw() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "rgb(255,0,0)";
ctx.fillRect(25,25,100,100);
ctx.fillStyle = "rgb(0,255,0)";
ctx.fillRect(25,25,50,50);
}
</script>
</head>
<body onload="draw();">
<canvas style="image-rendering: -moz-crisp-edges; " id="canvas" width="300" height="300"></canvas>
</body>
</html>

View File

@ -1,3 +1,5 @@
== image-rendering-test.html image-rendering-ref.html
!= text-ltr-left.html text-blank.html
!= text-ltr-right.html text-blank.html
!= text-rtl-left.html text-blank.html

View File

@ -616,7 +616,7 @@ nsBaseDragService::DrawDragForImage(nsPresContext* aPresContext,
nsIntRect(0, 0, srcSize.width, srcSize.height));
return NS_OK;
} else {
return aCanvas->RenderContexts(ctx);
return aCanvas->RenderContexts(ctx, gfxPattern::FILTER_GOOD);
}
}