merge with changes for GPU backend



git-svn-id: http://skia.googlecode.com/svn/trunk@637 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index b9753c8..ad5706b 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -98,12 +98,18 @@
     */
     SkDevice* setDevice(SkDevice* device);
 
-    /** Deprecated - Specify a bitmap for the canvas to draw into. This is a
-        helper method for setDevice(), and it creates a device for the bitmap by
-        calling createDevice(). The structure of the bitmap is copied into the
-        device.
-    */
-    virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
+    /** May be overridden by subclasses. This returns a compatible device
+        for this canvas, with the specified config/width/height. If the device
+        is raster, the pixels will be allocated automatically.
+     */
+    virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
+                                   bool isOpaque, bool forLayer = false);
+
+    /**
+     *  Create a new raster device and make it current. This also returns
+     *  the new device.
+     */
+    SkDevice* setBitmapDevice(const SkBitmap& bitmap, bool forLayer = false);
 
     ///////////////////////////////////////////////////////////////////////////
 
@@ -692,16 +698,7 @@
     */
     const SkRegion& getTotalClip() const;
 
-    /** May be overridden by subclasses. This returns a compatible device
-        for this canvas, with the specified config/width/height. If isOpaque
-        is true, then the underlying bitmap is optimized to assume that every
-        pixel will be drawn to, and thus it does not need to clear the alpha
-        channel ahead of time (assuming the specified config supports per-pixel
-        alpha.) If isOpaque is false, then the bitmap should clear its alpha
-        channel.
-    */
-    virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
-                                   bool isOpaque, bool isForLayer);
+    void setExternalMatrix(const SkMatrix* = NULL);
 
     ///////////////////////////////////////////////////////////////////////////
 
@@ -737,7 +734,7 @@
         // in our constructor to ensure that fStorage is large enough
         // (though needs to be a compile-time-assert!). We use intptr_t to work
         // safely with 32 and 64 bit machines (to ensure the storage is enough)
-        intptr_t          fStorage[12];
+        intptr_t          fStorage[32];
         class SkDrawIter* fImpl;    // this points at fStorage
         SkPaint           fDefaultPaint;
         bool              fDone;
@@ -745,8 +742,8 @@
 
 protected:
     // all of the drawBitmap variants call this guy
-    virtual void commonDrawBitmap(const SkBitmap&, const SkMatrix& m,
-                                  const SkPaint& paint);
+    virtual void commonDrawBitmap(const SkBitmap&, const SkIRect*,
+                                  const SkMatrix&, const SkPaint& paint);
     
 private:
     class MCRec;
@@ -761,7 +758,7 @@
     SkDevice*   fLastDeviceToGainFocus;
     SkDeviceFactory* fDeviceFactory;
 
-    void prepareForDeviceDraw(SkDevice*);
+    void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&);
     
     bool fDeviceCMDirty;            // cleared by updateDeviceCMCache()
     void updateDeviceCMCache();
@@ -769,7 +766,7 @@
     friend class SkDrawIter;    // needs setupDrawForLayerDevice()
 
     SkDevice* init(SkDevice*);
-    void internalDrawBitmap(const SkBitmap&, const SkMatrix& m,
+    void internalDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix& m,
                                   const SkPaint* paint);
     void drawDevice(SkDevice*, int x, int y, const SkPaint*);
     // shared by save() and saveLayer()
@@ -807,6 +804,9 @@
         }
     }
     void computeLocalClipBoundsCompareType(EdgeType et) const;
+
+    SkMatrix    fExternalMatrix, fExternalInverse;
+    bool        fUseExternalMatrix;
 };
 
 /** Stack helper class to automatically call restoreToCount() on the canvas
diff --git a/include/core/SkChunkAlloc.h b/include/core/SkChunkAlloc.h
index 810e7b6..ba9e2c9 100644
--- a/include/core/SkChunkAlloc.h
+++ b/include/core/SkChunkAlloc.h
@@ -55,7 +55,14 @@
     size_t unalloc(void* ptr);
     
     size_t totalCapacity() const { return fTotalCapacity; }
-    
+
+    /**
+     *  Returns true if the specified address is within one of the chunks, and
+     *  has at least 1-byte following the address (i.e. if addr points to the
+     *  end of a chunk, then contains() will return false).
+     */
+    bool contains(const void* addr) const;
+
 private:
     struct Block;
     Block*  fBlock;
diff --git a/include/core/SkColorShader.h b/include/core/SkColorShader.h
index 7c5f941..44a6148 100644
--- a/include/core/SkColorShader.h
+++ b/include/core/SkColorShader.h
@@ -29,14 +29,16 @@
     /** Create a ColorShader that will inherit its color from the Paint
         at draw time.
     */
