aboutsummaryrefslogtreecommitdiffstats
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkCanvas.h47
-rw-r--r--include/core/SkDevice.h45
-rw-r--r--include/core/SkGraphics.h7
-rw-r--r--include/core/SkPaint.h8
-rw-r--r--include/core/SkPath.h3
-rw-r--r--include/core/SkPictureFlat.h209
-rw-r--r--include/core/SkRect.h14
-rw-r--r--include/core/SkTypes.h6
-rw-r--r--include/core/SkXfermode.h2
9 files changed, 311 insertions, 30 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index bfa0d10..b5ccca6 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -29,6 +29,7 @@
class SkBounder;
class SkDevice;
+class SkDeviceFactory;
class SkDraw;
class SkDrawFilter;
class SkPicture;
@@ -51,29 +52,37 @@ class SkShape;
*/
class SkCanvas : public SkRefCnt {
public:
- /** Construct a canvas with the specified bitmap to draw into.
+ /** 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);
+
+ /** 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);
+
+ /** Deprecated - Construct a canvas with the specified bitmap to draw into.
@param bitmap Specifies a bitmap for the canvas to draw into. Its
structure are copied to the canvas.
*/
explicit SkCanvas(const SkBitmap& bitmap);
- /** Construct a canvas with the specified device to draw into.
- @param device Specifies a device for the canvas to draw into. The
- device may be null.
- */
- explicit SkCanvas(SkDevice* device = NULL);
virtual ~SkCanvas();
///////////////////////////////////////////////////////////////////////////
- /** If this subclass of SkCanvas supports GL viewports, return true and set
- size (if not null) to the size of the viewport. If it is not supported,
- ignore vp and return false.
+ /** If the Device supports GL viewports, return true and set size (if not
+ null) to the size of the viewport. If it is not supported, ignore size
+ and return false.
*/
virtual bool getViewport(SkIPoint* size) const;
-
- /** If this subclass of SkCanvas supports GL viewports, return true and set
- the viewport to the specified x and y dimensions. If it is not
- supported, ignore x and y and return false.
+
+ /** If the Device supports GL viewports, return true and set the viewport
+ to the specified x and y dimensions. If it is not supported, ignore x
+ and y and return false.
*/
virtual bool setViewport(int x, int y);
@@ -88,15 +97,16 @@ public:
device, its reference count is decremented. The new device is returned.
*/
SkDevice* setDevice(SkDevice* device);
-
- /** Specify a bitmap for the canvas to draw into. This is a help method for
- setDevice(), and it creates a device for the bitmap by calling
- createDevice(). The structure of the bitmap is copied into the device.
+
+ /** Deprecated - Specify a bitmap for the canvas to draw into. This is a
+ helper method for setDevice(), and it creates a device for the bitmap by
+ calling createDevice(). The structure of the bitmap is copied into the
+ device.
*/
virtual SkDevice* setBitmapDevice(const SkBitmap& bitmap);
///////////////////////////////////////////////////////////////////////////
-
+
enum SaveFlags {
/** save the matrix state, restoring it on restore() */
kMatrix_SaveFlag = 0x01,
@@ -758,6 +768,7 @@ private:
SkBounder* fBounder;
SkDevice* fLastDeviceToGainFocus;
+ SkDeviceFactory* fDeviceFactory;
void prepareForDeviceDraw(SkDevice*);
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 0d724ba..dbc8fcf 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 The Android Open Source Project
+ * 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.
@@ -22,26 +22,53 @@
#include "SkCanvas.h"
#include "SkColor.h"
+class SkDevice;
class SkDraw;
struct SkIRect;
class SkMatrix;
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 SkDeviceFactory {
+public:
+ virtual ~SkDeviceFactory();
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer) = 0;
+};
+
+class SkRasterDeviceFactory : public SkDeviceFactory {
+public:
+ virtual SkDevice* newDevice(SkBitmap::Config config, int width, int height,
+ bool isOpaque, bool isForLayer);
+};
+
class SkDevice : public SkRefCnt {
public:
SkDevice();
- /** Construct a new device, extracting the width/height/config/isOpaque values from
- the bitmap. If transferPixelOwnership is true, and the bitmap claims to own its
- own pixels (getOwnsPixels() == true), then transfer this responsibility to the
- device, and call setOwnsPixels(false) on the bitmap.
-
- Subclasses may override the destructor, which is virtual, even though this class
- doesn't have one. SkRefCnt does.
-
+ /** Construct a new device, extracting the width/height/config/isOpaque
+ values from the bitmap. Subclasses may override the destructor, which
+ is virtual, even though this class doesn't have one. SkRefCnt does.
+
@param bitmap A copy of this bitmap is made and stored in the device
*/
SkDevice(const SkBitmap& bitmap);
+ virtual SkDeviceFactory* getDeviceFactory() {
+ return SkNEW(SkRasterDeviceFactory);
+ }
+
+ enum Capabilities {
+ kGL_Capability = 0x1, //!< mask indicating GL support
+ kVector_Capability = 0x2, //!< mask indicating a vector representation
+ kAll_Capabilities = 0x3
+ };
+ virtual uint32_t getDeviceCapabilities() { return 0; }
+
/** Return the width of the device (in pixels).
*/
int width() const { return fBitmap.width(); }
diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h
index dd5808a..25c926f 100644
--- a/include/core/SkGraphics.h
+++ b/include/core/SkGraphics.h
@@ -33,7 +33,12 @@ public:
Returns true if some amount was purged from the font cache.
*/
static bool SetFontCacheUsed(size_t usageInBytes);
-
+
+ /** 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);
+
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/SkPaint.h b/include/core/SkPaint.h
index 5fef527..ea21ceb 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -806,6 +806,11 @@ public:
void getTextPath(const void* text, size_t length, SkScalar x, SkScalar y,
SkPath* path) const;
+ const SkGlyph& getUnicharMetrics(SkUnichar);
+ const void* findImage(const SkGlyph&);
+
+ uint32_t getGenerationID() const;
+
private:
SkTypeface* fTypeface;
SkScalar fTextSize;
@@ -830,6 +835,7 @@ private:
unsigned fStyle : 2;
unsigned fTextEncoding : 2; // 3 values
unsigned fHinting : 2;
+ uint32_t fGenerationID;
SkDrawCacheProc getDrawCacheProc() const;
SkMeasureCacheProc getMeasureCacheProc(TextBufferDirection dir,
@@ -842,7 +848,7 @@ private:
void descriptorProc(const SkMatrix* deviceMatrix,
void (*proc)(const SkDescriptor*, void*),
- void* context) const;
+ void* context, bool ignoreGamma = false) const;
const SkRect& computeStrokeFastBounds(const SkRect& orig,
SkRect* storage) const;
diff --git a/include/core/SkPath.h b/include/core/SkPath.h
index 3afea09..eb5ff6d 100644
--- a/include/core/SkPath.h
+++ b/include/core/SkPath.h
@@ -571,6 +571,8 @@ public:
*/
void subdivide(SkScalar dist, bool bendLines, SkPath* dst = NULL) const;
+ uint32_t getGenerationID() const;
+
SkDEBUGCODE(void validate() const;)
private:
@@ -580,6 +582,7 @@ private:
mutable uint8_t fBoundsIsDirty;
uint8_t fFillType;
uint8_t fIsConvex;
+ uint32_t fGenerationID;
// called, if dirty, by getBounds()
void computeBounds() const;
diff --git a/include/core/SkPictureFlat.h b/include/core/SkPictureFlat.h
new file mode 100644
index 0000000..2c0af5a
--- /dev/null
+++ b/include/core/SkPictureFlat.h
@@ -0,0 +1,209 @@
+#ifndef SkPictureFlat_DEFINED
+#define SkPictureFlat_DEFINED
+
+#include "SkChunkAlloc.h"
+#include "SkBitmap.h"
+#include "SkPicture.h"
+#include "SkMatrix.h"
+#include "SkPaint.h"
+#include "SkPath.h"
+#include "SkRegion.h"
+
+enum DrawType {
+ UNUSED,
+ CLIP_PATH,
+ CLIP_REGION,
+ CLIP_RECT,
+ CONCAT,
+ DRAW_BITMAP,
+ DRAW_BITMAP_MATRIX,
+ DRAW_BITMAP_RECT,
+ DRAW_DATA,
+ DRAW_PAINT,
+ DRAW_PATH,
+ DRAW_PICTURE,
+ DRAW_POINTS,
+ DRAW_POS_TEXT,
+ DRAW_POS_TEXT_H,
+ DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H
+ DRAW_RECT,
+ DRAW_SHAPE,
+ DRAW_SPRITE,
+ DRAW_TEXT,
+ DRAW_TEXT_ON_PATH,
+ DRAW_TEXT_TOP_BOTTOM, // fast variant of DRAW_TEXT
+ DRAW_VERTICES,
+ RESTORE,
+ ROTATE,
+ SAVE,
+ SAVE_LAYER,
+ SCALE,
+ SET_MATRIX,
+ SKEW,
+ TRANSLATE
+};
+
+enum DrawVertexFlags {
+ DRAW_VERTICES_HAS_TEXS = 0x01,
+ DRAW_VERTICES_HAS_COLORS = 0x02,
+ DRAW_VERTICES_HAS_INDICES = 0x04
+};
+
+class SkRefCntPlayback {
+public:
+ SkRefCntPlayback();
+ virtual ~SkRefCntPlayback();
+
+ int count() const { return fCount; }
+
+ void reset(const SkRefCntRecorder*);
+
+ void setCount(int count);
+ SkRefCnt* set(int index, SkRefCnt*);
+
+ virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+ buffer.setRefCntArray(fArray, fCount);
+ }
+
+protected:
+ int fCount;
+ SkRefCnt** fArray;
+};
+
+class SkTypefacePlayback : public SkRefCntPlayback {
+public:
+ virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+ buffer.setTypefaceArray((SkTypeface**)fArray, fCount);
+ }
+};
+
+class SkFactoryPlayback {
+public:
+ SkFactoryPlayback(int count) : fCount(count) {
+ fArray = SkNEW_ARRAY(SkFlattenable::Factory, count);
+ }
+
+ ~SkFactoryPlayback() {
+ SkDELETE_ARRAY(fArray);
+ }
+
+ SkFlattenable::Factory* base() const { return fArray; }
+
+ void setupBuffer(SkFlattenableReadBuffer& buffer) const {
+ buffer.setFactoryPlayback(fArray, fCount);
+ }
+
+private:
+ int fCount;
+ SkFlattenable::Factory* fArray;
+};
+
+class SkFlatData {
+public:
+ static int Compare(const SkFlatData* a, const SkFlatData* b) {
+ return memcmp(&a->fAllocSize, &b->fAllocSize, a->fAllocSize);
+ }
+
+ int index() const { return fIndex; }
+
+#ifdef SK_DEBUG_SIZE
+ size_t size() const { return sizeof(fIndex) + fAllocSize; }
+#endif
+
+protected:
+ static SkFlatData* Alloc(SkChunkAlloc* heap, int32_t size, int index);
+
+ int fIndex;
+ int32_t fAllocSize;
+};
+
+class SkFlatBitmap : public SkFlatData {
+public:
+ static SkFlatBitmap* Flatten(SkChunkAlloc*, const SkBitmap&, int index,
+ SkRefCntRecorder*);
+
+ void unflatten(SkBitmap* bitmap, SkRefCntPlayback* rcp) const {
+ SkFlattenableReadBuffer buffer(fBitmapData);
+ if (rcp) {
+ rcp->setupBuffer(buffer);
+ }
+ bitmap->unflatten(buffer);
+ }
+
+#ifdef SK_DEBUG_VALIDATE
+ void validate() const {
+ // to be written
+ }
+#endif
+
+private:
+ char fBitmapData[1];
+ typedef SkFlatData INHERITED;
+};
+
+class SkFlatMatrix : public SkFlatData {
+public:
+ static SkFlatMatrix* Flatten(SkChunkAlloc* heap, const SkMatrix& matrix, int index);
+
+ void unflatten(SkMatrix* result) const {
+ memcpy(result, fMatrixData, sizeof(SkMatrix));
+ }
+
+#ifdef SK_DEBUG_DUMP
+ void dump() const;
+#endif
+
+#ifdef SK_DEBUG_VALIDATE
+ void validate() const {
+ // to be written
+ }
+#endif
+
+private:
+ char fMatrixData[1];
+ typedef SkFlatData INHERITED;
+};
+
+class SkFlatPaint : public SkFlatData {
+public:
+ static SkFlatPaint* Flatten(SkChunkAlloc* heap, const SkPaint& paint,
+ int index, SkRefCntRecorder*,
+ SkRefCntRecorder* faceRecorder);
+
+ void unflatten(SkPaint* result, SkRefCntPlayback* rcp,
+ SkTypefacePlayback* facePlayback) const {
+ Read(fPaintData, result, rcp, facePlayback);
+ }
+
+ static void Read(const void* storage, SkPaint* paint, SkRefCntPlayback*,
+ SkTypefacePlayback* facePlayback);
+
+#ifdef SK_DEBUG_DUMP
+ void dump() const;
+#endif
+
+private:
+ char fPaintData[1];
+ typedef SkFlatData INHERITED;
+};
+
+class SkFlatRegion : public SkFlatData {
+public:
+ static SkFlatRegion* Flatten(SkChunkAlloc* heap, const SkRegion& region, int index);
+
+ void unflatten(SkRegion* result) const {
+ result->unflatten(fRegionData);
+ }
+
+#ifdef SK_DEBUG_VALIDATE
+ void validate() const {
+ // to be written
+ }
+#endif
+
+private:
+ char fRegionData[1];
+ typedef SkFlatData INHERITED;
+};
+
+#endif
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 879d81a..fbd9f7f 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -233,6 +233,18 @@ struct SkIRect {
struct SkRect {
SkScalar fLeft, fTop, fRight, fBottom;
+ static SkRect MakeEmpty() {
+ SkRect r;
+ r.setEmpty();
+ return r;
+ }
+
+ static SkRect MakeWH(SkScalar w, SkScalar h) {
+ SkRect r;
+ r.set(0, 0, w, h);
+ return r;
+ }
+
static SkRect MakeSize(const SkSize& size) {
SkRect r;
r.set(0, 0, size.width(), size.height());
@@ -250,7 +262,7 @@ struct SkRect {
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; }
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index fa21adc..1f8ecaa 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -30,6 +30,12 @@
/** \file SkTypes.h
*/
+/** See SkGraphics::GetVersion() to retrieve these at runtime
+ */
+#define SKIA_VERSION_MAJOR 1
+#define SKIA_VERSION_MINOR 0
+#define SKIA_VERSION_PATCH 0
+
/*
memory wrappers to be implemented by the porting layer (platform)
*/
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 7a06467..d92d346 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -137,6 +137,8 @@ public:
return false and ignore the mode parameter.
*/
static bool IsMode(SkXfermode*, Mode* mode);
+
+ Mode fMode;
protected:
SkXfermode(SkFlattenableReadBuffer& rb) : SkFlattenable(rb) {}