aboutsummaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/Sk64.h18
-rwxr-xr-x[-rw-r--r--]include/core/SkAdvancedTypefaceMetrics.h28
-rw-r--r--include/core/SkAutoKern.h24
-rw-r--r--include/core/SkBitmap.h134
-rw-r--r--include/core/SkBlitRow.h40
-rw-r--r--include/core/SkBlitter.h107
-rw-r--r--include/core/SkBounder.h17
-rw-r--r--include/core/SkBuffer.h17
-rw-r--r--include/core/SkCanvas.h240
-rw-r--r--include/core/SkChunkAlloc.h17
-rw-r--r--include/core/SkClampRange.h19
-rw-r--r--include/core/SkClipStack.h15
-rw-r--r--include/core/SkColor.h17
-rw-r--r--include/core/SkColorFilter.h49
-rw-r--r--include/core/SkColorPriv.h47
-rw-r--r--include/core/SkColorShader.h51
-rw-r--r--include/core/SkComposeShader.h17
-rw-r--r--include/core/SkData.h137
-rw-r--r--include/core/SkDeque.h17
-rw-r--r--include/core/SkDescriptor.h17
-rw-r--r--include/core/SkDevice.h305
-rw-r--r--include/core/SkDither.h17
-rw-r--r--include/core/SkDraw.h24
-rw-r--r--include/core/SkDrawFilter.h17
-rw-r--r--include/core/SkDrawLooper.h17
-rw-r--r--include/core/SkEdgeClipper.h17
-rw-r--r--include/core/SkEmptyShader.h43
-rw-r--r--include/core/SkEndian.h30
-rw-r--r--include/core/SkFDot6.h17
-rw-r--r--include/core/SkFixed.h41
-rw-r--r--include/core/SkFlate.h43
-rw-r--r--include/core/SkFlattenable.h101
-rw-r--r--include/core/SkFloatBits.h17
-rw-r--r--include/core/SkFloatingPoint.h33
-rw-r--r--include/core/SkFontHost.h72
-rw-r--r--include/core/SkGeometry.h35
-rw-r--r--include/core/SkGlobals.h67
-rw-r--r--include/core/SkGraphics.h74
-rw-r--r--include/core/SkImageFilter.h97
-rw-r--r--include/core/SkLineClipper.h7
-rw-r--r--include/core/SkMMapStream.h17
-rw-r--r--include/core/SkMallocPixelRef.h18
-rw-r--r--include/core/SkMask.h110
-rw-r--r--include/core/SkMaskFilter.h77
-rw-r--r--include/core/SkMath.h17
-rw-r--r--include/core/SkMatrix.h150
-rw-r--r--include/core/SkMetaData.h17
-rw-r--r--include/core/SkOSFile.h25
-rw-r--r--include/core/SkPackBits.h17
-rw-r--r--include/core/SkPaint.h173
-rw-r--r--include/core/SkPath.h155
-rw-r--r--include/core/SkPathEffect.h41
-rw-r--r--include/core/SkPathMeasure.h17
-rw-r--r--include/core/SkPerspIter.h17
-rw-r--r--include/core/SkPicture.h17
-rw-r--r--include/core/SkPixelRef.h63
-rw-r--r--include/core/SkPoint.h120
-rw-r--r--include/core/SkPostConfig.h70
-rw-r--r--include/core/SkPreConfig.h45
-rw-r--r--include/core/SkPtrRecorder.h22
-rw-r--r--include/core/SkRandom.h17
-rw-r--r--include/core/SkRasterizer.h19
-rw-r--r--include/core/SkReader32.h51
-rw-r--r--include/core/SkRect.h129
-rw-r--r--include/core/SkRefCnt.h103
-rw-r--r--include/core/SkRefDict.h19
-rw-r--r--include/core/SkRegion.h25
-rw-r--r--include/core/SkRelay.h19
-rw-r--r--include/core/SkScalar.h77
-rw-r--r--include/core/SkScalarCompare.h17
-rw-r--r--include/core/SkScalerContext.h132
-rw-r--r--include/core/SkScan.h106
-rw-r--r--include/core/SkShader.h28
-rw-r--r--include/core/SkShape.h9
-rw-r--r--include/core/SkSize.h7
-rw-r--r--include/core/SkStream.h100
-rw-r--r--include/core/SkString.h38
-rw-r--r--include/core/SkStroke.h17
-rw-r--r--include/core/SkTArray.h415
-rw-r--r--include/core/SkTDArray.h29
-rw-r--r--include/core/SkTDStack.h75
-rw-r--r--include/core/SkTDict.h17
-rw-r--r--include/core/SkTLazy.h47
-rw-r--r--include/core/SkTRegistry.h19
-rw-r--r--include/core/SkTScopedPtr.h17
-rw-r--r--include/core/SkTSearch.h17
-rw-r--r--include/core/SkTemplates.h125
-rw-r--r--include/core/SkThread.h17
-rw-r--r--include/core/SkThread_platform.h60
-rw-r--r--include/core/SkTime.h17
-rw-r--r--include/core/SkTrace.h47
-rw-r--r--include/core/SkTypeface.h26
-rw-r--r--include/core/SkTypes.h150
-rw-r--r--include/core/SkUnPreMultiply.h17
-rw-r--r--include/core/SkUnitMapper.h17
-rw-r--r--include/core/SkUserConfig.h71
-rw-r--r--include/core/SkUtils.h39
-rw-r--r--include/core/SkWriter32.h29
-rw-r--r--include/core/SkXfermode.h47
99 files changed, 3489 insertions, 2012 deletions
diff --git a/include/core/Sk64.h b/include/core/Sk64.h
index b40b27f..b86e0be 100644
--- a/include/core/Sk64.h
+++ b/include/core/Sk64.h
@@ -1,24 +1,16 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef Sk64_DEFINED
#define Sk64_DEFINED
#include "SkFixed.h"
-#include "SkMath.h"
/** \class Sk64
diff --git a/include/core/SkAdvancedTypefaceMetrics.h b/include/core/SkAdvancedTypefaceMetrics.h
index 1b81909..09fc9a9 100644..100755
--- a/include/core/SkAdvancedTypefaceMetrics.h
+++ b/include/core/SkAdvancedTypefaceMetrics.h
@@ -1,19 +1,12 @@
+
/*
- * 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
+ * Copyright 2011 Google Inc.
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkAdvancedTypefaceMetrics_DEFINED
#define SkAdvancedTypefaceMetrics_DEFINED
@@ -139,10 +132,21 @@ void finishRange(
typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType
type);
+/** Retrieve advance data for glyphs. Used by the PDF backend. It calls
+ underlying platform dependent API getAdvance to acquire the data.
+ @param num_glyphs Total number of glyphs in the given font.
+ @param glyphIDs For per-glyph info, specify subset of the font by
+ giving glyph ids. Each integer represents a glyph
+ id. Passing NULL means all glyphs in the font.
+ @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
+ glyphIDs is NULL.
+*/
template <typename Data, typename FontHandle>
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
FontHandle fontHandle,
int num_glyphs,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount,
bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data));
} // namespace skia_advanced_typeface_metrics_utils
diff --git a/include/core/SkAutoKern.h b/include/core/SkAutoKern.h
index 023cb6b..7a5cdef 100644
--- a/include/core/SkAutoKern.h
+++ b/include/core/SkAutoKern.h
@@ -1,19 +1,11 @@
-/* libs/graphics/sgl/SkAutoKern.h
-**
-** Copyright 2006, 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.
-*/
+
+/*
+ * Copyright 2006 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkAutoKern_DEFINED
#define SkAutoKern_DEFINED
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 91143c1..57b80e5 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkBitmap_DEFINED
#define SkBitmap_DEFINED
@@ -165,14 +158,41 @@ public:
*/
Sk64 getSafeSize64() const ;
+ /** Returns true if this bitmap is marked as immutable, meaning that the
+ contents of its pixels will not change for the lifetime of the bitmap.
+ */
+ bool isImmutable() const;
+
+ /** Marks this bitmap as immutable, meaning that the contents of its
+ pixels will not change for the lifetime of the bitmap and of the
+ underlying pixelref. This state can be set, but it cannot be
+ cleared once it is set. This state propagates to all other bitmaps
+ that share the same pixelref.
+ */
+ void setImmutable();
+
/** Returns true if the bitmap is opaque (has no translucent/transparent pixels).
*/
bool isOpaque() const;
+
/** Specify if this bitmap's pixels are all opaque or not. Is only meaningful for configs
that support per-pixel alpha (RGB32, A1, A8).
*/
void setIsOpaque(bool);
+ /** Returns true if the bitmap is volatile (i.e. should not be cached by devices.)
+ */
+ bool isVolatile() const;
+
+ /** Specify whether this bitmap is volatile. Bitmaps are not volatile by
+ default. Temporary bitmaps that are discarded after use should be
+ marked as volatile. This provides a hint to the device that the bitmap
+ should not be cached. Providing this hint when appropriate can
+ improve performance by avoiding unnecessary overhead and resource
+ consumption on the device.
+ */
+ void setIsVolatile(bool);
+
/** Reset the bitmap to its initial state (see default constructor). If we are a (shared)
owner of the pixels, that ownership is decremented.
*/
@@ -218,12 +238,11 @@ public:
/** 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.
+ In the case when the dstRowBytes matches the bitmap's rowBytes, the copy
+ may be made faster by copying over the dst's per-row padding (for all
+ rows but the last). By setting preserveDstPad to true the caller can
+ disable this optimization and ensure that pixels in the padding are not
+ overwritten.
Always returns false for RLE formats.
@@ -232,27 +251,12 @@ public:
pixels using indicated stride.
@param dstRowBytes Width of each line in the buffer. If -1, uses
bitmap's internal stride.
+ @param preserveDstPad Must we preserve padding in the dst
*/
- bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1)
+ bool copyPixelsTo(void* const dst, size_t dstSize, int dstRowBytes = -1,
+ bool preserveDstPad = false)
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
@@ -316,6 +320,14 @@ public:
*/
void unlockPixels() const;
+ /**
+ * Some bitmaps can return a copy of their pixels for lockPixels(), but
+ * that copy, if modified, will not be pushed back. These bitmaps should
+ * not be used as targets for a raster device/canvas (since all pixels
+ * modifications will be lost when unlockPixels() is called.)
+ */
+ bool lockPixelsAreWritable() const;
+
/** Call this to be sure that the bitmap is valid enough to be drawn (i.e.
it has non-null pixels, and if required by its config, it has a
non-null colortable. Returns true if all of the above are met.
@@ -463,19 +475,29 @@ public:
*/
bool extractSubset(SkBitmap* dst, const SkIRect& subset) const;
- /** Makes a deep copy of this bitmap, respecting the requested config.
- Returns false if either there is an error (i.e. the src does not have
- pixels) or the request cannot be satisfied (e.g. the src has per-pixel
- alpha, and the requested config does not support alpha).
- @param dst The bitmap to be sized and allocated
- @param c The desired config for dst
- @param allocator Allocator used to allocate the pixelref for the dst
- bitmap. If this is null, the standard HeapAllocator
- will be used.
- @return true if the copy could be made.
- */
+ /** Makes a deep copy of this bitmap, respecting the requested config,
+ * and allocating the dst pixels on the cpu.
+ * Returns false if either there is an error (i.e. the src does not have
+ * pixels) or the request cannot be satisfied (e.g. the src has per-pixel
+ * alpha, and the requested config does not support alpha).
+ * @param dst The bitmap to be sized and allocated
+ * @param c The desired config for dst
+ * @param allocator Allocator used to allocate the pixelref for the dst
+ * bitmap. If this is null, the standard HeapAllocator
+ * will be used.
+ * @return true if the copy could be made.
+ */
bool copyTo(SkBitmap* dst, Config c, Allocator* allocator = NULL) const;
+ /** Makes a deep copy of this bitmap, respecting the requested config, and
+ * with custom allocation logic that will keep the copied pixels
+ * in the same domain as the source: If the src pixels are allocated for
+ * the cpu, then so will the dst. If the src pixels are allocated on the
+ * gpu (typically as a texture), the it will do the same for the dst.
+ * If the request cannot be fulfilled, returns false and dst is unmodified.
+ */
+ bool deepCopyTo(SkBitmap* dst, Config c) const;
+
/** Returns true if this bitmap can be deep copied into the requested config
by calling copyTo().
*/
@@ -580,7 +602,9 @@ private:
mutable int fRawPixelGenerationID;
enum Flags {
- kImageIsOpaque_Flag = 0x01
+ kImageIsOpaque_Flag = 0x01,
+ kImageIsVolatile_Flag = 0x02,
+ kImageIsImmutable_Flag = 0x04
};
uint32_t fRowBytes;
@@ -698,17 +722,23 @@ private:
void inval16BitCache();
};
-class SkAutoLockPixels {
+class SkAutoLockPixels : public SkNoncopyable {
public:
- SkAutoLockPixels(const SkBitmap& bitmap) : fBitmap(bitmap) {
- bitmap.lockPixels();
+ SkAutoLockPixels(const SkBitmap& bm, bool doLock = true) : fBitmap(bm) {
+ fDidLock = doLock;
+ if (doLock) {
+ bm.lockPixels();
+ }
}
~SkAutoLockPixels() {
- fBitmap.unlockPixels();
+ if (fDidLock) {
+ fBitmap.unlockPixels();
+ }
}
private:
const SkBitmap& fBitmap;
+ bool fDidLock;
};
/** Helper class that performs the lock/unlockColors calls on a colortable.
diff --git a/include/core/SkBlitRow.h b/include/core/SkBlitRow.h
index bb8cbc2..fb62f5a 100644
--- a/include/core/SkBlitRow.h
+++ b/include/core/SkBlitRow.h
@@ -1,3 +1,10 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkBlitRow_DEFINED
#define SkBlitRow_DEFINED
@@ -25,8 +32,8 @@ public:
@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,
+ typedef void (*Proc)(uint16_t* dst,
+ const SkPMColor* src,
int count, U8CPU alpha, int x, int y);
/** Function pointer that blends a single color with a row of 32-bit colors
@@ -51,8 +58,8 @@ public:
@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,
+ typedef void (*Proc32)(uint32_t* dst,
+ const SkPMColor* src,
int count, U8CPU alpha);
static Proc32 Factory32(unsigned flags32);
@@ -84,29 +91,4 @@ private:
};
};
-/**
- * Factory for blitmask procs
- */
-class SkBlitMask {
-public:
- /**
- * Function pointer that blits the mask into a device (dst) colorized
- * by color. The number of pixels to blit is specified by width and height,
- * but each scanline is offset by dstRB (rowbytes) and srcRB respectively.
- */
- typedef void (*Proc)(void* dst, size_t dstRB, SkBitmap::Config dstConfig,
- const uint8_t* mask, size_t maskRB, SkColor color,
- int width, int height);
-
- /* Public entry-point to return a blitmask function ptr
- */
- static Proc Factory(SkBitmap::Config dstConfig, SkColor color);
-
- /* return either platform specific optimized blitmask function-ptr,
- * or NULL if no optimized
- */
- static Proc PlatformProcs(SkBitmap::Config dstConfig, SkColor color);
-};
-
-
#endif
diff --git a/include/core/SkBlitter.h b/include/core/SkBlitter.h
index 11b84fd..ce74a28 100644
--- a/include/core/SkBlitter.h
+++ b/include/core/SkBlitter.h
@@ -1,19 +1,11 @@
-/* libs/graphics/sgl/SkBlitter.h
-**
-** Copyright 2006, 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.
-*/
+
+/*
+ * Copyright 2006 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkBlitter_DEFINED
#define SkBlitter_DEFINED
@@ -25,28 +17,49 @@
#include "SkRegion.h"
#include "SkMask.h"
+/** SkBlitter and its subclasses are responsible for actually writing pixels
+ into memory. Besides efficiency, they handle clipping and antialiasing.
+*/
class SkBlitter {
public:
virtual ~SkBlitter();
+ /// Blit a horizontal run of one or more pixels.
virtual void blitH(int x, int y, int width);
- virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
+ /// Blit a horizontal run of antialiased pixels; runs[] is a *sparse*
+ /// zero-terminated run-length encoding of spans of constant alpha values.
+ virtual void blitAntiH(int x, int y, const SkAlpha antialias[],
+ const int16_t runs[]);
+ /// Blit a vertical run of pixels with a constant alpha value.
virtual void blitV(int x, int y, int height, SkAlpha alpha);
+ /// Blit a solid rectangle one or more pixels wide.
virtual void blitRect(int x, int y, int width, int height);
+ /** Blit a rectangle with one alpha-blended column on the left,
+ width (zero or more) opaque pixels, and one alpha-blended column
+ on the right.
+ The result will always be at least two pixels wide.
+ */
+ virtual void blitAntiRect(int x, int y, int width, int height,
+ SkAlpha leftAlpha, SkAlpha rightAlpha);
+ /// Blit a pattern of pixels defined by a rectangle-clipped mask;
+ /// typically used for text.
virtual void blitMask(const SkMask&, const SkIRect& clip);
- /* If the blitter just sets a single value for each pixel, return the
+ /** If the blitter just sets a single value for each pixel, return the
bitmap it draws into, and assign value. If not, return NULL and ignore
the value parameter.
*/
virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
- // not virtual, just helpers
+ ///@name non-virtual helpers
void blitMaskRegion(const SkMask& mask, const SkRegion& clip);
void blitRectRegion(const SkIRect& rect, const SkRegion& clip);
void blitRegion(const SkRegion& clip);
+ ///@}
- // factories
+ /** @name Factories
+ Return the correct blitter to use given the specified context.
+ */
static SkBlitter* Choose(const SkBitmap& device,
const SkMatrix& matrix,
const SkPaint& paint) {
@@ -63,6 +76,7 @@ public:
const SkBitmap& src,
int left, int top,
void* storage, size_t storageSize);
+ ///@}
private:
};
@@ -71,12 +85,13 @@ private:
*/
class SkNullBlitter : public SkBlitter {
public:
- virtual void blitH(int x, int y, int width);
- virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
- virtual void blitV(int x, int y, int height, SkAlpha alpha);
- virtual void blitRect(int x, int y, int width, int height);
- virtual void blitMask(const SkMask&, const SkIRect& clip);
- virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
+ virtual void blitH(int x, int y, int width) SK_OVERRIDE;
+ virtual void blitAntiH(int x, int y, const SkAlpha[],
+ const int16_t runs[]) SK_OVERRIDE;
+ virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
+ virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
+ virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
+ virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
};
/** Wraps another (real) blitter, and ensures that the real blitter is only
@@ -91,13 +106,15 @@ public:
fClipRect = clipRect;
}
- // overrides
- virtual void blitH(int x, int y, int width);
- virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
- virtual void blitV(int x, int y, int height, SkAlpha alpha);
- virtual void blitRect(int x, int y, int width, int height);
- virtual void blitMask(const SkMask&, const SkIRect& clip);
- virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
+ virtual void blitH(int x, int y, int width) SK_OVERRIDE;
+ virtual void blitAntiH(int x, int y, const SkAlpha[],
+ const int16_t runs[]) SK_OVERRIDE;
+ virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
+ virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
+ virtual void blitAntiRect(int x, int y, int width, int height,
+ SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE;
+ virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
+ virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
private:
SkBlitter* fBlitter;
@@ -105,8 +122,8 @@ private:
};
/** Wraps another (real) blitter, and ensures that the real blitter is only
-called with coordinates that have been clipped by the specified clipRgn.
-This means the caller need not perform the clipping ahead of time.
+ called with coordinates that have been clipped by the specified clipRgn.
+ This means the caller need not perform the clipping ahead of time.
*/
class SkRgnClipBlitter : public SkBlitter {
public:
@@ -116,19 +133,25 @@ public:
fRgn = clipRgn;
}
- // overrides
- virtual void blitH(int x, int y, int width);
- virtual void blitAntiH(int x, int y, const SkAlpha[], const int16_t runs[]);
- virtual void blitV(int x, int y, int height, SkAlpha alpha);
- virtual void blitRect(int x, int y, int width, int height);
- virtual void blitMask(const SkMask&, const SkIRect& clip);
- virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
+ virtual void blitH(int x, int y, int width) SK_OVERRIDE;
+ virtual void blitAntiH(int x, int y, const SkAlpha[],
+ const int16_t runs[]) SK_OVERRIDE;
+ virtual void blitV(int x, int y, int height, SkAlpha alpha) SK_OVERRIDE;
+ virtual void blitRect(int x, int y, int width, int height) SK_OVERRIDE;
+ virtual void blitAntiRect(int x, int y, int width, int height,
+ SkAlpha leftAlpha, SkAlpha rightAlpha) SK_OVERRIDE;
+ virtual void blitMask(const SkMask&, const SkIRect& clip) SK_OVERRIDE;
+ virtual const SkBitmap* justAnOpaqueColor(uint32_t* value) SK_OVERRIDE;
private:
SkBlitter* fBlitter;
const SkRegion* fRgn;
};
+/** Factory to set up the appropriate most-efficient wrapper blitter
+ to apply a clip. Returns a pointer to a member, so lifetime must
+ be managed carefully.
+*/
class SkBlitterClipper {
public:
SkBlitter* apply(SkBlitter* blitter, const SkRegion* clip,
diff --git a/include/core/SkBounder.h b/include/core/SkBounder.h
index fa4f7fb..5bac358 100644
--- a/include/core/SkBounder.h
+++ b/include/core/SkBounder.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkBounder_DEFINED
#define SkBounder_DEFINED
diff --git a/include/core/SkBuffer.h b/include/core/SkBuffer.h
index 6745650..7a63d3a 100644
--- a/include/core/SkBuffer.h
+++ b/include/core/SkBuffer.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkBuffer_DEFINED
#define SkBuffer_DEFINED
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 273153f..24e4141 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkCanvas_DEFINED
#define SkCanvas_DEFINED
@@ -30,11 +23,9 @@
class SkBounder;
class SkDevice;
-class SkDeviceFactory;
class SkDraw;
class SkDrawFilter;
class SkPicture;
-class SkShape;
/** \class SkCanvas
@@ -53,15 +44,10 @@ class SkShape;
*/
class SK_API SkCanvas : public SkRefCnt {
public:
- /** Construct a canvas with the given device factory.
- @param factory Specify the factory for generating additional devices.
- The factory may be null, in which case
- SkRasterDeviceFactory will be used.
- */
- explicit SkCanvas(SkDeviceFactory* factory = NULL);
+ SkCanvas();
+
+ /** Construct a canvas with the specified device to draw into.
- /** Construct a canvas with the specified device to draw into. The device
- factory will be retrieved from the passed device.
@param device Specifies a device for the canvas to draw into.
*/
explicit SkCanvas(SkDevice* device);
@@ -75,6 +61,13 @@ public:
///////////////////////////////////////////////////////////////////////////
+ /**
+ * Return the width/height of the underlying device. The current drawable
+ * area may be small (due to clipping or saveLayer). For a canvas with
+ * no device, 0,0 will be returned.
+ */
+ SkISize getDeviceSize() const;
+
/** Return the canvas' device object, which may be null. The device holds
the bitmap of the pixels that the canvas draws into. The reference count
of the returned device is not changed by this call.
@@ -96,49 +89,123 @@ public:
*/
SkDevice* getTopDevice() const;
- /** 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);
+ SkDevice* setBitmapDevice(const SkBitmap& bitmap);
/**
- * Return the current device factory, or NULL. The reference count of
- * the returned factory is not changed.
+ * Shortcut for getDevice()->createCompatibleDevice(...).
+ * If getDevice() == NULL, this method does nothing, and returns NULL.
*/
- SkDeviceFactory* getDeviceFactory() const { return fDeviceFactory; }
+ SkDevice* createCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque);
+
+ ///////////////////////////////////////////////////////////////////////////
/**
- * Replace any existing factory with the specified factory, unrefing the
- * previous (if any), and refing the new one (if any). For convenience,
- * the factory parameter is also returned.
+ * This enum can be used with read/writePixels to perform a pixel ops to or
+ * from an 8888 config other than Skia's native config (SkPMColor). There
+ * are three byte orders supported: native, BGRA, and RGBA. Each has a
+ * premultiplied and unpremultiplied variant.
+ *
+ * Components of a 8888 pixel can be packed/unpacked from a 32bit word using
+ * either byte offsets or shift values. Byte offsets are endian-invariant
+ * while shifts are not. BGRA and RGBA configs are defined by byte
+ * orderings. The native config is defined by shift values (SK_A32_SHIFT,
+ * ..., SK_B32_SHIFT).
*/
- SkDeviceFactory* setDeviceFactory(SkDeviceFactory*);
+ enum Config8888 {
+ /**
+ * Skia's native order specified by:
+ * SK_A32_SHIFT, SK_R32_SHIFT, SK_G32_SHIFT, and SK_B32_SHIFT
+ *
+ * kNative_Premul_Config8888 is equivalent to SkPMColor
+ * kNative_Unpremul_Config8888 has the same component order as SkPMColor
+ * but is not premultiplied.
+ */
+ kNative_Premul_Config8888,
+ kNative_Unpremul_Config8888,
+ /**
+ * low byte to high byte: B, G, R, A.
+ */
+ kBGRA_Premul_Config8888,
+ kBGRA_Unpremul_Config8888,
+ /**
+ * low byte to high byte: R, G, B, A.
+ */
+ kRGBA_Premul_Config8888,
+ kRGBA_Unpremul_Config8888,
+ };
- ///////////////////////////////////////////////////////////////////////////
+ /**
+ * On success (returns true), copy the canvas pixels into the bitmap.
+ * On failure, the bitmap parameter is left unchanged and false is
+ * returned.
+ *
+ * The canvas' pixels are converted to the bitmap's config. The only
+ * supported config is kARGB_8888_Config, though this is likely to be
+ * relaxed in the future. The meaning of config kARGB_8888_Config is
+ * modified by the enum param config8888. The default value interprets
+ * kARGB_8888_Config as SkPMColor
+ *
+ * If the bitmap has pixels already allocated, the canvas pixels will be
+ * written there. If not, bitmap->allocPixels() will be called
+ * automatically. If the bitmap is backed by a texture readPixels will
+ * fail.
+ *
+ * The actual pixels written is the intersection of the canvas' bounds, and
+ * the rectangle formed by the bitmap's width,height and the specified x,y.
+ * If bitmap pixels extend outside of that intersection, they will not be
+ * modified.
+ *
+ * Other failure conditions:
+ * * If the canvas is backed by a non-raster device (e.g. PDF) then
+ * readPixels will fail.
+ * * If bitmap is texture-backed then readPixels will fail. (This may be
+ * relaxed in the future.)
+ *
+ * Example that reads the entire canvas into a bitmap using the native
+ * SkPMColor:
+ * SkISize size = canvas->getDeviceSize();
+ * bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
+ * size.fHeight);
+ * if (canvas->readPixels(bitmap, 0, 0)) {
+ * // use the pixels
+ * }
+ */
+ bool readPixels(SkBitmap* bitmap,
+ int x, int y,
+ Config8888 config8888 = kNative_Premul_Config8888);
/**
- * 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).
+ * DEPRECATED: This will be removed as soon as webkit is no longer relying
+ * on it. The bitmap is resized to the intersection of srcRect and the
+ * canvas bounds. New pixels are always allocated on success. Bitmap is
+ * unmodified on failure.
*/
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.
+ * the canvas, with the top/left corner specified by (x, y). The canvas'
+ * pixel values are completely replaced: there is no blending.
+ *
+ * Currently if bitmap is backed by a texture this is a no-op. This may be
+ * relaxed in the future.
+ *
+ * If the bitmap has config kARGB_8888_Config then the config8888 param
+ * will determines how the pixel valuess are intepreted. If the bitmap is
+ * not kARGB_8888_Config then this parameter is ignored.
+ *
+ * Note: If you are recording drawing commands on this canvas to
+ * SkPicture, writePixels() is ignored!
*/
- void writePixels(const SkBitmap& bitmap, int x, int y);
+ void writePixels(const SkBitmap& bitmap,
+ int x, int y,
+ Config8888 config8888 = kNative_Premul_Config8888);
///////////////////////////////////////////////////////////////////////////
@@ -220,6 +287,11 @@ public:
*/
void restoreToCount(int saveCount);
+ /** Returns true if drawing is currently going to a layer (from saveLayer)
+ * rather than to the root device.
+ */
+ bool isDrawingToLayer() const;
+
/** Preconcat the current matrix with the specified translation
@param dx The distance to translate in X
@param dy The distance to translate in Y
@@ -268,7 +340,8 @@ public:
@return true if the canvas' clip is non-empty
*/
virtual bool clipRect(const SkRect& rect,
- SkRegion::Op op = SkRegion::kIntersect_Op);
+ SkRegion::Op op = SkRegion::kIntersect_Op,
+ bool doAntiAlias = false);
/** Modify the current clip with the specified path.
@param path The path to apply to the current clip
@@ -276,7 +349,8 @@ public:
@return true if the canvas' new clip is non-empty
*/
virtual bool clipPath(const SkPath& path,
- SkRegion::Op op = SkRegion::kIntersect_Op);
+ SkRegion::Op op = SkRegion::kIntersect_Op,
+ bool doAntiAlias = false);
/** Modify the current clip with the specified region. Note that unlike
clipRect() and clipPath() which transform their arguments by the current
@@ -359,6 +433,13 @@ public:
*/
bool getClipBounds(SkRect* bounds, EdgeType et = kAA_EdgeType) const;
+ /** Return the bounds of the current clip, in device coordinates; returns
+ true if non-empty. Maybe faster than getting the clip explicitly and
+ then taking its bounds.
+ */
+ bool getClipDeviceBounds(SkIRect* bounds) const;
+
+
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified ARGB color, using the specified mode.
@param a the alpha component (0..255) of the color to fill the canvas
@@ -565,6 +646,23 @@ public:
virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
const SkPaint* paint = NULL);
+ /**
+ * Draw the bitmap stretched differentially to fit into dst.
+ * center is a rect within the bitmap, and logically divides the bitmap
+ * into 9 sections (3x3). For example, if the middle pixel of a [5x5]
+ * bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
+ *
+ * If the dst is >= the bitmap size, then...
+ * - The 4 corners are not stretch at all.
+ * - The sides are stretch in only one axis.
+ * - The center is stretch in both axes.
+ * Else, for each axis where dst < bitmap,
+ * - The corners shrink proportionally
+ * - The sides (along the shrink axis) and center are not drawn
+ */
+ virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
+ const SkRect& dst, 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
@@ -643,7 +741,7 @@ public:
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
/** Draw the text on path, with each character/glyph origin specified by the pos[]
array. The origin is interpreted by the Align setting in the paint.
@param text The text to be drawn
@@ -669,10 +767,6 @@ public:
*/
virtual void drawPicture(SkPicture& picture);
- /** Draws the specified shape
- */
- virtual void drawShape(SkShape*);
-
enum VertexMode {
kTriangles_VertexMode,
kTriangleStrip_VertexMode,
@@ -753,6 +847,17 @@ public:
*/
const SkMatrix& getTotalMatrix() const;
+ enum ClipType {
+ kEmpty_ClipType = 0,
+ kRect_ClipType,
+ kComplex_ClipType
+ };
+
+ /** Returns a description of the total clip; may be cheaper than
+ getting the clip and querying it directly.
+ */
+ ClipType getClipType() const;
+
/** Return the current device clip (concatenation of all clip calls).
This does not account for the translate in any of the devices.
@return the current device clip (concatenation of all clip calls).
@@ -760,6 +865,14 @@ public:
const SkRegion& getTotalClip() const;
/**
+ * Return true if the current clip is non-empty.
+ *
+ * If bounds is not NULL, set it to the bounds of the current clip
+ * in global coordinates.
+ */
+ bool getTotalClipBounds(SkIRect* bounds) const;
+
+ /**
* Return the current clipstack. This mirrors the result in getTotalClip()
* but is represented as a stack of geometric clips + region-ops.
*/
@@ -824,7 +937,7 @@ private:
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
- SkDeviceFactory* fDeviceFactory;
+ int fLayerCount; // number of successful saveLayer calls
void prepareForDeviceDraw(SkDevice*, const SkMatrix&, const SkRegion&,
const SkClipStack& clipStack);
@@ -834,13 +947,31 @@ private:
friend class SkDrawIter; // needs setupDrawForLayerDevice()
+ SkDevice* createLayerDevice(SkBitmap::Config, int width, int height,
+ bool isOpaque);
+
SkDevice* init(SkDevice*);
+
+ // internal methods are not virtual, so they can safely be called by other
+ // canvas apis, without confusing subclasses (like SkPictureRecording)
void internalDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix& m,
const SkPaint* paint);
+ void internalDrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
+ const SkRect& dst, const SkPaint* paint);
+ void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
+ const SkRect& dst, const SkPaint* paint);
+ void internalDrawPaint(const SkPaint& paint);
+
+
void drawDevice(SkDevice*, int x, int y, const SkPaint*);
// shared by save() and saveLayer()
int internalSave(SaveFlags flags);
void internalRestore();
+ static void DrawRect(const SkDraw& draw, const SkPaint& paint,
+ const SkRect& r, SkScalar textSize);
+ static void DrawTextDecorations(const SkDraw& draw, const SkPaint& paint,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y);
/* These maintain a cache of the clip bounds in local coordinates,
(converted to 2s-compliment if floats are slow).
@@ -918,4 +1049,3 @@ private:
};
#endif
-
diff --git a/include/core/SkChunkAlloc.h b/include/core/SkChunkAlloc.h
index ba9e2c9..28d3c7e 100644
--- a/include/core/SkChunkAlloc.h
+++ b/include/core/SkChunkAlloc.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkChunkAlloc_DEFINED
#define SkChunkAlloc_DEFINED
diff --git a/include/core/SkClampRange.h b/include/core/SkClampRange.h
index 9acf1ad..68a27e9 100644
--- a/include/core/SkClampRange.h
+++ b/include/core/SkClampRange.h
@@ -1,19 +1,12 @@
-/*
- 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.
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkClampRange_DEFINED
#define SkClampRange_DEFINED
diff --git a/include/core/SkClipStack.h b/include/core/SkClipStack.h
index 6e8da76..fc96f03 100644
--- a/include/core/SkClipStack.h
+++ b/include/core/SkClipStack.h
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
#ifndef SkClipStack_DEFINED
#define SkClipStack_DEFINED
@@ -27,10 +34,10 @@ public:
SkRegion::Op op = SkRegion::kIntersect_Op) {
SkRect r;
r.set(ir);
- this->clipDevRect(r, op);
+ this->clipDevRect(r, op, false);
}
- void clipDevRect(const SkRect&, SkRegion::Op = SkRegion::kIntersect_Op);
- void clipDevPath(const SkPath&, SkRegion::Op = SkRegion::kIntersect_Op);
+ void clipDevRect(const SkRect&, SkRegion::Op, bool doAA);
+ void clipDevPath(const SkPath&, SkRegion::Op, bool doAA);
class B2FIter {
public:
@@ -42,11 +49,13 @@ public:
B2FIter(const SkClipStack& stack);
struct Clip {
+ Clip() : fRect(NULL), fPath(NULL), fOp(SkRegion::kIntersect_Op) {}
friend bool operator==(const Clip& a, const Clip& b);
friend bool operator!=(const Clip& a, const Clip& b);
const SkRect* fRect; // if non-null, this is a rect clip
const SkPath* fPath; // if non-null, this is a path clip
SkRegion::Op fOp;
+ bool fDoAA;
};
/**
diff --git a/include/core/SkColor.h b/include/core/SkColor.h
index 1f82aa7..e6d4352 100644
--- a/include/core/SkColor.h
+++ b/include/core/SkColor.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkColor_DEFINED
#define SkColor_DEFINED
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h
index 3e9aee8..97db5cc 100644
--- a/include/core/SkColorFilter.h
+++ b/include/core/SkColorFilter.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkColorFilter_DEFINED
#define SkColorFilter_DEFINED
@@ -30,6 +23,31 @@ public:
*/
virtual bool asColorMode(SkColor* color, SkXfermode::Mode* mode);
+ /**
+ * If the filter can be represented by a 5x4 matrix, this
+ * returns true, and sets the matrix appropriately.
+ * If not, this returns false and ignores the parameter.
+ */
+ virtual bool asColorMatrix(SkScalar matrix[20]);
+
+ /**
+ * If the filter can be represented by per-component table, return true,
+ * and if table is not null, copy the bitmap containing the table into it.
+ *
+ * The table bitmap will be in SkBitmap::kA8_Config. Each row corresponding
+ * to each component in ARGB order. e.g. row[0] == alpha, row[1] == red,
+ * etc. To transform a color, you (logically) perform the following:
+ *
+ * a' = *table.getAddr8(a, 0);
+ * r' = *table.getAddr8(r, 1);
+ * g' = *table.getAddr8(g, 2);
+ * b' = *table.getAddr8(b, 3);
+ *
+ * The original component value is the horizontal index for a given row,
+ * and the stored value at that index is the new value for that component.
+ */
+ virtual bool asComponentTable(SkBitmap* table);
+
/** Called with a scanline of colors, as if there was a shader installed.
The implementation writes out its filtered version into result[].
Note: shader and result may be the same buffer.
@@ -99,7 +117,8 @@ public:
are ignored.
*/
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add);
-
+
+ SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkColorFilter() {}
SkColorFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
@@ -126,8 +145,8 @@ public:
protected:
SkFilterShader(SkFlattenableReadBuffer& );
- virtual void flatten(SkFlattenableWriteBuffer& );
- virtual Factory getFactory() { return CreateProc; }
+ virtual void flatten(SkFlattenableWriteBuffer& ) SK_OVERRIDE;
+ virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkFilterShader, (buffer)); }
diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h
index 6fa9df3..714e845 100644
--- a/include/core/SkColorPriv.h
+++ b/include/core/SkColorPriv.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkColorPriv_DEFINED
#define SkColorPriv_DEFINED
@@ -51,6 +44,21 @@ static inline int SkAlphaBlend(int src, int dst, int scale256) {
return dst + SkAlphaMul(src - dst, scale256);
}
+/**
+ * Returns (src * alpha + dst * (255 - alpha)) / 255
+ *
+ * This is more accurate than SkAlphaBlend, but slightly slower
+ */
+static inline int SkAlphaBlend255(S16CPU src, S16CPU dst, U8CPU alpha) {
+ SkASSERT((int16_t)src == src);
+ SkASSERT((int16_t)dst == dst);
+ SkASSERT((uint8_t)alpha == alpha);
+
+ int prod = SkMulS16(src - dst, alpha) + 128;
+ prod = (prod + (prod >> 8)) >> 8;
+ return dst + prod;
+}
+
#define SK_R16_BITS 5
#define SK_G16_BITS 6
#define SK_B16_BITS 5
@@ -216,6 +224,21 @@ static inline SkPMColor SkPackARGB32NoCheck(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
(g << SK_G32_SHIFT) | (b << SK_B32_SHIFT);
}
+static inline
+SkPMColor SkPremultiplyARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
+ SkA32Assert(a);
+ SkA32Assert(r);
+ SkA32Assert(g);
+ SkA32Assert(b);
+
+ if (a != 255) {
+ r = SkMulDiv255Round(r, a);
+ g = SkMulDiv255Round(g, a);
+ b = SkMulDiv255Round(b, a);
+ }
+ return SkPackARGB32(a, r, g, b);
+}
+
SK_API extern const uint32_t gMask_00FF00FF;
static inline uint32_t SkAlphaMulQ(uint32_t c, unsigned scale) {
diff --git a/include/core/SkColorShader.h b/include/core/SkColorShader.h
index b7537e1..9b1fed3 100644
--- a/include/core/SkColorShader.h
+++ b/include/core/SkColorShader.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2007 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
+ * Copyright 2007 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkColorShader_DEFINED
#define SkColorShader_DEFINED
@@ -39,38 +32,38 @@ public:
virtual ~SkColorShader();
- virtual uint32_t getFlags() { return fFlags; }
- virtual uint8_t getSpan16Alpha() const;
+ virtual uint32_t getFlags() SK_OVERRIDE;
+ virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
+ virtual bool isOpaque() const SK_OVERRIDE;
virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix);
- virtual void shadeSpan(int x, int y, SkPMColor span[], int count);
- virtual void shadeSpan16(int x, int y, uint16_t span[], int count);
- virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count);
+ const SkMatrix& matrix) SK_OVERRIDE;
+ virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
+ virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
+ virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
+ // we return false for this, use asAGradient
virtual BitmapType asABitmap(SkBitmap* outTexture,
SkMatrix* outMatrix,
TileMode xy[2],
- SkScalar* twoPointRadialParams) const;
+ SkScalar* twoPointRadialParams) const SK_OVERRIDE;
- virtual GradientType asAGradient(GradientInfo* info) const;
+ virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
protected:
- SkColorShader(SkFlattenableReadBuffer& );
- virtual void flatten(SkFlattenableWriteBuffer& );
- virtual Factory getFactory() { return CreateProc; }
+ SkColorShader(SkFlattenableReadBuffer&);
+
+ virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
+ virtual Factory getFactory() SK_OVERRIDE;
+
private:
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkColorShader, (buffer));
- }
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
SkColor fColor; // ignored if fInheritColor is true
SkPMColor fPMColor; // cached after setContext()
uint32_t fFlags; // cached after setContext()
uint16_t fColor16; // cached after setContext()
SkBool8 fInheritColor;
- // deferred allocation, used for asABitmap()
- mutable SkPixelRef* fAsABitmapPixelRef;
-
typedef SkShader INHERITED;
};
diff --git a/include/core/SkComposeShader.h b/include/core/SkComposeShader.h
index ea37549..f243954 100644
--- a/include/core/SkComposeShader.h
+++ b/include/core/SkComposeShader.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkComposeShader_DEFINED
#define SkComposeShader_DEFINED
diff --git a/include/core/SkData.h b/include/core/SkData.h
new file mode 100644
index 0000000..a134536
--- /dev/null
+++ b/include/core/SkData.h
@@ -0,0 +1,137 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+
+#ifndef SkData_DEFINED
+#define SkData_DEFINED
+
+#include "SkRefCnt.h"
+
+/**
+ * SkData holds an immutable data buffer. Not only is the data immutable,
+ * but the actual ptr that is returned (by data() or bytes()) is guaranteed
+ * to always be the same for the life of this instance.
+ */
+class SkData : public SkRefCnt {
+public:
+ /**
+ * Returns the number of bytes stored.
+ */
+ size_t size() const { return fSize; }
+
+ /**
+ * Returns the ptr to the data.
+ */
+ const void* data() const { return fPtr; }
+
+ /**
+ * Like data(), returns a read-only ptr into the data, but in this case
+ * it is cast to uint8_t*, to make it easy to add an offset to it.
+ */
+ const uint8_t* bytes() const {
+ return reinterpret_cast<const uint8_t*>(fPtr);
+ }
+
+ /**
+ * Helper to copy a range of the data into a caller-provided buffer.
+ * Returns the actual number of bytes copied, after clamping offset and
+ * length to the size of the data. If buffer is NULL, it is ignored, and
+ * only the computed number of bytes is returned.
+ */
+ size_t copyRange(size_t offset, size_t length, void* buffer) const;
+
+ /**
+ * Function that, if provided, will be called when the SkData goes out
+ * of scope, allowing for custom allocation/freeing of the data.
+ */
+ typedef void (*ReleaseProc)(const void* ptr, size_t length, void* context);
+
+ /**
+ * Create a new dataref by copying the specified data
+ */
+ static SkData* NewWithCopy(const void* data, size_t length);
+
+ /**
+ * Create a new dataref, taking the data ptr as is, and using the
+ * releaseproc to free it. The proc may be NULL.
+ */
+ static SkData* NewWithProc(const void* data, size_t length,
+ ReleaseProc proc, void* context);
+
+ /**
+ * Create a new dataref, reference the data ptr as is, and calling
+ * sk_free to delete it.
+ */
+ static SkData* NewFromMalloc(const void* data, size_t length);
+
+ /**
+ * Create a new dataref using a subset of the data in the specified
+ * src dataref.
+ */
+ static SkData* NewSubset(const SkData* src, size_t offset, size_t length);
+
+ /**
+ * Returns a new empty dataref (or a reference to a shared empty dataref).
+ * New or shared, the caller must see that unref() is eventually called.
+ */
+ static SkData* NewEmpty();
+
+private:
+ ReleaseProc fReleaseProc;
+ void* fReleaseProcContext;
+
+ const void* fPtr;
+ size_t fSize;
+
+ SkData(const void* ptr, size_t size, ReleaseProc, void* context);
+ ~SkData();
+};
+
+/**
+ * Specialized version of SkAutoTUnref<SkData> for automatically unref-ing a
+ * SkData. If the SkData is null, data(), bytes() and size() will return 0.
+ */
+class SkAutoDataUnref : SkNoncopyable {
+public:
+ SkAutoDataUnref(SkData* data) : fRef(data) {
+ if (data) {
+ fData = data->data();
+ fSize = data->size();
+ } else {
+ fData = NULL;
+ fSize = 0;
+ }
+ }
+ ~SkAutoDataUnref() {
+ SkSafeUnref(fRef);
+ }
+
+ const void* data() const { return fData; }
+ const uint8_t* bytes() const {
+ return reinterpret_cast<const uint8_t*> (fData);
+ }
+ size_t size() const { return fSize; }
+ SkData* get() const { return fRef; }
+
+ void release() {
+ if (fRef) {
+ fRef->unref();
+ fRef = NULL;
+ fData = NULL;
+ fSize = 0;
+ }
+ }
+
+private:
+ SkData* fRef;
+ const void* fData;
+ size_t fSize;
+};
+
+#endif
diff --git a/include/core/SkDeque.h b/include/core/SkDeque.h
index 8bf8b5b..b4f420d 100644
--- a/include/core/SkDeque.h
+++ b/include/core/SkDeque.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDeque_DEFINED
#define SkDeque_DEFINED
diff --git a/include/core/SkDescriptor.h b/include/core/SkDescriptor.h
index 09397b7..b97b75f 100644
--- a/include/core/SkDescriptor.h
+++ b/include/core/SkDescriptor.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDescriptor_DEFINED
#define SkDescriptor_DEFINED
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index d9a4fde..c026a4b 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -1,19 +1,12 @@
+
/*
- * 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
+ * Copyright 2010 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDevice_DEFINED
#define SkDevice_DEFINED
@@ -23,55 +16,57 @@
#include "SkColor.h"
class SkClipStack;
-class SkDevice;
class SkDraw;
struct SkIRect;
class SkMatrix;
class SkMetaData;
class SkRegion;
-/** \class SkDeviceFactory
-
- Devices that extend SkDevice should also provide a SkDeviceFactory class
- to pass into SkCanvas. Doing so will eliminate the need to extend
- SkCanvas as well.
-*/
-class SK_API SkDeviceFactory : public SkRefCnt {
-public:
- SkDeviceFactory();
- virtual ~SkDeviceFactory();
- virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
- int height, bool isOpaque, bool isLayer) = 0;
-};
-
-class SkRasterDeviceFactory : public SkDeviceFactory {
-public:
- virtual SkDevice* newDevice(SkCanvas*, SkBitmap::Config, int width,
- int height, bool isOpaque, bool isLayer);
-};
+// This is an opaque class, not interpreted by skia
+class SkGpuRenderTarget;
class SK_API SkDevice : public SkRefCnt {
public:
- 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.
+ /**
+ * Construct a new device with the specified bitmap as its backend. It is
+ * valid for the bitmap to have no pixels associated with it. In that case,
+ * any drawing to this device will have no effect.
+ */
+ SkDevice(const SkBitmap& bitmap);
- Subclasses may override the destructor, which is virtual, even though this class
- doesn't have one. SkRefCnt does.
+ /**
+ * Create a new raster device and have the pixels be automatically
+ * allocated. The rowBytes of the device will be computed automatically
+ * based on the config and the width.
+ *
+ * @param config The desired config for the pixels. If the request cannot
+ * be met, the closest matching support config will be used.
+ * @param width width (in pixels) of the device
+ * @param height height (in pixels) of the device
+ * @param isOpaque Set to true if it is known that all of the pixels will
+ * be drawn to opaquely. Used as an accelerator when drawing
+ * these pixels to another device.
+ */
+ SkDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false);
- @param bitmap A copy of this bitmap is made and stored in the device
- */
- SkDevice(SkCanvas*, const SkBitmap& bitmap, bool forOffscreen);
virtual ~SkDevice();
/**
- * Return the factory that will create this subclass of SkDevice.
- * The returned factory is cached by the device, and so its reference count
- * is not changed by this call.
+ * Creates a device that is of the same type as this device (e.g. SW-raster,
+ * GPU, or PDF). The backing store for this device is created automatically
+ * (e.g. offscreen pixels or FBO or whatever is appropriate).
+ *
+ * @param width width of the device to create
+ * @param height height of the device to create
+ * @param isOpaque performance hint, set to true if you know that you will
+ * draw into this device such that all of the pixels will
+ * be opaque.
*/
- SkDeviceFactory* getDeviceFactory();
+ SkDevice* createCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque);
+
+ SkMetaData& getMetaData();
enum Capabilities {
kGL_Capability = 0x1, //!< mask indicating GL support
@@ -88,28 +83,20 @@ public:
virtual int height() const { return fBitmap.height(); }
/**
- * Return the device's origin: its offset in device coordinates from
- * the default origin in its canvas' matrix/clip
+ * Return the bounds of the device in the coordinate space of the root
+ * canvas. The root device will have its top-left at 0,0, but other devices
+ * such as those associated with saveLayer may have a non-zero origin.
*/
- const SkIPoint& getOrigin() const { return fOrigin; }
+ void getGlobalBounds(SkIRect* bounds) const;
- /** Return the bitmap config of the device's pixels
- */
- SkBitmap::Config config() const { return fBitmap.getConfig(); }
/** Returns true if the device's bitmap's config treats every pixels as
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.
+ /** Return the bitmap config of the device's pixels
*/
- bool intersects(const SkIRect& r, SkIRect* sect = NULL) const;
+ SkBitmap::Config config() const { return fBitmap.getConfig(); }
/** Return the bitmap associated with this device. Call this each time you need
to access the bitmap, as it notifies the subclass to perform any flushing
@@ -119,26 +106,56 @@ public:
*/
const SkBitmap& accessBitmap(bool changePixels);
- /** Clears the entire device to the specified color (including alpha).
- * Ignores the clip.
+ /**
+ * DEPRECATED: This will be made protected once WebKit stops using it.
+ * Instead use Canvas' writePixels method.
+ *
+ * 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.
+ *
+ * Currently if bitmap is backed by a texture this is a no-op. This may be
+ * relaxed in the future.
+ *
+ * If the bitmap has config kARGB_8888_Config then the config8888 param
+ * will determines how the pixel valuess are intepreted. If the bitmap is
+ * not kARGB_8888_Config then this parameter is ignored.
*/
- virtual void clear(SkColor color);
+ virtual void writePixels(const SkBitmap& bitmap, int x, int y,
+ SkCanvas::Config8888 config8888 = SkCanvas::kNative_Premul_Config8888);
/**
- * Deprecated name for clear.
+ * Return the device's associated gpu render target, or NULL.
*/
- void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
+ virtual SkGpuRenderTarget* accessRenderTarget() { return NULL; }
- /** Called when this device is installed into a Canvas. Balanaced by a call
- to unlockPixels() when the device is removed from a Canvas.
- */
- virtual void lockPixels();
- virtual void unlockPixels();
- /** Return the device's associated texture, or NULL. If returned, it may be
- drawn into another device
+ /**
+ * Return the device's origin: its offset in device coordinates from
+ * the default origin in its canvas' matrix/clip
+ */
+ const SkIPoint& getOrigin() const { return fOrigin; }
+
+protected:
+ enum Usage {
+ kGeneral_Usage,
+ kSaveLayer_Usage, // <! internal use only
+ };
+
+ struct TextFlags {
+ uint32_t fFlags; // SkPaint::getFlags()
+ SkPaint::Hinting fHinting;
+ };
+
+ /**
+ * Device may filter the text flags for drawing text here. If it wants to
+ * make a change to the specified values, it should write them into the
+ * textflags parameter (output) and return true. If the paint is fine as
+ * is, then ignore the textflags parameter and return false.
+ *
+ * The baseclass SkDevice filters based on its depth and blitters.
*/
- virtual SkGpuTexture* accessTexture() { return NULL; }
+ virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
/**
* Called with the correct matrix and clip before this device is drawn
@@ -161,24 +178,15 @@ public:
virtual void gainFocus(SkCanvas*, const SkMatrix&, const SkRegion&,
const SkClipStack&) {}
- /** 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).
+ /** Clears the entire device to the specified color (including alpha).
+ * Ignores the clip.
*/
- virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap);
+ virtual void clear(SkColor color);
/**
- * 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.
+ * Deprecated name for clear.
*/
- virtual void writePixels(const SkBitmap& bitmap, int x, int y);
+ void eraseColor(SkColor eraseColor) { this->clear(eraseColor); }
/** These are called inside the per-device-layer loop for each draw call.
When these are called, we have already applied any saveLayer operations,
@@ -210,6 +218,10 @@ public:
const SkMatrix& matrix, const SkPaint& paint);
virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
int x, int y, const SkPaint& paint);
+ /**
+ * Does not handle text decoration.
+ * Decorations (underline and stike-thru) will be handled by SkCanvas.
+ */
virtual void drawText(const SkDraw&, const void* text, size_t len,
SkScalar x, SkScalar y, const SkPaint& paint);
virtual void drawPosText(const SkDraw&, const void* text, size_t len,
@@ -218,7 +230,7 @@ public:
virtual void drawTextOnPath(const SkDraw&, const void* text, size_t len,
const SkPath& path, const SkMatrix* matrix,
const SkPaint& paint);
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix);
@@ -228,35 +240,44 @@ public:
const SkColor colors[], SkXfermode* xmode,
const uint16_t indices[], int indexCount,
const SkPaint& paint);
+ /** The SkDevice passed will be an SkDevice which was returned by a call to
+ onCreateCompatibleDevice on this device with kSaveLayer_Usage.
+ */
virtual void drawDevice(const SkDraw&, SkDevice*, int x, int y,
const SkPaint&);
- ///////////////////////////////////////////////////////////////////////////
-
- SkMetaData& getMetaData();
-
- struct TextFlags {
- uint32_t fFlags; // SkPaint::getFlags()
- SkPaint::Hinting fHinting;
- };
-
/**
- * Device may filter the text flags for drawing text here. If it wants to
- * make a change to the specified values, it should write them into the
- * textflags parameter (output) and return true. If the paint is fine as
- * is, then ignore the textflags parameter and return false.
+ * On success (returns true), copy the device pixels into the bitmap.
+ * On failure, the bitmap parameter is left unchanged and false is
+ * returned.
*
- * The baseclass SkDevice filters based on its depth and blitters.
+ * The device's pixels are converted to the bitmap's config. The only
+ * supported config is kARGB_8888_Config, though this is likely to be
+ * relaxed in the future. The meaning of config kARGB_8888_Config is
+ * modified by the enum param config8888. The default value interprets
+ * kARGB_8888_Config as SkPMColor
+ *
+ * If the bitmap has pixels already allocated, the device pixels will be
+ * written there. If not, bitmap->allocPixels() will be called
+ * automatically. If the bitmap is backed by a texture readPixels will
+ * fail.
+ *
+ * The actual pixels written is the intersection of the device's bounds,
+ * and the rectangle formed by the bitmap's width,height and the specified
+ * x,y. If bitmap pixels extend outside of that intersection, they will not
+ * be modified.
+ *
+ * Other failure conditions:
+ * * If the device is not a raster device (e.g. PDF) then readPixels will
+ * fail.
+ * * If bitmap is texture-backed then readPixels will fail. (This may be
+ * relaxed in the future.)
*/
- virtual bool filterTextFlags(const SkPaint& paint, TextFlags*);
+ bool readPixels(SkBitmap* bitmap,
+ int x, int y,
+ SkCanvas::Config8888 config8888);
-protected:
- /**
- * subclasses must override this to return a new (or ref'd) instance of
- * a device factory that will create this subclass of device. This value
- * is cached, so it should get called at most once for a given instance.
- */
- virtual SkDeviceFactory* onNewDeviceFactory();
+ ///////////////////////////////////////////////////////////////////////////
/** 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
@@ -270,18 +291,76 @@ protected:
fBitmap.setPixelRef(pr, offset);
return pr;
}
+
+ /**
+ * Implements readPixels API. The caller will ensure that:
+ * 1. bitmap has pixel config kARGB_8888_Config.
+ * 2. bitmap has pixels.
+ * 3. The rectangle (x, y, x + bitmap->width(), y + bitmap->height()) is
+ * contained in the device bounds.
+ */
+ virtual bool onReadPixels(const SkBitmap& bitmap,
+ int x, int y,
+ SkCanvas::Config8888 config8888);
+
+ /** Called when this device is installed into a Canvas. Balanaced by a call
+ to unlockPixels() when the device is removed from a Canvas.
+ */
+ virtual void lockPixels();
+ virtual void unlockPixels();
+
+ /**
+ * Returns true if the device allows processing of this imagefilter. If
+ * false is returned, then the filter is ignored. This may happen for
+ * some subclasses that do not support pixel manipulations after drawing
+ * has occurred (e.g. printing). The default implementation returns true.
+ */
+ virtual bool allowImageFilter(SkImageFilter*);
+
+ /**
+ * Override and return true for filters that the device handles
+ * intrinsically. Returning false means call the filter.
+ * Default impl returns false. This will only be called if allowImageFilter()
+ * returned true.
+ */
+ virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
+ const SkMatrix& ctm,
+ SkBitmap* result, SkIPoint* offset);
+
+ // This is equal kBGRA_Premul_Config8888 or kRGBA_Premul_Config8888 if
+ // either is identical to kNative_Premul_Config8888. Otherwise, -1.
+ static const SkCanvas::Config8888 kPMColorAlias;
private:
friend class SkCanvas;
+ friend struct DeviceCM; //for setMatrixClip
+ friend class SkDraw;
+ friend class SkDrawIter;
+ friend class SkDeviceFilteredPaint;
+ friend class DeviceImageFilterProxy;
+
// just called by SkCanvas when built as a layer
void setOrigin(int x, int y) { fOrigin.set(x, y); }
+ // just called by SkCanvas for saveLayer
+ SkDevice* createCompatibleDeviceForSaveLayer(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque);
+
+ /**
+ * Subclasses should override this to implement createCompatibleDevice.
+ */
+ virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
+ bool isOpaque,
+ Usage usage);
+
+ /** Causes any deferred drawing to the device to be completed.
+ */
+ virtual void flush() {}
- SkCanvas* fCanvas;
SkBitmap fBitmap;
SkIPoint fOrigin;
SkMetaData* fMetaData;
-
- SkDeviceFactory* fCachedDeviceFactory;
};
#endif
diff --git a/include/core/SkDither.h b/include/core/SkDither.h
index 5b2552d..692c7e4 100644
--- a/include/core/SkDither.h
+++ b/include/core/SkDither.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDither_DEFINED
#define SkDither_DEFINED
diff --git a/include/core/SkDraw.h b/include/core/SkDraw.h
index b751be0..8c659c2 100644
--- a/include/core/SkDraw.h
+++ b/include/core/SkDraw.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDraw_DEFINED
#define SkDraw_DEFINED
@@ -30,6 +23,7 @@ class SkClipStack;
class SkDevice;
class SkPath;
class SkRegion;
+class SkRasterClip;
struct SkDrawProcs;
class SkDraw {
@@ -61,7 +55,7 @@ public:
int scalarsPerPosition, const SkPaint& paint) const;
void drawTextOnPath(const char text[], size_t byteLength,
const SkPath&, const SkMatrix*, const SkPaint&) const;
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
void drawPosTextOnPath(const char text[], size_t byteLength,
const SkPoint pos[], const SkPaint& paint,
const SkPath& path, const SkMatrix* matrix) const;
@@ -112,7 +106,8 @@ private:
public:
const SkBitmap* fBitmap; // required
const SkMatrix* fMatrix; // required
- const SkRegion* fClip; // required
+ const SkRegion* fClip; // DEPRECATED
+ const SkRasterClip* fRC; // required
const SkClipStack* fClipStack; // optional
SkDevice* fDevice; // optional
@@ -154,6 +149,7 @@ private:
const SkPath* fPath; // returned in next
SkScalar fXPos; // accumulated xpos, returned in next
SkAutoKern fAutoKern;
+ int fXYIndex; // cache for horizontal -vs- vertical text
};
#endif
diff --git a/include/core/SkDrawFilter.h b/include/core/SkDrawFilter.h
index c8af187..303b80e 100644
--- a/include/core/SkDrawFilter.h
+++ b/include/core/SkDrawFilter.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2011 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
+ * Copyright 2011 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDrawFilter_DEFINED
#define SkDrawFilter_DEFINED
diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h
index 3830b4a..e8265db 100644
--- a/include/core/SkDrawLooper.h
+++ b/include/core/SkDrawLooper.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2011 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
+ * Copyright 2011 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkDrawLooper_DEFINED
#define SkDrawLooper_DEFINED
diff --git a/include/core/SkEdgeClipper.h b/include/core/SkEdgeClipper.h
index 6720b9c..a7eedd5 100644
--- a/include/core/SkEdgeClipper.h
+++ b/include/core/SkEdgeClipper.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2009 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
+ * Copyright 2009 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkEdgeClipper_DEFINED
#define SkEdgeClipper_DEFINED
diff --git a/include/core/SkEmptyShader.h b/include/core/SkEmptyShader.h
new file mode 100644
index 0000000..bf270bf
--- /dev/null
+++ b/include/core/SkEmptyShader.h
@@ -0,0 +1,43 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+
+#ifndef SkEmptyShader_DEFINED
+#define SkEmptyShader_DEFINED
+
+#include "SkShader.h"
+
+/**
+ * \class SkEmptyShader
+ * A Shader that always draws nothing. Its setContext always returns false,
+ * so it never expects that its shadeSpan() methods will get called.
+ */
+class SK_API SkEmptyShader : public SkShader {
+public:
+ SkEmptyShader() {}
+
+ virtual uint32_t getFlags() SK_OVERRIDE;
+ virtual uint8_t getSpan16Alpha() const SK_OVERRIDE;
+ virtual bool setContext(const SkBitmap&, const SkPaint&,
+ const SkMatrix&) SK_OVERRIDE;
+ virtual void shadeSpan(int x, int y, SkPMColor span[], int count) SK_OVERRIDE;
+ virtual void shadeSpan16(int x, int y, uint16_t span[], int count) SK_OVERRIDE;
+ virtual void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) SK_OVERRIDE;
+
+protected:
+ SkEmptyShader(SkFlattenableReadBuffer&);
+
+ virtual Factory getFactory() SK_OVERRIDE;
+ virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
+
+private:
+ typedef SkShader INHERITED;
+};
+
+#endif
diff --git a/include/core/SkEndian.h b/include/core/SkEndian.h
index a72dfe3..3eb67da 100644
--- a/include/core/SkEndian.h
+++ b/include/core/SkEndian.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkEndian_DEFINED
#define SkEndian_DEFINED
@@ -87,6 +80,19 @@ static inline void SkEndianSwap32s(uint32_t array[], int count) {
#define SkEndian_SwapLE32(n) SkEndianSwap32(n)
#endif
+// When a bytestream is embedded in a 32-bit word, how far we need to
+// shift the word to extract each byte from the low 8 bits by anding with 0xff.
+#ifdef SK_CPU_LENDIAN
+ #define SkEndian_Byte0Shift 0
+ #define SkEndian_Byte1Shift 8
+ #define SkEndian_Byte2Shift 16
+ #define SkEndian_Byte3Shift 24
+#else // SK_CPU_BENDIAN
+ #define SkEndian_Byte0Shift 24
+ #define SkEndian_Byte1Shift 16
+ #define SkEndian_Byte2Shift 8
+ #define SkEndian_Byte3Shift 0
+#endif
#endif
diff --git a/include/core/SkFDot6.h b/include/core/SkFDot6.h
index 9d56116..aa58857 100644
--- a/include/core/SkFDot6.h
+++ b/include/core/SkFDot6.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFDot6_DEFINED
#define SkFDot6_DEFINED
diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h
index 8b56c50..0af5d9d 100644
--- a/include/core/SkFixed.h
+++ b/include/core/SkFixed.h
@@ -1,23 +1,16 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFixed_DEFINED
#define SkFixed_DEFINED
-#include "SkMath.h"
+#include "SkTypes.h"
/** \file SkFixed.h
@@ -103,17 +96,23 @@ inline SkFixed SkFixedFraction(SkFixed x)
/** Converts a SkFract to a SkFixed
*/
#define SkFractToFixed(x) ((x) >> 14)
-/** Round a SkFixed to an integer
-*/
-#define SkFixedRound(x) (((x) + SK_FixedHalf) >> 16)
-#define SkFixedCeil(x) (((x) + SK_Fixed1 - 1) >> 16)
-#define SkFixedFloor(x) ((x) >> 16)
+
+#define SkFixedRoundToInt(x) (((x) + SK_FixedHalf) >> 16)
+#define SkFixedCeilToInt(x) (((x) + SK_Fixed1 - 1) >> 16)
+#define SkFixedFloorToInt(x) ((x) >> 16)
+
+#define SkFixedRoundToFixed(x) (((x) + SK_FixedHalf) & 0xFFFF0000)
+#define SkFixedCeilToFixed(x) (((x) + SK_Fixed1 - 1) & 0xFFFF0000)
+#define SkFixedFloorToFixed(x) ((x) & 0xFFFF0000)
+
+// DEPRECATED
+#define SkFixedFloor(x) SkFixedFloorToInt(x)
+#define SkFixedCeil(x) SkFixedCeilToInt(x)
+#define SkFixedRound(x) SkFixedRoundToInt(x)
+
#define SkFixedAbs(x) SkAbs32(x)
#define SkFixedAve(a, b) (((a) + (b)) >> 1)
-// The same as SkIntToFixed(SkFixedFloor(x))
-#define SkFixedFloorToFixed(x) ((x) & ~0xFFFF)
-
SkFixed SkFixedMul_portable(SkFixed, SkFixed);
SkFract SkFractMul_portable(SkFract, SkFract);
inline SkFixed SkFixedSquare_portable(SkFixed value)
diff --git a/include/core/SkFlate.h b/include/core/SkFlate.h
index b606742..c111de0 100644
--- a/include/core/SkFlate.h
+++ b/include/core/SkFlate.h
@@ -1,25 +1,19 @@
+
/*
- * 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
+ * Copyright 2010 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFlate_DEFINED
#define SkFlate_DEFINED
#include "SkTypes.h"
-class SkDynamicMemoryWStream;
+class SkData;
+class SkWStream;
class SkStream;
/** \class SkFlate
@@ -31,15 +25,28 @@ public:
*/
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.
+ /**
+ * 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);
-
+ static bool Deflate(SkStream* src, SkWStream* dst);
+
+ /**
+ * 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(const void* src, size_t len, SkWStream* dst);
+
+ /**
+ * Use the flate compression algorithm to compress the data,
+ * putting the result into dst. Returns false if an error occurs.
+ */
+ static bool Deflate(const SkData*, SkWStream* 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);
+ static bool Inflate(SkStream* src, SkWStream* dst);
};
#endif
diff --git a/include/core/SkFlattenable.h b/include/core/SkFlattenable.h
index 03bcab8..a66638e 100644
--- a/include/core/SkFlattenable.h
+++ b/include/core/SkFlattenable.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFlattenable_DEFINED
#define SkFlattenable_DEFINED
@@ -27,6 +20,40 @@ class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
class SkString;
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+
+#define SK_DECLARE_FLATTENABLE_REGISTRAR()
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable) \
+ static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
+ flattenable::CreateProc);
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable)
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
+ static SkFlattenable::Registrar g##flattenable##Reg(#flattenable, \
+ flattenable::CreateProc);
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
+
+#else
+
+#define SK_DECLARE_FLATTENABLE_REGISTRAR() static void Init();
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR(flattenable) \
+ void flattenable::Init() { \
+ SkFlattenable::Registrar(#flattenable, CreateProc); \
+ }
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(flattenable) \
+ void flattenable::Init() {
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(flattenable) \
+ SkFlattenable::Registrar(#flattenable, flattenable::CreateProc);
+
+#define SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END \
+ }
+
+#endif
+
/** \class SkFlattenable
SkFlattenable is the base class for objects that need to be flattened
@@ -68,6 +95,13 @@ public:
protected:
SkFlattenable(SkFlattenableReadBuffer&) {}
+
+private:
+#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+ static void InitializeFlattenables();
+#endif
+
+ friend class SkGraphics;
};
// helpers for matrix and region
@@ -100,11 +134,27 @@ public:
fTFArray = array;
fTFCount = count;
}
-
+
+ /**
+ * Call this with a pre-loaded array of Factories, in the same order as
+ * were created/written by the writer. SkPicture uses this.
+ */
void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
+ fFactoryTDArray = NULL;
fFactoryArray = array;
fFactoryCount = count;
}
+
+ /**
+ * Call this with an initially empty array, so the reader can cache each
+ * factory it sees by name. Used by the pipe code in conjunction with
+ * the writer's kInlineFactoryNames_Flag.
+ */
+ void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
+ fFactoryTDArray = array;
+ fFactoryArray = NULL;
+ fFactoryCount = 0;
+ }
SkTypeface* readTypeface();
SkRefCnt* readRefCnt();
@@ -118,6 +168,7 @@ private:
SkTypeface** fTFArray;
int fTFCount;
+ SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
SkFlattenable::Factory* fFactoryArray;
int fFactoryCount;
@@ -165,12 +216,22 @@ public:
SkFactorySet* setFactoryRecorder(SkFactorySet*);
enum Flags {
- kCrossProcess_Flag = 0x01
+ kCrossProcess_Flag = 0x01,
+ /**
+ * Instructs the writer to inline Factory names as there are seen the
+ * first time (after that we store an index). The pipe code uses this.
+ */
+ kInlineFactoryNames_Flag = 0x02,
};
- Flags getFlags() const { return fFlags; }
+ Flags getFlags() const { return (Flags)fFlags; }
void setFlags(Flags flags) { fFlags = flags; }
- bool isCrossProcess() const { return (fFlags & kCrossProcess_Flag) != 0; }
+ bool isCrossProcess() const {
+ return SkToBool(fFlags & kCrossProcess_Flag);
+ }
+ bool inlineFactoryNames() const {
+ return SkToBool(fFlags & kInlineFactoryNames_Flag);
+ }
bool persistBitmapPixels() const {
return (fFlags & kCrossProcess_Flag) != 0;
@@ -179,10 +240,10 @@ public:
bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; }
private:
- Flags fFlags;
- SkRefCntSet* fTFSet;
- SkRefCntSet* fRCSet;
- SkFactorySet* fFactorySet;
+ uint32_t fFlags;
+ SkRefCntSet* fTFSet;
+ SkRefCntSet* fRCSet;
+ SkFactorySet* fFactorySet;
typedef SkWriter32 INHERITED;
};
diff --git a/include/core/SkFloatBits.h b/include/core/SkFloatBits.h
index 288f2d8..e6fc5b5 100644
--- a/include/core/SkFloatBits.h
+++ b/include/core/SkFloatBits.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFloatBits_DEFINED
#define SkFloatBits_DEFINED
diff --git a/include/core/SkFloatingPoint.h b/include/core/SkFloatingPoint.h
index 8c3bb83..ee91cd9 100644
--- a/include/core/SkFloatingPoint.h
+++ b/include/core/SkFloatingPoint.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFloatingPoint_DEFINED
#define SkFloatingPoint_DEFINED
@@ -65,12 +58,24 @@ static inline float sk_float_copysign(float x, float y) {
#define sk_float_acos(x) acosf(x)
#define sk_float_asin(x) asinf(x)
#endif
- #define sk_float_atan2(y,x) atan2f(y,x)
+ #define sk_float_atan2(y,x) atan2f(y,x)
#define sk_float_abs(x) fabsf(x)
#define sk_float_mod(x,y) fmodf(x,y)
#define sk_float_exp(x) expf(x)
#define sk_float_log(x) logf(x)
- #define sk_float_isNaN(x) _isnan(x)
+#endif
+
+#ifdef SK_BUILD_FOR_WIN
+ #define sk_float_isfinite(x) _finite(x)
+ #define sk_float_isnan(x) _isnan(x)
+ static inline int sk_float_isinf(float x) {
+ int32_t bits = SkFloat2Bits(x);
+ return (bits << 1) == (0xFF << 24);
+ }
+#else
+ #define sk_float_isfinite(x) isfinite(x)
+ #define sk_float_isnan(x) isnan(x)
+ #define sk_float_isinf(x) isinf(x)
#endif
#ifdef SK_USE_FLOATBITS
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index e20ea05..c549519 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkFontHost_DEFINED
#define SkFontHost_DEFINED
@@ -31,7 +24,7 @@ typedef uint32_t SkFontTableTag;
This class is ported to each environment. It is responsible for bridging
the gap between the (sort of) abstract class SkTypeface and the
platform-specific implementation that provides access to font files.
-
+
One basic task is for each create (subclass of) SkTypeface, the FontHost is
resonsible for assigning a uniqueID. The ID should be unique for the
underlying font file/data, not unique per typeface instance. Thus it is
@@ -43,7 +36,7 @@ typedef uint32_t SkFontTableTag;
returned). Either way, the fontID for those instance(s) will be the same.
In addition, the fontID should never be set to 0. That value is used as a
sentinel to indicate no-font-id.
-
+
The major aspects are:
1) Given either a name/style, return a subclass of SkTypeface that
references the closest matching font available on the host system.
@@ -72,17 +65,17 @@ public:
/** Return a new typeface given the data buffer. If the data does not
represent a valid font, returns null.
-
+
If a typeface instance is returned, the caller is responsible for
calling unref() on the typeface when they are finished with it.
-
+
The returned typeface may or may not have called ref() on the stream
parameter. If the typeface has not called ref(), then it may have made
a copy of the releveant data. In either case, the caller is still
- responsible for its refcnt ownership of the stream.
+ responsible for its refcnt ownership of the stream.
*/
static SkTypeface* CreateTypefaceFromStream(SkStream*);
-
+
/** Return a new typeface from the specified file path. If the file does not
represent a valid font, this returns null. If a typeface is returned,
the caller is responsible for calling unref() when it is no longer used.
@@ -90,13 +83,13 @@ public:
static SkTypeface* CreateTypefaceFromFile(const char path[]);
///////////////////////////////////////////////////////////////////////////
-
+
/** Returns true if the specified unique ID matches an existing font.
Returning false is similar to calling OpenStream with an invalid ID,
which will return NULL in that case.
*/
static bool ValidFontID(SkFontID uniqueID);
-
+
/** Return a new stream to read the font data, or null if the uniqueID does
not match an existing typeface. .The caller must call stream->unref()
when it is finished reading the data.
@@ -145,7 +138,7 @@ public:
static SkTypeface* Deserialize(SkStream*);
///////////////////////////////////////////////////////////////////////////
-
+
/** Return a subclass of SkScalarContext
*/
static SkScalerContext* CreateScalerContext(const SkDescriptor* desc);
@@ -188,10 +181,17 @@ public:
names, etc.) should be populated.
@return The returned object has already been referenced. NULL is
returned if the font is not found.
+ @param glyphIDs For per-glyph info, specify subset of the font by
+ giving glyph ids. Each integer represents a glyph
+ id. Passing NULL means all glyphs in the font.
+ @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
+ glyphIDs is NULL.
*/
static SkAdvancedTypefaceMetrics* GetAdvancedTypefaceMetrics(
SkFontID fontID,
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo);
+ SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount);
/** Return the number of tables in the font
*/
@@ -206,7 +206,7 @@ public:
/** Given a table tag, return the size of its contents, or 0 if not present
*/
static size_t GetTableSize(SkFontID, SkFontTableTag);
-
+
/** Copy the contents of a table into data (allocated by the caller). Note
that the contents of the table will be in their native endian order
(which for most truetype tables is big endian). If the table tag is
@@ -232,20 +232,9 @@ public:
///////////////////////////////////////////////////////////////////////////
- /** Return the number of bytes (approx) that should be purged from the font
- cache. The input parameter is the cache's estimate of how much as been
- allocated by the cache so far.
- To purge (basically) everything, return the input parameter.
- To purge nothing, return 0
- */
- static size_t ShouldPurgeFontCache(size_t sizeAllocatedSoFar);
+ /** DEPRECATED -- only called by SkFontHost_FreeType internally
- /** Return SkScalerContext gamma flag, or 0, based on the paint that will be
- used to draw something with antialiasing.
- */
- static int ComputeGammaFlag(const SkPaint& paint);
-
- /** Return NULL or a pointer to 256 bytes for the black (table[0]) and
+ Return NULL or a pointer to 256 bytes for the black (table[0]) and
white (table[1]) gamma tables.
*/
static void GetGammaTables(const uint8_t* tables[2]);
@@ -286,7 +275,7 @@ public:
static void SetSubpixelOrder(LCDOrder order);
static LCDOrder GetSubpixelOrder();
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
///////////////////////////////////////////////////////////////////////////
/**
@@ -297,7 +286,14 @@ public:
*/
static uint32_t GetUnitsPerEm(SkFontID fontID);
#endif
+
+ /** If Skia is running in a constrained environment and the typeface
+ implementation is handle based, the typeface data may become
+ unavailable asynchronously. If a font host or scaler context method is
+ unable to access font data, it may call this function as a request to
+ make the handle contained in the typeface useable.
+ */
+ static void EnsureTypefaceAccessible(const SkTypeface& typeface);
};
#endif
-
diff --git a/include/core/SkGeometry.h b/include/core/SkGeometry.h
index 000ca73..26f27ba 100644
--- a/include/core/SkGeometry.h
+++ b/include/core/SkGeometry.h
@@ -1,19 +1,11 @@
-/* libs/graphics/sgl/SkGeometry.h
-**
-** Copyright 2006, 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.
-*/
+
+/*
+ * Copyright 2006 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkGeometry_DEFINED
#define SkGeometry_DEFINED
@@ -113,7 +105,11 @@ void SkEvalCubicAt(const SkPoint src[4], SkScalar t, SkPoint* locOrNull,
dst[0..3] and dst[3..6]
*/
void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], SkScalar t);
-void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], const SkScalar t[],
+/** Given a src cubic bezier, chop it at the specified t values,
+ where 0 < t < 1, and return the new cubics in dst:
+ dst[0..3],dst[3..6],...,dst[3*t_count..3*(t_count+1)]
+*/
+void SkChopCubicAt(const SkPoint src[4], SkPoint dst[], const SkScalar t[],
int t_count);
/** Given a src cubic bezier, chop it at the specified t == 1/2,
@@ -149,8 +145,9 @@ int SkChopCubicAtXExtrema(const SkPoint src[4], SkPoint dst[10]);
*/
int SkFindCubicInflections(const SkPoint src[4], SkScalar tValues[2]);
-/** Return 1 for no chop, or 2 for having chopped the cubic at its
- inflection point.
+/** Return 1 for no chop, 2 for having chopped the cubic at a single
+ inflection point, 3 for having chopped at 2 inflection points.
+ dst will hold the resulting 1, 2, or 3 cubics.
*/
int SkChopCubicAtInflections(const SkPoint src[4], SkPoint dst[10]);
diff --git a/include/core/SkGlobals.h b/include/core/SkGlobals.h
deleted file mode 100644
index 8e28290..0000000
--- a/include/core/SkGlobals.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2006 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 SkGlobals_DEFINED
-#define SkGlobals_DEFINED
-
-#include "SkThread.h"
-
-class SkGlobals {
-public:
- class Rec {
- public:
- virtual ~Rec();
- private:
- Rec* fNext;
- uint32_t fTag;
-
- friend class SkGlobals;
- };
-
- /** Look for a matching Rec for the specified tag. If one is found, return it.
- If one is not found, if create_proc is null, return null, else
- call the proc, and if it returns a Rec, add it to the global list
- and return it.
-
- create_proc can NOT call back into SkGlobals::Find (it would deadlock)
- */
- static Rec* Find(uint32_t tag, Rec* (*create_proc)());
- /** Helper for Find, when you want to assert that the Rec is already in the list
- */
- static Rec* Get(uint32_t tag)
- {
- Rec* rec = SkGlobals::Find(tag, NULL);
- SkASSERT(rec);
- return rec;
- }
-
- // used by porting layer
- struct BootStrap {
- SkMutex fMutex;
- Rec* fHead;
- };
-
-private:
- static void Init();
- static void Term();
- friend class SkGraphics;
-
- // This last function is implemented in the porting layer
- static BootStrap& GetBootStrap();
-};
-
-#endif
-
diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h
index 25c926f..c89758b 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkGraphics_DEFINED
#define SkGraphics_DEFINED
@@ -21,24 +14,57 @@
class SkGraphics {
public:
+ /**
+ * Call this at process initialization time if your environment does not
+ * permit static global initializers that execute code. Note that
+ * Init() is not thread-safe.
+ */
static void Init();
- static void Term();
- /** Return the (approximate) number of bytes used by the font cache.
- */
- static size_t GetFontCacheUsed();
-
- /** Attempt to purge the font cache until <= the specified amount remains
- in the cache. Specifying 0 will attempt to purge the entire cache.
- Returns true if some amount was purged from the font cache.
- */
- static bool SetFontCacheUsed(size_t usageInBytes);
+ /**
+ * Call this to release any memory held privately, such as the font cache.
+ */
+ static void Term();
- /** Return the version numbers for the library. If the parameter is not
- null, it is set to the version number.
+ /**
+ * Return the version numbers for the library. If the parameter is not
+ * null, it is set to the version number.
*/
static void GetVersion(int32_t* major, int32_t* minor, int32_t* patch);
+ /**
+ * Return the max number of bytes that should be used by the font cache.
+ * If the cache needs to allocate more, it will purge previous entries.
+ * This max can be changed by calling SetFontCacheLimit().
+ */
+ static size_t GetFontCacheLimit();
+
+ /**
+ * Specify the max number of bytes that should be used by the font cache.
+ * If the cache needs to allocate more, it will purge previous entries.
+ *
+ * This function returns the previous setting, as if GetFontCacheLimit()
+ * had be called before the new limit was set.
+ */
+ static size_t SetFontCacheLimit(size_t bytes);
+
+ /**
+ * For debugging purposes, this will attempt to purge the font cache. It
+ * does not change the limit, but will cause subsequent font measures and
+ * draws to be recreated, since they will no longer be in the cache.
+ */
+ static void PurgeFontCache();
+
+ /**
+ * Applications with command line options may pass optional state, such
+ * as cache sizes, here, for instance:
+ * font-cache-limit=12345678
+ *
+ * The flags format is name=value[;name=value...] with no spaces.
+ * This format is subject to change.
+ */
+ static void SetFlags(const char* flags);
+
private:
/** This is automatically called by SkGraphics::Init(), and must be
implemented by the host OS. This allows the host OS to register a callback
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
new file mode 100644
index 0000000..22b9569
--- /dev/null
+++ b/include/core/SkImageFilter.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkImageFilter_DEFINED
+#define SkImageFilter_DEFINED
+
+#include "SkFlattenable.h"
+
+class SkBitmap;
+class SkDevice;
+class SkMatrix;
+struct SkPoint;
+
+/**
+ * Experimental.
+ *
+ * Base class for image filters. If one is installed in the paint, then
+ * all drawing occurs as usual, but it is as if the drawing happened into an
+ * offscreen (before the xfermode is applied). This offscreen bitmap will
+ * then be handed to the imagefilter, who in turn creates a new bitmap which
+ * is what will finally be drawn to the device (using the original xfermode).
+ *
+ * THIS SIGNATURE IS TEMPORARY
+ *
+ * There are several weaknesses in this function signature:
+ * 1. Does not expose the destination/target device, so filters that can draw
+ * directly to it are unable to take advantage of that optimization.
+ * 2. Does not expose a way to create a "compabitible" image (i.e. gpu -> gpu)
+ * 3. As with #1, the filter is unable to "read" the dest (which would be slow)
+ *
+ * Therefore, we should not create any real dependencies on this API yet -- it
+ * is being checked in as a check-point so we can explore these and other
+ * considerations.
+ */
+class SK_API SkImageFilter : public SkFlattenable {
+public:
+ class Proxy {
+ public:
+ virtual SkDevice* createDevice(int width, int height) = 0;
+
+ // returns true if the proxy handled the filter itself. if this returns
+ // false then the filter's code will be called.
+ virtual bool filterImage(SkImageFilter*, const SkBitmap& src,
+ const SkMatrix& ctm,
+ SkBitmap* result, SkIPoint* offset) = 0;
+ virtual ~Proxy() {};
+ };
+
+ /**
+ * Request a new (result) image to be created from the src image.
+ * If the src has no pixels (isNull()) then the request just wants to
+ * receive the config and width/height of the result.
+ *
+ * The matrix is the current matrix on the canvas.
+ *
+ * Offset is the amount to translate the resulting image relative to the
+ * src when it is drawn.
+ *
+ * If the result image cannot be created, return false, in which case both
+ * the result and offset parameters will be ignored by the caller.
+ */
+ bool filterImage(Proxy*, const SkBitmap& src, const SkMatrix& ctm,
+ SkBitmap* result, SkIPoint* offset);
+
+ /**
+ * Given the src bounds of an image, this returns the bounds of the result
+ * image after the filter has been applied.
+ */
+ bool filterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst);
+
+ /**
+ * Experimental.
+ *
+ * If the filter can be expressed as a gaussian-blur, return true and
+ * set the sigma to the values for horizontal and vertical.
+ */
+ virtual bool asABlur(SkSize* sigma) const;
+
+protected:
+ SkImageFilter() {}
+ explicit SkImageFilter(SkFlattenableReadBuffer& rb) : INHERITED(rb) {}
+
+ // Default impl returns false
+ virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
+ SkBitmap* result, SkIPoint* offset);
+ // Default impl copies src into dst and returns true
+ virtual bool onFilterBounds(const SkIRect&, const SkMatrix&, SkIRect*);
+
+private:
+ typedef SkFlattenable INHERITED;
+};
+
+#endif
diff --git a/include/core/SkLineClipper.h b/include/core/SkLineClipper.h
index 4c23781..1958395 100644
--- a/include/core/SkLineClipper.h
+++ b/include/core/SkLineClipper.h
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
#ifndef SkLineClipper_DEFINED
#define SkLineClipper_DEFINED
diff --git a/include/core/SkMMapStream.h b/include/core/SkMMapStream.h
index 151ad87..19ba634 100644
--- a/include/core/SkMMapStream.h
+++ b/include/core/SkMMapStream.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMMapStream_DEFINED
#define SkMMapStream_DEFINED
diff --git a/include/core/SkMallocPixelRef.h b/include/core/SkMallocPixelRef.h
index edaab94..2ceb826 100644
--- a/include/core/SkMallocPixelRef.h
+++ b/include/core/SkMallocPixelRef.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMallocPixelRef_DEFINED
#define SkMallocPixelRef_DEFINED
@@ -44,6 +37,7 @@ public:
return SkNEW_ARGS(SkMallocPixelRef, (buffer));
}
+ SK_DECLARE_PIXEL_REF_REGISTRAR()
protected:
// overrides from SkPixelRef
virtual void* onLockPixels(SkColorTable**);
diff --git a/include/core/SkMask.h b/include/core/SkMask.h
index f437622..3f9a114 100644
--- a/include/core/SkMask.h
+++ b/include/core/SkMask.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMask_DEFINED
#define SkMask_DEFINED
@@ -28,30 +21,13 @@ struct SkMask {
kBW_Format, //!< 1bit per pixel mask (e.g. monochrome)
kA8_Format, //!< 8bits per pixel mask (e.g. antialiasing)
k3D_Format, //!< 3 8bit per pixl planes: alpha, mul, add
-
- /* The LCD formats look like this in memory:
-
- First, there's an A8 plane which contains the average alpha value for
- each pixel. Because of this, the LCD formats can be passed directly
- to functions which expect an A8 and everything will just work.
-
- After that in memory, there's a bitmap of 32-bit values which have
- been RGB order corrected for the current screen (based on the
- settings in SkFontHost at the time of renderering). The alpha value
- for each pixel is the maximum of the three alpha values.
-
- kHorizontalLCD_Format has an extra column of pixels on the left and right
- 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
kARGB32_Format, //!< SkPMColor
- kLCD16_Format //!< 565 alpha for r/g/b
+ kLCD16_Format, //!< 565 alpha for r/g/b
+ kLCD32_Format //!< 888 alpha for r/g/b
};
enum {
- kCountMaskFormats = kVerticalLCD_Format + 1
+ kCountMaskFormats = kLCD32_Format + 1
};
uint8_t* fImage;
@@ -80,7 +56,7 @@ struct SkMask {
x,y are in the same coordiate space as fBounds.
*/
uint8_t* getAddr1(int x, int y) const {
- SkASSERT(fFormat == kBW_Format);
+ SkASSERT(kBW_Format == fFormat);
SkASSERT(fBounds.contains(x, y));
SkASSERT(fImage != NULL);
return fImage + ((x - fBounds.fLeft) >> 3) + (y - fBounds.fTop) * fRowBytes;
@@ -90,8 +66,8 @@ struct SkMask {
Asserts that the mask is kA8_Format, and that x,y are in range.
x,y are in the same coordiate space as fBounds.
*/
- uint8_t* getAddr(int x, int y) const {
- SkASSERT(fFormat != kBW_Format);
+ uint8_t* getAddr8(int x, int y) const {
+ SkASSERT(kA8_Format == fFormat);
SkASSERT(fBounds.contains(x, y));
SkASSERT(fImage != NULL);
return fImage + x - fBounds.fLeft + (y - fBounds.fTop) * fRowBytes;
@@ -110,28 +86,32 @@ struct SkMask {
return row + (x - fBounds.fLeft);
}
- /** Return an address into the 32-bit plane of an LCD or VerticalLCD mask
- for the given position.
- */
- const uint32_t* getAddrLCD(int x, int y) const {
- SkASSERT(fFormat == kHorizontalLCD_Format || fFormat == kVerticalLCD_Format);
+ /**
+ * Return the address of the specified 32bit mask. In the debug build,
+ * this asserts that the mask's format is kLCD32_Format, and that (x,y)
+ * are contained in the mask's fBounds.
+ */
+ uint32_t* getAddrLCD32(int x, int y) const {
+ SkASSERT(kLCD32_Format == fFormat);
+ SkASSERT(fBounds.contains(x, y));
SkASSERT(fImage != NULL);
-
- return reinterpret_cast<const uint32_t*>(fImage + SkAlign4(fRowBytes * fBounds.height())) +
- x - fBounds.fLeft + (y - fBounds.fTop) * rowWordsLCD();
+ uint32_t* row = (uint32_t*)(fImage + (y - fBounds.fTop) * fRowBytes);
+ return row + (x - fBounds.fLeft);
}
- /** Return the number of 32-bit words in a row of the 32-bit plane of an
- LCD or VerticalLCD mask.
- */
- unsigned rowWordsLCD() const {
- SkASSERT(fFormat == kHorizontalLCD_Format || fFormat == kVerticalLCD_Format);
- if (fFormat == kHorizontalLCD_Format) {
- return fBounds.width() + 2;
- } else {
- return fBounds.width();
- }
- }
+ /**
+ * Returns the address of the specified pixel, computing the pixel-size
+ * at runtime based on the mask format. This will be slightly slower than
+ * using one of the routines where the format is implied by the name
+ * e.g. getAddr8 or getAddrLCD32.
+ *
+ * x,y must be contained by the mask's bounds (this is asserted in the
+ * debug build, but not checked in the release build.)
+ *
+ * This should not be called with kBW_Format, as it will give unspecified
+ * results (and assert in the debug build).
+ */
+ void* getAddr(int x, int y) const;
static uint8_t* AllocImage(size_t bytes);
static void FreeImage(void* image);
@@ -141,10 +121,28 @@ struct SkMask {
kJustRenderImage_CreateMode, //!< render into preallocate mask
kComputeBoundsAndRenderImage_CreateMode //!< compute bounds, alloc image and render into it
};
+};
+
+///////////////////////////////////////////////////////////////////////////////
- static bool FormatIsLCD(Format fm) {
- return kHorizontalLCD_Format == fm || kVerticalLCD_Format == fm;
+/**
+ * \class SkAutoMaskImage
+ *
+ * Stack class used to manage the fImage buffer in a SkMask.
+ * When this object loses scope, the buffer is freed with SkMask::FreeImage().
+ */
+class SkAutoMaskFreeImage {
+public:
+ SkAutoMaskFreeImage(uint8_t* maskImage) {
+ fImage = maskImage;
+ }
+
+ ~SkAutoMaskFreeImage() {
+ SkMask::FreeImage(fImage);
}
+
+private:
+ uint8_t* fImage;
};
#endif
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index 60dade9..2808de7 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMaskFilter_DEFINED
#define SkMaskFilter_DEFINED
@@ -24,7 +17,7 @@ class SkBlitter;
class SkBounder;
class SkMatrix;
class SkPath;
-class SkRegion;
+class SkRasterClip;
/** \class SkMaskFilter
@@ -62,16 +55,30 @@ public:
virtual bool filterMask(SkMask* dst, const SkMask& src, const SkMatrix&,
SkIPoint* margin);
- /** Helper method that, given a path in device space, will rasterize it into a kA8_Format mask
- and then call filterMask(). If this returns true, the specified blitter will be called
- to render that mask. Returns false if filterMask() returned false.
- This method is not exported to java.
- */
- bool filterPath(const SkPath& devPath, const SkMatrix& devMatrix,
- const SkRegion& devClip, SkBounder*, SkBlitter* blitter);
-
virtual void flatten(SkFlattenableWriteBuffer& ) {}
+ enum BlurType {
+ kNone_BlurType, //!< this maskfilter is not a blur
+ kNormal_BlurType, //!< fuzzy inside and outside
+ kSolid_BlurType, //!< solid inside, fuzzy outside
+ kOuter_BlurType, //!< nothing inside, fuzzy outside
+ kInner_BlurType, //!< fuzzy inside, nothing outside
+ };
+
+ struct BlurInfo {
+ SkScalar fRadius;
+ bool fIgnoreTransform;
+ bool fHighQuality;
+ };
+
+ /**
+ * Optional method for maskfilters that can be described as a blur. If so,
+ * they return the corresponding BlurType and set the fields in BlurInfo
+ * (if not null). If they cannot be described as a blur, they return
+ * kNone_BlurType and ignore the info parameter.
+ */
+ virtual BlurType asABlur(BlurInfo*) const;
+
/**
* The fast bounds function is used to enable the paint to be culled early
* in the drawing pipeline. This function accepts the current bounds of the
@@ -88,27 +95,17 @@ public:
protected:
// empty for now, but lets get our subclass to remember to init us for the future
SkMaskFilter(SkFlattenableReadBuffer&) {}
-};
-/** \class SkAutoMaskImage
-
- Stack class used to manage the fImage buffer in a SkMask.
- When this object loses scope, the buffer is freed with SkMask::FreeImage().
-*/
-class SkAutoMaskImage {
-public:
- SkAutoMaskImage(SkMask* mask, bool alloc) {
- if (alloc) {
- mask->fImage = SkMask::AllocImage(mask->computeImageSize());
- }
- fImage = mask->fImage;
- }
-
- ~SkAutoMaskImage() {
- SkMask::FreeImage(fImage);
- }
private:
- uint8_t* fImage;
+ friend class SkDraw;
+
+ /** Helper method that, given a path in device space, will rasterize it into a kA8_Format mask
+ and then call filterMask(). If this returns true, the specified blitter will be called
+ to render that mask. Returns false if filterMask() returned false.
+ This method is not exported to java.
+ */
+ bool filterPath(const SkPath& devPath, const SkMatrix& devMatrix,
+ const SkRasterClip&, SkBounder*, SkBlitter* blitter);
};
#endif
diff --git a/include/core/SkMath.h b/include/core/SkMath.h
index efe378a..5889103 100644
--- a/include/core/SkMath.h
+++ b/include/core/SkMath.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMath_DEFINED
#define SkMath_DEFINED
diff --git a/include/core/SkMatrix.h b/include/core/SkMatrix.h
index 480e077..8fdb818 100644
--- a/include/core/SkMatrix.h
+++ b/include/core/SkMatrix.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMatrix_DEFINED
#define SkMatrix_DEFINED
@@ -21,6 +14,16 @@
class SkString;
+#ifdef SK_SCALAR_IS_FLOAT
+ typedef SkScalar SkPersp;
+ #define SkScalarToPersp(x) (x)
+ #define SkPerspToScalar(x) (x)
+#else
+ typedef SkFract SkPersp;
+ #define SkScalarToPersp(x) SkFixedToFract(x)
+ #define SkPerspToScalar(x) SkFractToFixed(x)
+#endif
+
/** \class SkMatrix
The SkMatrix class holds a 3x3 matrix for transforming coordinates.
@@ -74,10 +77,11 @@ public:
bool preservesAxisAlignment() const { return this->rectStaysRect(); }
/**
- * Returns true if the perspective contains perspective elements.
+ * Returns true if the matrix contains perspective elements.
*/
bool hasPerspective() const {
- return SkToBool(this->getType() & kPerspective_Mask);
+ return SkToBool(this->getPerspectiveTypeMaskOnly() &
+ kPerspective_Mask);
}
enum {
@@ -92,6 +96,18 @@ public:
kMPersp2
};
+ /** Affine arrays are in column major order
+ because that's how PDF and XPS like it.
+ */
+ enum {
+ kAScaleX,
+ kASkewY,
+ kASkewX,
+ kAScaleY,
+ kATransX,
+ kATransY
+ };
+
SkScalar operator[](int index) const {
SkASSERT((unsigned)index < 9);
return fMat[index];
@@ -108,8 +124,8 @@ public:
SkScalar getSkewX() const { return fMat[kMSkewX]; }
SkScalar getTranslateX() const { return fMat[kMTransX]; }
SkScalar getTranslateY() const { return fMat[kMTransY]; }
- SkScalar getPerspX() const { return fMat[kMPersp0]; }
- SkScalar getPerspY() const { return fMat[kMPersp1]; }
+ SkPersp getPerspX() const { return fMat[kMPersp0]; }
+ SkPersp getPerspY() const { return fMat[kMPersp1]; }
SkScalar& operator[](int index) {
SkASSERT((unsigned)index < 9);
@@ -129,12 +145,12 @@ public:
void setSkewX(SkScalar v) { this->set(kMSkewX, v); }
void setTranslateX(SkScalar v) { this->set(kMTransX, v); }
void setTranslateY(SkScalar v) { this->set(kMTransY, v); }
- void setPerspX(SkScalar v) { this->set(kMPersp0, v); }
- void setPerspY(SkScalar v) { this->set(kMPersp1, v); }
+ void setPerspX(SkPersp v) { this->set(kMPersp0, v); }
+ void setPerspY(SkPersp v) { this->set(kMPersp1, v); }
void setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
SkScalar skewY, SkScalar scaleY, SkScalar transY,
- SkScalar persp0, SkScalar persp1, SkScalar persp2) {
+ SkPersp persp0, SkPersp persp1, SkPersp persp2) {
fMat[kMScaleX] = scaleX;
fMat[kMSkewX] = skewX;
fMat[kMTransX] = transX;
@@ -164,6 +180,10 @@ public:
/** Set the matrix to scale by sx and sy.
*/
void setScale(SkScalar sx, SkScalar sy);
+ /** Set the matrix to scale by 1/divx and 1/divy. Returns false and doesn't
+ touch the matrix if either divx or divy is zero.
+ */
+ bool setIDiv(int divx, int divy);
/** Set the matrix to rotate by the specified number of degrees, with a
pivot point at (px, py). The pivot point is the coordinate that should
remain unchanged by the specified transformation.
@@ -318,12 +338,19 @@ 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.
+ /** Fills the passed array with affine identity values
+ in column major order.
+ @param affine The array to fill with affine identity values.
+ Must not be NULL.
*/
- bool pdfTransform(SkScalar transform[6]) const;
+ static void SetAffineIdentity(SkScalar affine[6]);
+
+ /** Fills the passed array with the affine values in column major order.
+ If the matrix is a perspective transform, returns false
+ and does not change the passed array.
+ @param affine The array to fill with affine values. Ignored if NULL.
+ */
+ bool asAffine(SkScalar affine[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.
@@ -348,6 +375,31 @@ public:
this->mapPoints(pts, pts, count);
}
+ /** Like mapPoints but with custom byte stride between the points. Stride
+ * should be a multiple of sizeof(SkScalar).
+ */
+ void mapPointsWithStride(SkPoint pts[], size_t stride, int count) const {
+ SkASSERT(stride >= sizeof(SkPoint));
+ SkASSERT(0 == stride % sizeof(SkScalar));
+ for (int i = 0; i < count; ++i) {
+ this->mapPoints(pts, pts, 1);
+ pts = (SkPoint*)((intptr_t)pts + stride);
+ }
+ }
+
+ /** Like mapPoints but with custom byte stride between the points.
+ */
+ void mapPointsWithStride(SkPoint dst[], SkPoint src[],
+ size_t stride, int count) const {
+ SkASSERT(stride >= sizeof(SkPoint));
+ SkASSERT(0 == stride % sizeof(SkScalar));
+ for (int i = 0; i < count; ++i) {
+ this->mapPoints(dst, src, 1);
+ src = (SkPoint*)((intptr_t)src + stride);
+ dst = (SkPoint*)((intptr_t)dst + stride);
+ }
+ }
+
void mapXY(SkScalar x, SkScalar y, SkPoint* result) const {
SkASSERT(result);
this->getMapXYProc()(*this, x, y, result);
@@ -395,13 +447,6 @@ public:
return this->mapRect(rect, *rect);
}
- void mapPointsWithStride(SkPoint pts[], size_t stride, int count) const {
- for (int i = 0; i < count; ++i) {
- this->mapPoints(pts, pts, 1);
- pts = (SkPoint*)((intptr_t)pts + stride);
- }
- }
-
/** Return the mean radius of a circle after it has been mapped by
this matrix. NOTE: in perspective this value assumes the circle
has its center at the origin.
@@ -466,10 +511,10 @@ public:
void toDumpString(SkString*) const;
/**
- * Calculates the maximum stretching factor of the matrix. Only defined if
- * the matrix does not have perspective.
+ * Calculates the maximum stretching factor of the matrix. If the matrix has
+ * perspective -1 is returned.
*
- * @return maximum strecthing factor or negative if matrix has perspective.
+ * @return maximum strecthing factor
*/
SkScalar getMaxStretch() const;
@@ -484,6 +529,14 @@ public:
*/
static const SkMatrix& InvalidMatrix();
+ /**
+ * Testing routine; the matrix's type cache should never need to be
+ * manually invalidated during normal use.
+ */
+ void dirtyMatrixTypeCache() {
+ this->setTypeMask(kUnknown_Mask);
+ }
+
private:
enum {
/** Set if the matrix will map a rectangle to another rectangle. This
@@ -494,6 +547,11 @@ private:
*/
kRectStaysRect_Mask = 0x10,
+ /** Set if the perspective bit is valid even though the rest of
+ the matrix is Unknown.
+ */
+ kOnlyPerspectiveValid_Mask = 0x40,
+
kUnknown_Mask = 0x80,
kORableMasks = kTranslate_Mask |
@@ -512,10 +570,13 @@ private:
mutable uint8_t fTypeMask;
uint8_t computeTypeMask() const;
+ uint8_t computePerspectiveTypeMask() const;
void setTypeMask(int mask) {
// allow kUnknown or a valid mask
- SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask);
+ SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
+ ((kUnknown_Mask | kOnlyPerspectiveValid_Mask | kPerspective_Mask) & mask)
+ == mask);
fTypeMask = SkToU8(mask);
}
@@ -529,6 +590,24 @@ private:
SkASSERT((mask & kAllMasks) == mask);
fTypeMask &= ~mask;
}
+
+ TypeMask getPerspectiveTypeMaskOnly() const {
+ if ((fTypeMask & kUnknown_Mask) &&
+ !(fTypeMask & kOnlyPerspectiveValid_Mask)) {
+ fTypeMask = this->computePerspectiveTypeMask();
+ }
+ return (TypeMask)(fTypeMask & 0xF);
+ }
+
+ /** Returns true if we already know that the matrix is identity;
+ false otherwise.
+ */
+ bool isTriviallyIdentity() const {
+ if (fTypeMask & kUnknown_Mask) {
+ return false;
+ }
+ return ((fTypeMask & 0xF) == 0);
+ }
static bool Poly2Proc(const SkPoint[], SkMatrix*, const SkPoint& scale);
static bool Poly3Proc(const SkPoint[], SkMatrix*, const SkPoint& scale);
@@ -560,4 +639,3 @@ private:
};
#endif
-
diff --git a/include/core/SkMetaData.h b/include/core/SkMetaData.h
index 1c34fd5..86f186f 100644
--- a/include/core/SkMetaData.h
+++ b/include/core/SkMetaData.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkMetaData_DEFINED
#define SkMetaData_DEFINED
diff --git a/include/core/SkOSFile.h b/include/core/SkOSFile.h
index de8090c..9f01ead 100644
--- a/include/core/SkOSFile.h
+++ b/include/core/SkOSFile.h
@@ -1,26 +1,19 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
//
#ifndef SkOSFile_DEFINED
#define SkOSFile_DEFINED
#include "SkString.h"
-#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
+#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
#include <dirent.h>
#endif
@@ -55,13 +48,17 @@ public:
~Iter();
void reset(const char path[], const char suffix[] = NULL);
+ /** If getDir is true, only returns directories.
+ Results are undefined if true and false calls are
+ interleaved on a single iterator.
+ */
bool next(SkString* name, bool getDir = false);
private:
#ifdef SK_BUILD_FOR_WIN
HANDLE fHandle;
uint16_t* fPath16;
-#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX)
+#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)
DIR* fDIR;
SkString fPath, fSuffix;
#endif
diff --git a/include/core/SkPackBits.h b/include/core/SkPackBits.h
index c11231b..f0614a0 100644
--- a/include/core/SkPackBits.h
+++ b/include/core/SkPackBits.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPackBits_DEFINED
#define SkPackBits_DEFINED
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 5bd7060..445f7eb 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPaint_DEFINED
#define SkPaint_DEFINED
@@ -29,6 +22,7 @@ class SkFlattenableWriteBuffer;
struct SkGlyph;
struct SkRect;
class SkGlyphCache;
+class SkImageFilter;
class SkMaskFilter;
class SkMatrix;
class SkPath;
@@ -55,8 +49,8 @@ public:
SkPaint& operator=(const SkPaint&);
- SK_API friend int operator==(const SkPaint& a, const SkPaint& b);
- friend int operator!=(const SkPaint& a, const SkPaint& b) {
+ SK_API friend bool operator==(const SkPaint& a, const SkPaint& b);
+ friend bool operator!=(const SkPaint& a, const SkPaint& b) {
return !(a == b);
}
@@ -105,10 +99,12 @@ public:
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
+ kVerticalText_Flag = 0x1000,
+
// when adding extra flags, note that the fFlags member is specified
// with a bit-width and you'll have to expand it.
- kAllFlags = 0xFFF
+ kAllFlags = 0x1FFF
};
/** Return the paint's flags. Use the Flag enum to test flag values.
@@ -165,21 +161,24 @@ public:
return SkToBool(this->getFlags() & kSubpixelText_Flag);
}
- /** Helper for setFlags(), setting or clearing the kSubpixelText_Flag
- bit @param subpixelText true to set the subpixelText bit in the paint's flags,
- false to clear it.
- */
+ /**
+ * Helper for setFlags(), setting or clearing the kSubpixelText_Flag.
+ * @param subpixelText true to set the subpixelText bit in the paint's
+ * flags, false to clear it.
+ */
void setSubpixelText(bool subpixelText);
bool isLCDRenderText() const {
return SkToBool(this->getFlags() & kLCDRenderText_Flag);
}
- /** Helper for setFlags(), setting or clearing the kLCDRenderText_Flag bit
- @param subpixelRender true to set the subpixelRenderText bit in the paint's flags,
- false to clear it.
- */
- void setLCDRenderText(bool subpixelRender);
+ /**
+ * Helper for setFlags(), setting or clearing the kLCDRenderText_Flag.
+ * Note: antialiasing must also be on for lcd rendering
+ * @param lcdText true to set the LCDRenderText bit in the paint's flags,
+ * false to clear it.
+ */
+ void setLCDRenderText(bool lcdText);
bool isEmbeddedBitmapText() const {
return SkToBool(this->getFlags() & kEmbeddedBitmapText_Flag);
@@ -202,6 +201,20 @@ public:
*/
void setAutohinted(bool useAutohinter);
+ bool isVerticalText() const {
+ return SkToBool(this->getFlags() & kVerticalText_Flag);
+ }
+
+ /**
+ * Helper for setting or clearing the kVerticalText_Flag bit in
+ * setFlags(...).
+ *
+ * If this bit is set, then advances are treated as Y values rather than
+ * X values, and drawText will places its glyphs vertically rather than
+ * horizontally.
+ */
+ void setVerticalText(bool);
+
/** Helper for getFlags(), returning true if kUnderlineText_Flag bit is set
@return true if the underlineText bit is set in the paint's flags.
*/
@@ -600,6 +613,9 @@ public:
*/
SkRasterizer* setRasterizer(SkRasterizer* rasterizer);
+ SkImageFilter* getImageFilter() const { return fImageFilter; }
+ SkImageFilter* setImageFilter(SkImageFilter*);
+
/**
* Return the paint's SkDrawLooper (if any). Does not affect the looper's
* reference count.
@@ -748,23 +764,29 @@ public:
return this->textToGlyphs(text, byteLength, NULL);
}
- /** Return the width of the text.
- @param text The text to be measured
- @param length Number of bytes of text to measure
- @param bounds If not NULL, returns the bounds of the text,
- relative to (0, 0).
- @param scale If not 0, return width as if the canvas were scaled
- by this value
- @return The advance width of the text
- */
+ /** Return the width of the text. This will return the vertical measure
+ * if isVerticalText() is true, in which case the returned value should
+ * be treated has a height instead of a width.
+ *
+ * @param text The text to be measured
+ * @param length Number of bytes of text to measure
+ * @param bounds If not NULL, returns the bounds of the text,
+ * relative to (0, 0).
+ * @param scale If not 0, return width as if the canvas were scaled
+ * by this value
+ * @return The advance width of the text
+ */
SkScalar measureText(const void* text, size_t length,
SkRect* bounds, SkScalar scale = 0) const;
- /** Return the width of the text.
- @param text Address of the text
- @param length Number of bytes of text to measure
- @return The width of the text
- */
+ /** Return the width of the text. This will return the vertical measure
+ * if isVerticalText() is true, in which case the returned value should
+ * be treated has a height instead of a width.
+ *
+ * @param text Address of the text
+ * @param length Number of bytes of text to measure
+ * @return The width of the text
+ */
SkScalar measureText(const void* text, size_t length) const {
return this->measureText(text, length, NULL, 0);
}
@@ -782,33 +804,38 @@ public:
kBackward_TextBufferDirection
};
- /** Return the width of the text.
- @param text The text to be measured
- @param length Number of bytes of text to measure
- @param maxWidth Maximum width. Only the subset of text whose accumulated
- widths are <= maxWidth are measured.
- @param measuredWidth Optional. If non-null, this returns the actual
- width of the measured text.
- @param tbd Optional. The direction the text buffer should be
- traversed during measuring.
- @return The number of bytes of text that were measured. Will be
- <= length.
- */
+ /** Return the number of bytes of text that were measured. If
+ * isVerticalText() is true, then the vertical advances are used for
+ * the measurement.
+ *
+ * @param text The text to be measured
+ * @param length Number of bytes of text to measure
+ * @param maxWidth Maximum width. Only the subset of text whose accumulated
+ * widths are <= maxWidth are measured.
+ * @param measuredWidth Optional. If non-null, this returns the actual
+ * width of the measured text.
+ * @param tbd Optional. The direction the text buffer should be
+ * traversed during measuring.
+ * @return The number of bytes of text that were measured. Will be
+ * <= length.
+ */
size_t breakText(const void* text, size_t length, SkScalar maxWidth,
SkScalar* measuredWidth = NULL,
TextBufferDirection tbd = kForward_TextBufferDirection)
const;
- /** Return the advance widths for the characters in the string.
- @param text the text
- @param byteLength number of bytes to of text
- @param widths If not null, returns the array of advance widths of
- the glyphs. If not NULL, must be at least a large
- as the number of unichars in the specified text.
- @param bounds If not null, returns the bounds for each of
- character, relative to (0, 0)
- @return the number of unichars in the specified text.
- */
+ /** Return the advances for the text. These will be vertical advances if
+ * isVerticalText() returns true.
+ *
+ * @param text the text
+ * @param byteLength number of bytes to of text
+ * @param widths If not null, returns the array of advances for
+ * the glyphs. If not NULL, must be at least a large
+ * as the number of unichars in the specified text.
+ * @param bounds If not null, returns the bounds for each of
+ * character, relative to (0, 0)
+ * @return the number of unichars in the specified text.
+ */
int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
SkRect bounds[] = NULL) const;
@@ -819,7 +846,7 @@ public:
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
SkPath* path) const;
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
const SkGlyph& getUnicharMetrics(SkUnichar);
const SkGlyph& getGlyphMetrics(uint16_t);
const void* findImage(const SkGlyph&);
@@ -831,6 +858,10 @@ public:
unsigned getBaseGlyphCount(SkUnichar text) const;
#endif
+ // returns true if the paint's settings (e.g. xfermode + alpha) resolve to
+ // mean that we need not draw at all (e.g. SrcOver + 0-alpha)
+ bool nothingToDraw() const;
+
private:
SkTypeface* fTypeface;
SkScalar fTextSize;
@@ -844,20 +875,18 @@ private:
SkColorFilter* fColorFilter;
SkRasterizer* fRasterizer;
SkDrawLooper* fLooper;
+ SkImageFilter* fImageFilter;
SkColor fColor;
SkScalar fWidth;
SkScalar fMiterLimit;
- unsigned fFlags : 12;
+ unsigned fFlags : 14;
unsigned fTextAlign : 2;
unsigned fCapType : 2;
unsigned fJoinType : 2;
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
-#ifdef ANDROID
- uint32_t fGenerationID;
-#endif
SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
@@ -882,9 +911,15 @@ private:
friend class SkDraw;
friend class SkPDFDevice;
friend class SkTextToPathIter;
+
+#ifdef SK_BUILD_FOR_ANDROID
+ // In order for the == operator to work properly this must be the last field
+ // in the struct so that we can do a memcmp to this field's offset.
+ uint32_t fGenerationID;
+#endif
};
-//////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
#include "SkPathEffect.h"
@@ -902,20 +937,18 @@ public:
SkPaint::Cap, SkScalar miterLimit = -1);
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
// overrides for SkFlattenable
- // This method is not exported to java.
virtual void flatten(SkFlattenableWriteBuffer&);
- // This method is not exported to java.
virtual Factory getFactory();
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+
private:
SkScalar fWidth, fMiter;
uint8_t fStyle, fJoin, fCap;
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
SkStrokePathEffect(SkFlattenableReadBuffer&);
typedef SkPathEffect INHERITED;
diff --git a/include/core/SkPath.h b/include/core/SkPath.h
index 7120d3f..859486c 100644
--- a/include/core/SkPath.h
+++ b/include/core/SkPath.h
@@ -1,26 +1,19 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPath_DEFINED
#define SkPath_DEFINED
#include "SkMatrix.h"
#include "SkTDArray.h"
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
#define GEN_ID_INC fGenerationID++
#define GEN_ID_PTR_INC(ptr) ptr->fGenerationID++
#else
@@ -45,7 +38,7 @@ public:
~SkPath();
SkPath& operator=(const SkPath&);
-
+
friend bool operator==(const SkPath&, const SkPath&);
friend bool operator!=(const SkPath& a, const SkPath& b) {
return !(a == b);
@@ -77,7 +70,7 @@ public:
/** Set the path's fill type. This is used to define how "inside" is
computed. The default value is kWinding_FillType.
-
+
@param ft The new fill type for this path
*/
void setFillType(FillType ft) {
@@ -187,6 +180,35 @@ public:
*/
bool isEmpty() const;
+ /** Test a line for zero length
+
+ @return true if the line is of zero length; otherwise false.
+ */
+ static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2) {
+ return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero);
+ }
+
+ /** Test a quad for zero length
+
+ @return true if the quad is of zero length; otherwise false.
+ */
+ static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
+ const SkPoint& p3) {
+ return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero) &&
+ p2.equalsWithinTolerance(p3, SK_ScalarNearlyZero);
+ }
+
+ /** Test a cubic curve for zero length
+
+ @return true if the cubic is of zero length; otherwise false.
+ */
+ static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
+ const SkPoint& p3, const SkPoint& p4) {
+ return p1.equalsWithinTolerance(p2, SK_ScalarNearlyZero) &&
+ p2.equalsWithinTolerance(p3, SK_ScalarNearlyZero) &&
+ p3.equalsWithinTolerance(p4, SK_ScalarNearlyZero);
+ }
+
/** Returns true if the path specifies a rectangle. If so, and if rect is
not null, set rect to the bounds of the path. If the path does not
specify a rectangle, return false and ignore rect.
@@ -431,6 +453,24 @@ public:
kCCW_Direction
};
+ /**
+ * Tries to quickly compute the direction of the first non-degenerate
+ * contour. If it can be computed, return true and set dir to that
+ * direction. If it cannot be (quickly) determined, return false and ignore
+ * the dir parameter.
+ */
+ bool cheapComputeDirection(Direction* dir) const;
+
+ /**
+ * Returns true if the path's direction can be computed via
+ * cheapComputDirection() and if that computed direction matches the
+ * specified direction.
+ */
+ bool cheapIsDirection(Direction dir) const {
+ Direction computedDir;
+ return this->cheapComputeDirection(&computedDir) && computedDir == dir;
+ }
+
/** Add a closed rectangle contour to the path
@param rect The rectangle to add as a closed contour to the path
@param dir The direction to wind the rectangle's contour
@@ -504,7 +544,7 @@ public:
@param dx The amount to translate the path in X as it is added
@param dx The amount to translate the path in Y as it is added
*/
- void addPath(const SkPath& src, SkScalar dx, SkScalar dy);
+ void addPath(const SkPath& src, SkScalar dx, SkScalar dy);
/** Add a copy of src to the path
*/
@@ -519,6 +559,11 @@ public:
*/
void addPath(const SkPath& src, const SkMatrix& matrix);
+ /**
+ * Same as addPath(), but reverses the src input
+ */
+ void reverseAddPath(const SkPath& src);
+
/** Offset the path by (dx,dy), returning true on success
@param dx The amount in the X direction to offset the entire path
@@ -553,11 +598,12 @@ public:
}
/** Return the last point on the path. If no points have been added, (0,0)
- is returned.
+ is returned. If there are no points, this returns false, otherwise it
+ returns true.
@param lastPt The last point on the path is returned here
*/
- void getLastPt(SkPoint* lastPt) const;
+ bool getLastPt(SkPoint* lastPt) const;
/** Set the last point on the path. If no points have been added,
moveTo(x,y) is automatically called.
@@ -576,28 +622,47 @@ public:
this->setLastPt(p.fX, p.fY);
}
+ enum SegmentMask {
+ kLine_SegmentMask = 1 << 0,
+ kQuad_SegmentMask = 1 << 1,
+ kCubic_SegmentMask = 1 << 2
+ };
+
+ /**
+ * Returns a mask, where each bit corresponding to a SegmentMask is
+ * set if the path contains 1 or more segments of that type.
+ * Returns 0 for an empty path (no segments).
+ */
+ uint32_t getSegmentMasks() const { return fSegmentMask; }
+
enum Verb {
kMove_Verb, //!< iter.next returns 1 point
kLine_Verb, //!< iter.next returns 2 points
kQuad_Verb, //!< iter.next returns 3 points
kCubic_Verb, //!< iter.next returns 4 points
- kClose_Verb, //!< iter.next returns 1 point (the last point)
+ kClose_Verb, //!< iter.next returns 1 point (contour's moveTo pt)
kDone_Verb //!< iter.next returns 0 points
};
/** Iterate through all of the segments (lines, quadratics, cubics) of
each contours in a path.
+
+ The iterator cleans up the segments along the way, removing degenerate
+ segments and adding close verbs where necessary. When the forceClose
+ argument is provided, each contour (as defined by a new starting
+ move command) will be completed with a close verb regardless of the
+ contour's contents.
*/
class SK_API Iter {
public:
- Iter();
- Iter(const SkPath&, bool forceClose);
+ Iter();
+ Iter(const SkPath&, bool forceClose);
void setPath(const SkPath&, bool forceClose);
/** Return the next verb in this iteration of the path. When all
segments have been visited, return kDone_Verb.
-
+
@param pts The points representing the current verb and/or segment
@return The verb for the current segment
*/
@@ -607,12 +672,12 @@ public:
line was the result of a close() command (i.e. the end point is the
initial moveto for this contour). If next() returned a different
verb, this returns an undefined value.
-
+
@return If the last call to next() returned kLine_Verb, return true
if it was the result of an explicit close command.
*/
bool isCloseLine() const { return SkToBool(fCloseLine); }
-
+
/** Returns true if the current contour is closed (has a kClose_Verb)
@return true if the current contour is closed (has a kClose_Verb)
*/
@@ -626,11 +691,37 @@ public:
SkPoint fLastPt;
SkBool8 fForceClose;
SkBool8 fNeedClose;
- SkBool8 fNeedMoveTo;
SkBool8 fCloseLine;
+ SkBool8 fSegmentState;
bool cons_moveTo(SkPoint pts[1]);
Verb autoClose(SkPoint pts[2]);
+ void consumeDegenerateSegments();
+ };
+
+ /** Iterate through the verbs in the path, providing the associated points.
+ */
+ class SK_API RawIter {
+ public:
+ RawIter();
+ RawIter(const SkPath&);
+
+ void setPath(const SkPath&);
+
+ /** Return the next verb in this iteration of the path. When all
+ segments have been visited, return kDone_Verb.
+
+ @param pts The points representing the current verb and/or segment
+ @return The verb for the current segment
+ */
+ Verb next(SkPoint pts[4]);
+
+ private:
+ const SkPoint* fPts;
+ const uint8_t* fVerbs;
+ const uint8_t* fVerbStop;
+ SkPoint fMoveTo;
+ SkPoint fLastPt;
};
void dump(bool forceClose, const char title[] = NULL) const;
@@ -639,13 +730,7 @@ public:
void flatten(SkWriter32&) const;
void unflatten(SkReader32&);
- /** Subdivide the path so that no segment is longer that dist.
- If bendLines is true, then turn all line segments into curves.
- If dst == null, then the original path itself is modified (not const!)
- */
- void subdivide(SkScalar dist, bool bendLines, SkPath* dst = NULL) const;
-
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
uint32_t getGenerationID() const;
#endif
@@ -655,10 +740,11 @@ private:
SkTDArray<SkPoint> fPts;
SkTDArray<uint8_t> fVerbs;
mutable SkRect fBounds;
- mutable uint8_t fBoundsIsDirty;
uint8_t fFillType;
+ uint8_t fSegmentMask;
+ mutable uint8_t fBoundsIsDirty;
mutable uint8_t fConvexity;
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
uint32_t fGenerationID;
#endif
@@ -686,4 +772,3 @@ private:
};
#endif
-
diff --git a/include/core/SkPathEffect.h b/include/core/SkPathEffect.h
index eb1cc23..1b4cd5f 100644
--- a/include/core/SkPathEffect.h
+++ b/include/core/SkPathEffect.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPathEffect_DEFINED
#define SkPathEffect_DEFINED
@@ -31,7 +24,6 @@ class SkPath;
*/
class SK_API SkPathEffect : public SkFlattenable {
public:
- // This method is not exported to java.
SkPathEffect() {}
/** Given a src path and a width value, return true if the patheffect
@@ -42,6 +34,7 @@ public:
*/
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) = 0;
+ SK_DECLARE_FLATTENABLE_REGISTRAR()
private:
// illegal
SkPathEffect(const SkPathEffect&);
@@ -61,7 +54,7 @@ public:
protected:
SkPairPathEffect(SkFlattenableReadBuffer&);
- virtual void flatten(SkFlattenableWriteBuffer&);
+ virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
// these are visible to our subclasses
SkPathEffect* fPE0, *fPE1;
@@ -86,16 +79,16 @@ public:
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
-protected:
- virtual Factory getFactory() { return CreateProc; }
-
-private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkComposePathEffect, (buffer));
}
+
+protected:
+ virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
+
+private:
SkComposePathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
// illegal
@@ -121,16 +114,16 @@ public:
: INHERITED(first, second) {}
// overrides
- // This method is not exported to java.
virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width);
-protected:
- virtual Factory getFactory() { return CreateProc; }
-
-private:
static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
return SkNEW_ARGS(SkSumPathEffect, (buffer));
}
+
+protected:
+ virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
+
+private:
SkSumPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
// illegal
diff --git a/include/core/SkPathMeasure.h b/include/core/SkPathMeasure.h
index 2d94ae2..ec43834 100644
--- a/include/core/SkPathMeasure.h
+++ b/include/core/SkPathMeasure.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPathMeasure_DEFINED
#define SkPathMeasure_DEFINED
diff --git a/include/core/SkPerspIter.h b/include/core/SkPerspIter.h
index 81ce7c8..7f6add2 100644
--- a/include/core/SkPerspIter.h
+++ b/include/core/SkPerspIter.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPerspIter_DEFINED
#define SkPerspIter_DEFINED
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index ac21bc9..47a2b95 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2007 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
+ * Copyright 2007 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPicture_DEFINED
#define SkPicture_DEFINED
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index 8fb368a..e247479 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -1,26 +1,19 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPixelRef_DEFINED
#define SkPixelRef_DEFINED
+#include "SkBitmap.h"
#include "SkRefCnt.h"
#include "SkString.h"
-class SkBitmap;
class SkColorTable;
struct SkIRect;
class SkMutex;
@@ -30,6 +23,25 @@ class SkFlattenableWriteBuffer;
// this is an opaque class, not interpreted by skia
class SkGpuTexture;
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+
+#define SK_DECLARE_PIXEL_REF_REGISTRAR()
+
+#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
+ static SkPixelRef::Registrar g##pixelRef##Reg(#pixelRef, \
+ pixelRef::Create);
+
+#else
+
+#define SK_DECLARE_PIXEL_REF_REGISTRAR() static void Init();
+
+#define SK_DEFINE_PIXEL_REF_REGISTRAR(pixelRef) \
+ void pixelRef::Init() { \
+ SkPixelRef::Registrar(#pixelRef, Create); \
+ }
+
+#endif
+
/** \class SkPixelRef
This class is the smart container for pixel memory, and is used with
@@ -66,6 +78,14 @@ public:
*/
void unlockPixels();
+ /**
+ * Some bitmaps can return a copy of their pixels for lockPixels(), but
+ * that copy, if modified, will not be pushed back. These bitmaps should
+ * not be used as targets for a raster device/canvas (since all pixels
+ * modifications will be lost when unlockPixels() is called.)
+ */
+ bool lockPixelsAreWritable() const;
+
/** Returns a non-zero, unique value corresponding to the pixels in this
pixelref. Each time the pixels are changed (and notifyPixelsChanged is
called), a different generation ID will be returned.
@@ -116,6 +136,12 @@ public:
bool readPixels(SkBitmap* dst, const SkIRect* subset = NULL);
+ /** Makes a deep copy of this PixelRef, respecting the requested config.
+ Returns NULL if either there is an error (e.g. the destination could
+ not be created with the given config), or this PixelRef does not
+ support deep copies. */
+ virtual SkPixelRef* deepCopy(SkBitmap::Config config) { return NULL; }
+
// serialization
typedef SkPixelRef* (*Factory)(SkFlattenableReadBuffer&);
@@ -123,7 +149,7 @@ public:
virtual Factory getFactory() const { return NULL; }
virtual void flatten(SkFlattenableWriteBuffer&) const;
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
/**
* Acquire a "global" ref on this object.
* The default implementation just calls ref(), but subclasses can override
@@ -161,6 +187,9 @@ protected:
*/
virtual void onUnlockPixels() = 0;
+ /** Default impl returns true */
+ virtual bool onLockPixelsAreWritable() const;
+
/**
* For pixelrefs that don't have access to their raw pixels, they may be
* able to make a copy of them (e.g. if the pixels are on the GPU).
@@ -177,6 +206,10 @@ protected:
SkPixelRef(SkFlattenableReadBuffer&, SkMutex*);
private:
+#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+ static void InitializeFlattenables();
+#endif
+
SkMutex* fMutex; // must remain in scope for the life of this object
void* fPixels;
SkColorTable* fColorTable; // we do not track ownership, subclass does
@@ -188,6 +221,8 @@ private:
// can go from false to true, but never from true to false
bool fIsImmutable;
+
+ friend class SkGraphics;
};
#endif
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h
index d74435e..de7c0ef 100644
--- a/include/core/SkPoint.h
+++ b/include/core/SkPoint.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPoint_DEFINED
#define SkPoint_DEFINED
@@ -196,6 +189,16 @@ struct SK_API SkPoint {
}
void setRectFan(SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride);
+ static void Offset(SkPoint points[], int count, const SkPoint& offset) {
+ Offset(points, count, offset.fX, offset.fY);
+ }
+
+ static void Offset(SkPoint points[], int count, SkScalar dx, SkScalar dy) {
+ for (int i = 0; i < count; ++i) {
+ points[i].offset(dx, dy);
+ }
+ }
+
void offset(SkScalar dx, SkScalar dy) {
fX += dx;
fY += dy;
@@ -206,10 +209,19 @@ struct SK_API SkPoint {
SkScalar length() const { return SkPoint::Length(fX, fY); }
SkScalar distanceToOrigin() const { return this->length(); }
+ /**
+ * Return true if the computed length of the vector is >= the internal
+ * tolerance (used to avoid dividing by tiny values).
+ */
+ static bool CanNormalize(SkScalar dx, SkScalar dy);
+
+ bool canNormalize() const {
+ return CanNormalize(fX, fY);
+ }
+
/** Set the point (vector) to be unit-length in the same direction as it
- currently is, and return its old length. If the old length is
- degenerately small (nearly zero), do nothing and return false, otherwise
- return true.
+ already points. If the point has a degenerate length (i.e. nearly 0)
+ then return false and do nothing; otherwise return true.
*/
bool normalize();
@@ -303,6 +315,13 @@ struct SK_API SkPoint {
return a.fX != b.fX || a.fY != b.fY;
}
+ /** Return true if this and the given point are componentwise within tol.
+ */
+ bool equalsWithinTolerance(const SkPoint& v, SkScalar tol) const {
+ return SkScalarNearlyZero(fX - v.fX, tol)
+ && SkScalarNearlyZero(fY - v.fY, tol);
+ }
+
/** Returns a new point whose coordinates are the difference between
a's and b's (a - b)
*/
@@ -325,7 +344,13 @@ struct SK_API SkPoint {
static SkScalar Length(SkScalar x, SkScalar y);
/** Normalize pt, returning its previous length. If the prev length is too
- small (degenerate), return 0 and leave pt unchanged.
+ small (degenerate), return 0 and leave pt unchanged. This uses the same
+ tolerance as CanNormalize.
+
+ Note that this method may be significantly more expensive than
+ the non-static normalize(), because it has to return the previous length
+ of the point. If you don't need the previous length, call the
+ non-static normalize() method instead.
*/
static SkScalar Normalize(SkPoint* pt);
@@ -364,17 +389,70 @@ struct SK_API SkPoint {
SkScalar dy = fY - pt.fY;
return SkScalarMul(dx, dx) + SkScalarMul(dy, dy);
}
-
- SkScalar distanceToLineSegmentBetweenSqd(const SkPoint& a,
+
+ /**
+ * The side of a point relative to a line. If the line is from a to b then
+ * the values are consistent with the sign of (b-a) cross (pt-a)
+ */
+ enum Side {
+ kLeft_Side = -1,
+ kOn_Side = 0,
+ kRight_Side = 1
+ };
+
+ /**
+ * Returns the squared distance to the infinite line between two pts. Also
+ * optionally returns the side of the line that the pt falls on (looking
+ * along line from a to b)
+ */
+ SkScalar distanceToLineBetweenSqd(const SkPoint& a,
+ const SkPoint& b,
+ Side* side = NULL) const;
+
+ /**
+ * Returns the distance to the infinite line between two pts. Also
+ * optionally returns the side of the line that the pt falls on (looking
+ * along the line from a to b)
+ */
+ SkScalar distanceToLineBetween(const SkPoint& a,
+ const SkPoint& b,
+ Side* side = NULL) const {
+ return SkScalarSqrt(this->distanceToLineBetweenSqd(a, b, side));
+ }
+
+ /**
+ * Returns the squared distance to the line segment between pts a and b
+ */
+ SkScalar distanceToLineSegmentBetweenSqd(const SkPoint& a,
const SkPoint& b) const;
-
- SkScalar distanceToLineSegmentBetween(const SkPoint& a,
+
+ /**
+ * Returns the distance to the line segment between pts a and b.
+ */
+ SkScalar distanceToLineSegmentBetween(const SkPoint& a,
const SkPoint& b) const {
return SkScalarSqrt(this->distanceToLineSegmentBetweenSqd(a, b));
}
+
+ /**
+ * Make this vector be orthogonal to vec. Looking down vec the
+ * new vector will point in direction indicated by side (which
+ * must be kLeft_Side or kRight_Side).
+ */
+ void setOrthog(const SkPoint& vec, Side side = kLeft_Side) {
+ // vec could be this
+ SkScalar tmp = vec.fX;
+ if (kLeft_Side == side) {
+ fX = -vec.fY;
+ fY = tmp;
+ } else {
+ SkASSERT(kRight_Side == side);
+ fX = vec.fY;
+ fY = -tmp;
+ }
+ }
};
typedef SkPoint SkVector;
#endif
-
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index 23ce02b..edce334 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPostConfig_DEFINED
#define SkPostConfig_DEFINED
@@ -63,6 +56,32 @@
#endif
#endif
+#if !defined(SK_HAS_COMPILER_FEATURE)
+ #if defined(__has_feature)
+ #define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
+ #else
+ #define SK_HAS_COMPILER_FEATURE(x) 0
+ #endif
+#endif
+
+/**
+ * The clang static analyzer likes to know that when the program is not
+ * expected to continue (crash, assertion failure, etc). It will notice that
+ * some combination of parameters lead to a function call that does not return.
+ * It can then make appropriate assumptions about the parameters in code
+ * executed only if the non-returning function was *not* called.
+ */
+#if !defined(SkNO_RETURN_HINT)
+ #if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
+ namespace {
+ inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
+ void SkNO_RETURN_HINT() {}
+ }
+ #else
+ #define SkNO_RETURN_HINT() do {} while (false)
+ #endif
+#endif
+
///////////////////////////////////////////////////////////////////////////////
#ifndef SkNEW
@@ -75,9 +94,9 @@
#ifndef SK_CRASH
#if 1 // set to 0 for infinite loop, which can help connecting gdb
- #define SK_CRASH() *(int *)(uintptr_t)0xbbadbeef = 0
+ #define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
#else
- #define SK_CRASH() do {} while (true)
+ #define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
#endif
#endif
@@ -107,7 +126,7 @@
#endif
#ifndef SK_DEBUGBREAK
- #define SK_DEBUGBREAK(cond) do { if (!(cond)) __debugbreak(); } while (false)
+ #define SK_DEBUGBREAK(cond) do { if (!(cond)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
#endif
#ifndef SK_A32_SHIFT
@@ -252,7 +271,28 @@
#define DEBUG_CLIENTBLOCK
#endif // _DEBUG
+
#endif
#endif
+//////////////////////////////////////////////////////////////////////
+
+#ifndef SK_OVERRIDE
+#if defined(_MSC_VER)
+#define SK_OVERRIDE override
+#elif defined(__clang__)
+// Some documentation suggests we should be using __attribute__((override)),
+// but it doesn't work.
+#define SK_OVERRIDE override
+#else
+// Linux GCC ignores "__attribute__((override))" and rejects "override".
+#define SK_OVERRIDE
+#endif
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+#define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
+#endif
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h
index 6ec73ce..4485f1d 100644
--- a/include/core/SkPreConfig.h
+++ b/include/core/SkPreConfig.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPreConfig_DEFINED
#define SkPreConfig_DEFINED
@@ -23,7 +16,7 @@
//////////////////////////////////////////////////////////////////////
-#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)
+#if !defined(SK_BUILD_FOR_ANDROID) && !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"
@@ -37,7 +30,12 @@
#define SK_BUILD_FOR_WIN32
#elif defined(__SYMBIAN32__)
#define SK_BUILD_FOR_WIN32
- #elif defined(linux)
+ #elif defined(ANDROID_NDK)
+ #define SK_BUILD_FOR_ANDROID_NDK
+ #elif defined(ANDROID)
+ #define SK_BUILD_FOR_ANDROID
+ #elif defined(linux) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
+ defined(__sun) || defined(__NetBSD__) || defined(__DragonFly__)
#define SK_BUILD_FOR_UNIX
#elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#define SK_BUILD_FOR_IOS
@@ -45,12 +43,15 @@
#define SK_BUILD_FOR_MAC
#endif
- #if defined(ANDROID)
- #define SK_BUILD_FOR_ANDROID
- #endif
- #if defined(ANDROID_NDK)
- #define SK_BUILD_FOR_ANDROID_NDK
- #endif
+#endif
+
+/* Even if the user only defined the NDK variant we still need to build
+ * the default Android code. Therefore, when attempting to include/exclude
+ * something from the NDK variant check first that we are building for
+ * Android then check the status of the NDK define.
+ */
+#if defined(SK_BUILD_FOR_ANDROID_NDK) && !defined(SK_BUILD_FOR_ANDROID)
+ #define SK_BUILD_FOR_ANDROID
#endif
//////////////////////////////////////////////////////////////////////
@@ -64,7 +65,9 @@
#endif
#ifdef SK_BUILD_FOR_WIN32
- #define SK_RESTRICT
+ #if !defined(SK_RESTRICT)
+ #define SK_RESTRICT __restrict
+ #endif
#include "sk_stdint.h"
#endif
diff --git a/include/core/SkPtrRecorder.h b/include/core/SkPtrRecorder.h
index db6c64d..11fd170 100644
--- a/include/core/SkPtrRecorder.h
+++ b/include/core/SkPtrRecorder.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkPtrSet_DEFINED
#define SkPtrSet_DEFINED
@@ -89,10 +82,13 @@ private:
*/
template <typename T> class SkTPtrSet : public SkPtrSet {
public:
+ uint32_t find(T ptr) {
+ return this->INHERITED::find((void*)ptr);
+ }
uint32_t add(T ptr) {
return this->INHERITED::add((void*)ptr);
}
-
+
void copyToArray(T* array) const {
this->INHERITED::copyToArray((void**)array);
}
diff --git a/include/core/SkRandom.h b/include/core/SkRandom.h
index 33b563a..b850df3 100644
--- a/include/core/SkRandom.h
+++ b/include/core/SkRandom.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRandom_DEFINED
#define SkRandom_DEFINED
diff --git a/include/core/SkRasterizer.h b/include/core/SkRasterizer.h
index d81e613..d249898 100644
--- a/include/core/SkRasterizer.h
+++ b/include/core/SkRasterizer.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRasterizer_DEFINED
#define SkRasterizer_DEFINED
@@ -35,7 +28,7 @@ public:
const SkIRect* clipBounds, SkMaskFilter* filter,
SkMask* mask, SkMask::CreateMode mode);
- virtual void flatten(SkFlattenableWriteBuffer& ) {}
+ virtual void flatten(SkFlattenableWriteBuffer& ) SK_OVERRIDE {}
protected:
SkRasterizer(SkFlattenableReadBuffer&);
diff --git a/include/core/SkReader32.h b/include/core/SkReader32.h
index 654ebd5..37ace5c 100644
--- a/include/core/SkReader32.h
+++ b/include/core/SkReader32.h
@@ -1,27 +1,18 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkReader32_DEFINED
#define SkReader32_DEFINED
-#include "SkTypes.h"
-
#include "SkScalar.h"
-#include "SkPoint.h"
-#include "SkRect.h"
+
+class SkString;
class SkReader32 : SkNoncopyable {
public:
@@ -73,14 +64,6 @@ public:
return value;
}
- const SkPoint* skipPoint() {
- return (const SkPoint*)this->skip(sizeof(SkPoint));
- }
-
- const SkRect* skipRect() {
- return (const SkRect*)this->skip(sizeof(SkRect));
- }
-
const void* skip(size_t size) {
SkASSERT(ptr_align_4(fCurr));
const void* addr = fCurr;
@@ -89,6 +72,11 @@ public:
return addr;
}
+ template <typename T> const T& skipT() {
+ SkASSERT(SkAlign4(sizeof(T)) == sizeof(T));
+ return *(const T*)this->skip(sizeof(T));
+ }
+
void read(void* dst, size_t size) {
SkASSERT(0 == size || dst != NULL);
SkASSERT(ptr_align_4(fCurr));
@@ -103,12 +91,18 @@ public:
uint32_t readU32() { return this->readInt(); }
/**
- * Read the length of a string written by SkWriter32::writeString()
- * (if len is not NULL) and return the null-ternimated address of the
- * string.
+ * Read the length of a string (written by SkWriter32::writeString) into
+ * len (if len is not NULL) and return the null-ternimated address of the
+ * string within the reader's buffer.
*/
const char* readString(size_t* len = NULL);
+ /**
+ * Read the string (written by SkWriter32::writeString) and return it in
+ * copy (if copy is not null). Return the length of the string.
+ */
+ size_t readIntoString(SkString* copy);
+
private:
// these are always 4-byte aligned
const char* fCurr; // current position within buffer
@@ -116,8 +110,7 @@ private:
const char* fBase; // beginning of buffer
#ifdef SK_DEBUG
- static bool ptr_align_4(const void* ptr)
- {
+ static bool ptr_align_4(const void* ptr) {
return (((const char*)ptr - (const char*)NULL) & 3) == 0;
}
#endif
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 19ee12a..65e7611 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRect_DEFINED
#define SkRect_DEFINED
@@ -56,27 +49,39 @@ struct SK_API SkIRect {
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; }
- /** Returns the rectangle's width. This does not check for a valid rectangle (i.e. left <= right)
- so the result may be negative.
- */
+ int left() const { return fLeft; }
+ int top() const { return fTop; }
+ int right() const { return fRight; }
+ int bottom() const { return fBottom; }
+
+ /** return the left edge of the rect */
+ int x() const { return fLeft; }
+ /** return the top edge of the rect */
+ int y() const { return fTop; }
+ /**
+ * Returns the rectangle's width. This does not check for a valid rect
+ * (i.e. left <= right) so the result may be negative.
+ */
int width() const { return fRight - fLeft; }
-
- /** Returns the rectangle's height. This does not check for a valid rectangle (i.e. top <= bottom)
- so the result may be negative.
- */
+
+ /**
+ * Returns the rectangle's height. This does not check for a valid rect
+ * (i.e. top <= bottom) so the result may be negative.
+ */
int height() const { return fBottom - fTop; }
+
+ /**
+ * Return true if the rectangle's width or height are <= 0
+ */
+ bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
- friend int operator==(const SkIRect& a, const SkIRect& b) {
+ friend bool operator==(const SkIRect& a, const SkIRect& b) {
return !memcmp(&a, &b, sizeof(a));
}
- friend int operator!=(const SkIRect& a, const SkIRect& b) {
- return memcmp(&a, &b, sizeof(a));
+ friend bool operator!=(const SkIRect& a, const SkIRect& b) {
+ return !(a == b);
}
bool is16Bit() const {
@@ -330,10 +335,34 @@ struct SK_API SkRect {
return r;
}
- /** Return true if the rectangle's width or height are <= 0
- */
- bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
- bool hasValidCoordinates() const;
+ /**
+ * Return true if the rectangle's width or height are <= 0
+ */
+ bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+
+ /**
+ * Returns true iff all values in the rect are finite. If any are
+ * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this
+ * returns false.
+ */
+ bool isFinite() const {
+#ifdef SK_SCALAR_IS_FLOAT
+ // x * 0 will be NaN iff x is infinity or NaN.
+ // a + b will be NaN iff either a or b is NaN.
+ float value = fLeft * 0 + fTop * 0 + fRight * 0 + fBottom * 0;
+
+ // value is either NaN or it is finite (zero).
+ // value==value will be true iff value is not NaN
+ return value == value;
+#else
+ // use bit-or for speed, since we don't care about short-circuting the
+ // tests, and we expect the common case will be that we need to check all.
+ int isNaN = (SK_FixedNaN == fLeft) | (SK_FixedNaN == fTop) |
+ (SK_FixedNaN == fRight) | (SK_FixedNaN == fBottom);
+ return !isNaN;
+#endif
+ }
+
SkScalar left() const { return fLeft; }
SkScalar top() const { return fTop; }
SkScalar right() const { return fRight; }
@@ -343,12 +372,12 @@ struct SK_API SkRect {
SkScalar centerX() const { return SkScalarHalf(fLeft + fRight); }
SkScalar centerY() const { return SkScalarHalf(fTop + fBottom); }
- friend int operator==(const SkRect& a, const SkRect& b) {
- return !memcmp(&a, &b, sizeof(a));
+ friend bool operator==(const SkRect& a, const SkRect& b) {
+ return 0 == memcmp(&a, &b, sizeof(a));
}
- friend int operator!=(const SkRect& a, const SkRect& b) {
- return memcmp(&a, &b, sizeof(a));
+ friend bool operator!=(const SkRect& a, const SkRect& b) {
+ return 0 != memcmp(&a, &b, sizeof(a));
}
/** return the 4 points that enclose the rectangle
@@ -436,9 +465,10 @@ struct SK_API SkRect {
this->offset(delta.fX, delta.fY);
}
- /** Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards,
- making the rectangle narrower. If dx is negative, then the sides are moved outwards,
- making the rectangle wider. The same hods true for dy and the top and bottom.
+ /** Inset the rectangle by (dx,dy). If dx is positive, then the sides are
+ moved inwards, making the rectangle narrower. If dx is negative, then
+ the sides are moved outwards, making the rectangle wider. The same holds
+ true for dy and the top and bottom.
*/
void inset(SkScalar dx, SkScalar dy) {
fLeft += dx;
@@ -447,6 +477,13 @@ struct SK_API SkRect {
fBottom -= dy;
}
+ /** Outset the rectangle by (dx,dy). If dx is positive, then the sides are
+ moved outwards, making the rectangle wider. If dx is negative, then the
+ sides are moved inwards, making the rectangle narrower. The same hods
+ true for dy and the top and bottom.
+ */
+ void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
+
/** If this rectangle intersects r, return true and set this rectangle to that
intersection, otherwise return false and do not change this rectangle.
If either rectangle is empty, do nothing and return false.
@@ -472,6 +509,12 @@ struct SK_API SkRect {
fLeft < right && left < fRight &&
fTop < bottom && top < fBottom;
}
+
+ /** If rectangles a and b intersect, return true and set this rectangle to
+ * that intersection, otherwise return false and do not change this
+ * rectangle. If either rectangle is empty, do nothing and return false.
+ */
+ bool intersect(const SkRect& a, const SkRect& b);
/**
* Return true if rectangles a and b are not empty and intersect.
@@ -574,6 +617,18 @@ struct SK_API SkRect {
}
/**
+ * Expand this rectangle by rounding its coordinates "out", choosing the
+ * floor of top and left, and the ceil of right and bottom. If this rect
+ * is already on integer coordinates, then it will be unchanged.
+ */
+ void roundOut() {
+ this->set(SkScalarFloorToScalar(fLeft),
+ SkScalarFloorToScalar(fTop),
+ SkScalarCeilToScalar(fRight),
+ SkScalarCeilToScalar(fBottom));
+ }
+
+ /**
* Swap top/bottom or left/right if there are flipped (i.e. if width()
* or height() would have returned a negative value.) This should be called
* if the edges are computed separately, and may have crossed over each
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 36f4249..7af0017 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRefCnt_DEFINED
#define SkRefCnt_DEFINED
@@ -37,7 +30,12 @@ public:
/** Destruct, asserting that the reference count is 1.
*/
- virtual ~SkRefCnt() { SkASSERT(fRefCnt == 1); }
+ virtual ~SkRefCnt() {
+#ifdef SK_DEBUG
+ SkASSERT(fRefCnt == 1);
+ fRefCnt = 0; // illegal value, to catch us if we reuse after delete
+#endif
+ }
/** Return the reference count.
*/
@@ -63,20 +61,61 @@ public:
}
}
+ void validate() const {
+ SkASSERT(fRefCnt > 0);
+ }
+
private:
mutable int32_t fRefCnt;
};
+///////////////////////////////////////////////////////////////////////////////
+
+/** Helper macro to safely assign one SkRefCnt[TS]* to another, checking for
+ null in on each side of the assignment, and ensuring that ref() is called
+ before unref(), in case the two pointers point to the same object.
+ */
+#define SkRefCnt_SafeAssign(dst, src) \
+ do { \
+ if (src) src->ref(); \
+ if (dst) dst->unref(); \
+ dst = src; \
+ } while (0)
+
+
+/** Check if the argument is non-null, and if so, call obj->ref()
+ */
+template <typename T> static inline void SkSafeRef(T* obj) {
+ if (obj) {
+ obj->ref();
+ }
+}
+
+/** Check if the argument is non-null, and if so, call obj->unref()
+ */
+template <typename T> static inline void SkSafeUnref(T* obj) {
+ if (obj) {
+ obj->unref();
+ }
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
/**
* Utility class that simply unref's its argument in the destructor.
*/
template <typename T> class SkAutoTUnref : SkNoncopyable {
public:
- SkAutoTUnref(T* obj) : fObj(obj) {}
+ explicit SkAutoTUnref(T* obj = NULL) : fObj(obj) {}
~SkAutoTUnref() { SkSafeUnref(fObj); }
T* get() const { return fObj; }
+ void reset(T* obj) {
+ SkSafeUnref(fObj);
+ fObj = obj;
+ }
+
/**
* Return the hosted object (which may be null), transferring ownership.
* The reference count is not modified, and the internal ptr is set to NULL
@@ -98,35 +137,13 @@ public:
SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {}
};
-///////////////////////////////////////////////////////////////////////////////
-
-/** Helper macro to safely assign one SkRefCnt[TS]* to another, checking for
- null in on each side of the assignment, and ensuring that ref() is called
- before unref(), in case the two pointers point to the same object.
-*/
-#define SkRefCnt_SafeAssign(dst, src) \
- do { \
- if (src) src->ref(); \
- if (dst) dst->unref(); \
- dst = src; \
- } while (0)
-
-
-/** Check if the argument is non-null, and if so, call obj->ref()
- */
-template <typename T> static inline void SkSafeRef(T* obj) {
- if (obj) {
- obj->ref();
- }
-}
-
-/** Check if the argument is non-null, and if so, call obj->unref()
- */
-template <typename T> static inline void SkSafeUnref(T* obj) {
- if (obj) {
- obj->unref();
- }
-}
+class SkAutoRef : SkNoncopyable {
+public:
+ SkAutoRef(SkRefCnt* obj) : fObj(obj) { SkSafeRef(obj); }
+ ~SkAutoRef() { SkSafeUnref(fObj); }
+private:
+ SkRefCnt* fObj;
+};
/** Wrapper class for SkRefCnt pointers. This manages ref/unref of a pointer to
a SkRefCnt (or subclass) object.
diff --git a/include/core/SkRefDict.h b/include/core/SkRefDict.h
index 0c4b025..6751121 100644
--- a/include/core/SkRefDict.h
+++ b/include/core/SkRefDict.h
@@ -1,19 +1,12 @@
-/*
- 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.
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRefDict_DEFINED
#define SkRefDict_DEFINED
diff --git a/include/core/SkRegion.h b/include/core/SkRegion.h
index 1dace59..9d89d94 100644
--- a/include/core/SkRegion.h
+++ b/include/core/SkRegion.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2005 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
+ * Copyright 2005 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkRegion_DEFINED
#define SkRegion_DEFINED
@@ -93,9 +86,9 @@ public:
const SkIRect& getBounds() const { return fBounds; }
/**
- * Returns true if the region is non-empty, and if so, sets the specified
- * path to the boundary(s) of the region. If the region is empty, then
- * this returns false, and path is left unmodified.
+ * Returns true if the region is non-empty, and if so, appends the
+ * boundary(s) of the region to the specified path.
+ * If the region is empty, returns false, and path is left unmodified.
*/
bool getBoundaryPath(SkPath* path) const;
@@ -290,7 +283,7 @@ public:
*/
bool op(const SkRegion& rgna, const SkRegion& rgnb, Op op);
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
/** Returns a new char* containing the list of rectangles in this region
*/
char* toString();
diff --git a/include/core/SkRelay.h b/include/core/SkRelay.h
index 9361482..ef09ce4 100644
--- a/include/core/SkRelay.h
+++ b/include/core/SkRelay.h
@@ -1,19 +1,12 @@
-/*
- Copyright 2010 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.
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTRelay_DEFINED
#define SkTRelay_DEFINED
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h
index ba113f4..71aad98 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkScalar_DEFINED
#define SkScalar_DEFINED
@@ -99,7 +92,7 @@
*
* Either way, it's not good.
*/
- SkASSERT(!"looks like you passed an SkScalar into SkIntToScalar");
+ SkDEBUGFAIL("looks like you passed an SkScalar into SkIntToScalar");
return (float)0;
}
#else // not SK_DEBUG
@@ -123,15 +116,15 @@
/** SkScalarFraction(x) returns the signed fractional part of the argument
*/
#define SkScalarFraction(x) sk_float_mod(x, 1.0f)
- /** Rounds the SkScalar to the nearest integer value
- */
- #define SkScalarRound(x) sk_float_round2int(x)
- /** Returns the smallest integer that is >= the specified SkScalar
- */
- #define SkScalarCeil(x) sk_float_ceil2int(x)
- /** Returns the largest integer that is <= the specified SkScalar
- */
- #define SkScalarFloor(x) sk_float_floor2int(x)
+
+ #define SkScalarFloorToScalar(x) sk_float_floor(x)
+ #define SkScalarCeilToScalar(x) sk_float_ceil(x)
+ #define SkScalarRoundToScalar(x) sk_float_floor((x) + 0.5f)
+
+ #define SkScalarFloorToInt(x) sk_float_floor2int(x)
+ #define SkScalarCeilToInt(x) sk_float_ceil2int(x)
+ #define SkScalarRoundToInt(x) sk_float_round2int(x)
+
/** Returns the absolute value of the specified SkScalar
*/
#define SkScalarAbs(x) sk_float_abs(x)
@@ -237,9 +230,15 @@
#define SkDoubleToScalar(n) SkDoubleToFixed(n)
#endif
#define SkScalarFraction(x) SkFixedFraction(x)
- #define SkScalarRound(x) SkFixedRound(x)
- #define SkScalarCeil(x) SkFixedCeil(x)
- #define SkScalarFloor(x) SkFixedFloor(x)
+
+ #define SkScalarFloorToScalar(x) SkFixedFloorToFixed(x)
+ #define SkScalarCeilToScalar(x) SkFixedCeilToFixed(x)
+ #define SkScalarRoundToScalar(x) SkFixedRoundToFixed(x)
+
+ #define SkScalarFloorToInt(x) SkFixedFloorToInt(x)
+ #define SkScalarCeilToInt(x) SkFixedCeilToInt(x)
+ #define SkScalarRoundToInt(x) SkFixedRoundToInt(x)
+
#define SkScalarAbs(x) SkFixedAbs(x)
#define SkScalarCopySign(x, y) SkCopySign32(x, y)
#define SkScalarClampMax(x, max) SkClampMax(x, max)
@@ -284,17 +283,43 @@
}
#endif
+// DEPRECATED : use ToInt or ToScalar variant
+#define SkScalarFloor(x) SkScalarFloorToInt(x)
+#define SkScalarCeil(x) SkScalarCeilToInt(x)
+#define SkScalarRound(x) SkScalarRoundToInt(x)
+
+/**
+ * Returns -1 || 0 || 1 depending on the sign of value:
+ * -1 if x < 0
+ * 0 if x == 0
+ * 1 if x > 0
+ */
+static inline int SkScalarSignAsInt(SkScalar x) {
+ return x < 0 ? -1 : (x > 0);
+}
+
+// Scalar result version of above
+static inline SkScalar SkScalarSignAsScalar(SkScalar x) {
+ return x < 0 ? -SK_Scalar1 : ((x > 0) ? SK_Scalar1 : 0);
+}
+
#define SK_ScalarNearlyZero (SK_Scalar1 / (1 << 12))
/* <= is slower than < for floats, so we use < for our tolerance test
*/
static inline bool SkScalarNearlyZero(SkScalar x,
- SkScalar tolerance = SK_ScalarNearlyZero) {
+ SkScalar tolerance = SK_ScalarNearlyZero) {
SkASSERT(tolerance > 0);
return SkScalarAbs(x) < tolerance;
}
+static inline bool SkScalarNearlyEqual(SkScalar x, SkScalar y,
+ SkScalar tolerance = SK_ScalarNearlyZero) {
+ SkASSERT(tolerance > 0);
+ return SkScalarAbs(x-y) < tolerance;
+}
+
/** Linearly interpolate between A and B, based on t.
If t is 0, return A
If t is 1, return B
diff --git a/include/core/SkScalarCompare.h b/include/core/SkScalarCompare.h
index 7f0b176..0842fdd 100644
--- a/include/core/SkScalarCompare.h
+++ b/include/core/SkScalarCompare.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkScalarCompare_DEFINED
#define SkScalarCompare_DEFINED
diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h
index 2206c64..e7dd7d4 100644
--- a/include/core/SkScalerContext.h
+++ b/include/core/SkScalerContext.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkScalerContext_DEFINED
#define SkScalerContext_DEFINED
@@ -60,7 +53,9 @@ struct SkGlyph {
unsigned rb = width;
if (SkMask::kBW_Format == format) {
rb = (rb + 7) >> 3;
- } else if (SkMask::kARGB32_Format == format) {
+ } else if (SkMask::kARGB32_Format == format ||
+ SkMask::kLCD32_Format == format)
+ {
rb <<= 2;
} else if (SkMask::kLCD16_Format == format) {
rb = SkAlign4(rb << 1);
@@ -157,37 +152,41 @@ struct SkGlyph {
}
void toMask(SkMask* mask) const;
-
- /** Given a glyph which is has a mask format of LCD or VerticalLCD, take
- the A8 plane in fImage and produce a valid LCD plane from it.
- */
- void expandA8ToLCD() const;
};
class SkScalerContext {
public:
enum Flags {
- kFrameAndFill_Flag = 0x01,
- kDevKernText_Flag = 0x02,
- kGammaForBlack_Flag = 0x04, // illegal to set both Gamma flags
- kGammaForWhite_Flag = 0x08, // illegal to set both Gamma flags
+ kFrameAndFill_Flag = 0x0001,
+ kDevKernText_Flag = 0x0002,
+ kEmbeddedBitmapText_Flag = 0x0004,
+ kEmbolden_Flag = 0x0008,
+ kSubpixelPositioning_Flag = 0x0010,
+ kAutohinting_Flag = 0x0020,
+ kVertical_Flag = 0x0040,
+
// together, these two flags resulting in a two bit value which matches
// up with the SkPaint::Hinting enum.
- kHintingBit1_Flag = 0x10,
- kHintingBit2_Flag = 0x20,
- kEmbeddedBitmapText_Flag = 0x40,
- kEmbolden_Flag = 0x80,
- kSubpixelPositioning_Flag = 0x100,
- kAutohinting_Flag = 0x200,
- // these should only ever be set if fMaskFormat is LCD
- kLCD_Vertical_Flag = 0x400, // else Horizontal
- kLCD_BGROrder_Flag = 0x800, // else RGB order
+ kHinting_Shift = 7, // to shift into the other flags above
+ kHintingBit1_Flag = 0x0080,
+ kHintingBit2_Flag = 0x0100,
+
+ // these should only ever be set if fMaskFormat is LCD16 or LCD32
+ kLCD_Vertical_Flag = 0x0200, // else Horizontal
+ kLCD_BGROrder_Flag = 0x0400, // else RGB order
+
+ // luminance : 0 for black text, kLuminance_Max for white text
+ kLuminance_Shift = 11, // to shift into the other flags above
+ kLuminance_Bits = 3, // ensure Flags doesn't exceed 16bits
};
-private:
+
+ // computed values
enum {
- kHintingMask = kHintingBit1_Flag | kHintingBit2_Flag
+ kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag,
+ kLuminance_Max = (1 << kLuminance_Bits) - 1,
+ kLuminance_Mask = kLuminance_Max << kLuminance_Shift,
};
-public:
+
struct Rec {
uint32_t fOrigFontID;
uint32_t fFontID;
@@ -207,19 +206,33 @@ public:
void getSingleMatrix(SkMatrix*) const;
SkPaint::Hinting getHinting() const {
- return static_cast<SkPaint::Hinting>((fFlags & kHintingMask) >> 4);
+ unsigned hint = (fFlags & kHinting_Mask) >> kHinting_Shift;
+ return static_cast<SkPaint::Hinting>(hint);
}
void setHinting(SkPaint::Hinting hinting) {
- fFlags = (fFlags & ~kHintingMask) | (hinting << 4);
+ fFlags = (fFlags & ~kHinting_Mask) | (hinting << kHinting_Shift);
}
- SkMask::Format getFormat() const {
- return static_cast<SkMask::Format>(fMaskFormat);
+ unsigned getLuminanceBits() const {
+ return (fFlags & kLuminance_Mask) >> kLuminance_Shift;
+ }
+
+ void setLuminanceBits(unsigned lum) {
+ SkASSERT(lum <= kLuminance_Max);
+ fFlags = (fFlags & ~kLuminance_Mask) | (lum << kLuminance_Shift);
}
- bool isLCD() const {
- return SkMask::FormatIsLCD(this->getFormat());
+ U8CPU getLuminanceByte() const {
+ SkASSERT(3 == kLuminance_Bits);
+ unsigned lum = this->getLuminanceBits();
+ lum |= (lum << kLuminance_Bits);
+ lum |= (lum << kLuminance_Bits*2);
+ return lum >> (4*kLuminance_Bits - 8);
+ }
+
+ SkMask::Format getFormat() const {
+ return static_cast<SkMask::Format>(fMaskFormat);
}
};
@@ -230,6 +243,10 @@ public:
return (SkMask::Format)fRec.fMaskFormat;
}
+ bool isSubpixel() const {
+ return SkToBool(fRec.fFlags & kSubpixelPositioning_Flag);
+ }
+
// remember our glyph offset/base
void setBaseGlyphCount(unsigned baseGlyphCount) {
fBaseGlyphCount = baseGlyphCount;
@@ -240,14 +257,7 @@ public:
fact correspond to a different font/context. In that case, we use the
base-glyph-count to know how to translate back into local glyph space.
*/
- uint16_t charToGlyphID(SkUnichar uni);
-
-#ifdef ANDROID
- /** Return the ScalerContext for the specifier unichar. Since contexts may be chained,
- * the returned value can be the ScalerContext of the default font.
- */
- SkScalerContext* charToScalerContext(SkUnichar uni);
-#endif
+ uint16_t charToGlyphID(SkUnichar uni);
/** Map the glyphID to its glyph index, and then to its char code. Unmapped
glyphs return zero.
@@ -262,8 +272,8 @@ public:
void getFontMetrics(SkPaint::FontMetrics* mX,
SkPaint::FontMetrics* mY);
-#ifdef ANDROID
- inline unsigned getBaseGlyphCount() { return fBaseGlyphCount; }
+#ifdef SK_BUILD_FOR_ANDROID
+ unsigned getBaseGlyphCount(SkUnichar charCode);
#endif
static inline void MakeRec(const SkPaint&, const SkMatrix*, Rec* rec);
@@ -284,12 +294,18 @@ protected:
// default impl returns 0, indicating failure.
virtual SkUnichar generateGlyphToChar(uint16_t);
+ void forceGenerateImageFromPath() { fGenerateImageFromPath = true; }
+
private:
SkPathEffect* fPathEffect;
SkMaskFilter* fMaskFilter;
SkRasterizer* fRasterizer;
SkScalar fDevFrameWidth;
+ // if this is set, we draw the image from a path, rather than
+ // calling generateImage.
+ bool fGenerateImageFromPath;
+
void internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
SkPath* devPath, SkMatrix* fillToDevMatrix);
@@ -309,5 +325,21 @@ private:
#define kMaskFilter_SkDescriptorTag SkSetFourByteTag('m', 's', 'k', 'f')
#define kRasterizer_SkDescriptorTag SkSetFourByteTag('r', 'a', 's', 't')
+///////////////////////////////////////////////////////////////////////////////
+
+enum SkAxisAlignment {
+ kNone_SkAxisAlignment,
+ kX_SkAxisAlignment,
+ kY_SkAxisAlignment
+};
+
+/**
+ * Return the axis (if any) that the baseline for horizontal text will land on
+ * after running through the specified matrix.
+ *
+ * As an example, the identity matrix will return kX_SkAxisAlignment
+ */
+SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix);
+
#endif
diff --git a/include/core/SkScan.h b/include/core/SkScan.h
index 31d4845..61ba1b0 100644
--- a/include/core/SkScan.h
+++ b/include/core/SkScan.h
@@ -1,25 +1,18 @@
-/* libs/graphics/sgl/SkScan.h
-**
-** Copyright 2011, 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.
-*/
+
+/*
+ * Copyright 2011 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkScan_DEFINED
#define SkScan_DEFINED
#include "SkRect.h"
+class SkRasterClip;
class SkRegion;
class SkBlitter;
class SkPath;
@@ -31,57 +24,74 @@ typedef SkIRect SkXRect;
class SkScan {
public:
- static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
- static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
+ static void FillPath(const SkPath&, const SkIRect&, SkBlitter*);
+ ///////////////////////////////////////////////////////////////////////////
+ // rasterclip
+
+ static void FillIRect(const SkIRect&, const SkRasterClip&, SkBlitter*);
+ static void FillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
#ifdef SK_SCALAR_IS_FIXED
- static void FillRect(const SkRect& rect, const SkRegion* clip,
+ static void FillRect(const SkRect& rect, const SkRasterClip& clip,
SkBlitter* blitter) {
SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
}
-#else
- static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
-#endif
- static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
-
- static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
- static void FillTriangle(const SkPoint& a, const SkPoint& b,
- const SkPoint& c, const SkRegion* clip,
+ static void AntiFillRect(const SkRect& rect, const SkRasterClip& clip,
SkBlitter* blitter) {
- SkPoint pts[3];
- pts[0] = a;
- pts[1] = b;
- pts[2] = c;
- FillTriangle(pts, clip, blitter);
+ SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
}
-
- static void HairLine(const SkPoint&, const SkPoint&, const SkRegion*,
+#else
+ static void FillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
+ static void AntiFillRect(const SkRect&, const SkRasterClip&, SkBlitter*);
+#endif
+ static void AntiFillXRect(const SkXRect&, const SkRasterClip&, SkBlitter*);
+ static void FillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
+ static void AntiFillPath(const SkPath&, const SkRasterClip&, SkBlitter*);
+ static void FrameRect(const SkRect&, const SkPoint& strokeSize,
+ const SkRasterClip&, SkBlitter*);
+ static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
+ const SkRasterClip&, SkBlitter*);
+ static void FillTriangle(const SkPoint pts[], const SkRasterClip&, SkBlitter*);
+ static void HairLine(const SkPoint&, const SkPoint&, const SkRasterClip&,
SkBlitter*);
- static void HairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
- static void HairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
+ static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRasterClip&,
+ SkBlitter*);
+ static void HairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
+ static void AntiHairRect(const SkRect&, const SkRasterClip&, SkBlitter*);
+ static void HairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
+ static void AntiHairPath(const SkPath&, const SkRasterClip&, SkBlitter*);
+
+private:
+ friend class SkAAClip;
+ friend class SkRegion;
- static void AntiFillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
+ static void FillIRect(const SkIRect&, const SkRegion* clip, SkBlitter*);
+ static void FillXRect(const SkXRect&, const SkRegion* clip, SkBlitter*);
#ifdef SK_SCALAR_IS_FIXED
- static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
+ static void FillRect(const SkRect& rect, const SkRegion* clip,
SkBlitter* blitter) {
+ SkScan::FillXRect(*(const SkXRect*)&rect, clip, blitter);
+ }
+ static void AntiFillRect(const SkRect& rect, const SkRegion* clip,
+ SkBlitter* blitter) {
SkScan::AntiFillXRect(*(const SkXRect*)&rect, clip, blitter);
}
#else
+ static void FillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
static void AntiFillRect(const SkRect&, const SkRegion* clip, SkBlitter*);
#endif
+ static void AntiFillXRect(const SkXRect&, const SkRegion*, SkBlitter*);
+ static void FillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
+ static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*,
+ bool forceRLE = false);
+ static void FillTriangle(const SkPoint pts[], const SkRegion*, SkBlitter*);
- static void AntiFillPath(const SkPath&, const SkRegion& clip, SkBlitter*);
-
- static void AntiHairLine(const SkPoint&, const SkPoint&, const SkRegion*,
- SkBlitter*);
- static void AntiHairRect(const SkRect&, const SkRegion* clip, SkBlitter*);
- static void AntiHairPath(const SkPath&, const SkRegion* clip, SkBlitter*);
-
- // draws with a miter-join
- static void FrameRect(const SkRect&, const SkPoint& strokeSize,
- const SkRegion*, SkBlitter*);
static void AntiFrameRect(const SkRect&, const SkPoint& strokeSize,
const SkRegion*, SkBlitter*);
+ static void HairLineRgn(const SkPoint&, const SkPoint&, const SkRegion*,
+ SkBlitter*);
+ static void AntiHairLineRgn(const SkPoint&, const SkPoint&, const SkRegion*,
+ SkBlitter*);
};
/** Assign an SkXRect from a SkIRect, by promoting the src rect's coordinates
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index cf1d4e9..7c5be06 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkShader_DEFINED
#define SkShader_DEFINED
@@ -104,6 +97,15 @@ public:
virtual uint32_t getFlags() { return 0; }
/**
+ * Returns true if the shader is guaranteed to produce only opaque
+ * colors, subject to the SkPaint using the shader to apply an opaque
+ * alpha value. Subclasses should override this to allow some
+ * optimizations. isOpaque() can be called at any time, unlike getFlags,
+ * which only works properly when the context is set.
+ */
+ virtual bool isOpaque() const { return false; }
+
+ /**
* Return the alpha associated with the data returned by shadeSpan16(). If
* kHasSpan16_Flag is not set, this value is meaningless.
*/
@@ -277,7 +279,7 @@ public:
static SkShader* CreateBitmapShader(const SkBitmap& src,
TileMode tmx, TileMode tmy);
- virtual void flatten(SkFlattenableWriteBuffer& );
+ virtual void flatten(SkFlattenableWriteBuffer& ) SK_OVERRIDE;
protected:
enum MatrixClass {
kLinear_MatrixClass, // no perspective
diff --git a/include/core/SkShape.h b/include/core/SkShape.h
index 6cee70e..c7cf9ec 100644
--- a/include/core/SkShape.h
+++ b/include/core/SkShape.h
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
#ifndef SkShape_DEFINED
#define SkShape_DEFINED
@@ -31,6 +38,8 @@ public:
// public for Registrar
static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
+ SK_DECLARE_FLATTENABLE_REGISTRAR()
+
protected:
virtual void onDraw(SkCanvas*);
diff --git a/include/core/SkSize.h b/include/core/SkSize.h
index 8371c9b..12dbeae 100644
--- a/include/core/SkSize.h
+++ b/include/core/SkSize.h
@@ -1,4 +1,11 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#ifndef SkSize_DEFINED
#define SkSize_DEFINED
diff --git a/include/core/SkStream.h b/include/core/SkStream.h
index c3d8185..90d2357 100644
--- a/include/core/SkStream.h
+++ b/include/core/SkStream.h
@@ -1,25 +1,20 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkStream_DEFINED
#define SkStream_DEFINED
#include "SkRefCnt.h"
#include "SkScalar.h"
+class SkData;
+
class SK_API SkStream : public SkRefCnt {
public:
virtual ~SkStream();
@@ -100,6 +95,8 @@ public:
bool writePackedUInt(size_t);
bool writeStream(SkStream* input, size_t length);
+
+ bool writeData(const SkData*);
};
////////////////////////////////////////////////////////////////////////////////////////
@@ -127,9 +124,9 @@ public:
*/
void setPath(const char path[]);
- virtual bool rewind();
- virtual size_t read(void* buffer, size_t size);
- virtual const char* getFileName();
+ virtual bool rewind() SK_OVERRIDE;
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
+ virtual const char* getFileName() SK_OVERRIDE;
private:
SkFILE* fFILE;
@@ -151,9 +148,9 @@ public:
*/
bool isValid() const { return fFD >= 0; }
- virtual bool rewind();
- virtual size_t read(void* buffer, size_t size);
- virtual const char* getFileName() { return NULL; }
+ virtual bool rewind() SK_OVERRIDE;
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
+ virtual const char* getFileName() SK_OVERRIDE { return NULL; }
private:
int fFD;
@@ -182,18 +179,31 @@ public:
will be freed with sk_free.
*/
void setMemoryOwned(const void* data, size_t length);
+
+ /**
+ * Return the stream's data in a SkData. The caller must call unref() when
+ * it is finished using the data.
+ */
+ SkData* copyToData() const;
+
+ /**
+ * Use the specified data as the memory for this stream. The stream will
+ * call ref() on the data (assuming it is not null). The function returns
+ * the data parameter as a convenience.
+ */
+ SkData* setData(SkData*);
+
void skipToAlign4();
- virtual bool rewind();
- virtual size_t read(void* buffer, size_t size);
- virtual const void* getMemoryBase();
+ virtual bool rewind() SK_OVERRIDE;
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
+ virtual const void* getMemoryBase() SK_OVERRIDE;
const void* getAtPos();
size_t seek(size_t offset);
size_t peek() const { return fOffset; }
private:
- const void* fSrc;
- size_t fSize, fOffset;
- SkBool8 fWeOwnTheData;
+ SkData* fData;
+ size_t fOffset;
};
/** \class SkBufferStream
@@ -220,10 +230,10 @@ public:
SkBufferStream(SkStream* proxy, void* buffer, size_t bufferSize);
virtual ~SkBufferStream();
- virtual bool rewind();
- virtual const char* getFileName();
- virtual size_t read(void* buffer, size_t size);
- virtual const void* getMemoryBase();
+ virtual bool rewind() SK_OVERRIDE;
+ virtual const char* getFileName() SK_OVERRIDE;
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
+ virtual const void* getMemoryBase() SK_OVERRIDE;
private:
enum {
@@ -252,8 +262,8 @@ public:
*/
bool isValid() const { return fFILE != NULL; }
- virtual bool write(const void* buffer, size_t size);
- virtual void flush();
+ virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
+ virtual void flush() SK_OVERRIDE;
private:
SkFILE* fFILE;
};
@@ -261,7 +271,7 @@ private:
class SkMemoryWStream : public SkWStream {
public:
SkMemoryWStream(void* buffer, size_t size);
- virtual bool write(const void* buffer, size_t size);
+ virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
private:
char* fBuffer;
@@ -273,24 +283,24 @@ class SK_API SkDynamicMemoryWStream : public SkWStream {
public:
SkDynamicMemoryWStream();
virtual ~SkDynamicMemoryWStream();
- virtual bool write(const void* buffer, size_t size);
+
+ virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
// random access write
// 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() const { return fBytesWritten; }
+ size_t bytesWritten() const { return fBytesWritten; }
// copy what has been written to the stream into dst
- void copyTo(void* dst) const;
- /* return a cache of the flattened data returned by copyTo().
- This copy is only valid until the next call to write().
- The memory is managed by the stream class.
- */
- const char* getStream() const;
+ void copyTo(void* dst) const;
+
+ /**
+ * Return a copy of the data written so far. This call is responsible for
+ * calling unref() when they are finished with the data.
+ */
+ SkData* copyToData() const;
- // same as getStream, but additionally detach the flattened datat
- const char* detach();
-
// reset the stream to its original state
void reset();
void padToAlign4();
@@ -299,15 +309,17 @@ private:
Block* fHead;
Block* fTail;
size_t fBytesWritten;
- mutable char* fCopyToCache;
+ mutable SkData* fCopy; // is invalidated if we write after it is created
+
+ void invalidateCopy();
};
class SkDebugWStream : public SkWStream {
public:
// overrides
- virtual bool write(const void* buffer, size_t size);
- virtual void newline();
+ virtual bool write(const void* buffer, size_t size) SK_OVERRIDE;
+ virtual void newline() SK_OVERRIDE;
};
// for now
diff --git a/include/core/SkString.h b/include/core/SkString.h
index 0295b75..3fa367b 100644
--- a/include/core/SkString.h
+++ b/include/core/SkString.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkString_DEFINED
#define SkString_DEFINED
@@ -73,7 +66,7 @@ public:
SkString(const SkString&);
~SkString();
- bool isEmpty() const { return fRec->fLength == 0; }
+ bool isEmpty() const { return 0 == fRec->fLength; }
size_t size() const { return (size_t) fRec->fLength; }
const char* c_str() const { return fRec->data(); }
char operator[](size_t n) const { return this->c_str()[n]; }
@@ -89,19 +82,19 @@ public:
return SkStrEndsWith(fRec->data(), suffix);
}
- friend int operator==(const SkString& a, const SkString& b) {
+ friend bool operator==(const SkString& a, const SkString& b) {
return a.equals(b);
}
- friend int operator!=(const SkString& a, const SkString& b) {
+ friend bool operator!=(const SkString& a, const SkString& b) {
return !a.equals(b);
}
// these methods edit the string
- SkString& operator=(const SkString&);
- SkString& operator=(const char text[]);
+ SkString& operator=(const SkString&);
+ SkString& operator=(const char text[]);
- char* writable_str();
+ char* writable_str();
char& operator[](size_t n) { return this->writable_str()[n]; }
void reset();
@@ -158,8 +151,8 @@ public:
private:
struct Rec {
public:
- uint16_t fLength;
- uint16_t fRefCnt;
+ size_t fLength;
+ int32_t fRefCnt;
char fBeginningOfData;
char* data() { return &fBeginningOfData; }
@@ -175,7 +168,7 @@ private:
#endif
static const Rec gEmptyRec;
- static Rec* AllocRec(const char text[], U16CPU len);
+ static Rec* AllocRec(const char text[], size_t len);
static Rec* RefRec(Rec*);
};
@@ -197,4 +190,7 @@ private:
uint16_t* fUCS2;
};
+/// Creates a new string and writes into it using a printf()-style format.
+SkString SkStringPrintf(const char* format, ...);
+
#endif
diff --git a/include/core/SkStroke.h b/include/core/SkStroke.h
index b593b69..d055b83 100644
--- a/include/core/SkStroke.h
+++ b/include/core/SkStroke.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkStroke_DEFINED
#define SkStroke_DEFINED
diff --git a/include/core/SkTArray.h b/include/core/SkTArray.h
new file mode 100644
index 0000000..577e860
--- /dev/null
+++ b/include/core/SkTArray.h
@@ -0,0 +1,415 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTArray_DEFINED
+#define SkTArray_DEFINED
+
+#include <new>
+#include "SkTypes.h"
+#include "SkTemplates.h"
+
+template <typename T, bool MEM_COPY = false> class SkTArray;
+
+namespace SkTArrayExt {
+
+template<typename T>
+inline void copy(SkTArray<T, true>* self, const T* array) {
+ memcpy(self->fMemArray, array, self->fCount * sizeof(T));
+}
+template<typename T>
+inline void copyAndDelete(SkTArray<T, true>* self, char* newMemArray) {
+ memcpy(newMemArray, self->fMemArray, self->fCount * sizeof(T));
+}
+
+template<typename T>
+inline void copy(SkTArray<T, false>* self, const T* array) {
+ for (int i = 0; i < self->fCount; ++i) {
+ new (self->fItemArray + i) T(array[i]);
+ }
+}
+template<typename T>
+inline void copyAndDelete(SkTArray<T, false>* self, char* newMemArray) {
+ for (int i = 0; i < self->fCount; ++i) {
+ new (newMemArray + sizeof(T) * i) T(self->fItemArray[i]);
+ self->fItemArray[i].~T();
+ }
+}
+
+}
+
+/** When MEM_COPY is true T will be bit copied when moved.
+ When MEM_COPY is false, T will be copy constructed / destructed.
+ In all cases T's constructor will be called on allocation,
+ and its destructor will be called from this object's destructor.
+*/
+template <typename T, bool MEM_COPY> class SkTArray {
+public:
+ /**
+ * Creates an empty array with no initial storage
+ */
+ SkTArray() {
+ fCount = 0;
+ fReserveCount = gMIN_ALLOC_COUNT;
+ fAllocCount = 0;
+ fMemArray = NULL;
+ fPreAllocMemArray = NULL;
+ }
+
+ /**
+ * Creates an empty array that will preallocate space for reserveCount
+ * elements.
+ */
+ explicit SkTArray(int reserveCount) {
+ this->init(NULL, 0, NULL, reserveCount);
+ }
+
+ /**
+ * Copies one array to another. The new array will be heap allocated.
+ */
+ explicit SkTArray(const SkTArray& array) {
+ this->init(array.fItemArray, array.fCount, NULL, 0);
+ }
+
+ /**
+ * Creates a SkTArray by copying contents of a standard C array. The new
+ * array will be heap allocated. Be careful not to use this constructor
+ * when you really want the (void*, int) version.
+ */
+ SkTArray(const T* array, int count) {
+ this->init(array, count, NULL, 0);
+ }
+
+ /**
+ * assign copy of array to this
+ */
+ SkTArray& operator =(const SkTArray& array) {
+ for (int i = 0; i < fCount; ++i) {
+ fItemArray[i].~T();
+ }
+ fCount = 0;
+ checkRealloc((int)array.count());
+ fCount = array.count();
+ SkTArrayExt::copy(this, static_cast<const T*>(array.fMemArray));
+ return *this;
+ }
+
+ virtual ~SkTArray() {
+ for (int i = 0; i < fCount; ++i) {
+ fItemArray[i].~T();
+ }
+ if (fMemArray != fPreAllocMemArray) {
+ sk_free(fMemArray);
+ }
+ }
+
+ /**
+ * Resets to count() == 0
+ */
+ void reset() { this->pop_back_n(fCount); }
+
+ /**
+ * Number of elements in the array.
+ */
+ int count() const { return fCount; }
+
+ /**
+ * Is the array empty.
+ */
+ bool empty() const { return !fCount; }
+
+ /**
+ * Adds 1 new default-constructed T value and returns in by reference. Note
+ * the reference only remains valid until the next call that adds or removes
+ * elements.
+ */
+ T& push_back() {
+ checkRealloc(1);
+ new ((char*)fMemArray+sizeof(T)*fCount) T;
+ ++fCount;
+ return fItemArray[fCount-1];
+ }
+
+ /**
+ * Version of above that uses a copy constructor to initialize the new item
+ */
+ T& push_back(const T& t) {
+ checkRealloc(1);
+ new ((char*)fMemArray+sizeof(T)*fCount) T(t);
+ ++fCount;
+ return fItemArray[fCount-1];
+ }
+
+ /**
+ * Allocates n more default T values, and returns the address of the start
+ * of that new range. Note: this address is only valid until the next API
+ * call made on the array that might add or remove elements.
+ */
+ T* push_back_n(int n) {
+ SkASSERT(n >= 0);
+ checkRealloc(n);
+ for (int i = 0; i < n; ++i) {
+ new (fItemArray + fCount + i) T;
+ }
+ fCount += n;
+ return fItemArray + fCount - n;
+ }
+
+ /**
+ * Version of above that uses a copy constructor to initialize all n items
+ * to the same T.
+ */
+ T* push_back_n(int n, const T& t) {
+ SkASSERT(n >= 0);
+ checkRealloc(n);
+ for (int i = 0; i < n; ++i) {
+ new (fItemArray + fCount + i) T(t);
+ }
+ fCount += n;
+ return fItemArray + fCount - n;
+ }
+
+ /**
+ * Version of above that uses a copy constructor to initialize the n items
+ * to separate T values.
+ */
+ T* push_back_n(int n, const T t[]) {
+ SkASSERT(n >= 0);
+ checkRealloc(n);
+ for (int i = 0; i < n; ++i) {
+ new (fItemArray + fCount + i) T(t[i]);
+ }
+ fCount += n;
+ return fItemArray + fCount - n;
+ }
+
+ /**
+ * Removes the last element. Not safe to call when count() == 0.
+ */
+ void pop_back() {
+ SkASSERT(fCount > 0);
+ --fCount;
+ fItemArray[fCount].~T();
+ checkRealloc(0);
+ }
+
+ /**
+ * Removes the last n elements. Not safe to call when count() < n.
+ */
+ void pop_back_n(int n) {
+ SkASSERT(n >= 0);
+ SkASSERT(fCount >= n);
+ fCount -= n;
+ for (int i = 0; i < n; ++i) {
+ fItemArray[i].~T();
+ }
+ checkRealloc(0);
+ }
+
+ /**
+ * Pushes or pops from the back to resize. Pushes will be default
+ * initialized.
+ */
+ void resize_back(int newCount) {
+ SkASSERT(newCount >= 0);
+
+ if (newCount > fCount) {
+ push_back_n(newCount - fCount);
+ } else if (newCount < fCount) {
+ pop_back_n(fCount - newCount);
+ }
+ }
+
+ /**
+ * Get the i^th element.
+ */
+ T& operator[] (int i) {
+ SkASSERT(i < fCount);
+ SkASSERT(i >= 0);
+ return fItemArray[i];
+ }
+
+ const T& operator[] (int i) const {
+ SkASSERT(i < fCount);
+ SkASSERT(i >= 0);
+ return fItemArray[i];
+ }
+
+ /**
+ * equivalent to operator[](0)
+ */
+ T& front() { SkASSERT(fCount > 0); return fItemArray[0];}
+
+ const T& front() const { SkASSERT(fCount > 0); return fItemArray[0];}
+
+ /**
+ * equivalent to operator[](count() - 1)
+ */
+ T& back() { SkASSERT(fCount); return fItemArray[fCount - 1];}
+
+ const T& back() const { SkASSERT(fCount > 0); return fItemArray[fCount - 1];}
+
+ /**
+ * equivalent to operator[](count()-1-i)
+ */
+ T& fromBack(int i) {
+ SkASSERT(i >= 0);
+ SkASSERT(i < fCount);
+ return fItemArray[fCount - i - 1];
+ }
+
+ const T& fromBack(int i) const {
+ SkASSERT(i >= 0);
+ SkASSERT(i < fCount);
+ return fItemArray[fCount - i - 1];
+ }
+
+protected:
+ /**
+ * Creates an empty array that will use the passed storage block until it
+ * is insufficiently large to hold the entire array.
+ */
+ template <int N>
+ SkTArray(SkAlignedSTStorage<N,T>* storage) {
+ this->init(NULL, 0, storage->get(), N);
+ }
+
+ /**
+ * Copy another array, using preallocated storage if preAllocCount >=
+ * array.count(). Otherwise storage will only be used when array shrinks
+ * to fit.
+ */
+ template <int N>
+ SkTArray(const SkTArray& array, SkAlignedSTStorage<N,T>* storage) {
+ this->init(array.fItemArray, array.fCount, storage->get(), N);
+ }
+
+ /**
+ * Copy a C array, using preallocated storage if preAllocCount >=
+ * count. Otherwise storage will only be used when array shrinks
+ * to fit.
+ */
+ template <int N>
+ SkTArray(const T* array, int count, SkAlignedSTStorage<N,T>* storage) {
+ this->init(array, count, storage->get(), N);
+ }
+
+ void init(const T* array, int count,
+ void* preAllocStorage, int preAllocOrReserveCount) {
+ SkASSERT(count >= 0);
+ SkASSERT(preAllocOrReserveCount >= 0);
+ fCount = count;
+ fReserveCount = (preAllocOrReserveCount > 0) ?
+ preAllocOrReserveCount :
+ gMIN_ALLOC_COUNT;
+ fPreAllocMemArray = preAllocStorage;
+ if (fReserveCount >= fCount &&
+ NULL != preAllocStorage) {
+ fAllocCount = fReserveCount;
+ fMemArray = preAllocStorage;
+ } else {
+ fAllocCount = SkMax32(fCount, fReserveCount);
+ fMemArray = sk_malloc_throw(fAllocCount * sizeof(T));
+ }
+
+ SkTArrayExt::copy(this, array);
+ }
+
+private:
+
+ static const int gMIN_ALLOC_COUNT = 8;
+
+ inline void checkRealloc(int delta) {
+ SkASSERT(fCount >= 0);
+ SkASSERT(fAllocCount >= 0);
+
+ SkASSERT(-delta <= fCount);
+
+ int newCount = fCount + delta;
+ int newAllocCount = fAllocCount;
+
+ if (newCount > fAllocCount) {
+ newAllocCount = SkMax32(newCount + ((newCount + 1) >> 1),
+ fReserveCount);
+ } else if (newCount < fAllocCount / 3) {
+ newAllocCount = SkMax32(fAllocCount / 2, fReserveCount);
+ }
+
+ if (newAllocCount != fAllocCount) {
+
+ fAllocCount = newAllocCount;
+ char* newMemArray;
+
+ if (fAllocCount == fReserveCount && NULL != fPreAllocMemArray) {
+ newMemArray = (char*) fPreAllocMemArray;
+ } else {
+ newMemArray = (char*) sk_malloc_throw(fAllocCount*sizeof(T));
+ }
+
+ SkTArrayExt::copyAndDelete<T>(this, newMemArray);
+
+ if (fMemArray != fPreAllocMemArray) {
+ sk_free(fMemArray);
+ }
+ fMemArray = newMemArray;
+ }
+ }
+
+ template<typename X> friend void SkTArrayExt::copy(SkTArray<X, true>* that, const X*);
+ template<typename X> friend void SkTArrayExt::copyAndDelete(SkTArray<X, true>* that, char*);
+
+ template<typename X> friend void SkTArrayExt::copy(SkTArray<X, false>* that, const X*);
+ template<typename X> friend void SkTArrayExt::copyAndDelete(SkTArray<X, false>* that, char*);
+
+ int fReserveCount;
+ int fCount;
+ int fAllocCount;
+ void* fPreAllocMemArray;
+ union {
+ T* fItemArray;
+ void* fMemArray;
+ };
+};
+
+/**
+ * Subclass of SkTArray that contains a preallocated memory block for the array.
+ */
+template <int N, typename T, bool DATA_TYPE = false>
+class SkSTArray : public SkTArray<T, DATA_TYPE> {
+private:
+ typedef SkTArray<T, DATA_TYPE> INHERITED;
+
+public:
+ SkSTArray() : INHERITED(&fStorage) {
+ }
+
+ SkSTArray(const SkSTArray& array)
+ : INHERITED(array, &fStorage) {
+ }
+
+ explicit SkSTArray(const INHERITED& array)
+ : INHERITED(array, &fStorage) {
+ }
+
+ SkSTArray(const T* array, int count)
+ : INHERITED(array, count, &fStorage) {
+ }
+
+ SkSTArray& operator= (const SkSTArray& array) {
+ return *this = *(const INHERITED*)&array;
+ }
+
+ SkSTArray& operator= (const INHERITED& array) {
+ INHERITED::operator=(array);
+ return *this;
+ }
+
+private:
+ SkAlignedSTStorage<N,T> fStorage;
+};
+
+#endif
+
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index c64d773..5f62203 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTDArray_DEFINED
#define SkTDArray_DEFINED
@@ -71,7 +64,7 @@ public:
return *this;
}
- friend int operator==(const SkTDArray<T>& a, const SkTDArray<T>& b) {
+ friend bool operator==(const SkTDArray<T>& a, const SkTDArray<T>& b) {
return a.fCount == b.fCount &&
(a.fCount == 0 ||
!memcmp(a.fArray, b.fArray, a.fCount * sizeof(T)));
@@ -98,7 +91,17 @@ public:
}
bool isEmpty() const { return fCount == 0; }
+
+ /**
+ * Return the number of elements in the array
+ */
int count() const { return fCount; }
+
+ /**
+ * return the number of bytes in the array: count * sizeof(T)
+ */
+ size_t bytes() const { return fCount * sizeof(T); }
+
T* begin() const { return fArray; }
T* end() const { return fArray ? fArray + fCount : NULL; }
T& operator[](int index) const {
diff --git a/include/core/SkTDStack.h b/include/core/SkTDStack.h
index 321c138..be34e01 100644
--- a/include/core/SkTDStack.h
+++ b/include/core/SkTDStack.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTDStack_DEFINED
#define SkTDStack_DEFINED
@@ -21,18 +14,16 @@
template <typename T> class SkTDStack : SkNoncopyable {
public:
- SkTDStack() : fCount(0), fTotalCount(0)
- {
+ SkTDStack() : fCount(0), fTotalCount(0) {
fInitialRec.fNext = NULL;
fRec = &fInitialRec;
// fCount = kSlotCount;
}
- ~SkTDStack()
- {
+
+ ~SkTDStack() {
Rec* rec = fRec;
- while (rec != &fInitialRec)
- {
+ while (rec != &fInitialRec) {
Rec* next = rec->fNext;
sk_free(rec);
rec = next;
@@ -43,11 +34,9 @@ public:
int depth() const { return fTotalCount; }
bool empty() const { return fTotalCount == 0; }
- T* push()
- {
+ T* push() {
SkASSERT(fCount <= kSlotCount);
- if (fCount == kSlotCount)
- {
+ if (fCount == kSlotCount) {
Rec* rec = (Rec*)sk_malloc_throw(sizeof(Rec));
rec->fNext = fRec;
fRec = rec;
@@ -56,48 +45,48 @@ public:
++fTotalCount;
return &fRec->fSlots[fCount++];
}
+
void push(const T& elem) { *this->push() = elem; }
- const T& index(int idx) const
- {
+
+ const T& index(int idx) const {
SkASSERT(fRec && fCount > idx);
return fRec->fSlots[fCount - idx - 1];
- }
- T& index(int idx)
- {
+ }
+
+ T& index(int idx) {
SkASSERT(fRec && fCount > idx);
return fRec->fSlots[fCount - idx - 1];
- }
- const T& top() const
- {
+ }
+
+ const T& top() const {
SkASSERT(fRec && fCount > 0);
return fRec->fSlots[fCount - 1];
}
- T& top()
- {
+
+ T& top() {
SkASSERT(fRec && fCount > 0);
return fRec->fSlots[fCount - 1];
}
- void pop(T* elem)
- {
- if (elem)
+
+ void pop(T* elem) {
+ if (elem) {
*elem = fRec->fSlots[fCount - 1];
+ }
this->pop();
}
- void pop()
- {
+
+ void pop() {
SkASSERT(fCount > 0 && fRec);
--fTotalCount;
- if (--fCount == 0)
- {
- if (fRec != &fInitialRec)
- {
+ if (--fCount == 0) {
+ if (fRec != &fInitialRec) {
Rec* rec = fRec->fNext;
sk_free(fRec);
fCount = kSlotCount;
fRec = rec;
- }
- else
+ } else {
SkASSERT(fTotalCount == 0);
+ }
}
}
diff --git a/include/core/SkTDict.h b/include/core/SkTDict.h
index 0b92779..3620899 100644
--- a/include/core/SkTDict.h
+++ b/include/core/SkTDict.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTDict_DEFINED
#define SkTDict_DEFINED
diff --git a/include/core/SkTLazy.h b/include/core/SkTLazy.h
index fecc975..9cfaccb 100644
--- a/include/core/SkTLazy.h
+++ b/include/core/SkTLazy.h
@@ -1,24 +1,18 @@
-/*
- 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.
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTLazy_DEFINED
#define SkTLazy_DEFINED
#include "SkTypes.h"
+#include <new>
/**
* Efficient way to defer allocating/initializing a class until it is needed
@@ -35,14 +29,15 @@ public:
}
SkTLazy(const SkTLazy<T>& src) : fPtr(NULL) {
- const T* ptr = src.get();
- if (ptr) {
- fPtr = new (fStorage) T(*ptr);
+ if (src.isValid()) {
+ fPtr = new (fStorage) T(*src->get());
+ } else {
+ fPtr = NULL;
}
}
~SkTLazy() {
- if (fPtr) {
+ if (this->isValid()) {
fPtr->~T();
}
}
@@ -54,13 +49,13 @@ public:
* always returned.
*/
T* init() {
- if (fPtr) {
+ if (this->isValid()) {
fPtr->~T();
}
- fPtr = new (fStorage) T;
+ fPtr = new (SkTCast<T*>(fStorage)) T;
return fPtr;
}
-
+
/**
* Copy src into this, and return a pointer to a copy of it. Note this
* will always return the same pointer, so if it is called on a lazy that
@@ -68,19 +63,25 @@ public:
* contents.
*/
T* set(const T& src) {
- if (fPtr) {
+ if (this->isValid()) {
*fPtr = src;
} else {
- fPtr = new (fStorage) T(src);
+ fPtr = new (SkTCast<T*>(fStorage)) T(src);
}
return fPtr;
}
+
+ /**
+ * Returns true if a valid object has been initialized in the SkTLazy,
+ * false otherwise.
+ */
+ bool isValid() const { return NULL != fPtr; }
/**
* Returns either NULL, or a copy of the object that was passed to
* set() or the constructor.
*/
- T* get() const { return fPtr; }
+ T* get() const { SkASSERT(this->isValid()); return fPtr; }
private:
T* fPtr; // NULL or fStorage
diff --git a/include/core/SkTRegistry.h b/include/core/SkTRegistry.h
index 78c5a07..34fcffd 100644
--- a/include/core/SkTRegistry.h
+++ b/include/core/SkTRegistry.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright 2009, 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
+ * Copyright 2009 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTRegistry_DEFINED
#define SkTRegistry_DEFINED
@@ -28,7 +21,7 @@ public:
typedef T (*Factory)(P);
SkTRegistry(Factory fact) {
-#ifdef ANDROID
+#ifdef SK_BUILD_FOR_ANDROID
// work-around for double-initialization bug
{
SkTRegistry* reg = gHead;
diff --git a/include/core/SkTScopedPtr.h b/include/core/SkTScopedPtr.h
index 1e5d4c4..580d72f 100644
--- a/include/core/SkTScopedPtr.h
+++ b/include/core/SkTScopedPtr.h
@@ -1,19 +1,12 @@
+
/*
- * 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
+ * Copyright 2011 Google Inc.
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTScopedPtr_DEFINED
#define SkTScopedPtr_DEFINED
diff --git a/include/core/SkTSearch.h b/include/core/SkTSearch.h
index e208071..d5ab18c 100644
--- a/include/core/SkTSearch.h
+++ b/include/core/SkTSearch.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTSearch_DEFINED
#define SkTSearch_DEFINED
diff --git a/include/core/SkTemplates.h b/include/core/SkTemplates.h
index 55109bf..03f0892 100644
--- a/include/core/SkTemplates.h
+++ b/include/core/SkTemplates.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTemplates_DEFINED
#define SkTemplates_DEFINED
@@ -179,36 +172,88 @@ private:
*/
template <typename T> class SkAutoTMalloc : SkNoncopyable {
public:
- SkAutoTMalloc(size_t count)
- {
+ SkAutoTMalloc(size_t count) {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
}
- ~SkAutoTMalloc()
- {
+
+ ~SkAutoTMalloc() {
sk_free(fPtr);
}
+
+ // doesn't preserve contents
+ void reset (size_t count) {
+ sk_free(fPtr);
+ fPtr = fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
+
T* get() const { return fPtr; }
+ operator T*() {
+ return fPtr;
+ }
+
+ operator const T*() const {
+ return fPtr;
+ }
+
+ T& operator[](int index) {
+ return fPtr[index];
+ }
+
+ const T& operator[](int index) const {
+ return fPtr[index];
+ }
+
private:
T* fPtr;
};
-template <size_t N, typename T> class SkAutoSTMalloc : SkNoncopyable {
+template <size_t N, typename T> class SK_API SkAutoSTMalloc : SkNoncopyable {
public:
- SkAutoSTMalloc(size_t count)
- {
- if (count <= N)
+ SkAutoSTMalloc(size_t count) {
+ if (count <= N) {
fPtr = fTStorage;
- else
+ } else {
fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
}
- ~SkAutoSTMalloc()
- {
- if (fPtr != fTStorage)
+
+ ~SkAutoSTMalloc() {
+ if (fPtr != fTStorage) {
sk_free(fPtr);
+ }
}
+
+ // doesn't preserve contents
+ void reset(size_t count) {
+ if (fPtr != fTStorage) {
+ sk_free(fPtr);
+ }
+ if (count <= N) {
+ fPtr = fTStorage;
+ } else {
+ fPtr = (T*)sk_malloc_flags(count * sizeof(T), SK_MALLOC_THROW | SK_MALLOC_TEMP);
+ }
+ }
+
T* get() const { return fPtr; }
+ operator T*() {
+ return fPtr;
+ }
+
+ operator const T*() const {
+ return fPtr;
+ }
+
+ T& operator[](int index) {
+ return fPtr[index];
+ }
+
+ const T& operator[](int index) const {
+ return fPtr[index];
+ }
+
private:
T* fPtr;
union {
@@ -217,5 +262,37 @@ private:
};
};
+/**
+ * Reserves memory that is aligned on double and pointer boundaries.
+ * Hopefully this is sufficient for all practical purposes.
+ */
+template <size_t N> class SkAlignedSStorage : SkNoncopyable {
+public:
+ void* get() { return fData; }
+private:
+ union {
+ void* fPtr;
+ double fDouble;
+ char fData[N];
+ };
+};
+
+/**
+ * Reserves memory that is aligned on double and pointer boundaries.
+ * Hopefully this is sufficient for all practical purposes. Otherwise,
+ * we have to do some arcane trickery to determine alignment of non-POD
+ * types. Lifetime of the memory is the lifetime of the object.
+ */
+template <int N, typename T> class SkAlignedSTStorage : SkNoncopyable {
+public:
+ /**
+ * Returns void* because this object does not initialize the
+ * memory. Use placement new for types that require a cons.
+ */
+ void* get() { return fStorage.get(); }
+private:
+ SkAlignedSStorage<sizeof(T)*N> fStorage;
+};
+
#endif
diff --git a/include/core/SkThread.h b/include/core/SkThread.h
index 637492d..5f2da4a 100644
--- a/include/core/SkThread.h
+++ b/include/core/SkThread.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkThread_DEFINED
#define SkThread_DEFINED
diff --git a/include/core/SkThread_platform.h b/include/core/SkThread_platform.h
index f33f5dc..d83f3ed 100644
--- a/include/core/SkThread_platform.h
+++ b/include/core/SkThread_platform.h
@@ -1,30 +1,62 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkThread_platform_DEFINED
#define SkThread_platform_DEFINED
-#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
+#if defined(SK_BUILD_FOR_ANDROID)
-#include <utils/threads.h>
+#if defined(SK_BUILD_FOR_ANDROID_NDK)
+
+#include <stdint.h>
+
+/* Just use the GCC atomic intrinsics. They're supported by the NDK toolchain,
+ * have reasonable performance, and provide full memory barriers
+ */
+static __attribute__((always_inline)) int32_t sk_atomic_inc(int32_t *addr) {
+ return __sync_fetch_and_add(addr, 1);
+}
+
+static __attribute__((always_inline)) int32_t sk_atomic_dec(int32_t *addr) {
+ return __sync_fetch_and_add(addr, -1);
+}
+
+#else // !SK_BUILD_FOR_ANDROID_NDK
+
+/* The platform atomics operations are slightly more efficient than the
+ * GCC built-ins, so use them.
+ */
#include <utils/Atomic.h>
#define sk_atomic_inc(addr) android_atomic_inc(addr)
#define sk_atomic_dec(addr) android_atomic_dec(addr)
+#endif // !SK_BUILD_FOR_ANDROID_NDK
+
+#else // !SK_BUILD_FOR_ANDROID
+
+/** Implemented by the porting layer, this function adds 1 to the int specified
+ by the address (in a thread-safe manner), and returns the previous value.
+*/
+SK_API int32_t sk_atomic_inc(int32_t* addr);
+/** Implemented by the porting layer, this function subtracts 1 to the int
+ specified by the address (in a thread-safe manner), and returns the previous
+ value.
+*/
+SK_API int32_t sk_atomic_dec(int32_t* addr);
+
+#endif // !SK_BUILD_FOR_ANDROID
+
+#if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
+
+#include <utils/threads.h>
+
class SkMutex : android::Mutex {
public:
// if isGlobal is true, then ignore any errors in the platform-specific
diff --git a/include/core/SkTime.h b/include/core/SkTime.h
index 9ee7110..ede1fd9 100644
--- a/include/core/SkTime.h
+++ b/include/core/SkTime.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTime_DEFINED
#define SkTime_DEFINED
diff --git a/include/core/SkTrace.h b/include/core/SkTrace.h
new file mode 100644
index 0000000..2d48799
--- /dev/null
+++ b/include/core/SkTrace.h
@@ -0,0 +1,47 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTrace_DEFINED
+#define SkTrace_DEFINED
+
+#ifdef SK_USER_TRACE_INCLUDE_FILE
+
+/* If your system embeds skia and has complex event logging, in
+ src/config/SkUserConfig.h:
+ - define the three SK_TRACE_EVENT macros to map to your system's
+ equivalents,
+ - define the name of the include file in SK_USER_TRACE_INCLUDE_FILE
+ A trivial example is given in src/utils/SkDebugTrace.h.
+
+ All arguments are const char*. Skia typically passes the name of
+ the object and function (and sometimes region of interest within
+ the function) separated by double colons for 'event'.
+
+ SK_TRACE_EVENT1 and SK_TRACE_EVENT2 take one or two arbitrary
+ name-value pairs that you also want to log. SkStringPrintf() is useful
+ for formatting these values.
+
+ For example:
+ SK_TRACE_EVENT0("GrContext::createAndLockTexture");
+ SK_TRACE_EVENT1("GrDefaultPathRenderer::onDrawPath::renderPasses",
+ "verts", SkStringPrintf("%i", vert - base).c_str());
+*/
+
+ #include SK_USER_TRACE_INCLUDE_FILE
+
+#else
+
+ #define SK_TRACE_EVENT0(event)
+ #define SK_TRACE_EVENT1(event, name1, value1)
+ #define SK_TRACE_EVENT2(event, name1, value1, name2, value2)
+
+#endif
+
+#endif
+
+
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index e13a21d..03ed11c 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTypeface_DEFINED
#define SkTypeface_DEFINED
@@ -141,10 +134,17 @@ public:
/** Retrieve detailed typeface metrics. Used by the PDF backend.
@param perGlyphInfo Indicate what glyph specific information (advances,
names, etc.) should be populated.
+ @param glyphIDs For per-glyph info, specify subset of the font by
+ giving glyph ids. Each integer represents a glyph
+ id. Passing NULL means all glyphs in the font.
+ @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
+ glyphIDs is NULL.
@return The returned object has already been referenced.
*/
SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo) const;
+ SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ const uint32_t* glyphIDs = NULL,
+ uint32_t glyphIDsCount = 0) const;
protected:
/** uniqueID must be unique (please!) and non-zero
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 1a3a2e5..a584421 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkTypes_DEFINED
#define SkTypes_DEFINED
@@ -43,12 +36,12 @@
/** Called internally if we run out of memory. The platform implementation must
not return, but should either throw an exception or otherwise exit.
*/
-extern void sk_out_of_memory(void);
+SK_API extern void sk_out_of_memory(void);
/** Called internally if we hit an unrecoverable error.
The platform implementation must not return, but should either throw
an exception or otherwise exit.
*/
-extern void sk_throw(void);
+SK_API extern void sk_throw(void);
enum {
SK_MALLOC_TEMP = 0x01, //!< hint to sk_malloc that the requested memory will be freed in the scope of the stack frame
@@ -62,21 +55,35 @@ enum {
SK_API extern void* sk_malloc_flags(size_t size, unsigned flags);
/** Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag
*/
-extern void* sk_malloc_throw(size_t size);
+SK_API extern void* sk_malloc_throw(size_t size);
/** Same as standard realloc(), but this one never returns null on failure. It will throw
an exception if it fails.
*/
-extern void* sk_realloc_throw(void* buffer, size_t size);
+SK_API extern void* sk_realloc_throw(void* buffer, size_t size);
/** Free memory returned by sk_malloc(). It is safe to pass null.
*/
-SK_API extern void sk_free(void*);
+SK_API extern void sk_free(void*);
// bzero is safer than memset, but we can't rely on it, so... sk_bzero()
static inline void sk_bzero(void* buffer, size_t size) {
memset(buffer, 0, size);
}
-///////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef SK_OVERRIDE_GLOBAL_NEW
+#include <new>
+
+inline void* operator new(size_t size) {
+ return sk_malloc_throw(size);
+}
+
+inline void operator delete(void* p) {
+ sk_free(p);
+}
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
#define SK_INIT_TO_AVOID_WARNING = 0
@@ -86,6 +93,7 @@ static inline void sk_bzero(void* buffer, size_t size) {
#ifdef SK_DEBUG
#define SkASSERT(cond) SK_DEBUGBREAK(cond)
+ #define SkDEBUGFAIL(message) SkASSERT(false && message)
#define SkDEBUGCODE(code) code
#define SkDECLAREPARAM(type, var) , type var
#define SkPARAM(var) , var
@@ -94,6 +102,7 @@ static inline void sk_bzero(void* buffer, size_t size) {
#define SkAssertResult(cond) SkASSERT(cond)
#else
#define SkASSERT(cond)
+ #define SkDEBUGFAIL(message)
#define SkDEBUGCODE(code)
#define SkDEBUGF(args)
#define SkDECLAREPARAM(type, var)
@@ -209,6 +218,8 @@ static inline bool SkIsU16(long x) {
*/
#define SkAlign4(x) (((x) + 3) >> 2 << 2)
+#define SkIsAlign4(x) (((x) & 3) == 0)
+
typedef uint32_t SkFourByteTag;
#define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
@@ -394,20 +405,84 @@ private:
SkAutoFree& operator=(const SkAutoFree&);
};
-class SkAutoMalloc : public SkAutoFree {
+/**
+ * Manage an allocated block of heap memory. This object is the sole manager of
+ * the lifetime of the block, so the caller must not call sk_free() or delete
+ * on the block, unless detach() was called.
+ */
+class SkAutoMalloc : public SkNoncopyable {
public:
- explicit SkAutoMalloc(size_t size)
- : SkAutoFree(sk_malloc_flags(size, SK_MALLOC_THROW | SK_MALLOC_TEMP)) {}
+ explicit SkAutoMalloc(size_t size = 0) {
+ fPtr = size ? sk_malloc_throw(size) : NULL;
+ fSize = size;
+ }
+
+ ~SkAutoMalloc() {
+ sk_free(fPtr);
+ }
+
+ /**
+ * Passed to reset to specify what happens if the requested size is smaller
+ * than the current size (and the current block was dynamically allocated).
+ */
+ enum OnShrink {
+ /**
+ * If the requested size is smaller than the current size, and the
+ * current block is dynamically allocated, free the old block and
+ * malloc a new block of the smaller size.
+ */
+ kAlloc_OnShrink,
+
+ /**
+ * If the requested size is smaller than the current size, and the
+ * current block is dynamically allocated, just return the old
+ * block.
+ */
+ kReuse_OnShrink,
+ };
- SkAutoMalloc(size_t size, unsigned flags)
- : SkAutoFree(sk_malloc_flags(size, flags)) {}
- SkAutoMalloc() {}
+ /**
+ * Reallocates the block to a new size. The ptr may or may not change.
+ */
+ void* reset(size_t size, OnShrink shrink = kAlloc_OnShrink) {
+ if (size == fSize || (kReuse_OnShrink == shrink && size < fSize)) {
+ return fPtr;
+ }
+
+ sk_free(fPtr);
+ fPtr = size ? sk_malloc_throw(size) : NULL;
+ fSize = size;
+
+ return fPtr;
+ }
+
+ /**
+ * Releases the block back to the heap
+ */
+ void free() {
+ this->reset(0);
+ }
+
+ /**
+ * Return the allocated block.
+ */
+ void* get() { return fPtr; }
+ const void* get() const { return fPtr; }
- void* alloc(size_t size,
- unsigned flags = (SK_MALLOC_THROW | SK_MALLOC_TEMP)) {
- sk_free(set(sk_malloc_flags(size, flags)));
- return get();
+ /** 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.
+ */
+ void* detach() {
+ void* ptr = fPtr;
+ fPtr = NULL;
+ fSize = 0;
+ return ptr;
}
+
+private:
+ void* fPtr;
+ size_t fSize; // can be larger than the requested size (see kReuse)
};
/**
@@ -420,11 +495,12 @@ template <size_t kSize> class SkAutoSMalloc : SkNoncopyable {
public:
/**
* Creates initially empty storage. get() returns a ptr, but it is to
- * a zero-byte allocation. Must call realloc(size) to return an allocated
+ * a zero-byte allocation. Must call reset(size) to return an allocated
* block.
*/
SkAutoSMalloc() {
fPtr = fStorage;
+ fSize = 0;
}
/**
@@ -434,7 +510,8 @@ public:
*/
explicit SkAutoSMalloc(size_t size) {
fPtr = fStorage;
- this->realloc(size);
+ fSize = 0;
+ this->reset(size);
}
/**
@@ -461,7 +538,13 @@ public:
* then the return block may be allocated locally, rather than from the
* heap.
*/
- void* realloc(size_t size) {
+ void* reset(size_t size,
+ SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink) {
+ if (size == fSize || (SkAutoMalloc::kReuse_OnShrink == shrink &&
+ size < fSize)) {
+ return fPtr;
+ }
+
if (fPtr != (void*)fStorage) {
sk_free(fPtr);
}
@@ -476,13 +559,10 @@ public:
private:
void* fPtr;
+ size_t fSize; // can be larger than the requested size (see kReuse)
uint32_t fStorage[(kSize + 3) >> 2];
- // illegal
- SkAutoSMalloc(const SkAutoSMalloc&);
- SkAutoSMalloc& operator=(const SkAutoSMalloc&);
};
#endif /* C++ */
#endif
-
diff --git a/include/core/SkUnPreMultiply.h b/include/core/SkUnPreMultiply.h
index 44ea50e..7088918 100644
--- a/include/core/SkUnPreMultiply.h
+++ b/include/core/SkUnPreMultiply.h
@@ -1,22 +1,15 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkUnPreMultiply_DEFINED
#define SkUnPreMultiply_DEFINED
diff --git a/include/core/SkUnitMapper.h b/include/core/SkUnitMapper.h
index 5d1ea35..2bd482b 100644
--- a/include/core/SkUnitMapper.h
+++ b/include/core/SkUnitMapper.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkUnitMapper_DEFINED
#define SkUnitMapper_DEFINED
diff --git a/include/core/SkUserConfig.h b/include/core/SkUserConfig.h
index 29e64f2..b409e82 100644
--- a/include/core/SkUserConfig.h
+++ b/include/core/SkUserConfig.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkUserConfig_DEFINED
#define SkUserConfig_DEFINED
@@ -53,11 +46,6 @@
#include <utils/misc.h>
#endif
-#ifdef SK_BUILD_FOR_MAC
- #undef SK_BUILD_FOR_MAC
-#endif
-#define SK_BUILD_FOR_UNIX
-
/* Scalars (the fractional value type in skia) can be implemented either as
floats or 16.16 integers (fixed). Exactly one of these two symbols must be
defined.
@@ -68,7 +56,7 @@
/* Somewhat independent of how SkScalar is implemented, Skia also wants to know
if it can use floats at all. Naturally, if SK_SCALAR_IS_FLOAT is defined,
- then so muse SK_CAN_USE_FLOAT, but if scalars are fixed, SK_CAN_USE_FLOAT
+ SK_CAN_USE_FLOAT must be too; but if scalars are fixed, SK_CAN_USE_FLOAT
can go either way.
*/
#define SK_CAN_USE_FLOAT
@@ -119,25 +107,22 @@
#define SkLONGLONG int64_t
-/* Some envorinments do not suport writable globals (eek!). If yours does not,
- define this flag.
- */
-//#define SK_USE_RUNTIME_GLOBALS
-
-
/* To write debug messages to a console, skia will call SkDebugf(...) following
printf conventions (e.g. const char* format, ...). If you want to redirect
this to something other than printf, define yours here
*/
-#define SkDebugf(...) Android_SkDebugf(__FILE__, __LINE__, \
- __FUNCTION__, __VA_ARGS__)
-void Android_SkDebugf(const char* file, int line,
- const char* function, const char* format, ...);
+//#define SkDebugf(...) MyFunction(__VA_ARGS__)
-/* To enable additional blitters (and fontscaler code) to support separate
- alpha channels for R G B channels, define SK_SUPPORT_LCDTEXT
+/*
+ * To specify a different default font cache limit, define this. If this is
+ * undefined, skia will use a built-in value.
*/
-//#define SK_SUPPORT_LCDTEXT
+//#define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
+
+/* If defined, use CoreText instead of ATSUI on OS X.
+*/
+//#define SK_USE_MAC_CORE_TEXT
+
/* If zlib is available and you want to support the flate compression
algorithm (used in PDF generation), define SK_ZLIB_INCLUDE to be the
@@ -150,11 +135,22 @@ void Android_SkDebugf(const char* file, int line,
*/
//#define SK_ALLOW_LARGE_PDF_SCALARS
+/* Define this to provide font subsetter in PDF generation.
+ */
+//#define SK_SFNTLY_SUBSETTER "sfntly/subsetter/font_subsetter.h"
+
/* Define this to remove dimension checks on bitmaps. Not all blits will be
correct yet, so this is mostly for debugging the implementation.
*/
//#define SK_ALLOW_OVER_32K_BITMAPS
+/* Define this to set the upper limit for text to support LCD. Values that
+ are very large increase the cost in the font cache and draw slower, without
+ improving readability. If this is undefined, Skia will use its default
+ value (e.g. 48)
+ */
+//#define SK_MAX_SIZE_FOR_LCDTEXT 48
+
/* If SK_DEBUG is defined, then you can optionally define SK_SUPPORT_UNITTEST
which will run additional self-tests at startup. These can take a long time,
so this flag is optional.
@@ -163,6 +159,18 @@ void Android_SkDebugf(const char* file, int line,
#define SK_SUPPORT_UNITTEST
#endif
+/* If your system embeds skia and has complex event logging, define this
+ symbol to name a file that maps the following macros to your system's
+ equivalents:
+ SK_TRACE_EVENT0(event)
+ SK_TRACE_EVENT1(event, name1, value1)
+ SK_TRACE_EVENT2(event, name1, value1, name2, value2)
+ src/utils/SkDebugTrace.h has a trivial implementation that writes to
+ the debug output stream. If SK_USER_TRACE_INCLUDE_FILE is not defined,
+ SkTrace.h will define the above three macros to do nothing.
+*/
+//#undef SK_USER_TRACE_INCLUDE_FILE
+
/* Change the ordering to work in X windows.
*/
#ifdef SK_SAMPLES_FOR_X
@@ -173,4 +181,3 @@ void Android_SkDebugf(const char* file, int line,
#endif
#endif
-
diff --git a/include/core/SkUtils.h b/include/core/SkUtils.h
index a346d48..b700b96 100644
--- a/include/core/SkUtils.h
+++ b/include/core/SkUtils.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkUtils_DEFINED
#define SkUtils_DEFINED
@@ -39,13 +32,6 @@ 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();
-#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)
- #define sk_memset32(dst, value, count) android_memset32(dst, value, (count) << 2)
-#endif
-
#ifndef sk_memset16
extern SkMemset16Proc sk_memset16;
#endif
@@ -98,6 +84,21 @@ size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
char utf8[] = NULL);
+inline bool SkUnichar_IsVariationSelector(SkUnichar uni) {
+/* The 'true' ranges are:
+ * 0x180B <= uni <= 0x180D
+ * 0xFE00 <= uni <= 0xFE0F
+ * 0xE0100 <= uni <= 0xE01EF
+ */
+ if (uni < 0x180B || uni > 0xE01EF) {
+ return false;
+ }
+ if ((uni > 0x180D && uni < 0xFE00) || (uni > 0xFE0F && uni < 0xE0100)) {
+ return false;
+ }
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////
class SkAutoTrace {
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index c8ebb6a..d7159ff 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2008 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
+ * Copyright 2008 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkWriter32_DEFINED
#define SkWriter32_DEFINED
@@ -28,11 +21,13 @@ class SkWStream;
class SkWriter32 : SkNoncopyable {
public:
- SkWriter32(size_t minSize) {
- fMinSize = minSize;
- fSize = 0;
- fHead = fTail = NULL;
- fSingleBlock = NULL;
+ SkWriter32(size_t minSize)
+ : fMinSize(minSize),
+ fSize(0),
+ fSingleBlock(NULL),
+ fSingleBlockSize(0),
+ fHead(NULL),
+ fTail(NULL) {
}
~SkWriter32();
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 6ab9d6d..0d1c207 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -1,19 +1,12 @@
+
/*
- * Copyright (C) 2006 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
+ * Copyright 2006 The Android Open Source Project
*
- * 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.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
*/
+
#ifndef SkXfermode_DEFINED
#define SkXfermode_DEFINED
@@ -138,6 +131,18 @@ public:
*/
static bool AsMode(SkXfermode*, Mode* mode);
+ /**
+ * Returns true if the xfermode claims to be the specified Mode. This works
+ * correctly even if the xfermode is NULL (which equates to kSrcOver.) Thus
+ * you can say this without checking for a null...
+ *
+ * If (SkXfermode::IsMode(paint.getXfermode(),
+ * SkXfermode::kDstOver_Mode)) {
+ * ...
+ * }
+ */
+ static bool IsMode(SkXfermode* xfer, Mode mode);
+
/** Return an SkXfermode object for the specified mode.
*/
static SkXfermode* Create(Mode mode);
@@ -167,6 +172,7 @@ public:
return AsMode(xfer, mode);
}
+ SK_DECLARE_FLATTENABLE_REGISTRAR()
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}
@@ -200,21 +206,26 @@ public:
// overrides from SkXfermode
virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]);
+ const SkAlpha aa[]) SK_OVERRIDE;
virtual void xfer16(uint16_t dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]);
+ const SkAlpha aa[]) SK_OVERRIDE;
virtual void xfer4444(uint16_t dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]);
+ const SkAlpha aa[]) SK_OVERRIDE;
virtual void xferA8(SkAlpha dst[], const SkPMColor src[], int count,
- const SkAlpha aa[]);
+ const SkAlpha aa[]) SK_OVERRIDE;
// overrides from SkFlattenable
- virtual Factory getFactory() { return CreateProc; }
- virtual void flatten(SkFlattenableWriteBuffer&);
+ virtual Factory getFactory() SK_OVERRIDE { return CreateProc; }
+ virtual void flatten(SkFlattenableWriteBuffer&) SK_OVERRIDE;
protected:
SkProcXfermode(SkFlattenableReadBuffer&);
+ // allow subclasses to update this after we unflatten
+ void setProc(SkXfermodeProc proc) {
+ fProc = proc;
+ }
+
private:
SkXfermodeProc fProc;