-    SkColorShader() : fFlags(0), fInheritColor(true) {}
+    SkColorShader();
 
     /** Create a ColorShader that ignores the color in the paint, and uses the
         specified color. Note: like all shaders, at draw time the paint's alpha
         will be respected, and is applied to the specified color.
     */
-    SkColorShader(SkColor c) : fColor(c), fFlags(0), fInheritColor(false) {}
-    
+    SkColorShader(SkColor c);
+
+    virtual ~SkColorShader();
+
     virtual uint32_t getFlags() { return fFlags; }
     virtual uint8_t getSpan16Alpha() const;
     virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
@@ -45,6 +47,10 @@
     virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
     virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
 
+    virtual BitmapType asABitmap(SkBitmap* outTexture, 
+                                 SkMatrix* outMatrix,
+                                 TileMode xy[2], 
+                                 SkScalar* twoPointRadialParams);
 protected:
     SkColorShader(SkFlattenableReadBuffer& );
     virtual void flatten(SkFlattenableWriteBuffer& );
@@ -59,6 +65,9 @@
     uint16_t    fColor16;       // cached after setContext()
     SkBool8     fInheritColor;
 
+    // deferred allocation, used for asABitmap()
+    SkPixelRef* fAsABitmapPixelRef;
+
     typedef SkShader INHERITED;
 };
 
diff --git a/include/core/SkDescriptor.h b/include/core/SkDescriptor.h
index 8074cff..09397b7 100644
--- a/include/core/SkDescriptor.h
+++ b/include/core/SkDescriptor.h
@@ -120,13 +120,14 @@
         return true;
     }
 
+    uint32_t getChecksum() const { return fChecksum; }
+
     struct Entry {
         uint32_t fTag;
         uint32_t fLen;
     };
 
 #ifdef SK_DEBUG
