content/canvas/src/DocumentRendererParent.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "mozilla/ipc/DocumentRendererParent.h"
     6 #include "gfxImageSurface.h"
     7 #include "gfxPattern.h"
     8 #include "nsICanvasRenderingContextInternal.h"
    10 using namespace mozilla::ipc;
    12 DocumentRendererParent::DocumentRendererParent()
    13 {}
    15 DocumentRendererParent::~DocumentRendererParent()
    16 {}
    18 void DocumentRendererParent::SetCanvasContext(nsICanvasRenderingContextInternal* aCanvas,
    19                                               gfxContext* ctx)
    20 {
    21     mCanvas = aCanvas;
    22     mCanvasContext = ctx;
    23 }
    25 void DocumentRendererParent::DrawToCanvas(const nsIntSize& aSize,
    26                                           const nsCString& aData)
    27 {
    28     if (!mCanvas || !mCanvasContext)
    29         return;
    31     nsRefPtr<gfxImageSurface> surf =
    32         new gfxImageSurface(reinterpret_cast<uint8_t*>(const_cast<nsCString&>(aData).BeginWriting()),
    33                             gfxIntSize(aSize.width, aSize.height),
    34                             aSize.width * 4,
    35                             gfxImageFormat::ARGB32);
    36     nsRefPtr<gfxPattern> pat = new gfxPattern(surf);
    38     gfxRect rect(gfxPoint(0, 0), gfxSize(aSize.width, aSize.height));
    39     mCanvasContext->NewPath();
    40     mCanvasContext->PixelSnappedRectangleAndSetPattern(rect, pat);
    41     mCanvasContext->Fill();
    43     // get rid of the pattern surface ref, because aData is very
    44     // likely to go away shortly
    45     mCanvasContext->SetColor(gfxRGBA(1,1,1,1));
    47     gfxRect damageRect = mCanvasContext->UserToDevice(rect);
    48     mCanvas->Redraw(damageRect);
    49 }
    51 bool
    52 DocumentRendererParent::Recv__delete__(const nsIntSize& renderedSize,
    53                                        const nsCString& data)
    54 {
    55     DrawToCanvas(renderedSize, data);
    56     return true;
    57 }

mercurial