fix up a few lines based on nsICODecoder, to get nsSVGDecoder to draw a teal rectangle.
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 10 May 2010 11:53:36 -0700
changeset 1563 59d52fa39c2301c76f3375015eae69abe992fe1a
parent 1562 70a80121927daf521d67d8e4e028bb61cf4736c8
child 1564 5e6ad66a2f960a196f7e33da34ee5d4f90b246d5
push id1260
push userdholbert@mozilla.com
push dateMon, 10 May 2010 18:53:51 +0000
fix up a few lines based on nsICODecoder, to get nsSVGDecoder to draw a teal rectangle.
svg_images
--- a/svg_images
+++ b/svg_images
@@ -178,17 +178,17 @@ new file mode 100644
 +# LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/src
 +
 +include $(topsrcdir)/config/rules.mk
 +
 diff --git a/modules/libpr0n/decoders/svg/nsSVGDecoder.cpp b/modules/libpr0n/decoders/svg/nsSVGDecoder.cpp
 new file mode 100644
 --- /dev/null
 +++ b/modules/libpr0n/decoders/svg/nsSVGDecoder.cpp
-@@ -0,0 +1,135 @@
+@@ -0,0 +1,153 @@
 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 +/* ***** BEGIN LICENSE BLOCK *****
 + * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 + *
 + * The contents of this file are subject to the Mozilla Public License Version
 + * 1.1 (the "License"); you may not use this file except in compliance with
 + * the License. You may obtain a copy of the License at
 + * http://www.mozilla.org/MPL/
@@ -271,54 +271,72 @@ new file mode 100644
 +
 +  return NS_OK;
 +}
 +
 +/* void close (); */
 +NS_IMETHODIMP
 +nsSVGDecoder::Close(PRUint32 aFlags)
 +{
++  nsIntRect frameRect(0, 0, TMP_IMG_WIDTH, TMP_IMG_HEIGHT);
++  mImage->FrameUpdated(0, frameRect);
++
++  // From nsICODecoder
++  if (mObserver) {
++    mObserver->OnDataAvailable(nsnull, PR_TRUE, &frameRect);
++    mObserver->OnStopFrame(nsnull, 0);
++  }
 +  mImage->DecodingComplete();
 +  if (mObserver) {
-+    mObserver->OnStopContainer(nsnull, mImage);
++    mObserver->OnStopContainer(nsnull, 0);
 +    mObserver->OnStopDecode(nsnull, NS_OK, nsnull);
 +  }
 +  mImage = nsnull;
 +  return NS_OK;
 +}
 +
 +/* void flush (); */
 +NS_IMETHODIMP
 +nsSVGDecoder::Flush()
 +{
 +  return NS_OK;
 +}
 +
++// From nsBMPDecoder
++static inline void SetPixel(PRUint32*& aDecoded,
++                            PRUint8 aRed, PRUint8 aGreen, PRUint8 aBlue,
++                            PRUint8 aAlpha = 0xFF)
++{
++  *aDecoded++ = GFX_PACKED_PIXEL(aAlpha, aRed, aGreen, aBlue);
++}
++
++
 +NS_IMETHODIMP
 +nsSVGDecoder::Write(const char *aBuffer, PRUint32 aCount)
 +{
 +  // XXXdholbert TESTING
 +  if (!mHaveWrittenData) {
-+    PRUint8* imgDataPtr = nsnull;
++    PRUint32* imgDataPtr = nsnull;
 +    PRUint32 imgDataLength;
 +
 +    mImage->SetSize(TMP_IMG_WIDTH, TMP_IMG_HEIGHT);
-+    mImage->AppendFrame(0,0, TMP_IMG_WIDTH, TMP_IMG_HEIGHT,
++    if (mObserver) {
++      mObserver->OnStartContainer(nsnull, mImage);
++    }
++    mImage->AppendFrame(0, 0, TMP_IMG_WIDTH, TMP_IMG_HEIGHT,
 +                        gfxASurface::ImageFormatARGB32,
-+                        &imgDataPtr, &imgDataLength);
-+
++                        (PRUint8**)&imgDataPtr, &imgDataLength);
++    if (mObserver) {
++      mObserver->OnStartFrame(nsnull, 0);
++    }
 +
-+    nsIntRect frameRect(0, 0, TMP_IMG_WIDTH, TMP_IMG_HEIGHT);
-+    mImage->FrameUpdated(0, frameRect);
-+    mObserver->OnDataAvailable(nsnull, PR_TRUE, &frameRect);
++    for (PRUint32 pixelIdx = 0; pixelIdx < imgDataLength / sizeof(PRUint32); ++pixelIdx) {
++      SetPixel(imgDataPtr, 0x00, 0x80, 0x80);
++    }      
 +
-+    mImage->EndFrameDecode(0);
-+    mImage->DecodingComplete();
-+
-+    memset(imgDataPtr, 0xff, imgDataLength);
 +    mHaveWrittenData = PR_TRUE;
 +    // XXXdholbert END TESTING
 +  }
 +  return NS_OK;
 +}
 diff --git a/modules/libpr0n/decoders/svg/nsSVGDecoder.h b/modules/libpr0n/decoders/svg/nsSVGDecoder.h
 new file mode 100644
 --- /dev/null