-    uint32_t getChecksum() const { return fChecksum; }
     uint32_t getCount() const { return fCount; }
 #endif
 
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 089d6e6..ec62033 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -37,26 +37,30 @@
 class SkDeviceFactory {
 public:
     virtual ~SkDeviceFactory();
-    virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
-                                bool isOpaque, bool isForLayer) = 0;
+    virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
+                                int height, bool isOpaque, bool isLayer) = 0;
 };
 
 class SkRasterDeviceFactory : public SkDeviceFactory {
 public:
-    virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
-                                bool isOpaque, bool isForLayer);
+    virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
+                                int height, bool isOpaque, bool isLayer);
 };
 
 class SkDevice : public SkRefCnt {
 public:
-    SkDevice();
-    /** Construct a new device, extracting the width/height/config/isOpaque
-        values from the bitmap.  Subclasses may override the destructor, which
-        is virtual, even though this class doesn't have one. SkRefCnt does.
-
+    SkDevice(SkCanvas*);
+    /** Construct a new device, extracting the width/height/config/isOpaque values from
+        the bitmap. If transferPixelOwnership is true, and the bitmap claims to own its
+        own pixels (getOwnsPixels() == true), then transfer this responsibility to the
+        device, and call setOwnsPixels(false) on the bitmap.
+        
+        Subclasses may override the destructor, which is virtual, even though this class
+        doesn't have one. SkRefCnt does.
+    
         @param bitmap   A copy of this bitmap is made and stored in the device
     */
-    SkDevice(const SkBitmap& bitmap);
+    SkDevice(SkCanvas*, const SkBitmap& bitmap, bool forOffscreen);
 
     virtual SkDeviceFactory* getDeviceFactory() {
         return SkNEW(SkRasterDeviceFactory);
@@ -112,6 +116,11 @@
     virtual void lockPixels();
     virtual void unlockPixels();
 
+    /** Return the device's associated texture, or NULL. If returned, it may be
+        drawn into another device
+     */
+    virtual SkGpuTexture* accessTexture() { return NULL; }
+
     /** Called with the correct matrix and clip before this device is drawn
         to using those settings. If your subclass overrides this, be sure to
         call through to the base class as well.
@@ -121,7 +130,24 @@
     /** Called when this device gains focus (i.e becomes the current device
         for drawing).
     */
-    virtual void gainFocus(SkCanvas*) {}
+    virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&) {}
+    
+    /** Causes any deferred drawing to the device to be completed.
+     */
+    virtual void flush() {}
+
+    /**
+     *  Copy the pixels from the device into bitmap. Returns true on success.
+     *  If false is returned, then the bitmap parameter is left unchanged.
+     */
+    virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
+
+    /**
+     *  Similar to draw sprite, this method will copy the pixels in bitmap onto
+     *  the device, with the top/left corner specified by (x, y). The pixel
+     *  values in the device are completely replaced: there is no blending.
+     */
+    virtual void writePixels(const SkBitmap& bitmap, int x, int y);
 
     /** These are called inside the per-device-layer loop for each draw call.
      When these are called, we have already applied any saveLayer operations,
@@ -134,8 +160,11 @@
     virtual void drawRect(const SkDraw&, const SkRect& r,
                           const SkPaint& paint);
     virtual void drawPath(const SkDraw&, const SkPath& path,
-                          const SkPaint& paint);
+                          const SkPaint& paint,
+                          const SkMatrix* prePathMatrix = NULL,
+                          bool pathIsMutable = false);
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
+                            const SkIRect* srcRectOrNull,
                             const SkMatrix& matrix, const SkPaint& paint);
     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
                             int x, int y, const SkPaint& paint);
@@ -162,7 +191,15 @@
     */
     virtual void onAccessBitmap(SkBitmap*);
 
+    SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
+    // just for subclasses, to assign a custom pixelref
+    SkPixelRef* setPixelRef(SkPixelRef* pr, size_t offset) {
+        fBitmap.setPixelRef(pr, offset);
+        return pr;
+    }
+
 private:
+    SkCanvas* fCanvas;
     SkBitmap fBitmap;
 };
 
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index 5ed4aad..2c0fa49 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -33,12 +33,12 @@
 
 class SkDraw {
 public:
-    SkDraw() : fDevice(NULL), fBounder(NULL), fProcs(NULL) {}
+    SkDraw();
     SkDraw(const SkDraw& src);
 
     void    drawPaint(const SkPaint&) const;
     void    drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
-                       const SkPaint&) const;
+                       const SkPaint&, bool forceUseDevice = false) const;
     void    drawRect(const SkRect&, const SkPaint&) const;
     /*  To save on mallocs, we allow a flag that tells us that srcPath is
         mutable, so that we don't have to make copies of it as we transform it.
@@ -83,12 +83,18 @@
     const SkBitmap* fBitmap;        // required
     const SkMatrix* fMatrix;        // required
     const SkRegion* fClip;          // required
+
     SkDevice*       fDevice;        // optional
     SkBounder*      fBounder;       // optional
     SkDrawProcs*    fProcs;         // optional
 
+    const SkMatrix* fMVMatrix;      // optional
+    const SkMatrix* fExtMatrix;     // optional
+
 #ifdef SK_DEBUG
-    void    validate(int width, int height) const;
+    void validate() const;
+#else
+    void validate() const {}
 #endif
 };
 
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index b6a013d..ca59a8c 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -25,13 +25,15 @@
 class SkMallocPixelRef : public SkPixelRef {
 public:
     /** Allocate the specified buffer for pixels. The memory is freed when the
-        last owner of this pixelref is gone.
+        last owner of this pixelref is gone. If addr is NULL, sk_malloc_throw()
+        is called to allocate it.
      */
     SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable);
     virtual ~SkMallocPixelRef();
     
     //! Return the allocation size for the pixels
     size_t getSize() const { return fSize; }
+    void* getAddr() const { return fStorage; }
 
     // overrides from SkPixelRef
     virtual void flatten(SkFlattenableWriteBuffer&) const;
@@ -57,4 +59,5 @@
     typedef SkPixelRef INHERITED;
 };
 
+
 #endif
diff --git a/include/core/SkMask.h b/include/core/SkMask.h
index 608010d..58a2493 100644
--- a/include/core/SkMask.h
+++ b/include/core/SkMask.h
@@ -44,8 +44,9 @@
            edges. kVerticalLCD_Format has an extra row at the top and bottom.
         */
 
-        kHorizontalLCD_Format, //!< 4 bytes/pixel: a/r/g/b
-        kVerticalLCD_Format, //!< 4 bytes/pixel: a/r/g/b
+        kHorizontalLCD_Format,  //!< 4 bytes/pixel: a/r/g/b
+        kVerticalLCD_Format,    //!< 4 bytes/pixel: a/r/g/b
+        kARGB32_Format,         //!< SkPMColor
     };
 
     enum {
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index 22ebd60..af19083 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -161,6 +161,13 @@
     return 32 - SkCLZ(value - 1);
 }
 
