aboutsummaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-02-24 05:27:24 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-02-24 05:27:24 -0800
commit7157c81e3a5c916ab44a02273b140e1cd8a6d1bb (patch)
treea88326e04fd6523340a9e33b2a5642655894e61a /include/core
parentc7382c661f9256c4e53d613e4897a44597e4213b (diff)
parent40528743dbb9ce7f39f093e0cdc47849ac8887cf (diff)
downloadexternal_skia-7157c81e3a5c916ab44a02273b140e1cd8a6d1bb.zip
external_skia-7157c81e3a5c916ab44a02273b140e1cd8a6d1bb.tar.gz
external_skia-7157c81e3a5c916ab44a02273b140e1cd8a6d1bb.tar.bz2
Merge "Skia Merge (revision 808)"
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkAdvancedTypefaceMetrics.h136
-rw-r--r--include/core/SkBitmap.h83
-rw-r--r--include/core/SkBlitRow.h87
-rw-r--r--include/core/SkCanvas.h124
-rw-r--r--include/core/SkChunkAlloc.h9
-rw-r--r--include/core/SkColor.h19
-rw-r--r--include/core/SkColorPriv.h55
-rw-r--r--include/core/SkColorShader.h15
-rw-r--r--include/core/SkDescriptor.h3
-rw-r--r--include/core/SkDevice.h77
-rw-r--r--include/core/SkDraw.h12
-rw-r--r--include/core/SkFixed.h10
-rw-r--r--include/core/SkFlate.h48
-rw-r--r--include/core/SkFontHost.h24
-rw-r--r--include/core/SkGeometry.h21
-rw-r--r--include/core/SkMallocPixelRef.h5
-rw-r--r--include/core/SkMask.h5
-rw-r--r--include/core/SkMath.h17
-rw-r--r--include/core/SkMatrix.h7
-rw-r--r--include/core/SkPaint.h20
-rw-r--r--include/core/SkPictureFlat.h209
-rw-r--r--include/core/SkPixelRef.h7
-rw-r--r--include/core/SkPostConfig.h10
-rw-r--r--include/core/SkPreConfig.h16
-rw-r--r--include/core/SkRect.h31
-rw-r--r--include/core/SkRefCnt.h64
-rw-r--r--include/core/SkRefDict.h61
-rw-r--r--include/core/SkRegion.h10
-rw-r--r--include/core/SkScalar.h21
-rw-r--r--include/core/SkScalerContext.h57
-rw-r--r--include/core/SkShader.h52
-rw-r--r--include/core/SkSize.h8
-rw-r--r--include/core/SkStream.h10
-rw-r--r--include/core/SkString.h6
-rw-r--r--include/core/SkTScopedPtr.h83
-rw-r--r--include/core/SkTemplates.h7
-rw-r--r--include/core/SkThread_platform.h4
-rw-r--r--include/core/SkTypeface.h21
-rw-r--r--include/core/SkTypes.h82
-rw-r--r--include/core/SkUtils.h2
-rw-r--r--include/core/SkXfermode.h10
41 files changed, 1145 insertions, 403 deletions
diff --git a/include/core/SkAdvancedTypefaceMetrics.h b/include/core/SkAdvancedTypefaceMetrics.h
new file mode 100644
index 0000000..033e738
--- /dev/null
+++ b/include/core/SkAdvancedTypefaceMetrics.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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 SkAdvancedTypefaceMetrics_DEFINED
+#define SkAdvancedTypefaceMetrics_DEFINED
+
+#include "SkRect.h"
+#include "SkRefCnt.h"
+#include "SkString.h"
+#include "SkTDArray.h"
+#include "SkTemplates.h"
+#include "SkTScopedPtr.h"
+
+/** \class SkAdvancedTypefaceMetrics
+
+ The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
+ embed typefaces. This class is filled in with information about a given
+ typeface by the SkFontHost class.
+*/
+
+class SkAdvancedTypefaceMetrics : public SkRefCnt {
+public:
+ SkString fFontName;
+
+ enum FontType {
+ kType1_Font,
+ kType1CID_Font,
+ kCFF_Font,
+ kTrueType_Font,
+ kOther_Font,
+ kNotEmbeddable_Font,
+ };
+ // The type of the underlying font program. This field determines which
+ // of the following fields are valid. If it is kOther_Font or
+ // kNotEmbeddable_Font, the per glyph information will never be populated.
+ FontType fType;
+
+ // fMultiMaster may be true for Type1_Font or CFF_Font.
+ bool fMultiMaster;
+ uint16_t fLastGlyphID; // The last valid glyph ID in the font.
+ uint16_t fEmSize; // The size of the em box (defines font units).
+
+ // These enum values match the values used in the PDF file format.
+ enum StyleFlags {
+ kFixedPitch_Style = 0x00001,
+ kSerif_Style = 0x00002,
+ kSymbolic_Style = 0x00004,
+ kScript_Style = 0x00008,
+ kNonsymbolic_Style = 0x00020,
+ kItalic_Style = 0x00040,
+ kAllCaps_Style = 0x10000,
+ kSmallCaps_Style = 0x20000,
+ kForceBold_Style = 0x40000,
+ };
+ uint16_t fStyle; // Font style characteristics.
+ int16_t fItalicAngle; // Counterclockwise degrees from vertical of the
+ // dominant vertical stroke for an Italic face.
+ // The following fields are all in font units.
+ int16_t fAscent; // Max height above baseline, not including accents.
+ int16_t fDescent; // Max depth below baseline (negative).
+ int16_t fStemV; // Thickness of dominant vertical stem.
+ int16_t fCapHeight; // Height (from baseline) of top of flat capitals.
+
+ SkIRect fBBox; // The bounding box of all glyphs (in font units).
+
+ template <typename Data>
+ struct AdvanceMetric {
+ enum MetricType {
+ kDefault, // Default advance: fAdvance.count = 1
+ kRange, // Advances for a range: fAdvance.count = fEndID-fStartID
+ kRun, // fStartID-fEndID have same advance: fAdvance.count = 1
+ };
+ MetricType fType;
+ uint16_t fStartId;
+ uint16_t fEndId;
+ SkTDArray<Data> fAdvance;
+ SkTScopedPtr<AdvanceMetric<Data> > fNext;
+ };
+
+ struct VerticalMetric {
+ int16_t fVerticalAdvance;
+ int16_t fOriginXDisp; // Horiz. displacement of the secondary origin.
+ int16_t fOriginYDisp; // Vert. displacement of the secondary origin.
+ };
+ typedef AdvanceMetric<int16_t> WidthRange;
+ typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange;
+
+ // This is indexed by glyph id.
+ SkTScopedPtr<WidthRange> fGlyphWidths;
+ // Only used for Vertical CID fonts.
+ SkTScopedPtr<VerticalAdvanceRange> fVerticalMetrics;
+
+ // The names of each glyph, only populated for postscript fonts.
+ SkTScopedPtr<SkAutoTArray<SkString> > fGlyphNames;
+};
+
+namespace skia_advanced_typeface_metrics_utils {
+
+template <typename Data>
+void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
+ int startId);
+
+template <typename Data>
+SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
+ SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
+ int startId);
+
+template <typename Data>
+void finishRange(
+ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
+ int endId,
+ typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType
+ type);
+
+template <typename Data, typename FontHandle>
+SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
+ FontHandle fontHandle,
+ int num_glyphs,
+ bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data));
+
+} // namespace skia_advanced_typeface_metrics_utils
+
+#endif
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 84d069c..64a2a5b 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -30,6 +30,9 @@ class SkRegion;
class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
+// This is an opaque class, not interpreted by skia
+class SkGpuTexture;
+
/** \class SkBitmap
The SkBitmap class specifies a raster bitmap. A bitmap has an integer width
@@ -43,12 +46,22 @@ public:
enum Config {
kNo_Config, //!< bitmap has not been configured
- kA1_Config, //!< 1-bit per pixel, (0 is transparent, 1 is opaque)
+ /**
+ * 1-bit per pixel, (0 is transparent, 1 is opaque)
+ * Valid as a destination (target of a canvas), but not valid as a src.
+ * i.e. you can draw into a 1-bit bitmap, but you cannot draw from one.
+ */
+ kA1_Config,
kA8_Config, //!< 8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque)
kIndex8_Config, //!< 8-bits per pixel, using SkColorTable to specify the colors
kRGB_565_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
kARGB_4444_Config, //!< 16-bits per pixel, (see SkColorPriv.h for packing)
kARGB_8888_Config, //!< 32-bits per pixel, (see SkColorPriv.h for packing)
+ /**
+ * Custom compressed format, not supported on all platforms.
+ * Cannot be used as a destination (target of a canvas).
+ * i.e. you may be able to draw from one, but you cannot draw into one.
+ */
kRLE_Index8_Config,
kConfigCount
@@ -129,6 +142,12 @@ public:
*/
size_t getSize() const { return fHeight * fRowBytes; }
+ /** Return the number of bytes from the pointer returned by getPixels()
+ to the end of the allocated space in the buffer. Required in
+ cases where extractBitmap has been called.
+ */
+ size_t getSafeSize() const ;
+
/** Return the byte size of the pixels, based on the height and rowBytes.
This routine is slightly slower than getSize(), but does not truncate
the answer to 32bits.
@@ -139,6 +158,10 @@ public:
return size;
}
+ /** Same as getSafeSize(), but does not truncate the answer to 32bits.
+ */
+ Sk64 getSafeSize64() const ;
+
/** Returns true if the bitmap is opaque (has no translucent/transparent pixels).
*/
bool isOpaque() const;
@@ -189,6 +212,44 @@ public:
*/
void setPixels(void* p, SkColorTable* ctable = NULL);
+ /** Copies the bitmap's pixels to the location pointed at by dst and returns
+ true if possible, returns false otherwise.
+
+ In the event that the bitmap's stride is equal to dstRowBytes, and if
+ it is greater than strictly required by the bitmap's current config
+ (this may happen if the bitmap is an extracted subset of another), then
+ this function will copy bytes past the eand of each row, excluding the
+ last row. No copies are made outside of the declared size of dst,
+ however.
+
+ Always returns false for RLE formats.
+
+ @param dst Location of destination buffer.
+ @param dstSize Size of destination buffer. Must be large enough to hold
+ pixels using indicated stride.
+ @param dstRowBytes Width of each line in the buffer. If -1, uses
+ bitmap's internal stride.
+ */
+ bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1)
+ const;
+
+ /** Copies the pixels at location src to the bitmap's pixel buffer.
+ Returns true if copy if possible (bitmap buffer is large enough),
+ false otherwise.
+
+ Like copyPixelsTo, this function may write values beyond the end of
+ each row, although never outside the defined buffer.
+
+ Always returns false for RLE formats.
+
+ @param src Location of the source buffer.
+ @param srcSize Height of source buffer in pixels.
+ @param srcRowBytes Width of each line in the buffer. If -1, uses i
+ bitmap's internal stride.
+ */
+ bool copyPixelsFrom(const void* const src, size_t srcSize,
+ int srcRowBytes = -1);
+
/** Use the standard HeapAllocator to create the pixelref that manages the
pixel memory. It will be sized based on the current width/height/config.
If this is called multiple times, a new pixelref object will be created
@@ -227,7 +288,7 @@ public:
*/
bool allocPixels(Allocator* allocator, SkColorTable* ctable);
- /** Return the current pixelref object, of any
+ /** Return the current pixelref object, if any
*/
SkPixelRef* pixelRef() const { return fPixelRef; }
/** Return the offset into the pixelref, if any. Will return 0 if there is
@@ -258,10 +319,15 @@ public:
*/
bool readyToDraw() const {
return this->getPixels() != NULL &&
- ((this->config() != kIndex8_Config && this->config() != kRLE_Index8_Config) ||
+ ((this->config() != kIndex8_Config &&
+ this->config() != kRLE_Index8_Config) ||
fColorTable != NULL);
}
+ /** Returns the pixelRef's texture, or NULL
+ */
+ SkGpuTexture* getTexture() const;
+
/** Return the bitmap's colortable (if any). Does not affect the colortable's
reference count.
*/
@@ -490,6 +556,17 @@ private:
uint8_t fFlags;
uint8_t fBytesPerPixel; // based on config
+ /* Internal computations for safe size.
+ */
+ static Sk64 ComputeSafeSize64(Config config,
+ uint32_t width,
+ uint32_t height,
+ uint32_t rowBytes);
+ static size_t ComputeSafeSize(Config config,
+ uint32_t width,
+ uint32_t height,
+ uint32_t rowBytes);
+
/* Unreference any pixelrefs or colortables
*/
void freePixels();
diff --git a/include/core/SkBlitRow.h b/include/core/SkBlitRow.h
new file mode 100644
index 0000000..2b652c2
--- /dev/null
+++ b/include/core/SkBlitRow.h
@@ -0,0 +1,87 @@
+#ifndef SkBlitRow_DEFINED
+#define SkBlitRow_DEFINED
+
+#include "SkBitmap.h"
+#include "SkColor.h"
+
+class SkBlitRow {
+public:
+ enum Flags16 {
+ //! If set, the alpha parameter will be != 255
+ kGlobalAlpha_Flag = 0x01,
+ //! If set, the src colors may have alpha != 255
+ kSrcPixelAlpha_Flag = 0x02,
+ //! If set, the resulting 16bit colors should be dithered
+ kDither_Flag = 0x04
+ };
+
+ /** Function pointer that reads a scanline of src SkPMColors, and writes
+ a corresponding scanline of 16bit colors (specific format based on the
+ config passed to the Factory.
+
+ The x,y params are useful just for dithering
+
+ @param alpha A global alpha to be applied to all of the src colors
+ @param x The x coordinate of the beginning of the scanline
+ @param y THe y coordinate of the scanline
+ */
+ typedef void (*Proc)(uint16_t* SK_RESTRICT dst,
+ const SkPMColor* SK_RESTRICT src,
+ int count, U8CPU alpha, int x, int y);
+
+ /** Function pointer that blends a single color with a row of 32-bit colors
+ onto a 32-bit destination
+ */
+ typedef void (*ColorProc)(SkPMColor* dst, const SkPMColor* src, int count,
+ SkPMColor color);
+
+ //! Public entry-point to return a blit function ptr
+ static Proc Factory(unsigned flags, SkBitmap::Config);
+
+ ///////////// D32 version
+
+ enum Flags32 {
+ kGlobalAlpha_Flag32 = 1 << 0,
+ kSrcPixelAlpha_Flag32 = 1 << 1,
+ };
+
+ /** Function pointer that blends 32bit colors onto a 32bit destination.
+ @param dst array of dst 32bit colors
+ @param src array of src 32bit colors (w/ or w/o alpha)
+ @param count number of colors to blend
+ @param alpha global alpha to be applied to all src colors
+ */
+ typedef void (*Proc32)(uint32_t* SK_RESTRICT dst,
+ const SkPMColor* SK_RESTRICT src,
+ int count, U8CPU alpha);
+
+ static Proc32 Factory32(unsigned flags32);
+
+ /** Blend a single color onto a row of S32 pixels, writing the result
+ into a row of D32 pixels. src and dst may be the same memory, but
+ if they are not, they may not overlap.
+ */
+ static void Color32(SkPMColor dst[], const SkPMColor src[],
+ int count, SkPMColor color);
+
+ static ColorProc ColorProcFactory();
+
+ /** These static functions are called by the Factory and Factory32
+ functions, and should return either NULL, or a
+ platform-specific function-ptr to be used in place of the
+ system default.
+ */
+
+ static Proc32 PlatformProcs32(unsigned flags);
+ static Proc PlatformProcs565(unsigned flags);
+ static Proc PlatformProcs4444(unsigned flags);
+ static ColorProc PlatformColorProc();
+
+private:
+ enum {
+ kFlags16_Mask = 7,
+ kFlags32_Mask = 3
+ };
+};
+
+#endif
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index b5ccca6..b2a9fa9 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -98,12 +98,46 @@ public:
*/
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);
+
+ /**
+ * Return the current device factory, or NULL.
+ */
+ SkDeviceFactory* getDeviceFactory() const { return fDeviceFactory; }
+
+ /**
+ * Replace any existing factory with the specified factory.
+ */
+ SkDeviceFactory* setDeviceFactory(SkDeviceFactory*);
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /**
+ * Copy the pixels from the device into bitmap. Returns true on success.
+ * If false is returned, then the bitmap parameter is left unchanged.
+ * The bitmap parameter is treated as output-only, and will be completely
+ * overwritten (if the method returns true).
+ */
+ bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
+ bool readPixels(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.
+ */
+ void writePixels(const SkBitmap& bitmap, int x, int y);
///////////////////////////////////////////////////////////////////////////
@@ -139,8 +173,10 @@ public:
offscreen bitmap. All drawing calls are directed there, and only when
the balancing call to restore() is made is that offscreen transfered to
the canvas (or the previous layer).
- @param bounds (may be null) the maximum size the offscreen bitmap needs
- to be (in local coordinates)
+ @param bounds (may be null) This rect, if non-null, is used as a hint to
+ limit the size of the offscreen, and thus drawing may be
+ clipped to it, though that clipping is not guaranteed to
+ happen. If exact clipping is desired, use clipRect().
@param paint (may be null) This is copied, and is applied to the
offscreen when restore() is called
@param flags LayerFlags
@@ -153,8 +189,10 @@ public:
offscreen bitmap. All drawing calls are directed there, and only when
the balancing call to restore() is made is that offscreen transfered to
the canvas (or the previous layer).
- @param bounds (may be null) the maximum size the offscreen bitmap needs
- to be (in local coordinates)
+ @param bounds (may be null) This rect, if non-null, is used as a hint to
+ limit the size of the offscreen, and thus drawing may be
+ clipped to it, though that clipping is not guaranteed to
+ happen. If exact clipping is desired, use clipRect().
@param alpha This is applied to the offscreen when restore() is called.
@param flags LayerFlags
@return The value to pass to restoreToCount() to balance this save()
@@ -213,12 +251,12 @@ public:
@return true if the operation succeeded (e.g. did not overflow)
*/
virtual bool concat(const SkMatrix& matrix);
-
+
/** Replace the current matrix with a copy of the specified matrix.
@param matrix The matrix that will be copied into the current matrix.
*/
virtual void setMatrix(const SkMatrix& matrix);
-
+
/** Helper for setMatrix(identity). Sets the current matrix to identity.
*/
void resetMatrix();
@@ -382,7 +420,7 @@ public:
details.
*/
void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
-
+
/** Draws a single pixel in the specified color.
@param x The X coordinate of which pixel to draw
@param y The Y coordiante of which pixel to draw
@@ -420,7 +458,7 @@ public:
r.set(rect); // promotes the ints to scalars
this->drawRect(r, paint);
}
-
+
/** Draw the specified rectangle using the specified paint. The rectangle
will be filled or framed based on the Style in the paint.
@param left The left side of the rectangle to be drawn
@@ -508,7 +546,7 @@ public:
virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
const SkPaint* paint = NULL);
-
+
/** Draw the specified bitmap, with its top/left corner at (x,y),
NOT transformed by the current matrix. Note: if the paint
contains a maskfilter that generates a mask which extends beyond the
@@ -535,7 +573,7 @@ public:
SkScalar y, const SkPaint& paint);
/** Draw the text, with each character/glyph origin specified by the pos[]
- array. The origin is interpreted by the Align setting in the paint.
+ array. The origin is interpreted by the Align setting in the paint.
@param text The text to be drawn
@param byteLength The number of bytes to read from the text parameter
@param pos Array of positions, used to position each character
@@ -543,10 +581,10 @@ public:
*/
virtual void drawPosText(const void* text, size_t byteLength,
const SkPoint pos[], const SkPaint& paint);
-
+
/** Draw the text, with each character/glyph origin specified by the x
coordinate taken from the xpos[] array, and the y from the constY param.
- The origin is interpreted by the Align setting in the paint.
+ The origin is interpreted by the Align setting in the paint.
@param text The text to be drawn
@param byteLength The number of bytes to read from the text parameter
@param xpos Array of x-positions, used to position each character
@@ -556,7 +594,7 @@ public:
virtual void drawPosTextH(const void* text, size_t byteLength,
const SkScalar xpos[], SkScalar constY,
const SkPaint& paint);
-
+
/** Draw the text, with origin at (x,y), using the specified paint, along
the specified path. The paint's Align setting determins where along the
path to start the text.
@@ -610,7 +648,7 @@ public:
canvas.
*/
virtual void drawPicture(SkPicture& picture);
-
+
/** Draws the specified shape
*/
virtual void drawShape(SkShape*);
@@ -620,7 +658,7 @@ public:
kTriangleStrip_VertexMode,
kTriangleFan_VertexMode
};
-
+
/** Draw the array of vertices, interpreted as triangles (based on mode).
@param vmode How to interpret the array of vertices
@param vertexCount The number of points in the vertices array (and
@@ -637,7 +675,7 @@ public:
@param indices If not null, array of indices to reference into the
vertex (texs, colors) array.
@param indexCount number of entries in the indices array (if not null)
- @param paint Specifies the shader/texture if present.
+ @param paint Specifies the shader/texture if present.
*/
virtual void drawVertices(VertexMode vmode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
@@ -654,7 +692,7 @@ public:
virtual void drawData(const void* data, size_t length);
//////////////////////////////////////////////////////////////////////////
-
+
/** Get the current bounder object.
The bounder's reference count is unchaged.
@return the canva's bounder (or NULL).
@@ -670,13 +708,13 @@ public:
@return the set bounder object
*/
virtual SkBounder* setBounder(SkBounder* bounder);
-
+
/** Get the current filter object. The filter's reference count is not
affected. The filter is saved/restored, just like the matrix and clip.
@return the canvas' filter (or NULL).
*/
SkDrawFilter* getDrawFilter() const;
-
+
/** Set the new filter (or NULL). Pass NULL to clear any existing filter.
As a convenience, the parameter is returned. If an existing filter
exists, its refcnt is decrement. If the new filter is not null, its
@@ -701,16 +739,7 @@ public:
*/
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);
///////////////////////////////////////////////////////////////////////////
@@ -725,12 +754,12 @@ public:
/** Initialize iterator with canvas, and set values for 1st device */
LayerIter(SkCanvas*, bool skipEmptyClips);
~LayerIter();
-
+
/** Return true if the iterator is done */
bool done() const { return fDone; }
/** Cycle to the next device */
void next();
-
+
// These reflect the current device in the iterator
SkDevice* device() const;
@@ -739,14 +768,14 @@ public:
const SkPaint& paint() const;
int x() const;
int y() const;
-
+
private:
// used to embed the SkDrawIter object directly in our instance, w/o
// having to expose that class def to the public. There is an assert
// 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;
@@ -754,9 +783,9 @@ public:
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;
@@ -770,21 +799,21 @@ private:
SkDevice* fLastDeviceToGainFocus;
SkDeviceFactory* fDeviceFactory;
- void prepareForDeviceDraw(SkDevice*);
-
+ void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&);
+
bool fDeviceCMDirty; // cleared by updateDeviceCMCache()
void updateDeviceCMCache();
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()
int internalSave(SaveFlags flags);
void internalRestore();
-
+
/* These maintain a cache of the clip bounds in local coordinates,
(converted to 2s-compliment if floats are slow).
*/
@@ -816,6 +845,9 @@ private:
}
}
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 @@ public:
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/SkColor.h b/include/core/SkColor.h
index c97a8ec..c17068f 100644
--- a/include/core/SkColor.h
+++ b/include/core/SkColor.h
@@ -36,13 +36,30 @@ typedef uint32_t SkColor;
/** Return a SkColor value from 8 bit component values
*/
-static inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
+static inline SkColor SkColorSetARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
{
SkASSERT(a <= 255 && r <= 255 && g <= 255 && b <= 255);
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
+#define SkColorSetARGBMacro(a, r, g, b) \
+ static_cast<SkColor>( \
+ (static_cast<U8CPU>(a) << 24) | \
+ (static_cast<U8CPU>(r) << 16) | \
+ (static_cast<U8CPU>(g) << 8) | \
+ (static_cast<U8CPU>(b) << 0))
+
+/** gcc will generate static initializers for code of this form:
+ * static const SkColor kMyColor = SkColorSetARGB(0xFF, 0x01, 0x02, 0x03)
+ * if SkColorSetARGB() is a static inline, but not if it's a macro.
+ */
+#if defined(NDEBUG)
+#define SkColorSetARGB(a, r, g, b) SkColorSetARGBMacro(a, r, g, b)
+#else
+#define SkColorSetARGB(a, r, g, b) SkColorSetARGBInline(a, r, g, b)
+#endif
+
/** Return a SkColor value from 8 bit component values, with an implied value
of 0xFF for alpha (fully opaque)
*/
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h
index 7c6b7d1..bd407da 100644
--- a/include/core/SkColorPriv.h
+++ b/include/core/SkColorPriv.h
@@ -28,7 +28,7 @@
/** Turn 0..255 into 0..256 by adding 1 at the half-way point. Used to turn a
byte into a scale value, so that we can say scale * value >> 8 instead of
alpha * value / 255.
-
+
In debugging, asserts that alpha is 0..255
*/
static inline unsigned SkAlpha255To256(U8CPU alpha) {
@@ -133,7 +133,7 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
int srcScale, int count) {
SkASSERT(count > 0);
SkASSERT((unsigned)srcScale <= 256);
-
+
srcScale >>= 3;
do {
@@ -148,7 +148,7 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
SkASSERT(SkGetPackedR16(a) + SkGetPackedR16(b) <= SK_R16_MASK);
SkASSERT(SkGetPackedG16(a) + SkGetPackedG16(b) <= SK_G16_MASK);
SkASSERT(SkGetPackedB16(a) + SkGetPackedB16(b) <= SK_B16_MASK);
-
+
return a + b;
}
#else
@@ -201,7 +201,7 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
unsigned r = SkGetPackedR32(c);
unsigned g = SkGetPackedG32(c);
unsigned b = SkGetPackedB32(c);
-
+
SkA32Assert(a);
SkASSERT(r <= a);
SkASSERT(g <= a);
@@ -211,6 +211,10 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
#define SkPMColorAssert(c)
#endif
+/**
+ * Pack the components into a SkPMColor, checking (in the debug version) that
+ * the components are 0..255, and are already premultiplied (i.e. alpha >= color)
+ */
static inline SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
SkA32Assert(a);
SkASSERT(r <= a);
@@ -221,6 +225,15 @@ static inline SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
(g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
}
+/**
+ * Same as SkPackARGB32, but this version guarantees to not check that the
+ * values are premultiplied in the debug version.
+ */
+static inline SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+ return (a << SK_A32_SHIFT) | (r << SK_R32_SHIFT) |
+ (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
+}
+
extern const uint32_t gMask_00FF00FF;
static inline uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) {
@@ -299,7 +312,7 @@ static inline uint16_t SkDitherPack888ToRGB16(U8CPU r, U8CPU g, U8CPU b) {
r = ((r << 1) - ((r >> (8 - SK_R16_BITS) << (8 - SK_R16_BITS)) | (r >> SK_R16_BITS))) >> (8 - SK_R16_BITS);
g = ((g << 1) - ((g >> (8 - SK_G16_BITS) << (8 - SK_G16_BITS)) | (g >> SK_G16_BITS))) >> (8 - SK_G16_BITS);
b = ((b << 1) - ((b >> (8 - SK_B16_BITS) << (8 - SK_B16_BITS)) | (b >> SK_B16_BITS))) >> (8 - SK_B16_BITS);
-
+
return SkPackRGB16(r, g, b);
}
@@ -318,7 +331,7 @@ static inline uint32_t SkPMColorToExpanded16x5(SkPMColor c) {
unsigned sr = SkPacked32ToR16(c);
unsigned sg = SkPacked32ToG16(c);
unsigned sb = SkPacked32ToB16(c);
-
+
sr = (sr << 5) | sr;
sg = (sg << 5) | (sg >> 1);
sb = (sb << 5) | sb;
@@ -332,17 +345,17 @@ static inline U16CPU SkSrcOver32To16(SkPMColor src, uint16_t dst) {
unsigned sr = SkGetPackedR32(src);
unsigned sg = SkGetPackedG32(src);
unsigned sb = SkGetPackedB32(src);
-
+
unsigned dr = SkGetPackedR16(dst);
unsigned dg = SkGetPackedG16(dst);
unsigned db = SkGetPackedB16(dst);
-
+
unsigned isa = 255 - SkGetPackedA32(src);
-
+
dr = (sr + SkMul16ShiftRound(dr, isa, SK_R16_BITS)) >> (8 - SK_R16_BITS);
dg = (sg + SkMul16ShiftRound(dg, isa, SK_G16_BITS)) >> (8 - SK_G16_BITS);
db = (sb + SkMul16ShiftRound(db, isa, SK_B16_BITS)) >> (8 - SK_B16_BITS);
-
+
return SkPackRGB16(dr, dg, db);
}
@@ -382,15 +395,15 @@ static inline SkPMColor SkPixel16ToPixel32(U16CPU src) {
// similar to SkPixel16ToPixel32, but returns SkColor instead of SkPMColor
static inline SkColor SkPixel16ToColor(U16CPU src) {
SkASSERT(src == SkToU16(src));
-
+
unsigned r = SkPacked16ToR32(src);
unsigned g = SkPacked16ToG32(src);
unsigned b = SkPacked16ToB32(src);
-
+
SkASSERT((r >> (8 - SK_R16_BITS)) == SkGetPackedR16(src));
SkASSERT((g >> (8 - SK_G16_BITS)) == SkGetPackedG16(src));
SkASSERT((b >> (8 - SK_B16_BITS)) == SkGetPackedB16(src));
-
+
return SkColorSetRGB(r, g, b);
}
@@ -435,7 +448,7 @@ static inline void SkPMColor16Assert(U16CPU c) {
unsigned r = SkGetPackedR4444(c);
unsigned g = SkGetPackedG4444(c);
unsigned b = SkGetPackedB4444(c);
-
+
SkASSERT(a <= 0xF);
SkASSERT(r <= a);
SkASSERT(g <= a);
@@ -480,7 +493,7 @@ static inline SkPMColor16 SkPackARGB4444(unsigned a, unsigned r,
SkASSERT(r <= a);
SkASSERT(g <= a);
SkASSERT(b <= a);
-
+
return (SkPMColor16)((a << SK_A4444_SHIFT) | (r << SK_R4444_SHIFT) |
(g << SK_G4444_SHIFT) | (b << SK_B4444_SHIFT));
}
@@ -491,7 +504,7 @@ static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) {
SkASSERT(scale <= 16);
const unsigned mask = 0xF0F; //gMask_0F0F;
-
+
#if 0
unsigned rb = ((c & mask) * scale) >> 4;
unsigned ag = ((c >> 4) & mask) * scale;
@@ -508,7 +521,7 @@ static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) {
*/
static inline uint32_t SkExpand_4444(U16CPU c) {
SkASSERT(c == (uint16_t)c);
-
+
const unsigned mask = 0xF0F; //gMask_0F0F;
return (c & mask) | ((c & ~mask) << 12);
}
@@ -541,7 +554,7 @@ static inline uint16_t SkSrcOver4444To16(SkPMColor16 s, uint16_t d) {
unsigned dr = SkAlphaMul4(SkGetPackedR16(d), scale);
unsigned dg = SkAlphaMul4(SkGetPackedG16(d), scale);
unsigned db = SkAlphaMul4(SkGetPackedB16(d), scale);
-
+
#if 0
if (sg + dg > 63) {
SkDebugf("---- SkSrcOver4444To16 src=%x dst=%x scale=%d, sg=%d dg=%d\n", s, d, scale, sg, dg);
@@ -552,13 +565,13 @@ static inline uint16_t SkSrcOver4444To16(SkPMColor16 s, uint16_t d) {
static inline uint16_t SkBlend4444To16(SkPMColor16 src, uint16_t dst, int scale16) {
SkASSERT((unsigned)scale16 <= 16);
-
+
return SkSrcOver4444To16(SkAlphaMulQ4(src, scale16), dst);
}
static inline uint16_t SkBlend4444(SkPMColor16 src, SkPMColor16 dst, int scale16) {
SkASSERT((unsigned)scale16 <= 16);
-
+
uint32_t src32 = SkExpand_4444(src) * scale16;
// the scaled srcAlpha is the bottom byte
#ifdef SK_DEBUG
@@ -600,7 +613,7 @@ static inline SkPMColor16 SkDitherARGB32To4444(U8CPU a, U8CPU r,
r = ((r << 1) - ((r >> 4 << 4) | (r >> 4))) >> 4;
g = ((g << 1) - ((g >> 4 << 4) | (g >> 4))) >> 4;
b = ((b << 1) - ((b >> 4 << 4) | (b >> 4))) >> 4;
-
+
return SkPackARGB4444(a, r, g, b);
}
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 @@ public:
/** 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 @@ public:
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 @@ private:
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 @@ public:
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 dbc8fcf..1b4630d 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -21,6 +21,7 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColor.h"
+#include "SkRefDict.h"
class SkDevice;
class SkDraw;
@@ -37,26 +38,30 @@ class SkRegion;
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);
@@ -71,10 +76,10 @@ public:
/** Return the width of the device (in pixels).
*/
- int width() const { return fBitmap.width(); }
+ virtual int width() const { return fBitmap.width(); }
/** Return the height of the device (in pixels).
*/
- int height() const { return fBitmap.height(); }
+ virtual int height() const { return fBitmap.height(); }
/** Return the bitmap config of the device's pixels
*/
SkBitmap::Config config() const { return fBitmap.getConfig(); }
@@ -82,11 +87,11 @@ public:
implicitly opaque.
*/
bool isOpaque() const { return fBitmap.isOpaque(); }
-
+
/** Return the bounds of the device
*/
void getBounds(SkIRect* bounds) const;
-
+
/** Return true if the specified rectangle intersects the bounds of the
device. If sect is not NULL and there is an intersection, sect returns
the intersection.
@@ -112,6 +117,11 @@ public:
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 +131,26 @@ public:
/** 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.
+ * The bitmap parameter is treated as output-only, and will be completely
+ * overwritten (if the method returns true).
+ */
+ 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 +163,11 @@ public:
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);
@@ -158,6 +190,10 @@ public:
virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
const SkPaint&);
+ ///////////////////////////////////////////////////////////////////////////
+
+ SkRefDict& getRefDict() { return fRefDict; }
+
protected:
/** Update as needed the pixel value in the bitmap, so that the caller can access
the pixels directly. Note: only the pixels field should be altered. The config/width/height/rowbytes
@@ -165,8 +201,17 @@ protected:
*/
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:
- SkBitmap fBitmap;
+ SkCanvas* fCanvas;
+ SkBitmap fBitmap;
+ SkRefDict fRefDict;
};
#endif
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index a86ef67..fb2f292 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -33,12 +33,12 @@ struct SkDrawProcs;
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.
@@ -86,12 +86,18 @@ public:
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() const;
+ void validate() const;
+#else
+ void validate() const {}
#endif
};
diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h
index be4bf99..2a2456e 100644
--- a/include/core/SkFixed.h
+++ b/include/core/SkFixed.h
@@ -17,7 +17,7 @@
#ifndef SkFixed_DEFINED
#define SkFixed_DEFINED
-#include "SkTypes.h"
+#include "SkMath.h"
/** \file SkFixed.h
@@ -39,7 +39,15 @@ typedef int32_t SkFixed;
#ifdef SK_CAN_USE_FLOAT
#define SkFixedToFloat(x) ((x) * 1.5258789e-5f)
+#if 1
#define SkFloatToFixed(x) ((SkFixed)((x) * SK_Fixed1))
+#else
+ // pins over/under flows to max/min int32 (slower than just a cast)
+ static inline SkFixed SkFloatToFixed(float x) {
+ int64_t n = x * SK_Fixed1;
+ return (SkFixed)n;
+ }
+#endif
#define SkFixedToDouble(x) ((x) * 1.5258789e-5)
#define SkDoubleToFixed(x) ((SkFixed)((x) * SK_Fixed1))
diff --git a/include/core/SkFlate.h b/include/core/SkFlate.h
new file mode 100644
index 0000000..c496b6f
--- /dev/null
+++ b/include/core/SkFlate.h
@@ -0,0 +1,48 @@
+/*
+ * 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 SkFlate_DEFINED
+#define SkFlate_DEFINED
+
+#include "SkTypes.h"
+
+class SkDynamicMemoryWStream;
+class SkStream;
+
+/** \class SkFlate
+ A class to provide access to the flate compression algorithm.
+*/
+class SkFlate {
+public:
+ /** Indicates if the flate algorithm is available.
+ */
+ static bool HaveFlate();
+
+ /** Use the flate compression algorithm to compress the data in src,
+ putting the result into dst. Returns false if an error occurs.
+ */
+ static bool Deflate(SkStream* src, SkDynamicMemoryWStream* dst);
+
+ /** Use the flate compression algorithm to decompress the data in src,
+ putting the result into dst. Returns false if an error occurs.
+ */
+ static bool Inflate(SkStream* src, SkDynamicMemoryWStream* dst);
+
+private:
+ static const size_t kBufferSize;
+};
+
+#endif
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index 84e575f..d70ba65 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -59,14 +59,16 @@ typedef uint32_t SkFontTableTag;
class SkFontHost {
public:
/** Return a new, closest matching typeface given either an existing family
- (specified by a typeface in that family) or by a familyName, and a
- requested style.
- 1) If familyFace is null, use famillyName.
- 2) If famillyName is null, use familyFace.
- 3) If both are null, return the default font that best matches style
+ (specified by a typeface in that family) or by a familyName and a
+ requested style, or by a set of Unicode codepoitns to cover in a given
+ style.
+ 1) If familyFace is null, use familyName.
+ 2) If familyName is null, use data (UTF-16 to cover).
+ 3) If all are null, return the default font that best matches style
*/
static SkTypeface* CreateTypeface(const SkTypeface* familyFace,
- const char famillyName[],
+ const char familyName[],
+ const void* data, size_t bytelength,
SkTypeface::Style style);
/** Return a new typeface given the data buffer. If the data does not
@@ -174,6 +176,16 @@ public:
///////////////////////////////////////////////////////////////////////////
+ /** Retrieve detailed typeface metrics. Used by the PDF backend.
+ @param perGlyphInfo Indicate if the glyph specific information.
+ @param perGlyphInfo Indicate if the glyph specific information (advances
+ and names) should be populated.
+ @return The returned object has already been referenced. NULL is
+ returned if the font is not found.
+ */
+ static SkAdvancedTypefaceMetrics* GetAdvancedTypefaceMetrics(
+ SkFontID fontID, bool perGlyphInfo);
+
/** Return the number of tables in the font
*/
static int CountTables(SkFontID);
diff --git a/include/core/SkGeometry.h b/include/core/SkGeometry.h
index b8ab74c..a209783 100644
--- a/include/core/SkGeometry.h
+++ b/include/core/SkGeometry.h
@@ -26,10 +26,13 @@
*/
typedef SkPoint SkXRay;
-/** Given a line segment from pts[0] to pts[1], and ax xray, return true if
- they intersect.
+/** Given a line segment from pts[0] to pts[1], and an xray, return true if
+ they intersect. Optional outgoing "ambiguous" argument indicates
+ whether the answer is ambiguous because the query occurred exactly at
+ one of the endpoints' y coordinates, indicating that another query y
+ coordinate is preferred for robustness.
*/
-bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2]);
+bool SkXRayCrossesLine(const SkXRay& pt, const SkPoint pts[2], bool* ambiguous = NULL);
/** Given a quadratic equation Ax^2 + Bx + C = 0, return 0, 1, 2 roots for the
equation.
@@ -155,8 +158,12 @@ int SkChopCubicAtMaxCurvature(const SkPoint src[4], SkPoint dst[13], SkScalar tV
left of the curve, the line is not considered to cross the curve,
but if it is equal to cubic[3].fY then it is considered to
cross.
+ Optional outgoing "ambiguous" argument indicates whether the answer is
+ ambiguous because the query occurred exactly at one of the endpoints' y
+ coordinates, indicating that another query y coordinate is preferred
+ for robustness.
*/
-bool SkXRayCrossesMonotonicCubic(const SkXRay& pt, const SkPoint cubic[4]);
+bool SkXRayCrossesMonotonicCubic(const SkXRay& pt, const SkPoint cubic[4], bool* ambiguous = NULL);
/** Given an arbitrary cubic bezier, return the number of times an xray crosses
the cubic. Valid return values are [0..3]
@@ -165,8 +172,12 @@ bool SkXRayCrossesMonotonicCubic(const SkXRay& pt, const SkPoint cubic[4]);
left of the curve, the line is not considered to cross the curve,
but if it is equal to cubic[3].fY then it is considered to
cross.
+ Optional outgoing "ambiguous" argument indicates whether the answer is
+ ambiguous because the query occurred exactly at one of the endpoints' y
+ coordinates or at a tangent point, indicating that another query y
+ coordinate is preferred for robustness.
*/
-int SkNumXRayCrossingsForCubic(const SkXRay& pt, const SkPoint cubic[4]);
+int SkNumXRayCrossingsForCubic(const SkXRay& pt, const SkPoint cubic[4], bool* ambiguous = NULL);
///////////////////////////////////////////////////////////////////////////////////////////
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index 1c36b74..7022ba2 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;
@@ -58,4 +60,5 @@ private:
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 @@ struct SkMask {
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 e0f2361..af19083 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -161,6 +161,13 @@ static inline int SkNextLog2(uint32_t value) {
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.
@@ -213,6 +220,16 @@ static inline U8CPU SkMulDiv255Round(U8CPU a, U8CPU b) {
return (prod + (prod >> 8)) >> 8;
}
+/** Return (a*b)/255, taking the ceiling of any fractional bits. Only valid if
+ both a and b are 0..255. The expected result equals (a * b + 254) / 255.
+ */
+static inline U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b) {
+ SkASSERT((uint8_t)a == a);
+ SkASSERT((uint8_t)b == b);
+ unsigned prod = SkMulS16(a, b) + 255;
+ return (prod + (prod >> 8)) >> 8;
+}
+
/** Return a*b/((1 << shift) - 1), rounding any fractional bits.
Only valid if a and b are unsigned and <= 32767 and shift is > 0 and <= 8
*/
diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h
index 7ef7d8c..5c82d78 100644
--- a/include/core/SkMatrix.h
+++ b/include/core/SkMatrix.h
@@ -292,6 +292,13 @@ public:
*/
bool invert(SkMatrix* inverse) const;
+ /** Fills the passed array with the tranform values in the right order
+ for PDFs. If the matrix is a perspective transform, returns false
+ and fills the array with an identity transform.
+ @param transform The array to fill in.
+ */
+ bool pdfTransform(SkScalar transform[6]) const;
+
/** Apply this matrix to the array of points specified by src, and write
the transformed points into the array of points specified by dst.
dst[] = M * src[]
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index f2df226..3c847de 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -113,10 +113,11 @@ public:
kDevKernText_Flag = 0x100, //!< mask to enable device kerning text
kLCDRenderText_Flag = 0x200, //!< mask to enable subpixel glyph renderering
kEmbeddedBitmapText_Flag = 0x400, //!< mask to enable embedded bitmap strikes
+ kAutoHinting_Flag = 0x800, //!< mask to force Freetype's autohinter
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
- kAllFlags = 0x7FF
+ kAllFlags = 0xFFF
};
/** Return the paint's flags. Use the Flag enum to test flag values.
@@ -205,6 +206,18 @@ public:
*/
void setEmbeddedBitmapText(bool useEmbeddedBitmapText);
+ bool isAutohinted() const
+ {
+ return SkToBool(this->getFlags() & kAutoHinting_Flag);
+ }
+
+ /** Helper for setFlags(), setting or clearing the kAutoHinting_Flag bit
+ @param useAutohinter true to set the kEmbeddedBitmapText bit in the
+ paint's flags,
+ false to clear it.
+ */
+ void setAutohinted(bool useAutohinter);
+
/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
@return true if the underlineText bit is set in the paint's flags.
*/
@@ -831,7 +844,7 @@ private:
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
- unsigned fFlags : 11;
+ unsigned fFlags : 12;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
@@ -859,9 +872,10 @@ private:
enum {
kCanonicalTextSizeForPaths = 64
};
+ friend class SkAutoGlyphCache;
friend class SkCanvas;
friend class SkDraw;
- friend class SkAutoGlyphCache;
+ friend class SkPDFDevice;
friend class SkTextToPathIter;
};
diff --git a/include/core/SkPictureFlat.h b/include/core/SkPictureFlat.h
deleted file mode 100644
index 2c0af5a..0000000
--- a/include/core/SkPictureFlat.h
+++ /dev/null
@@ -1,209 +0,0 @@
-#ifndef SkPictureFlat_DEFINED
-#define SkPictureFlat_DEFINED
-
-#include "SkChunkAlloc.h"
-#include "SkBitmap.h"
-#include "SkPicture.h"
-#include "SkMatrix.h"
-#include "SkPaint.h"
-#include "SkPath.h"
-#include "SkRegion.h"
-
-enum DrawType {
- UNUSED,
- CLIP_PATH,
- CLIP_REGION,
- CLIP_RECT,
- CONCAT,
- DRAW_BITMAP,
- DRAW_BITMAP_MATRIX,
- DRAW_BITMAP_RECT,
- DRAW_DATA,
- DRAW_PAINT,
- DRAW_PATH,
- DRAW_PICTURE,
- DRAW_POINTS,
- DRAW_POS_TEXT,
- DRAW_POS_TEXT_H,
- DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H
- DRAW_RECT,
- DRAW_SHAPE,
- DRAW_SPRITE,
- DRAW_TEXT,
- DRAW_TEXT_ON_PATH,
- DRAW_TEXT_TOP_BOTTOM, // fast variant of DRAW_TEXT
- DRAW_VERTICES,
- RESTORE,
- ROTATE,
- SAVE,
- SAVE_LAYER,
- SCALE,
- SET_MATRIX,
- SKEW,
- TRANSLATE
-};
-
-enum DrawVertexFlags {
- DRAW_VERTICES_HAS_TEXS = 0x01,
- DRAW_VERTICES_HAS_COLORS = 0x02,
- DRAW_VERTICES_HAS_INDICES = 0x04
-};
-
-class SkRefCntPlayback {
-public:
- SkRefCntPlayback();
- virtual ~SkRefCntPlayback();
-
- int count() const { return fCount; }
-
- void reset(const SkRefCntRecorder*);
-
- void setCount(int count);
- SkRefCnt* set(int index, SkRefCnt*);
-
- virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
- buffer.setRefCntArray(fArray, fCount);
- }
-
-protected:
- int fCount;
- SkRefCnt** fArray;
-};
-
-class SkTypefacePlayback : public SkRefCntPlayback {
-public:
- virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
- buffer.setTypefaceArray((SkTypeface**)fArray, fCount);
- }
-};
-
-class SkFactoryPlayback {
-public:
- SkFactoryPlayback(int count) : fCount(count) {
- fArray = SkNEW_ARRAY(SkFlattenable::Factory, count);
- }
-
- ~SkFactoryPlayback() {
- SkDELETE_ARRAY(fArray);
- }
-
- SkFlattenable::Factory* base() const { return fArray; }
-
- void setupBuffer(SkFlattenableReadBuffer& buffer) const {
- buffer.setFactoryPlayback(fArray, fCount);
- }
-
-private:
- int fCount;
- SkFlattenable::Factory* fArray;
-};
-
-class SkFlatData {
-public:
- static int Compare(const SkFlatData* a, const SkFlatData* b) {
- return memcmp(&a->fAllocSize, &b->fAllocSize, a->fAllocSize);
- }
-
- int index() const { return fIndex; }
-
-#ifdef SK_DEBUG_SIZE
- size_t size() const { return sizeof(fIndex) + fAllocSize; }
-#endif
-
-protected:
- static SkFlatData* Alloc(SkChunkAlloc* heap, int32_t size, int index);
-
- int fIndex;
- int32_t fAllocSize;
-};
-
-class SkFlatBitmap : public SkFlatData {
-public:
- static SkFlatBitmap* Flatten(SkChunkAlloc*, const SkBitmap&, int index,
- SkRefCntRecorder*);
-
- void unflatten(SkBitmap* bitmap, SkRefCntPlayback* rcp) const {
- SkFlattenableReadBuffer buffer(fBitmapData);
- if (rcp) {
- rcp->setupBuffer(buffer);
- }
- bitmap->unflatten(buffer);
- }
-
-#ifdef SK_DEBUG_VALIDATE
- void validate() const {
- // to be written
- }
-#endif
-
-private:
- char fBitmapData[1];
- typedef SkFlatData INHERITED;
-};
-
-class SkFlatMatrix : public SkFlatData {
-public:
- static SkFlatMatrix* Flatten(SkChunkAlloc* heap, const SkMatrix& matrix, int index);
-
- void unflatten(SkMatrix* result) const {
- memcpy(result, fMatrixData, sizeof(SkMatrix));
- }
-
-#ifdef SK_DEBUG_DUMP
- void dump() const;
-#endif
-
-#ifdef SK_DEBUG_VALIDATE
- void validate() const {
- // to be written
- }
-#endif
-
-private:
- char fMatrixData[1];
- typedef SkFlatData INHERITED;
-};
-
-class SkFlatPaint : public SkFlatData {
-public:
- static SkFlatPaint* Flatten(SkChunkAlloc* heap, const SkPaint& paint,
- int index, SkRefCntRecorder*,
- SkRefCntRecorder* faceRecorder);
-
- void unflatten(SkPaint* result, SkRefCntPlayback* rcp,
- SkTypefacePlayback* facePlayback) const {
- Read(fPaintData, result, rcp, facePlayback);
- }
-
- static void Read(const void* storage, SkPaint* paint, SkRefCntPlayback*,
- SkTypefacePlayback* facePlayback);
-
-#ifdef SK_DEBUG_DUMP
- void dump() const;
-#endif
-
-private:
- char fPaintData[1];
- typedef SkFlatData INHERITED;
-};
-
-class SkFlatRegion : public SkFlatData {
-public:
- static SkFlatRegion* Flatten(SkChunkAlloc* heap, const SkRegion& region, int index);
-
- void unflatten(SkRegion* result) const {
- result->unflatten(fRegionData);
- }
-
-#ifdef SK_DEBUG_VALIDATE
- void validate() const {
- // to be written
- }
-#endif
-
-private:
- char fRegionData[1];
- typedef SkFlatData INHERITED;
-};
-
-#endif
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index f1dab36..c0259af 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -25,6 +25,9 @@ class SkMutex;
class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
+// this is an opaque class, not interpreted by skia
+class SkGpuTexture;
+
/** \class SkPixelRef
This class is the smart container for pixel memory, and is used with
@@ -105,6 +108,10 @@ public:
*/
void setURI(const SkString& uri) { fURI = uri; }
+ /** Are we really wrapping a texture instead of a bitmap?
+ */
+ virtual SkGpuTexture* getTexture() { return NULL; }
+
// serialization
typedef SkPixelRef* (*Factory)(SkFlattenableReadBuffer&);
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..f907578 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) && !defined(SK_BUILD_FOR_BREW)
+
+ #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/SkRect.h b/include/core/SkRect.h
index fbd9f7f..b6caad5 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -27,6 +27,36 @@
struct SkIRect {
int32_t fLeft, fTop, fRight, fBottom;
+ static SkIRect MakeEmpty() {
+ SkIRect r;
+ r.setEmpty();
+ return r;
+ }
+
+ static SkIRect MakeWH(int32_t w, int32_t h) {
+ SkIRect r;
+ r.set(0, 0, w, h);
+ return r;
+ }
+
+ static SkIRect MakeSize(const SkISize& size) {
+ SkIRect r;
+ r.set(0, 0, size.width(), size.height());
+ return r;
+ }
+
+ static SkIRect MakeLTRB(int32_t l, int32_t t, int32_t r, int32_t b) {
+ SkIRect rect;
+ rect.set(l, t, r, b);
+ return rect;
+ }
+
+ static SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h) {
+ SkIRect r;
+ r.set(x, y, x + w, y + h);
+ return r;
+ }
+
/** Return true if the rectangle's width or height are <= 0
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
@@ -266,6 +296,7 @@ struct SkRect {
/** Return true if the rectangle's width or height are <= 0
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+ bool hasValidCoordinates() const;
SkScalar width() const { return fRight - fLeft; }
SkScalar height() const { return fBottom - fTop; }
SkScalar centerX() const { return SkScalarHalf(fLeft + fRight); }
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 7e325e0..f109ead 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -62,24 +62,6 @@ public:
SkDELETE(this);
}
}
-
- /** Helper version of ref(), that first checks to see if this is not null.
- If this is null, then do nothing.
- */
- void safeRef() const {
- if (this) {
- this->ref();
- }
- }
-
- /** Helper version of unref(), that first checks to see if this is not null.
- If this is null, then do nothing.
- */
- void safeUnref() const {
- if (this) {
- this->unref();
- }
- }
private:
mutable int32_t fRefCnt;
@@ -147,5 +129,51 @@ template <typename T> static inline void SkSafeUnref(T* obj) {
}
}
+/** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to
+ a SkRefCnt (or subclass) object.
+ */
+template <typename T> class SkRefPtr {
+public:
+ SkRefPtr() : fObj(NULL) {}
+ SkRefPtr(T* obj) : fObj(obj) { SkSafeRef(fObj); }
+ SkRefPtr(const SkRefPtr& o) : fObj(o.fObj) { SkSafeRef(fObj); }
+ ~SkRefPtr() { SkSafeUnref(fObj); }
+
+ SkRefPtr& operator=(const SkRefPtr& rp) {
+ SkRefCnt_SafeAssign(fObj, rp.fObj);
+ return *this;
+ }
+ SkRefPtr& operator=(T* obj) {
+ SkRefCnt_SafeAssign(fObj, obj);
+ return *this;
+ }
+
+ bool operator==(const SkRefPtr& rp) const { return fObj == rp.fObj; }
+ bool operator==(const T* obj) const { return fObj == obj; }
+ bool operator!=(const SkRefPtr& rp) const { return fObj != rp.fObj; }
+ bool operator!=(const T* obj) const { return fObj != obj; }
+
+ T* get() const { return fObj; }
+ T& operator*() const { return *fObj; }
+ T* operator->() const { return fObj; }
+ bool operator!() const { return !fObj; }
+
+ typedef T* SkRefPtr::*unspecified_bool_type;
+ operator unspecified_bool_type() const { return fObj ? &SkRefPtr::fObj : NULL; }
+
+private:
+ T* fObj;
+};
+
+template <typename T>
+inline bool operator==(T* obj, const SkRefPtr<T>& rp) {
+ return obj == rp.get();
+}
+
+template <typename T>
+inline bool operator!=(T* obj, const SkRefPtr<T>& rp) {
+ return obj != rp.get();
+}
+
#endif
diff --git a/include/core/SkRefDict.h b/include/core/SkRefDict.h
new file mode 100644
index 0000000..3ee27d9
--- /dev/null
+++ b/include/core/SkRefDict.h
@@ -0,0 +1,61 @@
+/*
+ Copyright 2011 Google Inc.
+
+ 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 SkRefDict_DEFINED
+#define SkRefDict_DEFINED
+
+#include "SkRefCnt.h"
+
+/**
+ * A dictionary of string,refcnt pairs. The dictionary is also an owner of the
+ * refcnt objects while they are contained.
+ */
+class SkRefDict : SkNoncopyable {
+public:
+ SkRefDict();
+ ~SkRefDict();
+
+ /**
+ * Return the data associated with name[], or NULL if no matching entry
+ * is found. The reference-count of the entry is not affected.
+ */
+ SkRefCnt* find(const char name[]) const;
+
+ /**
+ * If data is NULL, remove (if present) the entry matching name and call
+ * prev_data->unref() on the data for the matching entry.
+ * If data is not-NULL, replace the existing entry matching name and
+ * call (prev_data->unref()), or add a new one. In either case,
+ * data->ref() is called.
+ */
+ void set(const char name[], SkRefCnt* data);
+
+ /**
+ * Remove the matching entry (if found) and unref its data.
+ */
+ void remove(const char name[]) { this->set(name, NULL); }
+
+ /**
+ * Remove all entries, and unref() their associated data.
+ */
+ void removeAll();
+
+private:
+ struct Impl;
+ Impl* fImpl;
+};
+
+#endif
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h
index 09b835d..d8c4e00 100644
--- a/include/core/SkRegion.h
+++ b/include/core/SkRegion.h
@@ -98,6 +98,13 @@ public:
*/
bool setRect(int32_t left, int32_t top, int32_t right, int32_t bottom);
+ /** Set this region to the union of an array of rects. This is generally
+ faster than calling region.op(rect, kUnion_Op) in a loop. If count is
+ 0, then this region is set to the empty region.
+ @return true if the resulting region is non-empty
+ */
+ bool setRects(const SkIRect rects[], int count);
+
/** Set this region to the specified region, and return true if it is
non-empty. */
bool setRegion(const SkRegion&);
@@ -260,7 +267,8 @@ public:
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/SkScalar.h b/include/core/SkScalar.h
index 9130a7c..09f24b5 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -60,6 +60,12 @@
/** SkScalarIsNaN(n) returns true if argument is not a number
*/
static inline bool SkScalarIsNaN(float x) { return x != x; }
+ /** Returns true if x is not NaN and not infinite */
+ static inline bool SkScalarIsFinite(float x) {
+ uint32_t bits = SkFloat2Bits(x); // need unsigned for our shifts
+ int exponent = bits << 1 >> 24;
+ return exponent != 0xFF;
+ }
/** SkIntToScalar(n) returns its integer argument as an SkScalar
*/
#define SkIntToScalar(n) ((float)(n))
@@ -177,6 +183,8 @@
#define SK_ScalarMin SK_FixedMin
#define SK_ScalarNaN SK_FixedNaN
#define SkScalarIsNaN(x) ((x) == SK_FixedNaN)
+ #define SkScalarIsFinite(x) ((x) != SK_FixedNaN)
+
#define SkIntToScalar(n) SkIntToFixed(n)
#define SkFixedToScalar(x) (x)
#define SkScalarToFixed(x) (x)
@@ -253,5 +261,18 @@ static inline SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t) {
return A + SkScalarMul(B - A, t);
}
+/** Interpolate along the function described by (keys[length], values[length])
+ for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length]
+ clamp to the min or max value. This function was inspired by a desire
+ to change the multiplier for thickness in fakeBold; therefore it assumes
+ the number of pairs (length) will be small, and a linear search is used.
+ Repeated keys are allowed for discontinuous functions (so long as keys is
+ monotonically increasing), and if key is the value of a repeated scalar in
+ keys, the first one will be used. However, that may change if a binary
+ search is used.
+*/
+SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[],
+ const SkScalar values[], int length);
+
#endif
diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h
index 59d7125..0c93e2e 100644
--- a/include/core/SkScalerContext.h
+++ b/include/core/SkScalerContext.h
@@ -29,7 +29,10 @@ class SkPathEffect;
class SkRasterizer;
// needs to be != to any valid SkMask::Format
-#define MASK_FORMAT_JUST_ADVANCE (0xFF)
+#define MASK_FORMAT_UNKNOWN (0xFF)
+#define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN
+
+#define kMaxGlyphWidth (1<<13)
struct SkGlyph {
void* fImage;
@@ -42,25 +45,38 @@ struct SkGlyph {
uint8_t fMaskFormat;
int8_t fRsbDelta, fLsbDelta; // used by auto-kerning
-
+
+ void init(uint32_t id) {
+ fID = id;
+ fImage = NULL;
+ fPath = NULL;
+ fMaskFormat = MASK_FORMAT_UNKNOWN;
+#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);
}
return rb;
}
-
+
bool isJustAdvance() const {
return MASK_FORMAT_JUST_ADVANCE == fMaskFormat;
}
-
+
bool isFullMetrics() const {
return MASK_FORMAT_JUST_ADVANCE != fMaskFormat;
}
-
+
uint16_t getGlyphID() const {
return ID2Code(fID);
}
@@ -70,27 +86,27 @@ struct SkGlyph {
SkASSERT(code >= baseGlyphCount);
return code - baseGlyphCount;
}
-
+
unsigned getSubX() const {
return ID2SubX(fID);
}
-
+
SkFixed getSubXFixed() const {
return SubToFixed(ID2SubX(fID));
}
-
+
SkFixed getSubYFixed() const {
return SubToFixed(ID2SubY(fID));
}
-
+
size_t computeImageSize() const;
-
+
/** Call this to set all of the metrics fields to 0 (e.g. if the scaler
encounters an error measuring a glyph). Note: this does not alter the
fImage, fPath, fID, fMaskFormat fields.
*/
void zeroMetrics();
-
+
enum {
kSubBits = 2,
kSubMask = ((1 << kSubBits) - 1),
@@ -104,28 +120,28 @@ struct SkGlyph {
static unsigned ID2Code(uint32_t id) {
return id & kCodeMask;
}
-
+
static unsigned ID2SubX(uint32_t id) {
return id >> (kSubShift + kSubShiftX);
}
-
+
static unsigned ID2SubY(uint32_t id) {
return (id >> (kSubShift + kSubShiftY)) & kSubMask;
}
-
+
static unsigned FixedToSub(SkFixed n) {
return (n >> (16 - kSubBits)) & kSubMask;
}
-
+
static SkFixed SubToFixed(unsigned sub) {
SkASSERT(sub <= kSubMask);
return sub << (16 - kSubBits);
}
-
+
static uint32_t MakeID(unsigned code) {
return code;
}
-
+
static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) {
SkASSERT(code <= kCodeMask);
x = FixedToSub(x);
@@ -134,7 +150,7 @@ struct SkGlyph {
(y << (kSubShift + kSubShiftY)) |
code;
}
-
+
void toMask(SkMask* mask) const;
/** Given a glyph which is has a mask format of LCD or VerticalLCD, take
@@ -156,6 +172,8 @@ public:
kHintingBit2_Flag = 0x20,
kEmbeddedBitmapText_Flag = 0x40,
kEmbolden_Flag = 0x80,
+ kSubpixelPositioning_Flag = 0x100,
+ kAutohinting_Flag = 0x200,
};
private:
enum {
@@ -167,10 +185,9 @@ public:
SkScalar fTextSize, fPreScaleX, fPreSkewX;
SkScalar fPost2x2[2][2];
SkScalar fFrameWidth, fMiterLimit;
- bool fSubpixelPositioning;
uint8_t fMaskFormat;
uint8_t fStrokeJoin;
- uint8_t fFlags;
+ uint16_t fFlags;
// Warning: when adding members note that the size of this structure
// must be a multiple of 4. SkDescriptor requires that its arguments be
// multiples of four and this structure is put in an SkDescriptor in
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 @@ public:
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/SkSize.h b/include/core/SkSize.h
index 9df9508..8371c9b 100644
--- a/include/core/SkSize.h
+++ b/include/core/SkSize.h
@@ -83,19 +83,19 @@ struct SkSize : public SkTSize<SkScalar> {
return *this;
}
- SkISize round() const {
+ SkISize toRound() const {
SkISize s;
s.set(SkScalarRound(fWidth), SkScalarRound(fHeight));
return s;
}
-
- SkISize ceil() const {
+
+ SkISize toCeil() const {
SkISize s;
s.set(SkScalarCeil(fWidth), SkScalarCeil(fHeight));
return s;
}
- SkISize floor() const {
+ SkISize toFloor() const {
SkISize s;
s.set(SkScalarFloor(fWidth), SkScalarFloor(fHeight));
return s;
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index 798c6be..b02d482 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -91,6 +91,7 @@ public:
bool writeText(const char text[]);
bool writeDecAsText(int32_t);
+ bool writeBigDecAsText(int64_t, int minDigits = 0);
bool writeHexAsText(uint32_t, int minDigits = 0);
bool writeScalarAsText(SkScalar);
@@ -176,7 +177,11 @@ public:
*/
virtual void setMemory(const void* data, size_t length,
bool copyData = false);
- virtual void setMemoryOwned(const void* src, size_t size);
+ /** Replace any memory buffer with the specified buffer. The caller
+ must have allocated data with sk_malloc or sk_realloc, since it
+ will be freed with sk_free.
+ */
+ void setMemoryOwned(const void* data, size_t length);
void skipToAlign4();
virtual bool rewind();
virtual size_t read(void* buffer, size_t size);
@@ -273,7 +278,7 @@ public:
// modifies stream and returns true if offset + size is less than or equal to getOffset()
bool write(const void* buffer, size_t offset, size_t size);
bool read(void* buffer, size_t offset, size_t size);
- size_t getOffset() { return fBytesWritten; }
+ size_t getOffset() const { return fBytesWritten; }
// copy what has been written to the stream into dst
void copyTo(void* dst) const;
@@ -309,4 +314,3 @@ public:
typedef SkFILEStream SkURLStream;
#endif
-
diff --git a/include/core/SkString.h b/include/core/SkString.h
index 5ecfb1e..4498bba 100644
--- a/include/core/SkString.h
+++ b/include/core/SkString.h
@@ -28,6 +28,8 @@ int SkStrStartsWithOneOf(const char string[], const char prefixes[]);
#define SkStrAppendS32_MaxSize 11
char* SkStrAppendS32(char buffer[], int32_t);
+#define SkStrAppendS64_MaxSize 20
+char* SkStrAppendS64(char buffer[], int64_t, int minDigits);
#define SkStrAppendScalar_MaxSize 11
char* SkStrAppendScalar(char buffer[], SkScalar);
@@ -93,6 +95,7 @@ public:
void insert(size_t offset, const char text[], size_t len);
void insertUnichar(size_t offset, SkUnichar);
void insertS32(size_t offset, int32_t value);
+ void insertS64(size_t offset, int64_t value, int minDigits = 0);
void insertHex(size_t offset, uint32_t value, int minDigits = 0);
void insertScalar(size_t offset, SkScalar);
@@ -101,6 +104,7 @@ public:
void append(const char text[], size_t len) { this->insert((size_t)-1, text, len); }
void appendUnichar(SkUnichar uni) { this->insertUnichar((size_t)-1, uni); }
void appendS32(int32_t value) { this->insertS32((size_t)-1, value); }
+ void appendS64(int64_t value, int minDigits = 0) { this->insertS64((size_t)-1, value, minDigits); }
void appendHex(uint32_t value, int minDigits = 0) { this->insertHex((size_t)-1, value, minDigits); }
void appendScalar(SkScalar value) { this->insertScalar((size_t)-1, value); }
@@ -109,6 +113,7 @@ public:
void prepend(const char text[], size_t len) { this->insert(0, text, len); }
void prependUnichar(SkUnichar uni) { this->insertUnichar(0, uni); }
void prependS32(int32_t value) { this->insertS32(0, value); }
+ void prependS64(int32_t value, int minDigits = 0) { this->insertS64(0, value, minDigits); }
void prependHex(uint32_t value, int minDigits = 0) { this->insertHex(0, value, minDigits); }
void prependScalar(SkScalar value) { this->insertScalar((size_t)-1, value); }
@@ -165,4 +170,3 @@ private:
};
#endif
-
diff --git a/include/core/SkTScopedPtr.h b/include/core/SkTScopedPtr.h
new file mode 100644
index 0000000..1e5d4c4
--- /dev/null
+++ b/include/core/SkTScopedPtr.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * 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 SkTScopedPtr_DEFINED
+#define SkTScopedPtr_DEFINED
+
+#include "SkTypes.h"
+
+/** \class SkTScopedPtr
+ A SkTScopedPtr<T> is like a T*, except that the destructor of SkTScopedPtr<T>
+ automatically deletes the pointer it holds (if any). That is, SkTScopedPtr<T>
+ owns the T object that it points to. Like a T*, a SkTScopedPtr<T> may hold
+ either NULL or a pointer to a T object. Also like T*, SkTScopedPtr<T> is
+ thread-compatible, and once you dereference it, you get the threadsafety
+ guarantees of T.
+
+ The size of a SkTScopedPtr is small: sizeof(SkTScopedPtr<T>) == sizeof(T*)
+*/
+template <typename T> class SkTScopedPtr : SkNoncopyable {
+public:
+ explicit SkTScopedPtr(T* o = NULL) : fObj(o) {}
+ ~SkTScopedPtr() {
+ enum { kTypeMustBeComplete = sizeof(T) };
+ delete fObj;
+ }
+
+ /** Delete the current object, if any. Then take ownership of the
+ passed object.
+ */
+ void reset(T* o = NULL) {
+ if (o != fObj) {
+ enum { kTypeMustBeComplete = sizeof(T) };
+ delete fObj;
+ fObj = o;
+ }
+ }
+
+ /** Without deleting the current object, return it and forget about it.
+ Similar to calling get() and reset(), but the object is not deleted.
+ */
+ T* release() {
+ T* retVal = fObj;
+ fObj = NULL;
+ return retVal;
+ }
+
+ T& operator*() const {
+ SkASSERT(fObj != NULL);
+ return *fObj;
+ }
+ T* operator->() const {
+ SkASSERT(fObj != NULL);
+ return fObj;
+ }
+ T* get() const { return fObj; }
+
+ bool operator==(T* o) const { return fObj == o; }
+ bool operator!=(T* o) const { return fObj != o; }
+
+private:
+ T* fObj;
+
+ // Forbid comparison of SkTScopedPtr types. If T2 != T, it doesn't make
+ // sense, and if T2 == T, it still doesn't make sense because the same
+ // object can't be owned by two different scoped_ptrs.
+ template <class T2> bool operator==(SkTScopedPtr<T2> const& o2) const;
+ template <class T2> bool operator!=(SkTScopedPtr<T2> const& o2) const;
+};
+
+#endif
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h
index d484389..55109bf 100644
--- a/include/core/SkTemplates.h
+++ b/include/core/SkTemplates.h
@@ -59,12 +59,13 @@ private:
T* fObj;
};
+// See also SkTScopedPtr.
template <typename T> class SkAutoTDelete : SkNoncopyable {
public:
SkAutoTDelete(T* obj, bool deleteWhenDone = true) : fObj(obj) {
- this->deleteWhenDone = deleteWhenDone;
+ fDeleteWhenDone = deleteWhenDone;
}
- ~SkAutoTDelete() { if (deleteWhenDone) delete fObj; }
+ ~SkAutoTDelete() { if (fDeleteWhenDone) delete fObj; }
T* get() const { return fObj; }
void free() { delete fObj; fObj = NULL; }
@@ -72,7 +73,7 @@ public:
private:
T* fObj;
- bool deleteWhenDone;
+ bool fDeleteWhenDone;
};
template <typename T> class SkAutoTDeleteArray : SkNoncopyable {
diff --git a/include/core/SkThread_platform.h b/include/core/SkThread_platform.h
index 825b737..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>
@@ -61,7 +61,7 @@ public:
private:
bool fIsGlobal;
enum {
- kStorageIntCount = 12
+ kStorageIntCount = 64
};
uint32_t fStorage[kStorageIntCount];
};
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index bf783a3..cea6ab1 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -20,6 +20,7 @@
#include "SkRefCnt.h"
class SkStream;
+class SkAdvancedTypefaceMetrics;
class SkWStream;
/** \class SkTypeface
@@ -83,6 +84,18 @@ public:
*/
static SkTypeface* CreateFromName(const char familyName[], Style style);
+ /** Return a new reference to the typeface that covers a set of Unicode
+ code points with the specified Style. Use this call if you want to
+ pick any font that covers a given string of text.
+
+ @param data UTF-16 characters
+ @param bytelength length of data, in bytes
+ @return reference to the closest-matching typeface. Call must call
+ unref() when they are done.
+ */
+ static SkTypeface* CreateForChars(const void* data, size_t bytelength,
+ Style s);
+
/** Return a new reference to the typeface that most closely matches the
requested typeface and specified Style. Use this call if you want to
pick a new style from the same family of the existing typeface.
@@ -118,6 +131,14 @@ public:
*/
static SkTypeface* Deserialize(SkStream*);
+ /** Retrieve detailed typeface metrics. Used by the PDF backend.
+ @param perGlyphInfo Indicate if the glyph specific information (advances
+ and names) should be populated.
+ @return The returned object has already been referenced.
+ */
+ SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
+ bool perGlyphInfo) const;
+
protected:
/** uniqueID must be unique (please!) and non-zero
*/
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 1f8ecaa..8dbd51b 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -103,27 +103,53 @@ static inline void sk_bzero(void* buffer, size_t size) {
#define SkAssertResult(cond) cond
#endif
+namespace {
+
+template <bool>
+struct SkCompileAssert {
+};
+
+} // namespace
+
+#define SK_COMPILE_ASSERT(expr, msg) \
+ typedef SkCompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
+
///////////////////////////////////////////////////////////////////////
-/** Fast type for signed 8 bits. Use for parameter passing and local variables, not for storage
-*/
-typedef int S8CPU;
-/** Fast type for unsigned 8 bits. Use for parameter passing and local variables, not for storage
-*/
-typedef int S16CPU;
-/** Fast type for signed 16 bits. Use for parameter passing and local variables, not for storage
-*/
-typedef unsigned U8CPU;
-/** Fast type for unsigned 16 bits. Use for parameter passing and local variables, not for storage
-*/
-typedef unsigned U16CPU;
+/**
+ * Fast type for signed 8 bits. Use for parameter passing and local variables,
+ * not for storage.
+ */
+typedef int S8CPU;
-/** Meant to be faster than bool (doesn't promise to be 0 or 1, just 0 or non-zero
-*/
-typedef int SkBool;
-/** Meant to be a small version of bool, for storage purposes. Will be 0 or 1
-*/
-typedef uint8_t SkBool8;
+/**
+ * Fast type for unsigned 8 bits. Use for parameter passing and local
+ * variables, not for storage
+ */
+typedef unsigned U8CPU;
+
+/**
+ * Fast type for signed 16 bits. Use for parameter passing and local variables,
+ * not for storage
+ */
+typedef int S16CPU;
+
+/**
+ * Fast type for unsigned 16 bits. Use for parameter passing and local
+ * variables, not for storage
+ */
+typedef unsigned U16CPU;
+
+/**
+ * Meant to be faster than bool (doesn't promise to be 0 or 1,
+ * just 0 or non-zero
+ */
+typedef int SkBool;
+
+/**
+ * Meant to be a small version of bool, for storage purposes. Will be 0 or 1
+ */
+typedef uint8_t SkBool8;
#ifdef SK_DEBUG
int8_t SkToS8(long);
@@ -290,6 +316,20 @@ static inline uint32_t SkSetClearMask(uint32_t bits, bool cond,
return cond ? bits | mask : bits & ~mask;
}
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Use to cast a pointer to a different type, and maintaining strict-aliasing
+ */
+template <typename Dst> Dst SkTCast(const void* ptr) {
+ union {
+ const void* src;
+ Dst dst;
+ } data;
+ data.src = ptr;
+ return data.dst;
+}
+
//////////////////////////////////////////////////////////////////////////////
/** \class SkNoncopyable
@@ -300,7 +340,7 @@ be copied. It hides its copy-constructor and its assignment-operator.
class SkNoncopyable {
public:
SkNoncopyable() {}
-
+
private:
SkNoncopyable(const SkNoncopyable&);
SkNoncopyable& operator=(const SkNoncopyable&);
@@ -311,7 +351,7 @@ public:
SkAutoFree() : fPtr(NULL) {}
explicit SkAutoFree(void* ptr) : fPtr(ptr) {}
~SkAutoFree() { sk_free(fPtr); }
-
+
/** Return the currently allocate buffer, or null
*/
void* get() const { return fPtr; }
@@ -325,7 +365,7 @@ public:
fPtr = ptr;
return prev;
}
-
+
/** Transfer ownership of the current ptr to the caller, setting the
internal reference to null. Note the caller is reponsible for calling
sk_free on the returned address.
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 @@ void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
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/core/SkXfermode.h b/include/core/SkXfermode.h
index d92d346..714468c 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -115,6 +115,13 @@ public:
kLastMode = kExclusion_Mode
};
+ /** If the xfermode is one of the modes in the Mode enum, then asMode()
+ returns true and sets (if not null) mode accordingly.
+ This is a better version of IsMode(), which is only able to report
+ about modes that are expressible as coefficients.
+ */
+ virtual bool asMode(Mode* mode);
+
/** Return an SkXfermode object for the specified mode.
*/
static SkXfermode* Create(Mode mode);
@@ -137,7 +144,7 @@ public:
return false and ignore the mode parameter.
*/
static bool IsMode(SkXfermode*, Mode* mode);
-
+
Mode fMode;
protected:
@@ -184,6 +191,7 @@ public:
// overrides from SkFlattenable
virtual Factory getFactory() { return CreateProc; }
virtual void flatten(SkFlattenableWriteBuffer&);
+ virtual bool asMode(SkXfermode::Mode* mode);
protected:
SkProcXfermode(SkFlattenableReadBuffer&);