Bug 1087568 - Port the code that uses gfxContext::PixelSnappedRectangleAndSetPattern to Moz2D. r=mattwoodrow

This commit is contained in:
Jonathan Watt 2014-10-24 08:26:27 +01:00
parent 9e5994197d
commit 8622f2a289
3 changed files with 10 additions and 44 deletions

View File

@ -2,10 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/gfx/2D.h"
#include "mozilla/ipc/DocumentRendererParent.h"
#include "gfx2DGlue.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/gfx/PathHelpers.h"
#include "mozilla/RefPtr.h"
#include "gfxPattern.h"
#include "nsICanvasRenderingContextInternal.h"
using namespace mozilla;
@ -31,23 +33,18 @@ void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
if (!mCanvas || !mCanvasContext)
return;
DrawTarget* drawTarget = mCanvasContext->GetDrawTarget();
Rect rect(0, 0, aSize.width, aSize.height);
MaybeSnapToDevicePixels(rect, *drawTarget, true);
RefPtr<DataSourceSurface> dataSurface =
Factory::CreateWrappingDataSourceSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
aSize.width * 4,
IntSize(aSize.width, aSize.height),
SurfaceFormat::B8G8R8A8);
nsRefPtr<gfxPattern> pat = new gfxPattern(dataSurface, Matrix());
SurfacePattern pattern(dataSurface, ExtendMode::CLAMP);
drawTarget->FillRect(rect, pattern);
gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
mCanvasContext->NewPath();
mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
mCanvasContext->Fill();
// get rid of the pattern surface ref, because aData is very
// likely to go away shortly
mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
gfxRect damageRect = mCanvasContext->UserToDevice(rect);
gfxRect damageRect = mCanvasContext->UserToDevice(ThebesRect(rect));
mCanvas->Redraw(damageRect);
}

View File

@ -549,28 +549,6 @@ gfxContext::UserToDevicePixelSnapped(gfxPoint& pt, bool ignoreScale) const
return true;
}
void
gfxContext::PixelSnappedRectangleAndSetPattern(const gfxRect& rect,
gfxPattern *pattern)
{
gfxRect r(rect);
// Bob attempts to pixel-snap the rectangle, and returns true if
// the snapping succeeds. If it does, we need to set up an
// identity matrix, because the rectangle given back is in device
// coordinates.
//
// We then have to call a translate to dr.pos afterwards, to make
// sure the image lines up in the right place with our pixel
// snapped rectangle.
//
// If snapping wasn't successful, we just translate to where the
// pattern would normally start (in app coordinates) and do the
// same thing.
Rectangle(r, true);
SetPattern(pattern);
}
void
gfxContext::SetAntialiasMode(AntialiasMode mode)
{

View File

@ -308,15 +308,6 @@ public:
*/
bool UserToDevicePixelSnapped(gfxPoint& pt, bool ignoreScale = false) const;
/**
* Attempts to pixel snap the rectangle, add it to the current
* path, and to set pattern as the current painting source. This
* should be used for drawing filled pixel-snapped rectangles (like
* images), because the CTM at the time of the SetPattern call needs
* to have a snapped translation, or you get smeared images.
*/
void PixelSnappedRectangleAndSetPattern(const gfxRect& rect, gfxPattern *pattern);
/**
** Painting sources
**/