+/** Returns true if value is a power of 2. Does not explicitly check for
+    value <= 0.
+ */
+static inline bool SkIsPow2(int value) {
+    return (value & (value - 1)) == 0;
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 
 /** SkMulS16(a, b) multiplies a * b, but requires that a and b are both int16_t.
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index cb6473c..57cc368 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -107,8 +107,16 @@
     #endif
 
     #ifndef SK_DEBUGBREAK
-        #define SK_DEBUGBREAK(cond)     do { if (!(cond)) DebugBreak(); } while (false)
+        #define SK_DEBUGBREAK(cond)     do { if (!(cond)) __debugbreak(); } while (false)
     #endif
+
+    #ifndef SK_A32_SHIFT
+        #define SK_A32_SHIFT 24
+        #define SK_R32_SHIFT 16
+        #define SK_G32_SHIFT 8
+        #define SK_B32_SHIFT 0
+    #endif
+
 #elif defined(SK_BUILD_FOR_MAC)
     #ifndef SK_DEBUGBREAK
         #define SK_DEBUGBREAK(cond)     do { if (!(cond)) SK_CRASH(); } while (false)
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h
index 0a5170c..dd1538a 100644
--- a/include/core/SkPreConfig.h
+++ b/include/core/SkPreConfig.h
@@ -17,9 +17,17 @@
 #ifndef SkPreConfig_DEFINED
 #define SkPreConfig_DEFINED
 
+#ifdef WEBKIT_VERSION_MIN_REQUIRED
+    #include "config.h"
+#endif
+
 //////////////////////////////////////////////////////////////////////
 
-#if !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL)
+#if !defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_PALM) && !defined(SK_BUILD_FOR_WINCE) && !defined(SK_BUILD_FOR_WIN32) && !defined(SK_BUILD_FOR_SYMBIAN) && !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUILD_FOR_SDL)
+
+    #ifdef __APPLE__
+        #include "TargetConditionals.h"
+    #endif
 
     #if defined(PALMOS_SDK_VERSION)
         #define SK_BUILD_FOR_PALM
@@ -31,6 +39,12 @@
         #define SK_BUILD_FOR_WIN32
     #elif defined(linux)
         #define SK_BUILD_FOR_UNIX
+    #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+        #define SK_BUILD_FOR_IOS
+    #elif defined(ANDROID_NDK)
+        #define SK_BUILD_FOR_ANDROID_NDK
+    #elif defined(ANROID)
+        #define SK_BUILD_FOR_ANDROID
     #else
         #define SK_BUILD_FOR_MAC
     #endif
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h
index 103e2cc..8d9ff01 100644
--- a/include/core/SkRegion.h
+++ b/include/core/SkRegion.h
@@ -263,7 +263,8 @@
         bool done() { return fDone; }
         void next();
         const SkIRect& rect() const { return fRect; }
-
+        // may return null
+        const SkRegion* rgn() const { return fRgn; }
     private:
         const SkRegion* fRgn;
         const RunType*  fRuns;
diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h
index ab43b14..9617c57 100644
--- a/include/core/SkScalerContext.h
+++ b/include/core/SkScalerContext.h
@@ -44,11 +44,23 @@
 
     uint8_t     fMaskFormat;
     int8_t      fRsbDelta, fLsbDelta;  // used by auto-kerning
-    
+
+    void init(uint32_t id) {
+        fID             = id;
+        fImage          = NULL;
+        fPath           = NULL;
+#ifdef SK_GPU_AWARE_GLYPHCACHE
+        fGLCacheOffset  = SKGLYPH_GLCACHEOFFSET_INVALID;
+        fGLStrikePtr    = NULL;
+#endif
+    }
+
     unsigned rowBytes() const {
         unsigned rb = fWidth;
         if (SkMask::kBW_Format == fMaskFormat) {
             rb = (rb + 7) >> 3;
+		} else if (SkMask::kARGB32_Format == fMaskFormat) {
+			rb <<= 2;
         } else {
             rb = SkAlign4(rb);
         }
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index f3d4856..1cdbf17 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -145,12 +145,56 @@
     virtual void beginSession();
     virtual void endSession();
     
+    /**
+     Gives method bitmap should be read to implement a shader.
+     Also determines number and interpretation of "extra" parameters returned
+     by asABitmap
+     */
+    enum BitmapType {
+        kNone_BitmapType,   //<! Shader is not represented as a bitmap
+        kDefault_BitmapType,//<! Access bitmap using local coords transformed 
+                            //   by matrix. No extras
+        kRadial_BitmapType, //<! Access bitmap by transforming local coordinates 
+                            //   by the matrix and taking the distance of result 
+                            //   from  (0,0) as bitmap column. Bitmap is 1 pixel 
+                            //   tall. No extras
+        kSweep_BitmapType,  //<! Access bitmap by transforming local coordinates 
+                            //   by the matrix and taking the angle of result
+                            //   to (0,0) as bitmap x coord, where angle = 0 is
+                            //   bitmap left edge of bitmap = 2pi is the 
+                            //   right edge. Bitmap is 1 pixel tall. No extras
+        kTwoPointRadial_BitmapType
+                            //<! Matrix transforms to space where (0,0) is 
+                            //   the center of the starting circle.  The second
+                            //   circle will be centered (x, 0) where x  may be 
+                            //   0. The post-matrix space is normalized such 
+                            //   that 1 is the second radius - first radius.
+                            //   Three extra parameters are returned:
+                            //      0: x-offset of second circle center 
+                            //         to first.
+                            //      1: radius of first circle in post-matrix 
+                            //         space
+                            //      2: the second radius minus the first radius
+                            //         in pre-transformed space.        
+        
+    };
     /** Optional methods for shaders that can pretend to be a bitmap/texture
-        to play along with opengl. Default just returns false and ignores
-        the out parameters.
+        to play along with opengl. Default just returns kNone_BitmapType and 
+        ignores the out parameters.
+
+        @param outTexture if non-NULL will be the bitmap representing the shader
+                          after return.
+        @param outMatrix  if non-NULL will be the matrix to apply to vertices
+                          to access the bitmap after return.
+        @param xy         if non-NULL will be the tile modes that should be
+                          used to access the bitmap after return.
+        @param twoPointRadialParams Two extra return values needed for two point
+                                    radial bitmaps. The first is the x-offset of
+                                    the second point and the second is the radius
+                                    about the first point.
     */
-    virtual bool asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
-                           TileMode xy[2]);
+    virtual BitmapType asABitmap(SkBitmap* outTexture, SkMatrix* outMatrix,
+                                 TileMode xy[2], SkScalar* twoPointRadialParams);
 
     //////////////////////////////////////////////////////////////////////////
     //  Factory methods for stock shaders
