aboutsummaryrefslogtreecommitdiffstats
path: root/include/graphics
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:50 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:04:50 -0800
commit37df15a82319228ae28fe5d99c010b288aad7091 (patch)
tree6095cbf78077958db35a6e58e14aefedb2bff6a9 /include/graphics
parent262917823441f183fa67aa63b9c0ec4e52cce4c3 (diff)
downloadexternal_skia-37df15a82319228ae28fe5d99c010b288aad7091.zip
external_skia-37df15a82319228ae28fe5d99c010b288aad7091.tar.gz
external_skia-37df15a82319228ae28fe5d99c010b288aad7091.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'include/graphics')
-rw-r--r--include/graphics/SkBitmap.h9
-rw-r--r--include/graphics/SkBlurDrawLooper.h7
-rw-r--r--include/graphics/SkCanvas.h25
-rw-r--r--include/graphics/SkDrawLooper.h7
-rw-r--r--include/graphics/SkDumpCanvas.h139
-rw-r--r--include/graphics/SkFlattenable.h6
-rw-r--r--include/graphics/SkFlipPixelRef.h114
-rw-r--r--include/graphics/SkFontHost.h29
-rw-r--r--include/graphics/SkImageDecoder.h7
-rw-r--r--include/graphics/SkImageRef.h8
-rw-r--r--include/graphics/SkLayerDrawLooper.h70
-rw-r--r--include/graphics/SkPaint.h29
-rw-r--r--include/graphics/SkPath.h2
-rw-r--r--include/graphics/SkPicture.h6
-rw-r--r--include/graphics/SkPixelRef.h12
-rw-r--r--include/graphics/SkProxyCanvas.h90
-rw-r--r--include/graphics/SkScalerContext.h13
-rw-r--r--include/graphics/SkString.h168
-rw-r--r--include/graphics/SkUtils.h140
19 files changed, 551 insertions, 330 deletions
diff --git a/include/graphics/SkBitmap.h b/include/graphics/SkBitmap.h
index e446a01..02c8cd9 100644
--- a/include/graphics/SkBitmap.h
+++ b/include/graphics/SkBitmap.h
@@ -172,6 +172,9 @@ public:
static int ComputeShiftPerPixel(Config c) {
return ComputeBytesPerPixel(c) >> 1;
}
+
+ static Sk64 ComputeSize64(Config, int width, int height);
+ static size_t ComputeSize(Config, int width, int height);
/** Set the bitmap's config and dimensions. If rowBytes is 0, then
ComputeRowBytes() is called to compute the optimal value. This resets
@@ -603,6 +606,12 @@ public:
fCTable = bm.getColorTable();
fColors = fCTable ? fCTable->lockColors() : NULL;
}
+ /** Initialize with a colortable (may be null)
+ */
+ explicit SkAutoLockColors(SkColorTable* ctable) {
+ fCTable = ctable;
+ fColors = ctable ? ctable->lockColors() : NULL;
+ }
~SkAutoLockColors() {
if (fCTable) {
fCTable->unlockColors(false);
diff --git a/include/graphics/SkBlurDrawLooper.h b/include/graphics/SkBlurDrawLooper.h
index ae42393..028b2eb 100644
--- a/include/graphics/SkBlurDrawLooper.h
+++ b/include/graphics/SkBlurDrawLooper.h
@@ -37,6 +37,10 @@ public:
virtual bool next();
virtual void restore();
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
+ return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
+ }
+
protected:
SkBlurDrawLooper(SkFlattenableReadBuffer&);
// overrides from SkFlattenable
@@ -44,9 +48,6 @@ protected:
virtual Factory getFactory() { return CreateProc; }
private:
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return SkNEW_ARGS(SkBlurDrawLooper, (buffer)); }
-
SkCanvas* fCanvas;
SkPaint* fPaint;
SkMaskFilter* fBlur;
diff --git a/include/graphics/SkCanvas.h b/include/graphics/SkCanvas.h
index 12fd9c3..a19a5ae 100644
--- a/include/graphics/SkCanvas.h
+++ b/include/graphics/SkCanvas.h
@@ -25,6 +25,7 @@
#include "SkPorterDuff.h"
#include "SkPath.h"
#include "SkRegion.h"
+#include "SkScalarCompare.h"
class SkBounder;
class SkDevice;
@@ -310,7 +311,7 @@ public:
in a way similar to quickReject, in that it tells you that drawing
outside of these bounds will be clipped out.
*/
- bool getClipBounds(SkRect* bounds) const;
+ bool getClipBounds(SkRect* bounds, EdgeType et = kAA_EdgeType) const;
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
specified ARGB color, using the specified PorterDuff mode.
@@ -704,6 +705,7 @@ public:
SkDevice* device() const;
const SkMatrix& matrix() const;
const SkRegion& clip() const;
+ const SkPaint& paint() const;
int x() const;
int y() const;
@@ -711,9 +713,11 @@ public:
// used to embed the SkDrawIter object directly in our instance, w/o
// having to expose that class def to the public. There is an assert
// in our constructor to ensure that fStorage is large enough
- // (though needs to be a compile-time-assert!)
- uint32_t fStorage[11];
+ // (though needs to be a compile-time-assert!). We use intptr_t to work
+ // safely with 32 and 64 bit machines (to ensure the storage is enough)
+ intptr_t fStorage[12];
class SkDrawIter* fImpl; // this points at fStorage
+ SkPaint fDefaultPaint;
bool fDone;
};
@@ -747,6 +751,21 @@ private:
// shared by save() and saveLayer()
int internalSave(SaveFlags flags);
void internalRestore();
+
+ /* These maintain a cache of the clip bounds in local coordinates,
+ (converted to 2s-compliment if floats are slow).
+ */
+ mutable SkRectCompareType fLocalBoundsCompareType;
+ mutable bool fLocalBoundsCompareTypeDirty;
+
+ const SkRectCompareType& getLocalClipBoundsCompareType() const {
+ if (fLocalBoundsCompareTypeDirty) {
+ this->computeLocalClipBoundsCompareType();
+ fLocalBoundsCompareTypeDirty = false;
+ }
+ return fLocalBoundsCompareType;
+ }
+ void computeLocalClipBoundsCompareType() const;
};
/** Stack helper class to automatically call restoreToCount() on the canvas
diff --git a/include/graphics/SkDrawLooper.h b/include/graphics/SkDrawLooper.h
index e46576c..333fb41 100644
--- a/include/graphics/SkDrawLooper.h
+++ b/include/graphics/SkDrawLooper.h
@@ -52,6 +52,13 @@ public:
loop?
*/
virtual void restore() {}
+
+protected:
+ SkDrawLooper() {}
+ SkDrawLooper(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {}
+
+private:
+ typedef SkFlattenable INHERITED;
};
#endif
diff --git a/include/graphics/SkDumpCanvas.h b/include/graphics/SkDumpCanvas.h
new file mode 100644
index 0000000..b919627
--- /dev/null
+++ b/include/graphics/SkDumpCanvas.h
@@ -0,0 +1,139 @@
+#ifndef SkDumpCanvas_DEFINED
+#define SkDumpCanvas_DEFINED
+
+#include "SkCanvas.h"
+
+/** This class overrides all the draw methods on SkCanvas, and formats them
+ as text, and then sends that to a Dumper helper object.
+
+ Typical use might be to dump a display list to a log file to see what is
+ being drawn.
+ */
+class SkDumpCanvas : public SkCanvas {
+public:
+ class Dumper;
+
+ explicit SkDumpCanvas(Dumper* = 0);
+ virtual ~SkDumpCanvas();
+
+ enum Verb {
+ kNULL_Verb,
+
+ kSave_Verb,
+ kRestore_Verb,
+
+ kMatrix_Verb,
+
+ kClip_Verb,
+
+ kDrawPaint_Verb,
+ kDrawPoints_Verb,
+ kDrawRect_Verb,
+ kDrawPath_Verb,
+ kDrawBitmap_Verb,
+ kDrawText_Verb,
+ kDrawPicture_Verb,
+ kDrawVertices_Verb
+ };
+
+ /** Subclasses of this are installed on the DumpCanvas, and then called for
+ each drawing command.
+ */
+ class Dumper : public SkRefCnt {
+ public:
+ virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
+ const SkPaint*) = 0;
+ };
+
+ Dumper* getDumper() const { return fDumper; }
+ void setDumper(Dumper*);
+
+ // overrides from SkCanvas
+
+ virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
+ virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags = kARGB_ClipLayer_SaveFlag);
+ virtual void restore();
+
+ virtual bool translate(SkScalar dx, SkScalar dy);
+ virtual bool scale(SkScalar sx, SkScalar sy);
+ virtual bool rotate(SkScalar degrees);
+ virtual bool skew(SkScalar sx, SkScalar sy);
+ virtual bool concat(const SkMatrix& matrix);
+ virtual void setMatrix(const SkMatrix& matrix);
+
+ virtual bool clipRect(const SkRect& rect,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+ virtual bool clipPath(const SkPath& path,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+ virtual bool clipRegion(const SkRegion& deviceRgn,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+
+ virtual void drawPaint(const SkPaint& paint);
+ virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
+ const SkPaint& paint);
+ virtual void drawRect(const SkRect& rect, const SkPaint& paint);
+ virtual void drawPath(const SkPath& path, const SkPaint& paint);
+ virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
+ const SkPaint* paint = NULL);
+ virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
+ const SkRect& dst, const SkPaint* paint = NULL);
+ virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
+ const SkPaint* paint = NULL);
+ virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
+ const SkPaint* paint = NULL);
+ virtual void drawText(const void* text, size_t byteLength, SkScalar x,
+ SkScalar y, const SkPaint& paint);
+ virtual void drawPosText(const void* text, size_t byteLength,
+ const SkPoint pos[], const SkPaint& paint);
+ virtual void drawPosTextH(const void* text, size_t byteLength,
+ const SkScalar xpos[], SkScalar constY,
+ const SkPaint& paint);
+ virtual void drawTextOnPath(const void* text, size_t byteLength,
+ const SkPath& path, const SkMatrix* matrix,
+ const SkPaint& paint);
+ virtual void drawPicture(SkPicture& picture);
+ virtual void drawVertices(VertexMode vmode, int vertexCount,
+ const SkPoint vertices[], const SkPoint texs[],
+ const SkColor colors[], SkXfermode* xmode,
+ const uint16_t indices[], int indexCount,
+ const SkPaint& paint);
+
+private:
+ Dumper* fDumper;
+
+ void dump(Verb, const SkPaint*, const char format[], ...);
+
+ typedef SkCanvas INHERITED;
+};
+
+/** Formats the draw commands, and send them to a function-pointer provided
+ by the caller.
+ */
+class SkFormatDumper : public SkDumpCanvas::Dumper {
+public:
+ SkFormatDumper(void (*)(const char text[], void* refcon), void* refcon);
+
+ // override from baseclass that does the formatting, and in turn calls
+ // the function pointer that was passed to the constructor
+ virtual void dump(SkDumpCanvas*, SkDumpCanvas::Verb, const char str[],
+ const SkPaint*);
+
+private:
+ void (*fProc)(const char*, void*);
+ void* fRefcon;
+
+ typedef SkDumpCanvas::Dumper INHERITED;
+};
+
+/** Subclass of Dumper that dumps the drawing command to SkDebugf
+ */
+class SkDebugfDumper : public SkFormatDumper {
+public:
+ SkDebugfDumper();
+
+private:
+ typedef SkFormatDumper INHERITED;
+};
+
+#endif
diff --git a/include/graphics/SkFlattenable.h b/include/graphics/SkFlattenable.h
index d23e20f..6958462 100644
--- a/include/graphics/SkFlattenable.h
+++ b/include/graphics/SkFlattenable.h
@@ -25,6 +25,7 @@
class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
+class SkString;
/** \class SkFlattenable
@@ -49,6 +50,11 @@ public:
*/
virtual void flatten(SkFlattenableWriteBuffer&);
+ /** Set the string to describe the sublass and return true. If this is not
+ overridden, ignore the string param and return false.
+ */
+ virtual bool toDumpString(SkString*) const;
+
static Factory NameToFactory(const char name[]);
static const char* FactoryToName(Factory);
static void Register(const char name[], Factory);
diff --git a/include/graphics/SkFlipPixelRef.h b/include/graphics/SkFlipPixelRef.h
new file mode 100644
index 0000000..3b4e97a
--- /dev/null
+++ b/include/graphics/SkFlipPixelRef.h
@@ -0,0 +1,114 @@
+/*
+ * 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
+ *
+ * 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 SkFlipPixelRef_DEFINED
+#define SkFlipPixelRef_DEFINED
+
+#include "SkBitmap.h"
+#include "SkPageFlipper.h"
+#include "SkPixelRef.h"
+#include "SkThread.h"
+
+class SkRegion;
+
+class SkFlipPixelRef : public SkPixelRef {
+public:
+ SkFlipPixelRef(SkBitmap::Config, int width, int height);
+ virtual ~SkFlipPixelRef();
+
+ bool isDirty() const { return fFlipper.isDirty(); }
+ const SkRegion& dirtyRgn() const { return fFlipper.dirtyRgn(); }
+
+ void inval() { fFlipper.inval(); }
+ void inval(const SkIRect& rect) { fFlipper.inval(rect); }
+ void inval(const SkRegion& rgn) { fFlipper.inval(rgn); }
+ void inval(const SkRect& r, bool doAA) { fFlipper.inval(r, doAA); }
+
+ const SkRegion& beginUpdate(SkBitmap* device);
+ void endUpdate();
+
+private:
+ void getFrontBack(const void** front, void** back) const {
+ if (front) {
+ *front = fPage0;
+ }
+ if (back) {
+ *back = fPage1;
+ }
+ }
+
+ void swapPages();
+
+ // Helper to copy pixels from srcAddr to the dst bitmap, clipped to clip.
+ // srcAddr points to memory with the same config as dst.
+ static void CopyBitsFromAddr(const SkBitmap& dst, const SkRegion& clip,
+ const void* srcAddr);
+
+ // serialization
+
+public:
+ virtual Factory getFactory() const { return Create; }
+ virtual void flatten(SkFlattenableWriteBuffer&) const;
+ static SkPixelRef* Create(SkFlattenableReadBuffer& buffer);
+
+protected:
+ virtual void* onLockPixels(SkColorTable**);
+ virtual void onUnlockPixels();
+
+ SkFlipPixelRef(SkFlattenableReadBuffer&);
+
+private:
+ SkMutex fMutex;
+ SkPageFlipper fFlipper;
+
+ void* fStorage;
+ void* fPage0; // points into fStorage;
+ void* fPage1; // points into fStorage;
+ size_t fSize; // size of 1 page. fStorage holds 2 pages
+ SkBitmap::Config fConfig;
+
+ typedef SkPixelRef INHERITED;
+};
+
+class SkAutoFlipUpdate : SkNoncopyable {
+public:
+ SkAutoFlipUpdate(SkFlipPixelRef* ref) : fRef(ref) {
+ fDirty = &ref->beginUpdate(&fBitmap);
+ }
+ ~SkAutoFlipUpdate() {
+ if (fRef) {
+ fRef->endUpdate();
+ }
+ }
+
+ const SkBitmap& bitmap() const { return fBitmap; }
+ const SkRegion& dirty() const { return *fDirty; }
+
+ // optional. This gets automatically called in the destructor (only once)
+ void endUpdate() {
+ if (fRef) {
+ fRef->endUpdate();
+ fRef = NULL;
+ }
+ }
+
+private:
+ SkFlipPixelRef* fRef;
+ SkBitmap fBitmap;
+ const SkRegion* fDirty;
+};
+
+#endif
diff --git a/include/graphics/SkFontHost.h b/include/graphics/SkFontHost.h
index 73010e7..ede40b7 100644
--- a/include/graphics/SkFontHost.h
+++ b/include/graphics/SkFontHost.h
@@ -37,24 +37,38 @@ public:
1) If familyFace is null, use famillyName.
2) If famillyName is null, use familyFace.
3) If both are null, return the default font that best matches style
- */
+
+ NOTE: this does not return a new typeface, nor does it affect the
+ owner count of an existing one, so the caller is free to ignore the
+ return result, or just compare it against null.
+ */
static SkTypeface* FindTypeface(const SkTypeface* familyFace,
const char famillyName[],
SkTypeface::Style style);
/** Return the typeface associated with the uniqueID, or null if that ID
does not match any faces.
+
+ NOTE: this does not return a new typeface, nor does it affect the
+ owner count of an existing one, so the caller is free to ignore the
+ return result, or just compare it against null.
*/
static SkTypeface* ResolveTypeface(uint32_t uniqueID);
/** Return a new stream to read the font data, or null if the uniqueID does
- not match an existing typeface
+ not match an existing typeface. The caller must call CloseStream() when
+ it is finished reading the stream.
*/
static SkStream* OpenStream(uint32_t uniqueID);
+
+ /** Call this when finished reading from the stream returned by OpenStream.
+ The caller should NOT try to delete the stream.
+ */
static void CloseStream(uint32_t uniqueID, SkStream*);
/** Return a new typeface given the data buffer (owned by the caller).
- If the data does not represent a valid font, return null.
+ If the data does not represent a valid font, return null. The caller is
+ responsible for unref-ing the returned typeface (if it is not null).
*/
static SkTypeface* CreateTypeface(SkStream*);
@@ -64,6 +78,14 @@ public:
be retrieved with Deserialize().
*/
static void Serialize(const SkTypeface*, SkWStream*);
+
+ /** Given a stream created by Serialize(), return the corresponding typeface
+ or null if no match is found.
+
+ NOTE: this does not return a new typeface, nor does it affect the
+ owner count of an existing one, so the caller is free to ignore the
+ return result, or just compare it against null.
+ */
static SkTypeface* Deserialize(SkStream*);
///////////////////////////////////////////////////////////////////////////
@@ -71,6 +93,7 @@ public:
/** Return a subclass of SkScalarContext
*/
static SkScalerContext* CreateScalerContext(const SkDescriptor* desc);
+
/** Return a scalercontext using the "fallback" font. If there is no designated
fallback, return null.
*/
diff --git a/include/graphics/SkImageDecoder.h b/include/graphics/SkImageDecoder.h
index e6389e4..4a18cab 100644
--- a/include/graphics/SkImageDecoder.h
+++ b/include/graphics/SkImageDecoder.h
@@ -279,12 +279,17 @@ public:
static SkImageEncoder* Create(Type);
virtual ~SkImageEncoder();
-
+
/* Quality ranges from 0..100 */
bool encodeFile(const char file[], const SkBitmap&, int quality = 80);
bool encodeStream(SkWStream*, const SkBitmap&, int quality = 80);
+ static bool EncodeFile(const char file[], const SkBitmap&, Type,
+ int quality = 80);
+ static bool EncodeStream(SkWStream*, const SkBitmap&, Type,
+ int quality = 80);
+
protected:
virtual bool onEncode(SkWStream*, const SkBitmap&, int quality) = 0;
};
diff --git a/include/graphics/SkImageRef.h b/include/graphics/SkImageRef.h
index 7462d4e..e94b7d4 100644
--- a/include/graphics/SkImageRef.h
+++ b/include/graphics/SkImageRef.h
@@ -44,12 +44,12 @@ public:
SkImageRef(SkStream*, SkBitmap::Config config, int sampleSize = 1);
virtual ~SkImageRef();
- const char* getName() const { return fName.c_str(); }
- void setName(const char name[]) { fName.set(name); }
-
/** Return true if the image can be decoded. If so, and bitmap is non-null,
call its setConfig() with the corresponding values, but explicitly will
not set its pixels or colortable. Use SkPixelRef::lockPixels() for that.
+
+ If there has been an error decoding the bitmap, this will return false
+ and ignore the bitmap parameter.
*/
bool getInfo(SkBitmap* bm);
@@ -85,8 +85,6 @@ private:
SkBitmap::Config fConfig;
int fSampleSize;
bool fErrorInDecoding;
-
- SkString fName; // for debugging
friend class SkImageRefPool;
diff --git a/include/graphics/SkLayerDrawLooper.h b/include/graphics/SkLayerDrawLooper.h
new file mode 100644
index 0000000..670ac23
--- /dev/null
+++ b/include/graphics/SkLayerDrawLooper.h
@@ -0,0 +1,70 @@
+#ifndef SkLayerDrawLooper_DEFINED
+#define SkLayerDrawLooper_DEFINED
+
+#include "SkDrawLooper.h"
+
+struct SkPoint;
+
+class SkLayerDrawLooper : public SkDrawLooper {
+public:
+ SkLayerDrawLooper();
+ virtual ~SkLayerDrawLooper();
+
+ /** Call for each layer you want to add (from top to bottom).
+ This returns a paint you can modify, but that ptr is only valid until
+ the next call made to this object.
+ */
+ SkPaint* addLayer(SkScalar dx, SkScalar dy);
+
+ /** Helper for addLayer() which passes (0, 0) for the offset parameters
+ */
+ SkPaint* addLayer() {
+ return this->addLayer(0, 0);
+ }
+
+ // overrides from SkDrawLooper
+ virtual void init(SkCanvas*, SkPaint*);
+ virtual bool next();
+ virtual void restore();
+
+ // must be public for Registrar :(
+ static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
+ return SkNEW_ARGS(SkLayerDrawLooper, (buffer));
+ }
+
+protected:
+ SkLayerDrawLooper(SkFlattenableReadBuffer&);
+
+ // overrides from SkFlattenable
+ virtual void flatten(SkFlattenableWriteBuffer& );
+ virtual Factory getFactory() { return CreateProc; }
+
+private:
+ struct Rec {
+ Rec* fNext;
+ SkPaint fPaint;
+ SkPoint fOffset;
+
+ static Rec* Reverse(Rec*);
+ };
+ Rec* fRecs;
+ int fCount;
+
+ struct Iter {
+ SkPaint fSavedPaint;
+ SkPaint* fPaint;
+ SkCanvas* fCanvas;
+ Rec* fRec;
+ };
+ Iter fIter;
+
+ class MyRegistrar : public SkFlattenable::Registrar {
+ public:
+ MyRegistrar();
+ };
+
+ typedef SkDrawLooper INHERITED;
+};
+
+
+#endif
diff --git a/include/graphics/SkPaint.h b/include/graphics/SkPaint.h
index 6906b96..fc390ab 100644
--- a/include/graphics/SkPaint.h
+++ b/include/graphics/SkPaint.h
@@ -367,6 +367,35 @@ public:
*/
bool getFillPath(const SkPath& src, SkPath* dst) const;
+ /** Returns true if the current paint settings allow for fast computation of
+ bounds (i.e. there is nothing complex like a patheffect that would make
+ the bounds computation expensive.
+ */
+ bool canComputeFastBounds() const;
+
+ /** Only call this if canComputeFastBounds() returned true. This takes a
+ raw rectangle (the raw bounds of a shape), and adjusts it for stylistic
+ effects in the paint (e.g. stroking). If needed, it uses the storage
+ rect parameter. It returns the adjusted bounds that can then be used
+ for quickReject tests.
+
+ The returned rect will either be orig or storage, thus the caller
+ should not rely on storage being set to the result, but should always
+ use the retured value. It is legal for orig and storage to be the same
+ rect.
+
+ e.g.
+ if (paint.canComputeFastBounds()) {
+ SkRect r, storage;
+ path.computeBounds(&r, SkPath::kFast_BoundsType);
+ const SkRect& fastR = paint.computeFastBounds(r, &storage);
+ if (canvas->quickReject(fastR, ...)) {
+ // don't draw the path
+ }
+ }
+ */
+ const SkRect& computeFastBounds(const SkRect& orig, SkRect* storage) const;
+
/** Get the paint's shader object.
<p />
The shader's reference count is not affected.
diff --git a/include/graphics/SkPath.h b/include/graphics/SkPath.h
index 821c549..e2409ad 100644
--- a/include/graphics/SkPath.h
+++ b/include/graphics/SkPath.h
@@ -22,6 +22,7 @@
class SkFlattenableReadBuffer;
class SkFlattenableWriteBuffer;
+class SkAutoPathBoundsUpdate;
class SkString;
/** \class SkPath
@@ -580,6 +581,7 @@ private:
void reversePathTo(const SkPath&);
friend const SkPoint* sk_get_path_points(const SkPath&, int index);
+ friend class SkAutoPathBoundsUpdate;
};
#endif
diff --git a/include/graphics/SkPicture.h b/include/graphics/SkPicture.h
index 46d189c..fa614c9 100644
--- a/include/graphics/SkPicture.h
+++ b/include/graphics/SkPicture.h
@@ -86,6 +86,12 @@ public:
void serialize(SkWStream*) const;
+ /** Signals that the caller is prematurely done replaying the drawing
+ commands. This can be called from a canvas virtual while the picture
+ is drawing. Has no effect if the picture is not drawing.
+ */
+ void abortPlayback();
+
private:
int fWidth, fHeight;
SkPictureRecord* fRecord;
diff --git a/include/graphics/SkPixelRef.h b/include/graphics/SkPixelRef.h
index 0ddfedc..82e5ca7 100644
--- a/include/graphics/SkPixelRef.h
+++ b/include/graphics/SkPixelRef.h
@@ -89,9 +89,15 @@ public:
*/
const char* getURI() const { return fURI.size() ? fURI.c_str() : NULL; }
- /** Assign a URI string to this pixelref. If not null, the string is copied.
- */
- void setURI(const char uri[], size_t len = (size_t)-1) {
+ /** Copy a URI string to this pixelref, or clear the URI if the uri is null
+ */
+ void setURI(const char uri[]) {
+ fURI.set(uri);
+ }
+
+ /** Copy a URI string to this pixelref
+ */
+ void setURI(const char uri[], size_t len) {
fURI.set(uri, len);
}
diff --git a/include/graphics/SkProxyCanvas.h b/include/graphics/SkProxyCanvas.h
new file mode 100644
index 0000000..1bc411a
--- /dev/null
+++ b/include/graphics/SkProxyCanvas.h
@@ -0,0 +1,90 @@
+#ifndef SkProxyCanvas_DEFINED
+#define SkProxyCanvas_DEFINED
+
+#include "SkCanvas.h"
+
+/** This class overrides all virtual methods on SkCanvas, and redirects them
+ to a "proxy", another SkCanvas instance. It can be the basis for
+ intercepting (and possibly modifying) calls to a canvas.
+
+ There must be a proxy installed before the proxycanvas can be used (i.e.
+ before its virtual methods can be called).
+ */
+class SkProxyCanvas : public SkCanvas {
+public:
+ SkProxyCanvas() : fProxy(NULL) {}
+ SkProxyCanvas(SkCanvas* proxy);
+ virtual ~SkProxyCanvas();
+
+ SkCanvas* getProxy() const { return fProxy; }
+ void setProxy(SkCanvas* proxy);
+
+ // overrides from SkCanvas
+
+ virtual bool getViewport(SkIPoint* size) const;
+ virtual bool setViewport(int x, int y);
+
+ virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
+
+ virtual int save(SaveFlags flags = kMatrixClip_SaveFlag);
+ virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
+ SaveFlags flags = kARGB_ClipLayer_SaveFlag);
+ virtual void restore();
+
+ virtual bool translate(SkScalar dx, SkScalar dy);
+ virtual bool scale(SkScalar sx, SkScalar sy);
+ virtual bool rotate(SkScalar degrees);
+ virtual bool skew(SkScalar sx, SkScalar sy);
+ virtual bool concat(const SkMatrix& matrix);
+ virtual void setMatrix(const SkMatrix& matrix);
+
+ virtual bool clipRect(const SkRect& rect,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+ virtual bool clipPath(const SkPath& path,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+ virtual bool clipRegion(const SkRegion& deviceRgn,
+ SkRegion::Op op = SkRegion::kIntersect_Op);
+
+ virtual void drawPaint(const SkPaint& paint);
+ virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
+ const SkPaint& paint);
+ virtual void drawRect(const SkRect& rect, const SkPaint& paint);
+ virtual void drawPath(const SkPath& path, const SkPaint& paint);
+ virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
+ const SkPaint* paint = NULL);
+ virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
+ const SkRect& dst, const SkPaint* paint = NULL);
+ virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
+ const SkPaint* paint = NULL);
+ virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
+ const SkPaint* paint = NULL);
+ virtual void drawText(const void* text, size_t byteLength, SkScalar x,
+ SkScalar y, const SkPaint& paint);
+ virtual void drawPosText(const void* text, size_t byteLength,
+ const SkPoint pos[], const SkPaint& paint);
+ virtual void drawPosTextH(const void* text, size_t byteLength,
+ const SkScalar xpos[], SkScalar constY,
+ const SkPaint& paint);
+ virtual void drawTextOnPath(const void* text, size_t byteLength,
+ const SkPath& path, const SkMatrix* matrix,
+ const SkPaint& paint);
+ virtual void drawPicture(SkPicture& picture);
+ virtual void drawVertices(VertexMode vmode, int vertexCount,
+ const SkPoint vertices[], const SkPoint texs[],
+ const SkColor colors[], SkXfermode* xmode,
+ const uint16_t indices[], int indexCount,
+ const SkPaint& paint);
+
+ virtual SkBounder* setBounder(SkBounder* bounder);
+ virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
+
+ virtual SkDevice* createDevice(SkBitmap::Config, int width, int height,
+ bool isOpaque, bool isForLayer);
+
+private:
+ SkCanvas* fProxy;
+
+ typedef SkCanvas INHERITED;
+};
+
+#endif
diff --git a/include/graphics/SkScalerContext.h b/include/graphics/SkScalerContext.h
index 4b57f63..ec2cd0d 100644
--- a/include/graphics/SkScalerContext.h
+++ b/include/graphics/SkScalerContext.h
@@ -89,7 +89,10 @@ struct SkGlyph {
kSubBits = 2,
kSubMask = ((1 << kSubBits) - 1),
kSubShift = 24, // must be large enough for glyphs and unichars
- kCodeMask = ((1 << kSubShift) - 1)
+ kCodeMask = ((1 << kSubShift) - 1),
+ // relative offsets for X and Y subpixel bits
+ kSubShiftX = kSubBits,
+ kSubShiftY = 0
};
static unsigned ID2Code(uint32_t id) {
@@ -97,11 +100,11 @@ struct SkGlyph {
}
static unsigned ID2SubX(uint32_t id) {
- return id >> (kSubShift + kSubBits);
+ return id >> (kSubShift + kSubShiftX);
}
static unsigned ID2SubY(uint32_t id) {
- return (id >> kSubShift) & kSubMask;
+ return (id >> (kSubShift + kSubShiftY)) & kSubMask;
}
static unsigned FixedToSub(SkFixed n) {
@@ -121,7 +124,9 @@ struct SkGlyph {
SkASSERT(code <= kCodeMask);
x = FixedToSub(x);
y = FixedToSub(y);
- return (x << (kSubShift + kSubBits)) | (y << kSubShift) | code;
+ return (x << (kSubShift + kSubShiftX)) |
+ (y << (kSubShift + kSubShiftY)) |
+ code;
}
void toMask(SkMask* mask) const;
diff --git a/include/graphics/SkString.h b/include/graphics/SkString.h
deleted file mode 100644
index 46b1d9e..0000000
--- a/include/graphics/SkString.h
+++ /dev/null
@@ -1,168 +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 SkString_DEFINED
-#define SkString_DEFINED
-
-#include "SkScalar.h"
-
-/* Some helper functions for C strings
-*/
-
-bool SkStrStartsWith(const char string[], const char prefix[]);
-bool SkStrEndsWith(const char string[], const char suffix[]);
-int SkStrStartsWithOneOf(const char string[], const char prefixes[]);
-
-#define SkStrAppendS32_MaxSize 11
-char* SkStrAppendS32(char buffer[], int32_t);
-#define SkStrAppendScalar_MaxSize 11
-char* SkStrAppendScalar(char buffer[], SkScalar);
-
-/** \class SkString
-
- Light weight class for managing strings. Uses reference
- counting to make string assignments and copies very fast
- with no extra RAM cost. Assumes UTF8 encoding.
-*/
-class SkString {
-public:
- SkString();
- explicit SkString(size_t len);
- explicit SkString(const char text[]);
- SkString(const char text[], size_t len);
- explicit SkString(const SkString&);
- ~SkString();
-
- bool isEmpty() const { return fRec->fLength == 0; }
- size_t size() const { return (size_t) fRec->fLength; }
- const char* c_str() const { return fRec->data(); }
-
- bool equals(const SkString&) const;
- bool equals(const char text[]) const;
- bool equals(const char text[], size_t len) const;
-
- bool startsWith(const char prefix[]) const
- {
- return SkStrStartsWith(fRec->data(), prefix);
- }
- bool endsWith(const char suffix[]) const
- {
- return SkStrEndsWith(fRec->data(), suffix);
- }
-
- friend int operator==(const SkString& a, const SkString& b)
- {
- return a.equals(b);
- }
- friend int operator!=(const SkString& a, const SkString& b)
- {
- return !a.equals(b);
- }
-
- // these methods edit the string
-
- SkString& operator=(const SkString&);
-
- char* writable_str();
-
- void reset();
- void resize(size_t len) { this->set(NULL, len); }
- void set(const SkString& src) { *this = src; }
- void set(const char text[]);
- void set(const char text[], size_t len);
- void setUTF16(const uint16_t[]);
- void setUTF16(const uint16_t[], size_t len);
-
- void insert(size_t offset, const SkString& src) { this->insert(offset, src.c_str(), src.size()); }
- void insert(size_t offset, const char text[]);
- void insert(size_t offset, const char text[], size_t len);
- void insertUnichar(size_t offset, SkUnichar);
- void insertS32(size_t offset, int32_t value);
- void insertHex(size_t offset, uint32_t value, int minDigits = 0);
- void insertScalar(size_t offset, SkScalar);
-
- void append(const SkString& str) { this->insert((size_t)-1, str); }
- void append(const char text[]) { this->insert((size_t)-1, text); }
- void append(const char text[], size_t len) { this->insert((size_t)-1, text, len); }
- void appendUnichar(SkUnichar uni) { this->insertUnichar((size_t)-1, uni); }
- void appendS32(int32_t value) { this->insertS32((size_t)-1, value); }
- void appendHex(uint32_t value, int minDigits = 0) { this->insertHex((size_t)-1, value, minDigits); }
- void appendScalar(SkScalar value) { this->insertScalar((size_t)-1, value); }
-
- void prepend(const SkString& str) { this->insert(0, str); }
- void prepend(const char text[]) { this->insert(0, text); }
- void prepend(const char text[], size_t len) { this->insert(0, text, len); }
- void prependUnichar(SkUnichar uni) { this->insertUnichar(0, uni); }
- void prependS32(int32_t value) { this->insertS32(0, value); }
- void prependHex(uint32_t value, int minDigits = 0) { this->insertHex(0, value, minDigits); }
- void prependScalar(SkScalar value) { this->insertScalar((size_t)-1, value); }
-
- void printf(const char format[], ...);
-
- void remove(size_t offset, size_t length);
-
- /** Swap contents between this and other. This function is guaranteed
- to never fail or throw.
- */
- void swap(SkString& other);
-
- /** @cond UNIT_TEST */
- SkDEBUGCODE(static void UnitTest();)
- /** @endcond */
-
-private:
- struct Rec {
- public:
- uint16_t fLength;
- uint16_t fRefCnt;
- char fBeginningOfData;
-
- char* data() { return &fBeginningOfData; }
- const char* data() const { return &fBeginningOfData; }
- };
- Rec* fRec;
-
-#ifdef SK_DEBUG
- const char* fStr;
- void validate() const;
-#else
- void validate() const {}
-#endif
-
- static const Rec gEmptyRec;
- static Rec* AllocRec(const char text[], U16CPU len);
- static Rec* RefRec(Rec*);
-};
-
-class SkAutoUCS2 {
-public:
- SkAutoUCS2(const char utf8[]);
- ~SkAutoUCS2();
-
- /** This returns the number of ucs2 characters
- */
- int count() const { return fCount; }
- /** This returns a null terminated ucs2 string
- */
- const uint16_t* getUCS2() const { return fUCS2; }
-
-private:
- int fCount;
- uint16_t* fUCS2;
-};
-
-#endif
-
diff --git a/include/graphics/SkUtils.h b/include/graphics/SkUtils.h
deleted file mode 100644
index f3e3341..0000000
--- a/include/graphics/SkUtils.h
+++ /dev/null
@@ -1,140 +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 SkUtils_DEFINED
-#define SkUtils_DEFINED
-
-#include "SkTypes.h"
-
-///////////////////////////////////////////////////////////////////////////
-
-/** Similar to memset(), but it assigns a 16bit value into the buffer.
- @param buffer The memory to have value copied into it
- @param value The 16bit value to be copied into buffer
- @param count The number of times value should be copied into the buffer.
-*/
-void sk_memset16_portable(uint16_t dst[], uint16_t value, int count);
-
-/** Similar to memset(), but it assigns a 32bit value into the buffer.
- @param buffer The memory to have value copied into it
- @param value The 32bit value to be copied into buffer
- @param count The number of times value should be copied into the buffer.
-*/
-void sk_memset32_portable(uint32_t dst[], uint32_t value, int count);
-
-#ifdef ANDROID
- #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
- #define sk_memset16(dst, value, count) sk_memset16_portable(dst, value, count)
-#endif
-
-#ifndef sk_memset32
- #define sk_memset32(dst, value, count) sk_memset32_portable(dst, value, count)
-#endif
-
-
-///////////////////////////////////////////////////////////////////////////
-
-#define kMaxBytesInUTF8Sequence 4
-
-#ifdef SK_DEBUG
- int SkUTF8_LeadByteToCount(unsigned c);
-#else
- #define SkUTF8_LeadByteToCount(c) ((((0xE5 << 24) >> ((unsigned)c >> 4 << 1)) & 3) + 1)
-#endif
-
-inline int SkUTF8_CountUTF8Bytes(const char utf8[])
-{
- SkASSERT(utf8);
- return SkUTF8_LeadByteToCount(*(const uint8_t*)utf8);
-}
-
-int SkUTF8_CountUnichars(const char utf8[]);
-int SkUTF8_CountUnichars(const char utf8[], size_t byteLength);
-SkUnichar SkUTF8_ToUnichar(const char utf8[]);
-SkUnichar SkUTF8_NextUnichar(const char**);
-SkUnichar SkUTF8_PrevUnichar(const char**);
-
-/** Return the number of bytes need to convert a unichar
- into a utf8 sequence. Will be 1..kMaxBytesInUTF8Sequence,
- or 0 if uni is illegal.
-*/
-size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[] = NULL);
-
-///////////////////////////////////////////////////////////////////////////////
-
-#define SkUTF16_IsHighSurrogate(c) (((c) & 0xFC00) == 0xD800)
-#define SkUTF16_IsLowSurrogate(c) (((c) & 0xFC00) == 0xDC00)
-
-int SkUTF16_CountUnichars(const uint16_t utf16[]);
-int SkUTF16_CountUnichars(const uint16_t utf16[],
- int numberOf16BitValues);
-// returns the current unichar and then moves past it (*p++)
-SkUnichar SkUTF16_NextUnichar(const uint16_t**);
-// this guy backs up to the previus unichar value, and returns it (*--p)
-SkUnichar SkUTF16_PrevUnichar(const uint16_t**);
-size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t utf16[] = NULL);
-
-size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues,
- char utf8[] = NULL);
-
-class SkUtils {
-public:
-#ifdef SK_DEBUG
- static void UnitTest();
-#endif
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-class SkAutoTrace {
-public:
- /** NOTE: label contents are not copied, just the ptr is
- retained, so DON'T DELETE IT.
- */
- SkAutoTrace(const char label[]) : fLabel(label) {
- SkDebugf("--- trace: %s Enter\n", fLabel);
- }
- ~SkAutoTrace() {
- SkDebugf("--- trace: %s Leave\n", fLabel);
- }
-private:
- const char* fLabel;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-
-class SkAutoMemoryUsageProbe {
-public:
- /** Record memory usage in constructor, and dump the result
- (delta and current total) in the destructor, with the optional
- label. NOTE: label contents are not copied, just the ptr is
- retained, so DON'T DELETE IT.
- */
- SkAutoMemoryUsageProbe(const char label[]);
- ~SkAutoMemoryUsageProbe();
-private:
- const char* fLabel;
- size_t fBytesAllocated;
-};
-
-#endif
-