diff --git a/include/core/SkThread_platform.h b/include/core/SkThread_platform.h
index c2d0348..c6fd058 100644
--- a/include/core/SkThread_platform.h
+++ b/include/core/SkThread_platform.h
@@ -17,7 +17,7 @@
 #ifndef SkThread_platform_DEFINED
 #define SkThread_platform_DEFINED
 
-#ifdef ANDROID
+#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
 
 #include <utils/threads.h>
 #include <utils/Atomic.h>
diff --git a/include/core/SkUtils.h b/include/core/SkUtils.h
index 0700aeb..7cb2066 100644
--- a/include/core/SkUtils.h
+++ b/include/core/SkUtils.h
@@ -39,7 +39,7 @@
 typedef void (*SkMemset32Proc)(uint32_t dst[], uint32_t value, int count);
 SkMemset32Proc SkMemset32GetPlatformProc();
 
-#ifdef ANDROID
+#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
     #include "cutils/memory.h"
     
     #define sk_memset16(dst, value, count)    android_memset16(dst, value, (count) << 1)
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index b92dc3d..3ef234a 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -32,7 +32,7 @@
 class SkPDFStream;
 
 class SkPDFDeviceFactory : public SkDeviceFactory {
-    virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+    virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width, int height,
                                 bool isOpaque, bool isForLayer);
 };
 
@@ -66,6 +66,10 @@
     */
     virtual void setMatrixClip(const SkMatrix&, const SkRegion&);
 
+    virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
+        return false;
+    }
+
     /** These are called inside the per-device-layer loop for each draw call.
      When these are called, we have already applied any saveLayer operations,
      and are handling any looping from the paint, and any effects from the
@@ -79,6 +83,7 @@
     virtual void drawPath(const SkDraw&, const SkPath& path,
                           const SkPaint& paint);
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
+                            const SkIRect* srcRectOrNull,
                             const SkMatrix& matrix, const SkPaint& paint);
     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y,
                             const SkPaint& paint);
diff --git a/include/utils/SkProxyCanvas.h b/include/utils/SkProxyCanvas.h
index 082e0fd..98ef778 100644
--- a/include/utils/SkProxyCanvas.h
+++ b/include/utils/SkProxyCanvas.h
@@ -22,10 +22,7 @@
     // overrides from SkCanvas
 
     virtual bool getViewport(SkIPoint* size) const;
-    virtual bool setViewport(int x, int y);
     
-    virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
-
     virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
     virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
                           SaveFlags flags = kARGB_ClipLayer_SaveFlag);
diff --git a/include/utils/SkTextFormatParams.h b/include/utils/SkTextFormatParams.h
deleted file mode 100644
index 3306270..0000000
--- a/include/utils/SkTextFormatParams.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SkTextFormatParams_DEFINES
-#define SkTextFormatParams_DEFINES
-
-#include "SkScalar.h"
-#include "SkTypes.h"
-
-// Fraction of the text size to lower a strike through line below the baseline.
-#define kStdStrikeThru_Offset       (-SK_Scalar1 * 6 / 21)
-// Fraction of the text size to lower a underline below the baseline.
-#define kStdUnderline_Offset        (SK_Scalar1 / 9)
-// Fraction of the text size to use for a strike through or under-line.
-#define kStdUnderline_Thickness     (SK_Scalar1 / 18)
-
-// The fraction of text size to embolden fake bold text scales with text size.
-// At 9 points or below, the stroke width is increased by text size / 24.
-// At 36 points and above, it is increased by text size / 32.  In between,
-// it is interpolated between those values.
-static const SkScalar kStdFakeBoldInterpKeys[] = {
-    SkIntToScalar(9),
-    SkIntToScalar(36)
-};
-static const SkScalar kStdFakeBoldInterpValues[] = {
-    SK_Scalar1/24,
-    SK_Scalar1/32
-};
-SK_COMPILE_ASSERT(SK_ARRAY_COUNT(kStdFakeBoldInterpKeys) ==
-                  SK_ARRAY_COUNT(kStdFakeBoldInterpValues),
-                  mismatched_array_size);
-static const int kStdFakeBoldInterpLength =
-    SK_ARRAY_COUNT(kStdFakeBoldInterpKeys);
-
-#endif  //SkTextFormatParams_DEFINES
diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/mac/SkCGUtils.h
index 3b74b55..b1263f4 100644
--- a/include/utils/mac/SkCGUtils.h
+++ b/include/utils/mac/SkCGUtils.h
@@ -1,10 +1,18 @@
 #ifndef SkCGUtils_DEFINED
 #define SkCGUtils_DEFINED
 
-#include <Carbon/Carbon.h>
+#include "SkTypes.h"
+
+#ifdef SK_BUILD_FOR_MAC
+    #include <Carbon/Carbon.h>
+#else
+    #include <CoreGraphics/CoreGraphics.h>
+#endif
 
 class SkBitmap;
 
 CGImageRef SkCreateCGImageRef(const SkBitmap&);
 
+void SkCGDrawBitmap(CGContextRef, const SkBitmap&, float x, float y);
+
 #endif
diff --git a/include/views/SkEvent.h b/include/views/SkEvent.h
index 2b43f34..f6719d6 100644
--- a/include/views/SkEvent.h
+++ b/include/views/SkEvent.h
@@ -21,8 +21,6 @@
 #include "SkMetaData.h"
 #include "SkString.h"
 
-//class SkOSWindow;
-
 /** Unique 32bit id used to identify an instance of SkEventSink. When events are
     posted, they are posted to a specific sinkID. When it is time to dispatch the
     event, the sinkID is used to find the specific SkEventSink object. If it is found,
@@ -100,6 +98,9 @@
     */
     bool    findPtr(const char name[], void** value) const { return fMeta.findPtr(name, value); }
     bool    findBool(const char name[], bool* value) const { return fMeta.findBool(name, value); }
+    const void* findData(const char name[], size_t* byteCount = NULL) const {
+        return fMeta.findData(name, byteCount);
+    }
 
     /** Returns true if ethe event contains the named 32bit field, and if it equals the specified value */
     bool    hasS32(const char name[], int32_t value) const { return fMeta.hasS32(name, value); }
@@ -110,6 +111,9 @@
     /** Returns true if ethe event contains the named pointer field, and if it equals the specified value */
     bool    hasPtr(const char name[], void* value) const { return fMeta.hasPtr(name, value); }
     bool    hasBool(const char name[], bool value) const { return fMeta.hasBool(name, value); }
+    bool hasData(const char name[], const void* data, size_t byteCount) const {
+        return fMeta.hasData(name, data, byteCount);
+    }
 
     /** Add/replace the named 32bit field to the event. In XML use the subelement <data name=... s32=... /> */
     void    setS32(const char name[], int32_t value) { fMeta.setS32(name, value); }
@@ -124,6 +128,9 @@
     /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */
     void    setPtr(const char name[], void* value) { fMeta.setPtr(name, value); }
     void    setBool(const char name[], bool value) { fMeta.setBool(name, value); }
+    void setData(const char name[], const void* data, size_t byteCount) {
+        fMeta.setData(name, data, byteCount);
+    }
 
     /** Return the underlying metadata object */
     SkMetaData&         getMetaData() { return fMeta; }
@@ -197,6 +204,12 @@
     */
     static void     ServiceQueueTimer();
 
+    /** Return the number of queued events. note that this value may be obsolete
+        upon return, since another thread may have called ProcessEvent() or
+        Post() after the count was made.
+     */
+    static int CountEventsOnQueue();
+
     ////////////////////////////////////////////////////
     /** Porting layer must implement these functions **/
     ////////////////////////////////////////////////////
diff --git a/include/views/SkMetaData.h b/include/views/SkMetaData.h
index 21739fe..9509710 100644
--- a/include/views/SkMetaData.h
+++ b/include/views/SkMetaData.h
@@ -35,6 +35,7 @@
     const char* findString(const char name[]) const;
     bool    findPtr(const char name[], void** value = NULL) const;
     bool    findBool(const char name[], bool* value = NULL) const;
+    const void* findData(const char name[], size_t* byteCount = NULL) const;
 
     bool    hasS32(const char name[], int32_t value) const
     {
@@ -62,6 +63,11 @@
         bool    v;
         return this->findBool(name, &v) && v == value;
     }
+    bool hasData(const char name[], const void* data, size_t byteCount) const {
+        size_t len;
+        const void* ptr = this->findData(name, &len);
+        return NULL != ptr && len == byteCount && !memcmp(ptr, data, len);
+    }
 
     void    setS32(const char name[], int32_t value);
     void    setScalar(const char name[], SkScalar value);
@@ -69,12 +75,15 @@
     void    setString(const char name[], const char value[]);
     void    setPtr(const char name[], void* value);
     void    setBool(const char name[], bool value);
+    // the data is copied from the input pointer.
+    void    setData(const char name[], const void* data, size_t byteCount);
 
     bool    removeS32(const char name[]);
     bool    removeScalar(const char name[]);
     bool    removeString(const char name[]);
     bool    removePtr(const char name[]);
     bool    removeBool(const char name[]);
+    bool    removeData(const char name[]);
 
     SkDEBUGCODE(static void UnitTest();)
 
@@ -84,6 +93,7 @@
         kString_Type,
         kPtr_Type,
         kBool_Type,
+        kData_Type,
 
         kTypeCount
     };
diff --git a/include/views/SkOSWindow_Mac.h b/include/views/SkOSWindow_Mac.h
index 98e76b0..3a26d5a 100644
--- a/include/views/SkOSWindow_Mac.h
+++ b/include/views/SkOSWindow_Mac.h
@@ -33,7 +33,12 @@
     static OSStatus EventHandler(EventHandlerCallRef inHandler,
                                  EventRef inEvent, void* userData);
 
-    void    doPaint(void* ctx);
+    void   doPaint(void* ctx);
+
+
+    bool attachGL(const SkBitmap* offscreen);
+    void detachGL();
+    void presentGL();
 
 protected:
     // overrides from SkEventSink
@@ -43,10 +48,12 @@
     // overrides from SkView
     virtual void onAddMenu(const SkOSMenu*);
     virtual void onSetTitle(const char[]);
+    
 
 private:
     void*   fHWND;
     void*   fHVIEW;
+    void*   fAGLCtx;
 
     typedef SkWindow INHERITED;
 };
diff --git a/include/views/SkOSWindow_Win.h b/include/views/SkOSWindow_Win.h
index 0a70f75..09f0c5c 100644
--- a/include/views/SkOSWindow_Win.h
+++ b/include/views/SkOSWindow_Win.h
@@ -22,12 +22,23 @@
 class SkOSWindow : public SkWindow {
 public:
     SkOSWindow(void* hwnd);
+    virtual ~SkOSWindow();
 
     void*   getHWND() const { return fHWND; }
     void    setSize(int width, int height);
     void    updateSize();
 
     static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
+    
+    bool attachGL(const SkBitmap* offscreen);
+    void detachGL();
+    void presentGL();
+
+    bool attachD3D9();
+    void detachD3D9();
+    void presentD3D9();
+
+    void* d3d9Device() { return fD3D9Device; }
 
     bool wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
     static bool QuitOnDeactivate(HWND hWnd);
@@ -45,14 +56,23 @@
     // overrides from SkView
     virtual void onAddMenu(const SkOSMenu*);
 
+    virtual void onSetTitle(const char title[]);
+
 private:
-    void*   fHWND;
+    void*               fHWND;
+    
+    void                doPaint(void* ctx);
 
-    void    doPaint(void* ctx);
+    void*               fHGLRC;
 
-    HMENU   fMBar;
+    bool                fGLAttached;
 
-    typedef SkWindow INHERITED;
+    void*               fD3D9Device;
+    bool                fD3D9Attached;
+
+    HMENU               fMBar;
+
+    typedef SkWindow INHERITED; 
 };
 
 #endif
diff --git a/include/views/SkView.h b/include/views/SkView.h
index fc36d34..d3633db 100644
--- a/include/views/SkView.h
+++ b/include/views/SkView.h
@@ -38,6 +38,7 @@
         kFocusable_Shift,
         kFlexH_Shift,
         kFlexV_Shift,
+        kNoClip_Shift,
 
         kFlagShiftCount
     };
@@ -47,6 +48,7 @@
         kFocusable_Mask = 1 << kFocusable_Shift,    //!< set if the view can receive focus
         kFlexH_Mask     = 1 << kFlexH_Shift,        //!< set if the view's width is stretchable
         kFlexV_Mask     = 1 << kFlexV_Shift,        //!< set if the view's height is stretchable
+        kNoClip_Mask    = 1 << kNoClip_Shift,        //!< set if the view is not clipped to its bounds
 
         kAllFlagMasks   = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount)
     };
@@ -66,10 +68,12 @@
     int         isVisible() const { return fFlags & kVisible_Mask; }
     int         isEnabled() const { return fFlags & kEnabled_Mask; }
     int         isFocusable() const { return fFlags & kFocusable_Mask; }
+    int         isClipToBounds() const { return !(fFlags & kNoClip_Mask); }
     /** Helper to set/clear the view's kVisible_Mask flag */
     void        setVisibleP(bool);
     void        setEnabledP(bool);
     void        setFocusableP(bool);
+    void        setClipToBounds(bool);
 
     /** Return the view's width */
     SkScalar    width() const { return fWidth; }
@@ -302,7 +306,7 @@
         Tyically this is only overridden by the by the "window". If your subclass does handle the
         request, return true so the request will not continue to propogate to the parent.
     */
-    virtual bool    handleInval(const SkRect&);
+    virtual bool    handleInval(const SkRect*);
     //! called once before all of the children are drawn (or clipped/translated)
     virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; }
     //! called once after all of the children are drawn (or clipped/translated)
diff --git a/include/views/SkWindow.h b/include/views/SkWindow.h
index 1c8f9a3..5deefd5 100644
--- a/include/views/SkWindow.h
+++ b/include/views/SkWindow.h
@@ -19,6 +19,7 @@
 
 #include "SkView.h"
 #include "SkBitmap.h"
+#include "SkMatrix.h"
 #include "SkRegion.h"
 #include "SkEvent.h"
 #include "SkKey.h"
@@ -29,6 +30,8 @@
 #endif
 //#define USE_GX_SCREEN
 
+class SkCanvas;
+
 class SkOSMenu;
 
 class SkWindow : public SkView {
@@ -44,7 +47,13 @@
     void    eraseRGB(U8CPU r, U8CPU g, U8CPU b);
 
     bool    isDirty() const { return !fDirtyRgn.isEmpty(); }
-    bool    update(SkIRect* updateArea);
+    bool    update(SkIRect* updateArea, SkCanvas* = NULL);
+    // does not call through to onHandleInval(), but does force the fDirtyRgn
+    // to be wide open. Call before update() to ensure we redraw everything.
+    void    forceInvalAll();
+    // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
+    const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
+
     bool    handleClick(int x, int y, Click::State);
     bool    handleChar(SkUnichar);
     bool    handleKey(SkKey);
@@ -56,6 +65,11 @@
     const char* getTitle() const { return fTitle.c_str(); }
     void    setTitle(const char title[]);
 
+    const SkMatrix& getMatrix() const { return fMatrix; }
+    void    setMatrix(const SkMatrix&);
+    void    preConcat(const SkMatrix&);
+    void    postConcat(const SkMatrix&);
+
 protected:
     virtual bool onEvent(const SkEvent&);
 
@@ -68,7 +82,7 @@
     virtual void onSetTitle(const char title[]) {}
 
     // overrides from SkView
-    virtual bool handleInval(const SkRect&);
+    virtual bool handleInval(const SkRect*);
     virtual bool onGetFocusView(SkView** focus) const;
     virtual bool onSetFocusView(SkView* focus);
 
@@ -84,6 +98,7 @@
     bool    fWaitingOnInval;
     
     SkString    fTitle;
+    SkMatrix    fMatrix;
 
     typedef SkView INHERITED;
 };
@@ -100,6 +115,8 @@
   #include "SkOSWindow_Unix.h"
 #elif defined(SK_BUILD_FOR_SDL)
     #include "SkOSWindow_SDL.h"
+#elif defined(SK_BUILD_FOR_IOS)
+    #include "SkOSWindow_iOS.h"
 #endif
 
 #endif