aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-12 19:53:16 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-12 19:53:16 +0000
commitd38f137e9b813f8193675ebd3dfbfe8bc42639e9 (patch)
tree1e670c378d7b31a4538fde3c2b3e4e29b72c05b5 /include/gpu
parent4d5cb45f3e3e62633304b4911d131cdd02dfd541 (diff)
Move gpu/include/* to include/gpu and gpu/src/* to src/gpu
Review URL: http://codereview.appspot.com/5250070/ git-svn-id: http://skia.googlecode.com/svn/trunk@2471 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/gpu')
-rw-r--r--include/gpu/FlingState.h51
-rw-r--r--include/gpu/GrAllocPool.h64
-rwxr-xr-xinclude/gpu/GrAllocator.h249
-rw-r--r--include/gpu/GrAtlas.h84
-rw-r--r--include/gpu/GrClip.h141
-rw-r--r--include/gpu/GrClipIterator.h80
-rw-r--r--include/gpu/GrColor.h65
-rw-r--r--include/gpu/GrConfig.h438
-rw-r--r--include/gpu/GrContext.h733
-rw-r--r--include/gpu/GrFontScaler.h37
-rw-r--r--include/gpu/GrGLConfig.h265
-rw-r--r--include/gpu/GrGLConfig_chrome.h27
-rw-r--r--include/gpu/GrGLDefines.h659
-rw-r--r--include/gpu/GrGLInterface.h414
-rw-r--r--include/gpu/GrGlyph.h82
-rw-r--r--include/gpu/GrGpuVertex.h97
-rw-r--r--include/gpu/GrIPoint.h28
-rw-r--r--include/gpu/GrInstanceCounter.h40
-rw-r--r--include/gpu/GrKey.h40
-rw-r--r--include/gpu/GrMatrix.h19
-rw-r--r--include/gpu/GrMesh.h49
-rw-r--r--include/gpu/GrNoncopyable.h31
-rw-r--r--include/gpu/GrPaint.h254
-rw-r--r--include/gpu/GrPath.h20
-rw-r--r--include/gpu/GrPathSink.h29
-rw-r--r--include/gpu/GrPlotMgr.h77
-rw-r--r--include/gpu/GrPoint.h31
-rw-r--r--include/gpu/GrRandom.h55
-rw-r--r--include/gpu/GrRect.h37
-rw-r--r--include/gpu/GrRectanizer.h57
-rw-r--r--include/gpu/GrRefCnt.h34
-rw-r--r--include/gpu/GrRenderTarget.h209
-rw-r--r--include/gpu/GrResource.h78
-rw-r--r--include/gpu/GrSamplerState.h265
-rw-r--r--include/gpu/GrScalar.h49
-rw-r--r--include/gpu/GrStencil.h211
-rw-r--r--include/gpu/GrStopwatch.h128
-rw-r--r--include/gpu/GrStringBuilder.h19
-rw-r--r--include/gpu/GrTBSearch.h46
-rw-r--r--include/gpu/GrTDArray.h216
-rw-r--r--include/gpu/GrTHashCache.h219
-rw-r--r--include/gpu/GrTLList.h54
-rw-r--r--include/gpu/GrTemplates.h69
-rw-r--r--include/gpu/GrTextContext.h68
-rw-r--r--include/gpu/GrTextStrike.h115
-rw-r--r--include/gpu/GrTexture.h183
-rw-r--r--include/gpu/GrTypes.h637
-rw-r--r--include/gpu/GrUserConfig.h83
-rw-r--r--include/gpu/SkUIView.h65
49 files changed, 7001 insertions, 0 deletions
diff --git a/include/gpu/FlingState.h b/include/gpu/FlingState.h
new file mode 100644
index 0000000000..09557b90fb
--- /dev/null
+++ b/include/gpu/FlingState.h
@@ -0,0 +1,51 @@
+
+/*
+ * 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 SkFlingState_DEFINED
+#define SkFlingState_DEFINED
+
+#include "SkScalar.h"
+#include "SkPoint.h"
+
+class SkMatrix;
+
+struct FlingState {
+ FlingState() : fActive(false) {}
+
+ bool isActive() const { return fActive; }
+ void stop() { fActive = false; }
+
+ void reset(float sx, float sy);
+ bool evaluateMatrix(SkMatrix* matrix);
+
+private:
+ SkPoint fDirection;
+ SkScalar fSpeed0;
+ double fTime0;
+ bool fActive;
+};
+
+class GrAnimateFloat {
+public:
+ GrAnimateFloat();
+
+ void start(float v0, float v1, float duration);
+ bool isActive() const { return fTime0 != 0; }
+ void stop() { fTime0 = 0; }
+
+ float evaluate();
+
+private:
+ float fValue0, fValue1, fDuration;
+ SkMSec fTime0;
+};
+
+#endif
+
diff --git a/include/gpu/GrAllocPool.h b/include/gpu/GrAllocPool.h
new file mode 100644
index 0000000000..3ecc4aa189
--- /dev/null
+++ b/include/gpu/GrAllocPool.h
@@ -0,0 +1,64 @@
+
+/*
+ * 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 GrAllocPool_DEFINED
+#define GrAllocPool_DEFINED
+
+#include "GrNoncopyable.h"
+
+class GrAllocPool : GrNoncopyable {
+public:
+ GrAllocPool(size_t blockSize = 0);
+ ~GrAllocPool();
+
+ /**
+ * Frees all blocks that have been allocated with alloc().
+ */
+ void reset();
+
+ /**
+ * Returns a block of memory bytes size big. This address must not be
+ * passed to realloc/free/delete or any other function that assumes the
+ * address was allocated by malloc or new (because it hasn't).
+ */
+ void* alloc(size_t bytes);
+
+ /**
+ * Releases the most recently allocated bytes back to allocpool.
+ */
+ void release(size_t bytes);
+
+private:
+ struct Block;
+
+ Block* fBlock;
+ size_t fMinBlockSize;
+
+#if GR_DEBUG
+ int fBlocksAllocated;
+ void validate() const;
+#else
+ void validate() const {}
+#endif
+};
+
+template <typename T> class GrTAllocPool {
+public:
+ GrTAllocPool(int count) : fPool(count * sizeof(T)) {}
+
+ void reset() { fPool.reset(); }
+ T* alloc() { return (T*)fPool.alloc(sizeof(T)); }
+
+private:
+ GrAllocPool fPool;
+};
+
+#endif
+
diff --git a/include/gpu/GrAllocator.h b/include/gpu/GrAllocator.h
new file mode 100755
index 0000000000..21c79ec7aa
--- /dev/null
+++ b/include/gpu/GrAllocator.h
@@ -0,0 +1,249 @@
+
+/*
+ * 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 GrAllocator_DEFINED
+#define GrAllocator_DEFINED
+
+#include "GrConfig.h"
+#include "SkTArray.h"
+
+class GrAllocator : GrNoncopyable {
+public:
+ ~GrAllocator() {
+ reset();
+ }
+
+ /**
+ * Create an allocator
+ *
+ * @param itemSize the size of each item to allocate
+ * @param itemsPerBlock the number of items to allocate at once
+ * @param initialBlock optional memory to use for the first block.
+ * Must be at least itemSize*itemsPerBlock sized.
+ * Caller is responsible for freeing this memory.
+ */
+ GrAllocator(size_t itemSize, int itemsPerBlock, void* initialBlock) :
+ fItemSize(itemSize),
+ fItemsPerBlock(itemsPerBlock),
+ fOwnFirstBlock(NULL == initialBlock),
+ fCount(0) {
+ GrAssert(itemsPerBlock > 0);
+ fBlockSize = fItemSize * fItemsPerBlock;
+ fBlocks.push_back() = initialBlock;
+ GR_DEBUGCODE(if (!fOwnFirstBlock) {*((char*)initialBlock+fBlockSize-1)='a';} );
+ }
+
+ /**
+ * Adds an item and returns pointer to it.
+ *
+ * @return pointer to the added item.
+ */
+ void* push_back() {
+ int indexInBlock = fCount % fItemsPerBlock;
+ // we always have at least one block
+ if (0 == indexInBlock) {
+ if (0 != fCount) {
+ fBlocks.push_back() = GrMalloc(fBlockSize);
+ } else if (fOwnFirstBlock) {
+ fBlocks[0] = GrMalloc(fBlockSize);
+ }
+ }
+ void* ret = (char*)fBlocks[fCount/fItemsPerBlock] +
+ fItemSize * indexInBlock;
+ ++fCount;
+ return ret;
+ }
+
+ /**
+ * removes all added items
+ */
+ void reset() {
+ int blockCount = GrMax((unsigned)1,
+ GrUIDivRoundUp(fCount, fItemsPerBlock));
+ for (int i = 1; i < blockCount; ++i) {
+ GrFree(fBlocks[i]);
+ }
+ if (fOwnFirstBlock) {
+ GrFree(fBlocks[0]);
+ fBlocks[0] = NULL;
+ }
+ fBlocks.pop_back_n(blockCount-1);
+ fCount = 0;
+ }
+
+ /**
+ * count of items
+ */
+ int count() const {
+ return fCount;
+ }
+
+ /**
+ * is the count 0
+ */
+ bool empty() const { return fCount == 0; }
+
+ /**
+ * access last item, only call if count() != 0
+ */
+ void* back() {
+ GrAssert(fCount);
+ return (*this)[fCount-1];
+ }
+
+ /**
+ * access last item, only call if count() != 0
+ */
+ const void* back() const {
+ GrAssert(fCount);
+ return (*this)[fCount-1];
+ }
+
+ /**
+ * access item by index.
+ */
+ void* operator[] (int i) {
+ GrAssert(i >= 0 && i < fCount);
+ return (char*)fBlocks[i / fItemsPerBlock] +
+ fItemSize * (i % fItemsPerBlock);
+ }
+
+ /**
+ * access item by index.
+ */
+ const void* operator[] (int i) const {
+ GrAssert(i >= 0 && i < fCount);
+ return (const char*)fBlocks[i / fItemsPerBlock] +
+ fItemSize * (i % fItemsPerBlock);
+ }
+
+private:
+ static const int NUM_INIT_BLOCK_PTRS = 8;
+
+ SkSTArray<NUM_INIT_BLOCK_PTRS, void*> fBlocks;
+ size_t fBlockSize;
+ size_t fItemSize;
+ int fItemsPerBlock;
+ bool fOwnFirstBlock;
+ int fCount;
+
+ typedef GrNoncopyable INHERITED;
+};
+
+template <typename T>
+class GrTAllocator : GrNoncopyable {
+
+public:
+ virtual ~GrTAllocator() {};
+
+ /**
+ * Create an allocator
+ *
+ * @param itemsPerBlock the number of items to allocate at once
+ * @param initialBlock optional memory to use for the first block.
+ * Must be at least size(T)*itemsPerBlock sized.
+ * Caller is responsible for freeing this memory.
+ */
+ explicit GrTAllocator(int itemsPerBlock)
+ : fAllocator(sizeof(T), itemsPerBlock, NULL) {}
+
+ /**
+ * Adds an item and returns it.
+ *
+ * @return the added item.
+ */
+ T& push_back() {
+ void* item = fAllocator.push_back();
+ GrAssert(NULL != item);
+ new (item) T;
+ return *(T*)item;
+ }
+
+ T& push_back(const T& t) {
+ void* item = fAllocator.push_back();
+ GrAssert(NULL != item);
+ new (item) T(t);
+ return *(T*)item;
+ }
+
+ /**
+ * removes all added items
+ */
+ void reset() {
+ int c = fAllocator.count();
+ for (int i = 0; i < c; ++i) {
+ ((T*)fAllocator[i])->~T();
+ }
+ fAllocator.reset();
+ }
+
+ /**
+ * count of items
+ */
+ int count() const {
+ return fAllocator.count();
+ }
+
+ /**
+ * is the count 0
+ */
+ bool empty() const { return fAllocator.empty(); }
+
+ /**
+ * access last item, only call if count() != 0
+ */
+ T& back() {
+ return *(T*)fAllocator.back();
+ }
+
+ /**
+ * access last item, only call if count() != 0
+ */
+ const T& back() const {
+ return *(const T*)fAllocator.back();
+ }
+
+ /**
+ * access item by index.
+ */
+ T& operator[] (int i) {
+ return *(T*)(fAllocator[i]);
+ }
+
+ /**
+ * access item by index.
+ */
+ const T& operator[] (int i) const {
+ return *(const T*)(fAllocator[i]);
+ }
+
+protected:
+ GrTAllocator(int itemsPerBlock, void* initialBlock)
+ : fAllocator(sizeof(T), itemsPerBlock, initialBlock) {
+ }
+
+private:
+ GrAllocator fAllocator;
+ typedef GrNoncopyable INHERITED;
+};
+
+template <int N, typename T> class GrSTAllocator : public GrTAllocator<T> {
+private:
+ typedef GrTAllocator<T> INHERITED;
+
+public:
+ GrSTAllocator() : INHERITED(N, fStorage.get()) {
+ }
+
+private:
+ SkAlignedSTStorage<N, T> fStorage;
+};
+
+#endif
diff --git a/include/gpu/GrAtlas.h b/include/gpu/GrAtlas.h
new file mode 100644
index 0000000000..f0114e399d
--- /dev/null
+++ b/include/gpu/GrAtlas.h
@@ -0,0 +1,84 @@
+
+/*
+ * 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 GrAtlas_DEFINED
+#define GrAtlas_DEFINED
+
+#include "GrPoint.h"
+#include "GrTexture.h"
+#include "GrTDArray.h"
+
+class GrGpu;
+class GrRectanizer;
+class GrAtlasMgr;
+
+class GrAtlas {
+public:
+ GrAtlas(GrAtlasMgr*, int plotX, int plotY, GrMaskFormat);
+
+ int getPlotX() const { return fPlot.fX; }
+ int getPlotY() const { return fPlot.fY; }
+ GrMaskFormat getMaskFormat() const { return fMaskFormat; }
+
+ GrTexture* texture() const { return fTexture; }
+
+ bool addSubImage(int width, int height, const void*, GrIPoint16*);
+
+ static void FreeLList(GrAtlas* atlas) {
+ while (atlas) {
+ GrAtlas* next = atlas->fNext;
+ delete atlas;
+ atlas = next;
+ }
+ }
+
+ // testing
+ GrAtlas* nextAtlas() const { return fNext; }
+
+private:
+ ~GrAtlas(); // does not try to delete the fNext field
+
+ GrAtlas* fNext;
+ GrTexture* fTexture;
+ GrRectanizer* fRects;
+ GrAtlasMgr* fAtlasMgr;
+ GrIPoint16 fPlot;
+ GrMaskFormat fMaskFormat;
+
+ friend class GrAtlasMgr;
+};
+
+class GrPlotMgr;
+
+class GrAtlasMgr {
+public:
+ GrAtlasMgr(GrGpu*);
+ ~GrAtlasMgr();
+
+ GrAtlas* addToAtlas(GrAtlas*, int width, int height, const void*,
+ GrMaskFormat, GrIPoint16*);
+
+ GrTexture* getTexture(GrMaskFormat format) const {
+ GrAssert((unsigned)format < kCount_GrMaskFormats);
+ return fTexture[format];
+ }
+
+ // to be called by ~GrAtlas()
+ void freePlot(int x, int y);
+
+private:
+ GrGpu* fGpu;
+ GrTexture* fTexture[kCount_GrMaskFormats];
+ GrPlotMgr* fPlotMgr;
+};
+
+#endif
+
+
diff --git a/include/gpu/GrClip.h b/include/gpu/GrClip.h
new file mode 100644
index 0000000000..d86eb978c7
--- /dev/null
+++ b/include/gpu/GrClip.h
@@ -0,0 +1,141 @@
+
+/*
+ * 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 GrClip_DEFINED
+#define GrClip_DEFINED
+
+#include "GrClipIterator.h"
+#include "GrRect.h"
+#include "GrPath.h"
+#include "GrTemplates.h"
+
+#include "SkTArray.h"
+
+class GrClip {
+public:
+ GrClip();
+ GrClip(const GrClip& src);
+ /**
+ * If specified, the conservativeBounds parameter already takes (tx,ty)
+ * into account.
+ */
+ GrClip(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* conservativeBounds = NULL);
+ GrClip(const GrIRect& rect);
+ GrClip(const GrRect& rect);
+
+ ~GrClip();
+
+ GrClip& operator=(const GrClip& src);
+
+ bool hasConservativeBounds() const { return fConservativeBoundsValid; }
+
+ const GrRect& getConservativeBounds() const { return fConservativeBounds; }
+
+ int getElementCount() const { return fList.count(); }
+
+ GrClipType getElementType(int i) const { return fList[i].fType; }
+
+ const GrPath& getPath(int i) const {
+ GrAssert(kPath_ClipType == fList[i].fType);
+ return fList[i].fPath;
+ }
+
+ GrPathFill getPathFill(int i) const {
+ GrAssert(kPath_ClipType == fList[i].fType);
+ return fList[i].fPathFill;
+ }
+
+ const GrRect& getRect(int i) const {
+ GrAssert(kRect_ClipType == fList[i].fType);
+ return fList[i].fRect;
+ }
+
+ GrSetOp getOp(int i) const { return fList[i].fOp; }
+
+ bool isRect() const {
+ if (1 == fList.count() && kRect_ClipType == fList[0].fType &&
+ (kIntersect_SetOp == fList[0].fOp ||
+ kReplace_SetOp == fList[0].fOp)) {
+ // if we determined that the clip is a single rect
+ // we ought to have also used that rect as the bounds.
+ GrAssert(fConservativeBoundsValid);
+ GrAssert(fConservativeBounds == fList[0].fRect);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ bool isEmpty() const { return 0 == fList.count(); }
+
+ /**
+ * Resets this clip to be empty
+ */
+ void setEmpty();
+
+ /**
+ * If specified, the bounds parameter already takes (tx,ty) into account.
+ */
+ void setFromIterator(GrClipIterator* iter, GrScalar tx, GrScalar ty,
+ const GrRect* conservativeBounds = NULL);
+ void setFromRect(const GrRect& rect);
+ void setFromIRect(const GrIRect& rect);
+
+ friend bool operator==(const GrClip& a, const GrClip& b) {
+ if (a.fList.count() != b.fList.count()) {
+ return false;
+ }
+ int count = a.fList.count();
+ for (int i = 0; i < count; ++i) {
+ if (a.fList[i] != b.fList[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+ friend bool operator!=(const GrClip& a, const GrClip& b) {
+ return !(a == b);
+ }
+
+private:
+ struct Element {
+ GrClipType fType;
+ GrRect fRect;
+ GrPath fPath;
+ GrPathFill fPathFill;
+ GrSetOp fOp;
+ bool operator ==(const Element& e) const {
+ if (e.fType != fType || e.fOp != fOp) {
+ return false;
+ }
+ switch (fType) {
+ case kRect_ClipType:
+ return fRect == e.fRect;
+ case kPath_ClipType:
+ return fPath == e.fPath;
+ default:
+ GrCrash("Unknown clip element type.");
+ return false; // suppress warning
+ }
+ }
+ bool operator !=(const Element& e) const { return !(*this == e); }
+ };
+
+ GrRect fConservativeBounds;
+ bool fConservativeBoundsValid;
+
+ enum {
+ kPreAllocElements = 4,
+ };
+ SkSTArray<kPreAllocElements, Element> fList;
+};
+#endif
+
diff --git a/include/gpu/GrClipIterator.h b/include/gpu/GrClipIterator.h
new file mode 100644
index 0000000000..4a5cc7135f
--- /dev/null
+++ b/include/gpu/GrClipIterator.h
@@ -0,0 +1,80 @@
+
+/*
+ * 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 GrClipIterator_DEFINED
+#define GrClipIterator_DEFINED
+
+#include "GrPath.h"
+#include "GrRect.h"
+
+/**
+ * A clip is a list of paths and/or rects with set operations to combine them.
+ */
+class GrClipIterator {
+public:
+ virtual ~GrClipIterator() {}
+
+ /**
+ * Returns true if there are no more rects to process
+ */
+ virtual bool isDone() const = 0;
+
+ /**
+ * Rewind the iterator to replay the set of clip elements again
+ */
+ virtual void rewind() = 0;
+
+ /**
+ * Get the type of the current clip element
+ */
+ virtual GrClipType getType() const = 0;
+
+ /**
+ * Return the current path. It is an error to call this when isDone() is
+ * true or when getType() is kRect_Type.
+ */
+ virtual const GrPath* getPath() = 0;
+
+ /**
+ * Return the fill rule for the path. It is an error to call this when
+ * isDone() is true or when getType is kRect_Type.
+ */
+ virtual GrPathFill getPathFill() const = 0;
+
+ /**
+ * Return the current rect. It is an error to call this when isDone is true
+ * or when getType() is kPath_Type.
+ */
+ virtual void getRect(GrRect* rect) const = 0;
+
+ /**
+ * Gets the operation used to apply the current item to previously iterated
+ * items. Iterators should not produce a Replace op.
+ */
+ virtual GrSetOp getOp() const = 0;
+
+ /**
+ * Call to move to the next element in the list, previous path iter can be
+ * made invalid.
+ */
+ virtual void next() = 0;
+};
+
+/**
+ * Call to rewind iter, first checking to see if iter is NULL
+ */
+static inline void GrSafeRewind(GrClipIterator* iter) {
+ if (iter) {
+ iter->rewind();
+ }
+}
+
+#endif
+
diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h
new file mode 100644
index 0000000000..5c9e408889
--- /dev/null
+++ b/include/gpu/GrColor.h
@@ -0,0 +1,65 @@
+
+/*
+ * 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 GrColor_DEFINED
+#define GrColor_DEFINED
+
+#include "GrTypes.h"
+
+/**
+ * GrColor is 4 bytes for R, G, B, A, in a compile-time specific order. The
+ * components are stored premultiplied.
+ */
+typedef uint32_t GrColor;
+
+// indices for address a GrColor as an array of bytes
+
+#define GrColor_INDEX_R 0
+#define GrColor_INDEX_G 1
+#define GrColor_INDEX_B 2
+#define GrColor_INDEX_A 3
+
+// shfit amount to assign a component to a GrColor int
+
+#define GrColor_SHIFT_R 0
+#define GrColor_SHIFT_G 8
+#define GrColor_SHIFT_B 16
+#define GrColor_SHIFT_A 24
+
+/**
+ * Pack 4 components (RGBA) into a GrColor int
+ */
+static inline GrColor GrColorPackRGBA(unsigned r, unsigned g,
+ unsigned b, unsigned a) {
+ GrAssert((uint8_t)r == r);
+ GrAssert((uint8_t)g == g);
+ GrAssert((uint8_t)b == b);
+ GrAssert((uint8_t)a == a);
+ return (r << GrColor_SHIFT_R) |
+ (g << GrColor_SHIFT_G) |
+ (b << GrColor_SHIFT_B) |
+ (a << GrColor_SHIFT_A);
+}
+
+// extract a component (byte) from a GrColor int
+
+#define GrColorUnpackR(color) (((color) >> GrColor_SHIFT_R) & 0xFF)
+#define GrColorUnpackG(color) (((color) >> GrColor_SHIFT_G) & 0xFF)
+#define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF)
+#define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF)
+
+/**
+ * Since premultiplied means that alpha >= color, we construct a color with
+ * each component==255 and alpha == 0 to be "illegal"
+ */
+#define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A))
+
+#endif
+
diff --git a/include/gpu/GrConfig.h b/include/gpu/GrConfig.h
new file mode 100644
index 0000000000..1d07af1919
--- /dev/null
+++ b/include/gpu/GrConfig.h
@@ -0,0 +1,438 @@
+
+/*
+ * 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 GrConfig_DEFINED
+#define GrConfig_DEFINED
+
+///////////////////////////////////////////////////////////////////////////////
+// preconfig section:
+//
+// All the work before including GrUserConfig.h should center around guessing
+// what platform we're on, and defining low-level symbols based on that.
+//
+// A build environment may have already defined symbols, so we first check
+// for that
+//
+
+// hack to ensure we know what sort of Apple platform we're on
+#if defined(__APPLE_CPP__) || defined(__APPLE_CC__)
+ #include <TargetConditionals.h>
+#endif
+
+/**
+ * Gr defines are set to 0 or 1, rather than being undefined or defined
+ */
+
+#if !defined(GR_ANDROID_BUILD)
+ #define GR_ANDROID_BUILD 0
+#endif
+#if !defined(GR_IOS_BUILD)
+ #define GR_IOS_BUILD 0
+#endif
+#if !defined(GR_LINUX_BUILD)
+ #define GR_LINUX_BUILD 0
+#endif
+#if !defined(GR_MAC_BUILD)
+ #define GR_MAC_BUILD 0
+#endif
+#if !defined(GR_WIN32_BUILD)
+ #define GR_WIN32_BUILD 0
+#endif
+#if !defined(GR_QNX_BUILD)
+ #define GR_QNX_BUILD 0
+#endif
+
+/**
+ * If no build target has been defined, attempt to infer.
+ */
+#if !GR_ANDROID_BUILD && !GR_IOS_BUILD && !GR_LINUX_BUILD && !GR_MAC_BUILD && !GR_WIN32_BUILD && !GR_QNX_BUILD
+ #if defined(_WIN32)
+ #undef GR_WIN32_BUILD
+ #define GR_WIN32_BUILD 1
+// #error "WIN"
+ #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
+ #undef GR_IOS_BUILD
+ #define GR_IOS_BUILD 1
+// #error "IOS"
+ #elif (defined(ANDROID_NDK) && ANDROID_NDK) || defined(ANDROID)
+ #undef GR_ANDROID_BUILD
+ #define GR_ANDROID_BUILD 1
+// #error "ANDROID"
+ #elif TARGET_OS_MAC
+ #undef GR_MAC_BUILD
+ #define GR_MAC_BUILD 1
+// #error "MAC"
+ #elif TARGET_OS_QNX || defined(__QNXNTO__)
+ #undef GR_QNX_BUILD
+ #define GR_QNX_BUILD 1
+// #error "QNX"
+ #else
+ #undef GR_LINUX_BUILD
+ #define GR_LINUX_BUILD 1
+// #error "LINUX"
+ #endif
+#endif
+
+// we need both GR_DEBUG and GR_RELEASE to be defined as 0 or 1
+//
+#ifndef GR_DEBUG
+ #ifdef GR_RELEASE
+ #define GR_DEBUG !GR_RELEASE
+ #else
+ #ifdef NDEBUG
+ #define GR_DEBUG 0
+ #else
+ #define GR_DEBUG 1
+ #endif
+ #endif
+#endif
+
+#ifndef GR_RELEASE
+ #define GR_RELEASE !GR_DEBUG
+#endif
+
+#if GR_DEBUG == GR_RELEASE
+ #error "GR_DEBUG and GR_RELEASE must not be the same"
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+#if GR_WIN32_BUILD
+// VC8 doesn't support stdint.h, so we define those types here.
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned uint32_t;
+typedef __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+#else
+/*
+ * Include stdint.h with defines that trigger declaration of C99 limit/const
+ * macros here before anyone else has a chance to include stdint.h without
+ * these.
+ */
+#define __STDC_LIMIT_MACROS
+#define __STDC_CONSTANT_MACROS
+#include <stdint.h>
+#endif
+
+/*
+ * The "user config" file can be empty, and everything should work. It is
+ * meant to store a given platform/client's overrides of our guess-work.
+ *
+ * A alternate user config file can be specified by defining
+ * GR_USER_CONFIG_FILE. It should be defined relative to GrConfig.h
+ *
+ * e.g. it can specify GR_DEBUG/GR_RELEASE as it please, change the BUILD
+ * target, or supply its own defines for anything else (e.g. GR_SCALAR)
+ */
+#if !defined(GR_USER_CONFIG_FILE)
+ #include "GrUserConfig.h"
+#else
+ #include GR_USER_CONFIG_FILE
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// postconfig section:
+//
+
+// GR_IMPLEMENTATION should be define to 1 when building Gr and 0 when including
+// it in another dependent build. The Gr makefile/ide-project should define this
+// to 1.
+#if !defined(GR_IMPLEMENTATION)
+ #define GR_IMPLEMENTATION 0
+#endif
+
+// If Gr is built as a shared library then GR_DLL should be defined to 1 (both
+// when building Gr and when including its headers in dependent builds). Only
+// currently supported minimally for Chrome's Win32 Multi-DLL build (TODO:
+// correctly exort all of the public API correctly and support shared lib on
+// other platforms).
+#if !defined(GR_DLL)
+ #define GR_DLL 0
+#endif
+
+#if GR_DLL
+ #if GR_WIN32_BUILD
+ #if GR_IMPLEMENTATION
+ #define GR_API __declspec(dllexport)
+ #else
+ #define GR_API __declspec(dllimport)
+ #endif
+ #else
+ #define GR_API __attribute__((visibility("default")))
+ #endif
+#else
+ #define GR_API
+#endif
+
+// By now we must have a GR_..._BUILD symbol set to 1, and a decision about
+// debug -vs- release
+//
+
+extern GR_API void GrPrintf(const char format[], ...);
+
+/**
+ * GR_STRING makes a string of X where X is expanded before conversion to a string
+ * if X itself contains macros.
+ */
+#define GR_STRING(X) GR_STRING_IMPL(X)
+#define GR_STRING_IMPL(X) #X
+
+/**
+ * GR_CONCAT concatenates X and Y where each is expanded before
+ * contanenation if either contains macros.
+ */
+#define GR_CONCAT(X,Y) GR_CONCAT_IMPL(X,Y)
+#define GR_CONCAT_IMPL(X,Y) X##Y
+
+/**
+ * Creates a string of the form "<filename>(<linenumber>) : "
+ */
+#define GR_FILE_AND_LINE_STR __FILE__ "(" GR_STRING(__LINE__) ") : "
+
+/**
+ * Compilers have different ways of issuing warnings. This macro
+ * attempts to abstract them, but may need to be specialized for your
+ * particular compiler.
+ * To insert compiler warnings use "#pragma message GR_WARN(<string>)"
+ */
+#if defined(_MSC_VER) && _MSC_VER
+ #define GR_WARN(MSG) (GR_FILE_AND_LINE_STR "WARNING: " MSG)
+#else//__GNUC__ - may need other defines for different compilers
+ #define GR_WARN(MSG) ("WARNING: " MSG)
+#endif
+
+/**
+ * GR_ALWAYSBREAK is an unconditional break in all builds.
+ */
+#if !defined(GR_ALWAYSBREAK)
+ #if GR_WIN32_BUILD
+ #define GR_ALWAYSBREAK __debugbreak()
+ #else
+ // TODO: do other platforms really not have continuable breakpoints?
+ // sign extend for 64bit architectures to be sure this is
+ // in the high address range
+ #define GR_ALWAYSBREAK *((int*)(int64_t)(int32_t)0xbeefcafe) = 0;
+ #endif
+#endif
+
+/**
+ * GR_DEBUGBREAK is an unconditional break in debug builds.
+ */
+#if !defined(GR_DEBUGBREAK)
+ #if GR_DEBUG
+ #define GR_DEBUGBREAK GR_ALWAYSBREAK
+ #else
+ #define GR_DEBUGBREAK
+ #endif
+#endif
+
+/**
+ * GR_ALWAYSASSERT is an assertion in all builds.
+ */
+#if !defined(GR_ALWAYSASSERT)
+ #define GR_ALWAYSASSERT(COND) \
+ do { \
+ if (!(COND)) { \
+ GrPrintf("%s %s failed\n", GR_FILE_AND_LINE_STR, #COND); \
+ GR_ALWAYSBREAK; \
+ } \
+ } while (false)
+#endif
+
+/**
+ * GR_DEBUGASSERT is an assertion in debug builds only.
+ */
+#if !defined(GR_DEBUGASSERT)
+ #if GR_DEBUG
+ #define GR_DEBUGASSERT(COND) GR_ALWAYSASSERT(COND)
+ #else
+ #define GR_DEBUGASSERT(COND)
+ #endif
+#endif
+
+/**
+ * Prettier forms of the above macros.
+ */
+#define GrAssert(COND) GR_DEBUGASSERT(COND)
+#define GrAlwaysAssert(COND) GR_ALWAYSASSERT(COND)
+
+/**
+ * Crash from unrecoverable condition, optionally with a message.
+ */
+inline void GrCrash() { GrAlwaysAssert(false); }
+inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
+
+/**
+ * GR_DEBUGCODE compiles the code X in debug builds only
+ */
+#if !defined(GR_DEBUGCODE)
+ #if GR_DEBUG
+ #define GR_DEBUGCODE(X) X
+ #else
+ #define GR_DEBUGCODE(X)
+ #endif
+#endif
+
+/**
+ * GR_STATIC_ASSERT is a compile time assertion. Depending on the platform
+ * it may print the message in the compiler log. Obviously, the condition must
+ * be evaluatable at compile time.
+ */
+// VS 2010 and GCC compiled with c++0x or gnu++0x support the new
+// static_assert.
+#if !defined(GR_STATIC_ASSERT)
+ #if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__GXX_EXPERIMENTAL_CXX0X__) && __GXX_EXPERIMENTAL_CXX0X__)
+ #define GR_STATIC_ASSERT(CONDITION) static_assert(CONDITION, "bug")
+ #else
+ template <bool> class GR_STATIC_ASSERT_FAILURE;
+ template <> class GR_STATIC_ASSERT_FAILURE<true> {};
+ #define GR_STATIC_ASSERT(CONDITION) \
+ enum {GR_CONCAT(X,__LINE__) = \
+ sizeof(GR_STATIC_ASSERT_FAILURE<CONDITION>)}
+ #endif
+#endif
+
+#if !defined(GR_SCALAR_IS_FLOAT)
+ #define GR_SCALAR_IS_FLOAT 0
+#endif
+#if !defined(GR_SCALAR_IS_FIXED)
+ #define GR_SCALAR_IS_FIXED 0
+#endif
+
+#if !defined(GR_TEXT_SCALAR_TYPE_IS_USHORT)
+ #define GR_TEXT_SCALAR_TYPE_IS_USHORT 0
+#endif
+#if !defined(GR_TEXT_SCALAR_TYPE_IS_FLOAT)
+ #define GR_TEXT_SCALAR_TYPE_IS_FLOAT 0
+#endif
+#if !defined(GR_TEXT_SCALAR_TYPE_IS_FIXED)
+ #define GR_TEXT_SCALAR_TYPE_IS_FIXED 0
+#endif
+
+#ifndef GR_DUMP_TEXTURE_UPLOAD
+ #define GR_DUMP_TEXTURE_UPLOAD 0
+#endif
+
+/**
+ * GR_COLLECT_STATS controls whether the GrGpu class collects stats.
+ * If not already defined then collect in debug build but not release.
+ */
+#if !defined(GR_COLLECT_STATS)
+ #define GR_COLLECT_STATS GR_DEBUG
+#endif
+
+/**
+ * GR_STATIC_RECT_VB controls whether rects are drawn by issuing a vertex
+ * for each corner or using a static vb that is positioned by modifying the
+ * view / texture matrix.
+ */
+#if !defined(GR_STATIC_RECT_VB)
+ #define GR_STATIC_RECT_VB 0
+#endif
+
+/**
+ * GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
+ * for special cases. On systems where program changes are expensive this
+ * may not be advantageous. Consecutive draws may no longer use the same
+ * program.
+ */
+#if !defined(GR_AGGRESSIVE_SHADER_OPTS)
+ #define GR_AGGRESSIVE_SHADER_OPTS 0
+#endif
+
+/**
+ * GR_GEOM_BUFFER_LOCK_THRESHOLD gives a threshold (in bytes) for when Gr should
+ * lock a GrGeometryBuffer to update its contents. It will use lock() if the
+ * size of the updated region is greater than the threshold. Otherwise it will
+ * use updateData().
+ */
+#if !defined(GR_GEOM_BUFFER_LOCK_THRESHOLD)
+ #define GR_GEOM_BUFFER_LOCK_THRESHOLD (1 << 15)
+#endif
+
+/**
+ * Enables/disables use of offscreen AA
+ */
+#if !defined(GR_USE_OFFSCREEN_AA)
+ #define GR_USE_OFFSCREEN_AA 1
+#endif
+
+/**
+ * GR_MAX_OFFSCREEN_AA_SIZE controls the size at which offscreen AA will tile.
+ * Tiling saves GPU memory by limiting the size of the offscreen buffer. The
+ * max offscreen may be as large as (4*GR_MAX_OFFSCREEN_AA_SIZE)^2 pixels.
+ */
+#if !defined(GR_MAX_OFFSCREEN_AA_SIZE)
+ #define GR_MAX_OFFSCREEN_AA_SIZE 256
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// tail section:
+//
+// Now we just assert if we are missing some required define, or if we detect
+// and inconsistent combination of defines
+//
+
+
+/**
+ * Only one build target macro should be 1 and the rest should be 0.
+ */
+#define GR_BUILD_SUM (GR_WIN32_BUILD + GR_MAC_BUILD + GR_IOS_BUILD + GR_ANDROID_BUILD + GR_LINUX_BUILD + GR_QNX_BUILD)
+#if 0 == GR_BUILD_SUM
+ #error "Missing a GR_BUILD define"
+#elif 1 != GR_BUILD_SUM
+ #error "More than one GR_BUILD defined"
+#endif
+
+
+#if !GR_SCALAR_IS_FLOAT && !GR_SCALAR_IS_FIXED
+ #undef GR_SCALAR_IS_FLOAT
+ #define GR_SCALAR_IS_FLOAT 1
+ #pragma message GR_WARN("Scalar type not defined, defaulting to float")
+#endif
+
+#if !GR_TEXT_SCALAR_IS_FLOAT && \
+ !GR_TEXT_SCALAR_IS_FIXED && \
+ !GR_TEXT_SCALAR_IS_USHORT
+ #undef GR_TEXT_SCALAR_IS_FLOAT
+ #define GR_TEXT_SCALAR_IS_FLOAT 1
+ #pragma message GR_WARN("Text scalar type not defined, defaulting to float")
+#endif
+
+#if 0
+#if GR_WIN32_BUILD
+// #pragma message GR_WARN("GR_WIN32_BUILD")
+#endif
+#if GR_MAC_BUILD
+// #pragma message GR_WARN("GR_MAC_BUILD")
+#endif
+#if GR_IOS_BUILD
+// #pragma message GR_WARN("GR_IOS_BUILD")
+#endif
+#if GR_ANDROID_BUILD
+// #pragma message GR_WARN("GR_ANDROID_BUILD")
+#endif
+#if GR_LINUX_BUILD
+// #pragma message GR_WARN("GR_LINUX_BUILD")
+#endif
+#if GR_QNX_BUILD
+// #pragma message GR_WARN("GR_QNX_BUILD")
+#endif
+#endif
+
+#endif
+
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
new file mode 100644
index 0000000000..4a1f1da8c4
--- /dev/null
+++ b/include/gpu/GrContext.h
@@ -0,0 +1,733 @@
+
+/*
+ * 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 GrContext_DEFINED
+#define GrContext_DEFINED
+
+#include "GrClip.h"
+#include "GrPaint.h"
+// not strictly needed but requires WK change in LayerTextureUpdaterCanvas to
+// remove.
+#include "GrRenderTarget.h"
+
+class GrDrawTarget;
+class GrFontCache;
+class GrGpu;
+struct GrGpuStats;
+class GrIndexBuffer;
+class GrIndexBufferAllocPool;
+class GrInOrderDrawBuffer;
+class GrPathRenderer;
+class GrPathRendererChain;
+class GrResourceEntry;
+class GrResourceCache;
+class GrStencilBuffer;
+class GrVertexBuffer;
+class GrVertexBufferAllocPool;
+
+class GR_API GrContext : public GrRefCnt {
+public:
+ /**
+ * Creates a GrContext from within a 3D context.
+ */
+ static GrContext* Create(GrEngine engine,
+ GrPlatform3DContext context3D);
+
+ /**
+ * Helper to create a opengl-shader based context
+ */
+ static GrContext* CreateGLShaderContext();
+
+ virtual ~GrContext();
+
+ /**
+ * The GrContext normally assumes that no outsider is setting state
+ * within the underlying 3D API's context/device/whatever. This call informs
+ * the context that the state was modified and it should resend. Shouldn't
+ * be called frequently for good performance.
+ */
+ void resetContext();
+
+ /**
+ * Abandons all gpu resources, assumes 3D API state is unknown. Call this
+ * if you have lost the associated GPU context, and thus internal texture,
+ * buffer, etc. references/IDs are now invalid. Should be called even when
+ * GrContext is no longer going to be used for two reasons:
+ * 1) ~GrContext will not try to free the objects in the 3D API.
+ * 2) If you've created GrResources that outlive the GrContext they will
+ * be marked as invalid (GrResource::isValid()) and won't attempt to
+ * free their underlying resource in the 3D API.
+ * Content drawn since the last GrContext::flush() may be lost.
+ */
+ void contextLost();
+
+ /**
+ * Similar to contextLost, but makes no attempt to reset state.
+ * Use this method when GrContext destruction is pending, but
+ * the graphics context is destroyed first.
+ */
+ void contextDestroyed();
+
+ /**
+ * Frees gpu created by the context. Can be called to reduce GPU memory
+ * pressure.
+ */
+ void freeGpuResources();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Textures
+
+ /**
+ * Token that refers to an entry in the texture cache. Returned by
+ * functions that lock textures. Passed to unlockTexture.
+ */
+ class TextureCacheEntry {
+ public:
+ TextureCacheEntry() : fEntry(NULL) {}
+ TextureCacheEntry(const TextureCacheEntry& e) : fEntry(e.fEntry) {}
+ TextureCacheEntry& operator= (const TextureCacheEntry& e) {
+ fEntry = e.fEntry;
+ return *this;
+ }
+ GrTexture* texture() const;
+ void reset() { fEntry = NULL; }
+ private:
+ explicit TextureCacheEntry(GrResourceEntry* entry) { fEntry = entry; }
+ void set(GrResourceEntry* entry) { fEntry = entry; }
+ GrResourceEntry* cacheEntry() { return fEntry; }
+ GrResourceEntry* fEntry;
+ friend class GrContext;
+ };
+
+ /**
+ * Key generated by client. Should be a unique key on the texture data.
+ * Does not need to consider that width and height of the texture. Two
+ * textures with the same TextureKey but different bounds will not collide.
+ */
+ typedef uint64_t TextureKey;
+
+ /**
+ * Search for an entry based on key and dimensions. If found, "lock" it and
+ * return it. The entry's texture() function will return NULL if not found.
+ * Must call be balanced with an unlockTexture() call.
+ */
+ TextureCacheEntry findAndLockTexture(TextureKey key,
+ int width,
+ int height,
+ const GrSamplerState&);
+
+ /**
+ * Create a new entry, based on the specified key and texture, and return
+ * its "locked" entry. Must call be balanced with an unlockTexture() call.
+ */
+ TextureCacheEntry createAndLockTexture(TextureKey key,
+ const GrSamplerState&,
+ const GrTextureDesc&,
+ void* srcData, size_t rowBytes);
+
+ /**
+ * Enum that determines how closely a returned scratch texture must match
+ * a provided GrTextureDesc.
+ */
+ enum ScratchTexMatch {
+ /**
+ * Finds a texture that exactly matches the descriptor.
+ */
+ kExact_ScratchTexMatch,
+ /**
+ * Finds a texture that approximately matches the descriptor. Will be
+ * at least as large in width and height as desc specifies. If desc
+ * specifies that texture is a render target then result will be a
+ * render target. If desc specifies a render target and doesn't set the
+ * no stencil flag then result will have a stencil. Format and aa level
+ * will always match.
+ */
+ kApprox_ScratchTexMatch
+ };
+
+ /**
+ * Returns a texture matching the desc. It's contents are unknown. Subsequent
+ * requests with the same descriptor are not guaranteed to return the same
+ * texture. The same texture is guaranteed not be returned again until it is
+ * unlocked. Must call be balanced with an unlockTexture() call.
+ *
+ * Textures created by createAndLockTexture() hide the complications of
+ * tiling non-power-of-two textures on APIs that don't support this (e.g.
+ * unextended GLES2). Tiling a npot texture created by lockScratchTexture on
+ * such an API will create gaps in the tiling pattern. This includes clamp
+ * mode. (This may be addressed in a future update.)
+ */
+ TextureCacheEntry lockScratchTexture(const GrTextureDesc& desc, ScratchTexMatch match);
+
+ /**
+ * When done with an entry, call unlockTexture(entry) on it, which returns
+ * it to the cache, where it may be purged.
+ */
+ void unlockTexture(TextureCacheEntry entry);
+
+ /**
+ * Creates a texture that is outside the cache. Does not count against
+ * cache's budget.
+ */
+ GrTexture* createUncachedTexture(const GrTextureDesc&,
+ void* srcData,
+ size_t rowBytes);
+
+ /**
+ * Returns true if the specified use of an indexed texture is supported.
+ */
+ bool supportsIndex8PixelConfig(const GrSamplerState&,
+ int width,
+ int height) const;
+
+ /**
+ * Return the current texture cache limits.
+ *
+ * @param maxTextures If non-null, returns maximum number of textures that
+ * can be held in the cache.
+ * @param maxTextureBytes If non-null, returns maximum number of bytes of
+ * texture memory that can be held in the cache.
+ */
+ void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const;
+
+ /**
+ * Specify the texture cache limits. If the current cache exceeds either
+ * of these, it will be purged (LRU) to keep the cache within these limits.
+ *
+ * @param maxTextures The maximum number of textures that can be held in
+ * the cache.
+ * @param maxTextureBytes The maximum number of bytes of texture memory
+ * that can be held in the cache.
+ */
+ void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes);
+
+ /**
+ * Return the max width or height of a texture supported by the current gpu
+ */
+ int getMaxTextureSize() const;
+
+ /**
+ * Return the max width or height of a render target supported by the
+ * current gpu
+ */
+ int getMaxRenderTargetSize() const;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Render targets
+
+ /**
+ * Sets the render target.
+ * @param target the render target to set. (should not be NULL.)
+ */
+ void setRenderTarget(GrRenderTarget* target);
+
+ /**
+ * Gets the current render target.
+ * @return the currently bound render target. Should never be NULL.
+ */
+ const GrRenderTarget* getRenderTarget() const;
+ GrRenderTarget* getRenderTarget();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Platform Surfaces
+
+ /**
+ * Wraps an existing 3D API surface in a GrObject. desc.fFlags determines
+ * the type of object returned. If kIsTexture is set the returned object
+ * will be a GrTexture*. Otherwise, it will be a GrRenderTarget*. If both
+ * are set the render target object is accessible by
+ * GrTexture::asRenderTarget().
+ *
+ * GL: if the object is a texture Gr may change its GL texture parameters
+ * when it is drawn.
+ *
+ * @param desc description of the object to create.
+ * @return either a GrTexture* or GrRenderTarget* depending on desc. NULL
+ * on failure.
+ */
+ GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc);
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Matrix state
+
+ /**
+ * Gets the current transformation matrix.
+ * @return the current matrix.
+ */
+ const GrMatrix& getMatrix() const;
+
+ /**
+ * Sets the transformation matrix.
+ * @param m the matrix to set.
+ */
+ void setMatrix(const GrMatrix& m);
+
+ /**
+ * Concats the current matrix. The passed matrix is applied before the
+ * current matrix.
+ * @param m the matrix to concat.
+ */
+ void concatMatrix(const GrMatrix& m) const;
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Clip state
+ /**
+ * Gets the current clip.
+ * @return the current clip.
+ */
+ const GrClip& getClip() const;
+
+ /**
+ * Sets the clip.
+ * @param clip the clip to set.
+ */
+ void setClip(const GrClip& clip);
+
+ /**
+ * Convenience method for setting the clip to a rect.
+ * @param rect the rect to set as the new clip.
+ */
+ void setClip(const GrIRect& rect);
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Draws
+
+ /**
+ * Clear the entire or rect of the render target, ignoring any clips.
+ * @param rect the rect to clear or the whole thing if rect is NULL.
+ * @param color the color to clear to.
+ */
+ void clear(const GrIRect* rect, GrColor color);
+
+ /**
+ * Draw everywhere (respecting the clip) with the paint.
+ */
+ void drawPaint(const GrPaint& paint);
+
+ /**
+ * Draw the rect using a paint.
+ * @param paint describes how to color pixels.
+ * @param strokeWidth If strokeWidth < 0, then the rect is filled, else
+ * the rect is mitered stroked based on strokeWidth. If
+ * strokeWidth == 0, then the stroke is always a single
+ * pixel thick.
+ * @param matrix Optional matrix applied to the rect. Applied before
+ * context's matrix or the paint's matrix.
+ * The rects coords are used to access the paint (through texture matrix)
+ */
+ void drawRect(const GrPaint& paint,
+ const GrRect&,
+ GrScalar strokeWidth = -1,
+ const GrMatrix* matrix = NULL);
+
+ /**
+ * Maps a rect of paint coordinates onto the a rect of destination
+ * coordinates. Each rect can optionally be transformed. The srcRect
+ * is stretched over the dstRect. The dstRect is transformed by the
+ * context's matrix and the srcRect is transformed by the paint's matrix.
+ * Additional optional matrices can be provided by parameters.
+ *
+ * @param paint describes how to color pixels.
+ * @param dstRect the destination rect to draw.
+ * @param srcRect rect of paint coordinates to be mapped onto dstRect
+ * @param dstMatrix Optional matrix to transform dstRect. Applied before
+ * context's matrix.
+ * @param srcMatrix Optional matrix to transform srcRect Applied before
+ * paint's matrix.
+ */
+ void drawRectToRect(const GrPaint& paint,
+ const GrRect& dstRect,
+ const GrRect& srcRect,
+ const GrMatrix* dstMatrix = NULL,
+ const GrMatrix* srcMatrix = NULL);
+
+ /**
+ * Draws a path.
+ *
+ * @param paint describes how to color pixels.
+ * @param path the path to draw
+ * @param fill the path filling rule to use.
+ * @param translate optional additional translation applied to the
+ * path.
+ */
+ void drawPath(const GrPaint& paint, const GrPath& path, GrPathFill fill,
+ const GrPoint* translate = NULL);
+
+ /**
+ * Draws vertices with a paint.
+ *
+ * @param paint describes how to color pixels.
+ * @param primitiveType primitives type to draw.
+ * @param vertexCount number of vertices.
+ * @param positions array of vertex positions, required.
+ * @param texCoords optional array of texture coordinates used
+ * to access the paint.
+ * @param colors optional array of per-vertex colors, supercedes
+ * the paint's color field.
+ * @param indices optional array of indices. If NULL vertices
+ * are drawn non-indexed.
+ * @param indexCount if indices is non-null then this is the
+ * number of indices.
+ */
+ void drawVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ int vertexCount,
+ const GrPoint positions[],
+ const GrPoint texs[],
+ const GrColor colors[],
+ const uint16_t indices[],
+ int indexCount);
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Misc.
+
+ /**
+ * Currently needed by SkGpuDevice. Ideally this shouldn't be exposed.
+ */
+ bool supportsShaders() const;
+
+ /**
+ * Flags that affect flush() behavior.
+ */
+ enum FlushBits {
+ /**
+ * A client may want Gr to bind a GrRenderTarget in the 3D API so that
+ * it can be rendered to directly. However, Gr lazily sets state. Simply
+ * calling setRenderTarget() followed by flush() without flags may not
+ * bind the render target. This flag forces the context to bind the last
+ * set render target in the 3D API.
+ */
+ kForceCurrentRenderTarget_FlushBit = 0x1,
+ /**
+ * A client may reach a point where it has partially rendered a frame
+ * through a GrContext that it knows the user will never see. This flag
+ * causes the flush to skip submission of deferred content to the 3D API
+ * during the flush.
+ */
+ kDiscard_FlushBit = 0x2,
+ };
+
+ /**
+ * Call to ensure all drawing to the context has been issued to the
+ * underlying 3D API.
+ * @param flagsBitfield flags that control the flushing behavior. See
+ * FlushBits.
+ */
+ void flush(int flagsBitfield = 0);
+
+ /**
+ * Reads a rectangle of pixels from a render target.
+ * @param renderTarget the render target to read from. NULL means the
+ * current render target.
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ *
+ * @return true if the read succeeded, false if not. The read can fail
+ * because of a unsupported pixel config or because no render
+ * target is currently set.
+ */
+ bool readRenderTargetPixels(GrRenderTarget* target,
+ int left, int top, int width, int height,
+ GrPixelConfig config, void* buffer);
+
+ /**
+ * Reads a rectangle of pixels from a texture.
+ * @param texture the render target to read from.
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ *
+ * @return true if the read succeeded, false if not. The read can fail
+ * because of a unsupported pixel config.
+ */
+ bool readTexturePixels(GrTexture* target,
+ int left, int top, int width, int height,
+ GrPixelConfig config, void* buffer);
+
+ /**
+ * Copy the src pixels [buffer, stride, pixelconfig] into the current
+ * render-target at the specified rectangle.
+ */
+ void writePixels(int left, int top, int width, int height,
+ GrPixelConfig, const void* buffer, size_t stride);
+
+ /**
+ * Applies a 1D convolution kernel in the X direction to a rectangle of
+ * pixels from a given texture.
+ * @param texture the texture to read from
+ * @param rect the destination rectangle
+ * @param kernel the convolution kernel (kernelWidth elements)
+ * @param kernelWidth the width of the convolution kernel
+ */
+ void convolveInX(GrTexture* texture,
+ const SkRect& rect,
+ const float* kernel,
+ int kernelWidth);
+ /**
+ * Applies a 1D convolution kernel in the Y direction to a rectangle of
+ * pixels from a given texture.
+ * direction.
+ * @param texture the texture to read from
+ * @param rect the destination rectangle
+ * @param kernel the convolution kernel (kernelWidth elements)
+ * @param kernelWidth the width of the convolution kernel
+ */
+ void convolveInY(GrTexture* texture,
+ const SkRect& rect,
+ const float* kernel,
+ int kernelWidth);
+ ///////////////////////////////////////////////////////////////////////////
+ // Helpers
+
+ class AutoRenderTarget : ::GrNoncopyable {
+ public:
+ AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
+ fContext = NULL;
+ fPrevTarget = context->getRenderTarget();
+ if (fPrevTarget != target) {
+ context->setRenderTarget(target);
+ fContext = context;
+ }
+ }
+ ~AutoRenderTarget() {
+ if (fContext) {
+ fContext->setRenderTarget(fPrevTarget);
+ }
+ }
+ private:
+ GrContext* fContext;
+ GrRenderTarget* fPrevTarget;
+ };
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Functions intended for internal use only.
+ GrGpu* getGpu() { return fGpu; }
+ const GrGpu* getGpu() const { return fGpu; }
+ GrFontCache* getFontCache() { return fFontCache; }
+ GrDrawTarget* getTextTarget(const GrPaint& paint);
+ void flushText();
+ const GrIndexBuffer* getQuadIndexBuffer() const;
+ void resetStats();
+ const GrGpuStats& getStats() const;
+ void printStats() const;
+ /**
+ * Stencil buffers add themselves to the cache using
+ * addAndLockStencilBuffer. When a SB's RT-attachment count
+ * reaches zero the SB unlocks itself using unlockStencilBuffer and is
+ * eligible for purging. findStencilBuffer is called to check the cache for
+ * a SB that matching an RT's criteria. If a match is found that has been
+ * unlocked (its attachment count has reached 0) then it will be relocked.
+ */
+ GrResourceEntry* addAndLockStencilBuffer(GrStencilBuffer* sb);
+ void unlockStencilBuffer(GrResourceEntry* sbEntry);
+ GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt);
+
+private:
+ // used to keep track of when we need to flush the draw buffer
+ enum DrawCategory {
+ kBuffered_DrawCategory, // last draw was inserted in draw buffer
+ kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
+ kText_DrawCategory // text context was last to draw
+ };
+ DrawCategory fLastDrawCategory;
+
+ GrGpu* fGpu;
+ GrResourceCache* fTextureCache;
+ GrFontCache* fFontCache;
+
+ GrPathRendererChain* fPathRendererChain;
+
+ GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
+ GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
+ GrInOrderDrawBuffer* fDrawBuffer;
+
+ GrIndexBuffer* fAAFillRectIndexBuffer;
+ GrIndexBuffer* fAAStrokeRectIndexBuffer;
+ int fMaxOffscreenAASize;
+
+ GrContext(GrGpu* gpu);
+
+ void fillAARect(GrDrawTarget* target,
+ const GrRect& devRect,
+ bool useVertexCoverage);
+
+ void strokeAARect(GrDrawTarget* target,
+ const GrRect& devRect,
+ const GrVec& devStrokeSize,
+ bool useVertexCoverage);
+
+ inline int aaFillRectIndexCount() const;
+ GrIndexBuffer* aaFillRectIndexBuffer();
+
+ inline int aaStrokeRectIndexCount() const;
+ GrIndexBuffer* aaStrokeRectIndexBuffer();
+
+ void setupDrawBuffer();
+
+ void flushDrawBuffer();
+
+ static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
+
+ GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
+
+ GrPathRenderer* getPathRenderer(const GrDrawTarget* target,
+ const GrPath& path,
+ GrPathFill fill);
+
+ struct OffscreenRecord;
+
+ // determines whether offscreen AA should be applied
+ bool doOffscreenAA(GrDrawTarget* target,
+ bool isHairLines) const;
+
+ // attempts to setup offscreen AA. All paint state must be transferred to
+ // target by the time this is called.
+ bool prepareForOffscreenAA(GrDrawTarget* target,
+ bool requireStencil,
+ const GrIRect& boundRect,
+ GrPathRenderer* pr,
+ OffscreenRecord* record);
+
+ // sets up target to draw coverage to the supersampled render target
+ void setupOffscreenAAPass1(GrDrawTarget* target,
+ const GrIRect& boundRect,
+ int tileX, int tileY,
+ OffscreenRecord* record);
+
+ // sets up target to sample coverage of supersampled render target back
+ // to the main render target using stage kOffscreenStage.
+ void doOffscreenAAPass2(GrDrawTarget* target,
+ const GrPaint& paint,
+ const GrIRect& boundRect,
+ int tileX, int tileY,
+ OffscreenRecord* record);
+
+ // restored the draw target state and releases offscreen target to cache
+ void cleanupOffscreenAA(GrDrawTarget* target,
+ GrPathRenderer* pr,
+ OffscreenRecord* record);
+
+ void convolve(GrTexture* texture,
+ const SkRect& rect,
+ float imageIncrement[2],
+ const float* kernel,
+ int kernelWidth);
+
+ // computes vertex layout bits based on the paint. If paint expresses
+ // a texture for a stage, the stage coords will be bound to postitions
+ // unless hasTexCoords[s]==true in which case stage s's input coords
+ // are bound to tex coord index s. hasTexCoords == NULL is a shortcut
+ // for an array where all the values are false.
+ static int PaintStageVertexLayoutBits(
+ const GrPaint& paint,
+ const bool hasTexCoords[GrPaint::kTotalStages]);
+
+};
+
+/**
+ * Save/restore the view-matrix in the context.
+ */
+class GrAutoMatrix : GrNoncopyable {
+public:
+ GrAutoMatrix() : fContext(NULL) {}
+ GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ }
+ GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ ctx->setMatrix(matrix);
+ }
+ void set(GrContext* ctx) {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ fMatrix = ctx->getMatrix();
+ fContext = ctx;
+ }
+ void set(GrContext* ctx, const GrMatrix& matrix) {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ fMatrix = ctx->getMatrix();
+ ctx->setMatrix(matrix);
+ fContext = ctx;
+ }
+ ~GrAutoMatrix() {
+ if (NULL != fContext) {
+ fContext->setMatrix(fMatrix);
+ }
+ }
+
+private:
+ GrContext* fContext;
+ GrMatrix fMatrix;
+};
+
+/**
+ * Gets and locks a scratch texture from a descriptor using
+ * either exact or approximate criteria. Unlocks texture in
+ * the destructor.
+ */
+class GrAutoScratchTexture : ::GrNoncopyable {
+public:
+ GrAutoScratchTexture()
+ : fContext(NULL) {
+ }
+
+ GrAutoScratchTexture(GrContext* context,
+ const GrTextureDesc& desc,
+ GrContext::ScratchTexMatch match =
+ GrContext::kApprox_ScratchTexMatch)
+ : fContext(NULL) {
+ this->set(context, desc, match);
+ }
+
+ ~GrAutoScratchTexture() {
+ if (NULL != fContext) {
+ fContext->unlockTexture(fEntry);
+ }
+ }
+
+ GrTexture* set(GrContext* context,
+ const GrTextureDesc& desc,
+ GrContext::ScratchTexMatch match =
+ GrContext::kApprox_ScratchTexMatch) {
+ if (NULL != fContext) {
+ fContext->unlockTexture(fEntry);
+ }
+ fContext = context;
+ if (NULL != fContext) {
+ fEntry = fContext->lockScratchTexture(desc, match);
+ GrTexture* ret = fEntry.texture();
+ if (NULL == ret) {
+ fContext = NULL;
+ }
+ return ret;
+ } else {
+ return NULL;
+ }
+ }
+
+ GrTexture* texture() { return fEntry.texture(); }
+private:
+ GrContext* fContext;
+ GrContext::TextureCacheEntry fEntry;
+};
+
+#endif
+
diff --git a/include/gpu/GrFontScaler.h b/include/gpu/GrFontScaler.h
new file mode 100644
index 0000000000..657647dea5
--- /dev/null
+++ b/include/gpu/GrFontScaler.h
@@ -0,0 +1,37 @@
+
+/*
+ * 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 GrFontScaler_DEFINED
+#define GrFontScaler_DEFINED
+
+#include "GrGlyph.h"
+#include "GrKey.h"
+
+class SkPath;
+
+/**
+ * This is a virtual base class which Gr's interface to the host platform's
+ * font scaler.
+ *
+ * The client is responsible for subclassing, and instantiating this. The
+ * instance is create for a specific font+size+matrix.
+ */
+class GrFontScaler : public GrRefCnt {
+public:
+ virtual const GrKey* getKey() = 0;
+ virtual GrMaskFormat getMaskFormat() = 0;
+ virtual bool getPackedGlyphBounds(GrGlyph::PackedID, GrIRect* bounds) = 0;
+ virtual bool getPackedGlyphImage(GrGlyph::PackedID, int width, int height,
+ int rowBytes, void* image) = 0;
+ virtual bool getGlyphPath(uint16_t glyphID, SkPath*) = 0;
+};
+
+#endif
+
diff --git a/include/gpu/GrGLConfig.h b/include/gpu/GrGLConfig.h
new file mode 100644
index 0000000000..44a3b8647c
--- /dev/null
+++ b/include/gpu/GrGLConfig.h
@@ -0,0 +1,265 @@
+
+/*
+ * 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 GrGLConfig_DEFINED
+#define GrGLConfig_DEFINED
+
+#include "GrTypes.h"
+#include "GrGLDefines.h"
+
+/**
+ * Optional GL config file.
+ */
+#ifdef GR_GL_CUSTOM_SETUP_HEADER
+ #include GR_GL_CUSTOM_SETUP_HEADER
+#endif
+
+#if !defined(GR_GL_FUNCTION_TYPE)
+ #define GR_GL_FUNCTION_TYPE
+#endif
+
+/**
+ * The following are optional defines that can be enabled at the compiler
+ * command line, in a IDE project, in a GrUserConfig.h file, or in a GL custom
+ * file (if one is in use). If a GR_GL_CUSTOM_SETUP_HEADER is used they can
+ * also be placed there.
+ *
+ * GR_GL_LOG_CALLS: if 1 Gr can print every GL call using GrPrintf. Defaults to
+ * 0. Logging can be enabled and disabled at runtime using a debugger via to
+ * global gLogCallsGL. The initial value of gLogCallsGL is controlled by
+ * GR_GL_LOG_CALLS_START.
+ *
+ * GR_GL_LOG_CALLS_START: controls the initial value of gLogCallsGL when
+ * GR_GL_LOG_CALLS is 1. Defaults to 0.
+ *
+ * GR_GL_CHECK_ERROR: if enabled Gr can do a glGetError() after every GL call.
+ * Defaults to 1 if GR_DEBUG is set, otherwise 0. When GR_GL_CHECK_ERROR is 1
+ * this can be toggled in a debugger using the gCheckErrorGL global. The initial
+ * value of gCheckErrorGL is controlled by by GR_GL_CHECK_ERROR_START.
+ *
+ * GR_GL_CHECK_ERROR_START: controls the initial value of gCheckErrorGL
+ * when GR_GL_CHECK_ERROR is 1. Defaults to 1.
+ *
+ * GR_GL_NO_CONSTANT_ATTRIBUTES: if this evaluates to true then the GL backend
+ * will use uniforms instead of attributes in all cases when there is not
+ * per-vertex data. This is important when the underlying GL implementation
+ * doesn't actually support immediate style attribute values (e.g. when
+ * the GL stream is converted to DX as in ANGLE on Chrome). Defaults to 0.
+ *
+ * GR_GL_ATTRIBUTE_MATRICES: If changing uniforms is very expensive it may be
+ * faster to use vertex attributes for matrices (set via glVertexAttrib3fv).
+ * Setting this build flag enables this behavior. GR_GL_NO_CONSTANT_ATTRIBUTES
+ * must not be set since this uses constant attributes for the matrices.
+ * Defaults to 0.
+ *
+ * GR_GL_USE_BUFFER_DATA_NULL_HINT: When specifing new data for a vertex/index
+ * buffer that replaces old data Ganesh can give a hint to the driver that the
+ * previous data will not be used in future draws like this:
+ * glBufferData(GL_..._BUFFER, size, NULL, usage); //<--hint, NULL means
+ * glBufferSubData(GL_..._BUFFER, 0, lessThanSize, data) // old data can't be
+ * // used again.
+ * However, this can be an unoptimization on some platforms, esp. Chrome.
+ * Chrome's cmd buffer will create a new allocation and memset the whole thing
+ * to zero (for security reasons). Defaults to 1 (enabled).
+ *
+ * GR_GL_PER_GL_FUNC_CALLBACK: When set to 1 the GrGLInterface object provides
+ * a function pointer that is called just before every gl function. The ptr must
+ * be valid (i.e. there is no NULL check). However, by default the callback will
+ * be set to a function that does nothing. The signature of the function is:
+ * void function(const GrGLInterface*)
+ * It is not extern "C".
+ * The GrGLInterface field fCallback specifies the function ptr and there is an
+ * additional field fCallbackData of type intptr_t for client data.
+ */
+
+#if !defined(GR_GL_LOG_CALLS)
+ #define GR_GL_LOG_CALLS GR_DEBUG
+#endif
+
+#if !defined(GR_GL_LOG_CALLS_START)
+ #define GR_GL_LOG_CALLS_START 0
+#endif
+
+#if !defined(GR_GL_CHECK_ERROR)
+ #define GR_GL_CHECK_ERROR GR_DEBUG
+#endif
+
+#if !defined(GR_GL_CHECK_ERROR_START)
+ #define GR_GL_CHECK_ERROR_START 1
+#endif
+
+#if !defined(GR_GL_NO_CONSTANT_ATTRIBUTES)
+ #define GR_GL_NO_CONSTANT_ATTRIBUTES 0
+#endif
+
+#if !defined(GR_GL_ATTRIBUTE_MATRICES)
+ #define GR_GL_ATTRIBUTE_MATRICES 0
+#endif
+
+#if !defined(GR_GL_USE_BUFFER_DATA_NULL_HINT)
+ #define GR_GL_USE_BUFFER_DATA_NULL_HINT 1
+#endif
+
+#if !defined(GR_GL_PER_GL_FUNC_CALLBACK)
+ #define GR_GL_PER_GL_FUNC_CALLBACK 0
+#endif
+
+#if(GR_GL_NO_CONSTANT_ATTRIBUTES) && (GR_GL_ATTRIBUTE_MATRICES)
+ #error "Cannot combine GR_GL_NO_CONSTANT_ATTRIBUTES and GR_GL_ATTRIBUTE_MATRICES"
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * The following macros are used to staticlly configure the default
+ * GrGLInterface, but should not be used outside of the GrGLInterface
+ * scaffolding. Undefine here to prevent accidental use.
+ */
+#undef GR_SUPPORT_GLDESKTOP
+#undef GR_SUPPORT_GLES1
+#undef GR_SUPPORT_GLES2
+#undef GR_SUPPORT_GLES
+
+////////////////////////////////////////////////////////////////////////////////
+
+#if GR_SCALAR_IS_FIXED
+ #define GrGLType GL_FIXED
+#elif GR_SCALAR_IS_FLOAT
+ #define GrGLType GR_GL_FLOAT
+#else
+ #error "unknown GR_SCALAR type"
+#endif
+
+#if GR_TEXT_SCALAR_IS_USHORT
+ #define GrGLTextType GR_GL_UNSIGNED_SHORT
+ #define GR_GL_TEXT_TEXTURE_NORMALIZED 1
+#elif GR_TEXT_SCALAR_IS_FLOAT
+ #define GrGLTextType GR_GL_FLOAT
+ #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
+#elif GR_TEXT_SCALAR_IS_FIXED
+ #define GrGLTextType GR_GL_FIXED
+ #define GR_GL_TEXT_TEXTURE_NORMALIZED 0
+#else
+ #error "unknown GR_TEXT_SCALAR type"
+#endif
+
+// Pick a pixel config for 32bit bitmaps. Our default is GL_RGBA (except on
+// Windows where we match GDI's order).
+#ifndef GR_GL_32BPP_COLOR_FORMAT
+ #if GR_WIN32_BUILD || GR_LINUX_BUILD
+ #define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
+ #else
+ #define GR_GL_32BPP_COLOR_FORMAT GR_GL_RGBA
+ #endif
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+struct GrGLInterface;
+
+extern void GrGLCheckErr(const GrGLInterface* gl,
+ const char* location,
+ const char* call);
+
+extern void GrGLClearErr(const GrGLInterface* gl);
+
+#if GR_GL_CHECK_ERROR
+ extern bool gCheckErrorGL;
+ #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
+ if (gCheckErrorGL) \
+ GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
+#else
+ #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
+#endif
+
+#if GR_GL_LOG_CALLS
+ extern bool gLogCallsGL;
+ #define GR_GL_LOG_CALLS_IMPL(X) \
+ if (gLogCallsGL) \
+ GrPrintf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
+#else
+ #define GR_GL_LOG_CALLS_IMPL(X)
+#endif
+
+#if GR_GL_PER_GL_FUNC_CALLBACK
+ #define GR_GL_CALLBACK_IMPL(IFACE) (IFACE)->fCallback(IFACE)
+#else
+ #define GR_GL_CALLBACK_IMPL(IFACE)
+#endif
+
+#define GR_GL_CALL(IFACE, X) \
+ do { \
+ GR_GL_CALL_NOERRCHECK(IFACE, X); \
+ GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
+ } while (false)
+
+#define GR_GL_CALL_NOERRCHECK(IFACE, X) \
+ do { \
+ GR_GL_CALLBACK_IMPL(IFACE); \
+ (IFACE)->f##X; \
+ GR_GL_LOG_CALLS_IMPL(X); \
+ } while (false)
+
+#define GR_GL_CALL_RET(IFACE, RET, X) \
+ do { \
+ GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
+ GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
+ } while (false)
+
+#define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
+ do { \
+ GR_GL_CALLBACK_IMPL(IFACE); \
+ (RET) = (IFACE)->f##X; \
+ GR_GL_LOG_CALLS_IMPL(X); \
+ } while (false)
+
+#define GR_GL_GET_ERROR(IFACE) (IFACE)->fGetError()
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * GrGLResetRowLength() will reset GL_UNPACK_ROW_LENGTH to 0. We write
+ * this wrapper, since GL_UNPACK_ROW_LENGTH is not available on all GL versions
+ */
+extern void GrGLResetRowLength(const GrGLInterface*);
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Some drivers want the var-int arg to be zero-initialized on input.
+ */
+#define GR_GL_INIT_ZERO 0
+#define GR_GL_GetIntegerv(gl, e, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetIntegerv(e, p)); \
+ } while (0)
+
+#define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
+ } while (0)
+
+#define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
+ } while (0)
+
+#define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
+ do { \
+ *(p) = GR_GL_INIT_ZERO; \
+ GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
+ } while (0)
+
+////////////////////////////////////////////////////////////////////////////////
+
+#endif
diff --git a/include/gpu/GrGLConfig_chrome.h b/include/gpu/GrGLConfig_chrome.h
new file mode 100644
index 0000000000..c00f269952
--- /dev/null
+++ b/include/gpu/GrGLConfig_chrome.h
@@ -0,0 +1,27 @@
+
+/*
+ * 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 GrGLConfig_chrome_DEFINED
+#define GrGLConfig_chrome_DEFINED
+
+// chrome always assumes BGRA
+#define GR_GL_32BPP_COLOR_FORMAT GR_GL_BGRA
+
+// glGetError() forces a sync with gpu process on chrome
+#define GR_GL_CHECK_ERROR_START 0
+
+// ANGLE creates a temp VB for vertex attributes not specified per-vertex.
+#define GR_GL_NO_CONSTANT_ATTRIBUTES GR_WIN32_BUILD
+
+// cmd buffer allocates memory and memsets it to zero when it sees glBufferData
+// with NULL.
+#define GR_GL_USE_BUFFER_DATA_NULL_HINT 0
+
+// chrome uses this to set the context on each GL call.
+#define GR_GL_PER_GL_FUNC_CALLBACK 1
+
+#endif
diff --git a/include/gpu/GrGLDefines.h b/include/gpu/GrGLDefines.h
new file mode 100644
index 0000000000..dcacb77686
--- /dev/null
+++ b/include/gpu/GrGLDefines.h
@@ -0,0 +1,659 @@
+
+/*
+ * 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 GrGLDefines_DEFINED
+#define GrGLDefines_DEFINED
+
+// The following constants consist of the intersection of GL constants
+// exported by GLES 1.0, GLES 2.0, and desktop GL required by the system.
+
+#define GR_GL_DEPTH_BUFFER_BIT 0x00000100
+#define GR_GL_STENCIL_BUFFER_BIT 0x00000400
+#define GR_GL_COLOR_BUFFER_BIT 0x00004000
+
+/* Boolean */
+#define GR_GL_FALSE 0
+#define GR_GL_TRUE 1
+
+/* BeginMode */
+#define GR_GL_POINTS 0x0000
+#define GR_GL_LINES 0x0001
+#define GR_GL_LINE_LOOP 0x0002
+#define GR_GL_LINE_STRIP 0x0003
+#define GR_GL_TRIANGLES 0x0004
+#define GR_GL_TRIANGLE_STRIP 0x0005
+#define GR_GL_TRIANGLE_FAN 0x0006
+
+/* AlphaFunction (not supported in ES20) */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* BlendingFactorDest */
+#define GR_GL_ZERO 0
+#define GR_GL_ONE 1
+#define GR_GL_SRC_COLOR 0x0300
+#define GR_GL_ONE_MINUS_SRC_COLOR 0x0301
+#define GR_GL_SRC_ALPHA 0x0302
+#define GR_GL_ONE_MINUS_SRC_ALPHA 0x0303
+#define GR_GL_DST_ALPHA 0x0304
+#define GR_GL_ONE_MINUS_DST_ALPHA 0x0305
+
+/* BlendingFactorSrc */
+/* GL_ZERO */
+/* GL_ONE */
+#define GR_GL_DST_COLOR 0x0306
+#define GR_GL_ONE_MINUS_DST_COLOR 0x0307
+#define GR_GL_SRC_ALPHA_SATURATE 0x0308
+/* GL_SRC_ALPHA */
+/* GL_ONE_MINUS_SRC_ALPHA */
+/* GL_DST_ALPHA */
+/* GL_ONE_MINUS_DST_ALPHA */
+
+/* ExtendedBlendFactors */
+#define GR_GL_SRC1_COLOR 0x88F9
+#define GR_GL_ONE_MINUS_SRC1_COLOR 0x88FA
+/* GL_SRC1_ALPHA */
+#define GR_GL_ONE_MINUS_SRC1_ALPHA 0x88FB
+
+/* BlendEquationSeparate */
+#define GR_GL_FUNC_ADD 0x8006
+#define GR_GL_BLEND_EQUATION 0x8009
+#define GR_GL_BLEND_EQUATION_RGB 0x8009 /* same as BLEND_EQUATION */
+#define GR_GL_BLEND_EQUATION_ALPHA 0x883D
+
+/* BlendSubtract */
+#define GR_GL_FUNC_SUBTRACT 0x800A
+#define GR_GL_FUNC_REVERSE_SUBTRACT 0x800B
+
+/* Separate Blend Functions */
+#define GR_GL_BLEND_DST_RGB 0x80C8
+#define GR_GL_BLEND_SRC_RGB 0x80C9
+#define GR_GL_BLEND_DST_ALPHA 0x80CA
+#define GR_GL_BLEND_SRC_ALPHA 0x80CB
+#define GR_GL_CONSTANT_COLOR 0x8001
+#define GR_GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GR_GL_CONSTANT_ALPHA 0x8003
+#define GR_GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#define GR_GL_BLEND_COLOR 0x8005
+
+/* Buffer Objects */
+#define GR_GL_ARRAY_BUFFER 0x8892
+#define GR_GL_ELEMENT_ARRAY_BUFFER 0x8893
+#define GR_GL_ARRAY_BUFFER_BINDING 0x8894
+#define GR_GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
+
+#define GR_GL_STREAM_DRAW 0x88E0
+#define GR_GL_STATIC_DRAW 0x88E4
+#define GR_GL_DYNAMIC_DRAW 0x88E8
+
+#define GR_GL_BUFFER_SIZE 0x8764
+#define GR_GL_BUFFER_USAGE 0x8765
+
+#define GR_GL_CURRENT_VERTEX_ATTRIB 0x8626
+
+/* CullFaceMode */
+#define GR_GL_FRONT 0x0404
+#define GR_GL_BACK 0x0405
+#define GR_GL_FRONT_AND_BACK 0x0408
+
+/* DepthFunction */
+/* GL_NEVER */
+/* GL_LESS */
+/* GL_EQUAL */
+/* GL_LEQUAL */
+/* GL_GREATER */
+/* GL_NOTEQUAL */
+/* GL_GEQUAL */
+/* GL_ALWAYS */
+
+/* EnableCap */
+#define GR_GL_TEXTURE_2D 0x0DE1
+#define GR_GL_CULL_FACE 0x0B44
+#define GR_GL_BLEND 0x0BE2
+#define GR_GL_DITHER 0x0BD0
+#define GR_GL_STENCIL_TEST 0x0B90
+#define GR_GL_DEPTH_TEST 0x0B71
+#define GR_GL_SCISSOR_TEST 0x0C11
+#define GR_GL_POLYGON_OFFSET_FILL 0x8037
+#define GR_GL_SAMPLE_ALPHA_TO_COVERAGE 0x809E
+#define GR_GL_SAMPLE_COVERAGE 0x80A0
+
+/* ErrorCode */
+#define GR_GL_NO_ERROR 0
+#define GR_GL_INVALID_ENUM 0x0500
+#define GR_GL_INVALID_VALUE 0x0501
+#define GR_GL_INVALID_OPERATION 0x0502
+#define GR_GL_OUT_OF_MEMORY 0x0505
+#define GR_GL_CONTEXT_LOST 0x300E // TODO(gman): What value?
+
+/* FrontFaceDirection */
+#define GR_GL_CW 0x0900
+#define GR_GL_CCW 0x0901
+
+/* GetPName */
+#define GR_GL_LINE_WIDTH 0x0B21
+#define GR_GL_ALIASED_POINT_SIZE_RANGE 0x846D
+#define GR_GL_ALIASED_LINE_WIDTH_RANGE 0x846E
+#define GR_GL_CULL_FACE_MODE 0x0B45
+#define GR_GL_FRONT_FACE 0x0B46
+#define GR_GL_DEPTH_RANGE 0x0B70
+#define GR_GL_DEPTH_WRITEMASK 0x0B72
+#define GR_GL_DEPTH_CLEAR_VALUE 0x0B73
+#define GR_GL_DEPTH_FUNC 0x0B74
+#define GR_GL_STENCIL_CLEAR_VALUE 0x0B91
+#define GR_GL_STENCIL_FUNC 0x0B92
+#define GR_GL_STENCIL_FAIL 0x0B94
+#define GR_GL_STENCIL_PASS_DEPTH_FAIL 0x0B95
+#define GR_GL_STENCIL_PASS_DEPTH_PASS 0x0B96
+#define GR_GL_STENCIL_REF 0x0B97
+#define GR_GL_STENCIL_VALUE_MASK 0x0B93
+#define GR_GL_STENCIL_WRITEMASK 0x0B98
+#define GR_GL_STENCIL_BACK_FUNC 0x8800
+#define GR_GL_STENCIL_BACK_FAIL 0x8801
+#define GR_GL_STENCIL_BACK_PASS_DEPTH_FAIL 0x8802
+#define GR_GL_STENCIL_BACK_PASS_DEPTH_PASS 0x8803
+#define GR_GL_STENCIL_BACK_REF 0x8CA3
+#define GR_GL_STENCIL_BACK_VALUE_MASK 0x8CA4
+#define GR_GL_STENCIL_BACK_WRITEMASK 0x8CA5
+#define GR_GL_VIEWPORT 0x0BA2
+#define GR_GL_SCISSOR_BOX 0x0C10
+/* GL_SCISSOR_TEST */
+#define GR_GL_COLOR_CLEAR_VALUE 0x0C22
+#define GR_GL_COLOR_WRITEMASK 0x0C23
+#define GR_GL_UNPACK_ALIGNMENT 0x0CF5
+#define GR_GL_PACK_ALIGNMENT 0x0D05
+#define GR_GL_MAX_TEXTURE_SIZE 0x0D33
+#define GR_GL_MAX_VIEWPORT_DIMS 0x0D3A
+#define GR_GL_SUBPIXEL_BITS 0x0D50
+#define GR_GL_RED_BITS 0x0D52
+#define GR_GL_GREEN_BITS 0x0D53
+#define GR_GL_BLUE_BITS 0x0D54
+#define GR_GL_ALPHA_BITS 0x0D55
+#define GR_GL_DEPTH_BITS 0x0D56
+#define GR_GL_STENCIL_BITS 0x0D57
+#define GR_GL_POLYGON_OFFSET_UNITS 0x2A00
+/* GL_POLYGON_OFFSET_FILL */
+#define GR_GL_POLYGON_OFFSET_FACTOR 0x8038
+#define GR_GL_TEXTURE_BINDING_2D 0x8069
+#define GR_GL_SAMPLE_BUFFERS 0x80A8
+#define GR_GL_SAMPLES 0x80A9
+#define GR_GL_SAMPLE_COVERAGE_VALUE 0x80AA
+#define GR_GL_SAMPLE_COVERAGE_INVERT 0x80AB
+
+/* GetTextureParameter */
+/* GL_TEXTURE_MAG_FILTER */
+/* GL_TEXTURE_MIN_FILTER */
+/* GL_TEXTURE_WRAP_S */
+/* GL_TEXTURE_WRAP_T */
+
+#define GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS 0x86A2
+#define GR_GL_COMPRESSED_TEXTURE_FORMATS 0x86A3
+
+/* HintMode */
+#define GR_GL_DONT_CARE 0x1100
+#define GR_GL_FASTEST 0x1101
+#define GR_GL_NICEST 0x1102
+
+/* HintTarget */
+#define GR_GL_GENERATE_MIPMAP_HINT 0x8192
+
+/* DataType */
+#define GR_GL_BYTE 0x1400
+#define GR_GL_UNSIGNED_BYTE 0x1401
+#define GR_GL_SHORT 0x1402
+#define GR_GL_UNSIGNED_SHORT 0x1403
+#define GR_GL_INT 0x1404
+#define GR_GL_UNSIGNED_INT 0x1405
+#define GR_GL_FLOAT 0x1406
+#define GR_GL_FIXED 0x140C
+
+/* Lighting */
+#define GR_GL_LIGHTING 0x0B50
+#define GR_GL_LIGHT0 0x4000
+#define GR_GL_LIGHT1 0x4001
+#define GR_GL_LIGHT2 0x4002
+#define GR_GL_LIGHT3 0x4003
+#define GR_GL_LIGHT4 0x4004
+#define GR_GL_LIGHT5 0x4005
+#define GR_GL_LIGHT6 0x4006
+#define GR_GL_LIGHT7 0x4007
+#define GR_GL_SPOT_EXPONENT 0x1205
+#define GR_GL_SPOT_CUTOFF 0x1206
+#define GR_GL_CONSTANT_ATTENUATION 0x1207
+#define GR_GL_LINEAR_ATTENUATION 0x1208
+#define GR_GL_QUADRATIC_ATTENUATION 0x1209
+#define GR_GL_AMBIENT 0x1200
+#define GR_GL_DIFFUSE 0x1201
+#define GR_GL_SPECULAR 0x1202
+#define GR_GL_SHININESS 0x1601
+#define GR_GL_EMISSION 0x1600
+#define GR_GL_POSITION 0x1203
+#define GR_GL_SPOT_DIRECTION 0x1204
+#define GR_GL_AMBIENT_AND_DIFFUSE 0x1602
+#define GR_GL_COLOR_INDEXES 0x1603
+#define GR_GL_LIGHT_MODEL_TWO_SIDE 0x0B52
+#define GR_GL_LIGHT_MODEL_LOCAL_VIEWER 0x0B51
+#define GR_GL_LIGHT_MODEL_AMBIENT 0x0B53
+#define GR_GL_FRONT_AND_BACK 0x0408
+#define GR_GL_SHADE_MODEL 0x0B54
+#define GR_GL_FLAT 0x1D00
+#define GR_GL_SMOOTH 0x1D01
+#define GR_GL_COLOR_MATERIAL 0x0B57
+#define GR_GL_COLOR_MATERIAL_FACE 0x0B55
+#define GR_GL_COLOR_MATERIAL_PARAMETER 0x0B56
+#define GR_GL_NORMALIZE 0x0BA1
+
+/* Matrix Mode */
+#define GR_GL_MATRIX_MODE 0x0BA0
+#define GR_GL_MODELVIEW 0x1700
+#define GR_GL_PROJECTION 0x1701
+#define GR_GL_TEXTURE 0x1702
+
+/* multisample */
+#define GR_GL_MULTISAMPLE 0x809D
+
+/* Points */
+#define GR_GL_POINT_SMOOTH 0x0B10
+#define GR_GL_POINT_SIZE 0x0B11
+#define GR_GL_POINT_SIZE_GRANULARITY 0x0B13
+#define GR_GL_POINT_SIZE_RANGE 0x0B12
+
+/* Lines */
+#define GR_GL_LINE_SMOOTH 0x0B20
+#define GR_GL_LINE_STIPPLE 0x0B24
+#define GR_GL_LINE_STIPPLE_PATTERN 0x0B25
+#define GR_GL_LINE_STIPPLE_REPEAT 0x0B26
+#define GR_GL_LINE_WIDTH 0x0B21
+#define GR_GL_LINE_WIDTH_GRANULARITY 0x0B23
+#define GR_GL_LINE_WIDTH_RANGE 0x0B22
+
+/* PixelFormat */
+#define GR_GL_DEPTH_COMPONENT 0x1902
+#define GR_GL_ALPHA 0x1906
+#define GR_GL_RGB 0x1907
+#define GR_GL_RGBA 0x1908
+#define GR_GL_BGRA 0x80E1
+#define GR_GL_LUMINANCE 0x1909
+#define GR_GL_LUMINANCE_ALPHA 0x190A
+#define GR_GL_PALETTE8_RGBA8 0x8B96
+
+/* PixelType */
+/* GL_UNSIGNED_BYTE */
+#define GR_GL_UNSIGNED_SHORT_4_4_4_4 0x8033
+#define GR_GL_UNSIGNED_SHORT_5_5_5_1 0x8034
+#define GR_GL_UNSIGNED_SHORT_5_6_5 0x8363
+
+/* Shaders */
+#define GR_GL_FRAGMENT_SHADER 0x8B30
+#define GR_GL_VERTEX_SHADER 0x8B31
+#define GR_GL_GEOMETRY_SHADER 0x8DD9
+#define GR_GL_MAX_VERTEX_ATTRIBS 0x8869
+#define GR_GL_MAX_VERTEX_UNIFORM_VECTORS 0x8DFB
+#define GR_GL_MAX_VARYING_VECTORS 0x8DFC
+#define GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS 0x8B4D
+#define GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS 0x8B4C
+#define GR_GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
+#define GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS 0x8DFD
+#define GR_GL_SHADER_TYPE 0x8B4F
+#define GR_GL_DELETE_STATUS 0x8B80
+#define GR_GL_LINK_STATUS 0x8B82
+#define GR_GL_VALIDATE_STATUS 0x8B83
+#define GR_GL_ATTACHED_SHADERS 0x8B85
+#define GR_GL_ACTIVE_UNIFORMS 0x8B86
+#define GR_GL_ACTIVE_UNIFORM_MAX_LENGTH 0x8B87
+#define GR_GL_ACTIVE_ATTRIBUTES 0x8B89
+#define GR_GL_ACTIVE_ATTRIBUTE_MAX_LENGTH 0x8B8A
+#define GR_GL_SHADING_LANGUAGE_VERSION 0x8B8C
+#define GR_GL_CURRENT_PROGRAM 0x8B8D
+#define GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49
+#define GR_GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A
+
+/* StencilFunction */
+#define GR_GL_NEVER 0x0200
+#define GR_GL_LESS 0x0201
+#define GR_GL_EQUAL 0x0202
+#define GR_GL_LEQUAL 0x0203
+#define GR_GL_GREATER 0x0204
+#define GR_GL_NOTEQUAL 0x0205
+#define GR_GL_GEQUAL 0x0206
+#define GR_GL_ALWAYS 0x0207
+
+/* StencilOp */
+/* GL_ZERO */
+#define GR_GL_KEEP 0x1E00
+#define GR_GL_REPLACE 0x1E01
+#define GR_GL_INCR 0x1E02
+#define GR_GL_DECR 0x1E03
+#define GR_GL_INVERT 0x150A
+#define GR_GL_INCR_WRAP 0x8507
+#define GR_GL_DECR_WRAP 0x8508
+
+/* StringName */
+#define GR_GL_VENDOR 0x1F00
+#define GR_GL_RENDERER 0x1F01
+#define GR_GL_VERSION 0x1F02
+#define GR_GL_EXTENSIONS 0x1F03
+
+/* Pixel Mode / Transfer */
+#define GR_GL_UNPACK_ROW_LENGTH 0x0CF2
+
+/* TextureMagFilter */
+#define GR_GL_NEAREST 0x2600
+#define GR_GL_LINEAR 0x2601
+
+/* TextureMinFilter */
+/* GL_NEAREST */
+/* GL_LINEAR */
+#define GR_GL_NEAREST_MIPMAP_NEAREST 0x2700
+#define GR_GL_LINEAR_MIPMAP_NEAREST 0x2701
+#define GR_GL_NEAREST_MIPMAP_LINEAR 0x2702
+#define GR_GL_LINEAR_MIPMAP_LINEAR 0x2703
+
+/* TextureParameterName */
+#define GR_GL_TEXTURE_MAG_FILTER 0x2800
+#define GR_GL_TEXTURE_MIN_FILTER 0x2801
+#define GR_GL_TEXTURE_WRAP_S 0x2802
+#define GR_GL_TEXTURE_WRAP_T 0x2803
+
+/* TextureTarget */
+/* GL_TEXTURE_2D */
+#define GR_GL_TEXTURE 0x1702
+#define GR_GL_TEXTURE_CUBE_MAP 0x8513
+#define GR_GL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define GR_GL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define GR_GL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define GR_GL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define GR_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define GR_GL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define GR_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define GR_GL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+
+/* TextureUnit */
+#define GR_GL_TEXTURE0 0x84C0
+#define GR_GL_TEXTURE1 0x84C1
+#define GR_GL_TEXTURE2 0x84C2
+#define GR_GL_TEXTURE3 0x84C3
+#define GR_GL_TEXTURE4 0x84C4
+#define GR_GL_TEXTURE5 0x84C5
+#define GR_GL_TEXTURE6 0x84C6
+#define GR_GL_TEXTURE7 0x84C7
+#define GR_GL_TEXTURE8 0x84C8
+#define GR_GL_TEXTURE9 0x84C9
+#define GR_GL_TEXTURE10 0x84CA
+#define GR_GL_TEXTURE11 0x84CB
+#define GR_GL_TEXTURE12 0x84CC
+#define GR_GL_TEXTURE13 0x84CD
+#define GR_GL_TEXTURE14 0x84CE
+#define GR_GL_TEXTURE15 0x84CF
+#define GR_GL_TEXTURE16 0x84D0
+#define GR_GL_TEXTURE17 0x84D1
+#define GR_GL_TEXTURE18 0x84D2
+#define GR_GL_TEXTURE19 0x84D3
+#define GR_GL_TEXTURE20 0x84D4
+#define GR_GL_TEXTURE21 0x84D5
+#define GR_GL_TEXTURE22 0x84D6
+#define GR_GL_TEXTURE23 0x84D7
+#define GR_GL_TEXTURE24 0x84D8
+#define GR_GL_TEXTURE25 0x84D9
+#define GR_GL_TEXTURE26 0x84DA
+#define GR_GL_TEXTURE27 0x84DB
+#define GR_GL_TEXTURE28 0x84DC
+#define GR_GL_TEXTURE29 0x84DD
+#define GR_GL_TEXTURE30 0x84DE
+#define GR_GL_TEXTURE31 0x84DF
+#define GR_GL_ACTIVE_TEXTURE 0x84E0
+#define GR_GL_MAX_TEXTURE_UNITS 0x84E2
+
+/* TextureWrapMode */
+#define GR_GL_REPEAT 0x2901
+#define GR_GL_CLAMP_TO_EDGE 0x812F
+#define GR_GL_MIRRORED_REPEAT 0x8370
+
+/* Texture mapping */
+#define GR_GL_TEXTURE_ENV 0x2300
+#define GR_GL_TEXTURE_ENV_MODE 0x2200
+#define GR_GL_TEXTURE_1D 0x0DE0
+/* GL_TEXTURE_2D */
+/* GL_TEXTURE_WRAP_S */
+/* GL_TEXTURE_WRAP_T */
+/* GL_TEXTURE_MAG_FILTER */
+/* GL_TEXTURE_MIN_FILTER */
+#define GR_GL_TEXTURE_ENV_COLOR 0x2201
+#define GR_GL_TEXTURE_GEN_S 0x0C60
+#define GR_GL_TEXTURE_GEN_T 0x0C61
+#define GR_GL_TEXTURE_GEN_MODE 0x2500
+#define GR_GL_TEXTURE_BORDER_COLOR 0x1004
+#define GR_GL_TEXTURE_WIDTH 0x1000
+#define GR_GL_TEXTURE_HEIGHT 0x1001
+#define GR_GL_TEXTURE_BORDER 0x1005
+#define GR_GL_TEXTURE_COMPONENTS 0x1003
+#define GR_GL_TEXTURE_RED_SIZE 0x805C
+#define GR_GL_TEXTURE_GREEN_SIZE 0x805D
+#define GR_GL_TEXTURE_BLUE_SIZE 0x805E
+#define GR_GL_TEXTURE_ALPHA_SIZE 0x805F
+#define GR_GL_TEXTURE_LUMINANCE_SIZE 0x8060
+#define GR_GL_TEXTURE_INTENSITY_SIZE 0x8061
+#define GR_GL_TEXTURE_INTERNAL_FORMAT 0x1003
+/* GL_NEAREST_MIPMAP_NEAREST */
+/* GL_NEAREST_MIPMAP_LINEAR */
+/* GL_LINEAR_MIPMAP_NEAREST */
+/* GL_LINEAR_MIPMAP_LINEAR */
+#define GR_GL_OBJECT_LINEAR 0x2401
+#define GR_GL_OBJECT_PLANE 0x2501
+#define GR_GL_EYE_LINEAR 0x2400
+#define GR_GL_EYE_PLANE 0x2502
+#define GR_GL_SPHERE_MAP 0x2402
+#define GR_GL_DECAL 0x2101
+#define GR_GL_MODULATE 0x2100
+/* GL_NEAREST */
+/* GL_REPEAT */
+#define GR_GL_CLAMP 0x2900
+#define GR_GL_S 0x2000
+#define GR_GL_T 0x2001
+#define GR_GL_R 0x2002
+#define GR_GL_Q 0x2003
+#define GR_GL_TEXTURE_GEN_R 0x0C62
+#define GR_GL_TEXTURE_GEN_Q 0x0C63
+
+/* texture_env_combine */
+#define GR_GL_COMBINE 0x8570
+#define GR_GL_COMBINE_RGB 0x8571
+#define GR_GL_COMBINE_ALPHA 0x8572
+#define GR_GL_SOURCE0_RGB 0x8580
+#define GR_GL_SOURCE1_RGB 0x8581
+#define GR_GL_SOURCE2_RGB 0x8582
+#define GR_GL_SOURCE0_ALPHA 0x8588
+#define GR_GL_SOURCE1_ALPHA 0x8589
+#define GR_GL_SOURCE2_ALPHA 0x858A
+#define GR_GL_OPERAND0_RGB 0x8590
+#define GR_GL_OPERAND1_RGB 0x8591
+#define GR_GL_OPERAND2_RGB 0x8592
+#define GR_GL_OPERAND0_ALPHA 0x8598
+#define GR_GL_OPERAND1_ALPHA 0x8599
+#define GR_GL_OPERAND2_ALPHA 0x859A
+#define GR_GL_RGB_SCALE 0x8573
+#define GR_GL_ADD_SIGNED 0x8574
+#define GR_GL_INTERPOLATE 0x8575
+#define GR_GL_SUBTRACT 0x84E7
+#define GR_GL_CONSTANT 0x8576
+#define GR_GL_PRIMARY_COLOR 0x8577
+#define GR_GL_PREVIOUS 0x8578
+#define GR_GL_SRC0_RGB 0x8580
+#define GR_GL_SRC1_RGB 0x8581
+#define GR_GL_SRC2_RGB 0x8582
+#define GR_GL_SRC0_ALPHA 0x8588
+#define GR_GL_SRC1_ALPHA 0x8589
+#define GR_GL_SRC2_ALPHA 0x858A
+
+/* Uniform Types */
+#define GR_GL_FLOAT_VEC2 0x8B50
+#define GR_GL_FLOAT_VEC3 0x8B51
+#define GR_GL_FLOAT_VEC4 0x8B52
+#define GR_GL_INT_VEC2 0x8B53
+#define GR_GL_INT_VEC3 0x8B54
+#define GR_GL_INT_VEC4 0x8B55
+#define GR_GL_BOOL 0x8B56
+#define GR_GL_BOOL_VEC2 0x8B57
+#define GR_GL_BOOL_VEC3 0x8B58
+#define GR_GL_BOOL_VEC4 0x8B59
+#define GR_GL_FLOAT_MAT2 0x8B5A
+#define GR_GL_FLOAT_MAT3 0x8B5B
+#define GR_GL_FLOAT_MAT4 0x8B5C
+#define GR_GL_SAMPLER_2D 0x8B5E
+#define GR_GL_SAMPLER_CUBE 0x8B60
+
+/* Vertex Arrays */
+#define GR_GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
+#define GR_GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
+#define GR_GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
+#define GR_GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
+#define GR_GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
+#define GR_GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
+#define GR_GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING 0x889F
+#define GR_GL_VERTEX_ARRAY 0x8074
+#define GR_GL_NORMAL_ARRAY 0x8075
+#define GR_GL_COLOR_ARRAY 0x8076
+#define GR_GL_INDEX_ARRAY 0x8077
+#define GR_GL_TEXTURE_COORD_ARRAY 0x8078
+#define GR_GL_EDGE_FLAG_ARRAY 0x8079
+#define GR_GL_VERTEX_ARRAY_SIZE 0x807A
+#define GR_GL_VERTEX_ARRAY_TYPE 0x807B
+#define GR_GL_VERTEX_ARRAY_STRIDE 0x807C
+#define GR_GL_NORMAL_ARRAY_TYPE 0x807E
+#define GR_GL_NORMAL_ARRAY_STRIDE 0x807F
+#define GR_GL_COLOR_ARRAY_SIZE 0x8081
+#define GR_GL_COLOR_ARRAY_TYPE 0x8082
+#define GR_GL_COLOR_ARRAY_STRIDE 0x8083
+#define GR_GL_INDEX_ARRAY_TYPE 0x8085
+#define GR_GL_INDEX_ARRAY_STRIDE 0x8086
+#define GR_GL_TEXTURE_COORD_ARRAY_SIZE 0x8088
+#define GR_GL_TEXTURE_COORD_ARRAY_TYPE 0x8089
+#define GR_GL_TEXTURE_COORD_ARRAY_STRIDE 0x808A
+#define GR_GL_EDGE_FLAG_ARRAY_STRIDE 0x808C
+#define GR_GL_VERTEX_ARRAY_POINTER 0x808E
+#define GR_GL_NORMAL_ARRAY_POINTER 0x808F
+#define GR_GL_COLOR_ARRAY_POINTER 0x8090
+#define GR_GL_INDEX_ARRAY_POINTER 0x8091
+#define GR_GL_TEXTURE_COORD_ARRAY_POINTER 0x8092
+#define GR_GL_EDGE_FLAG_ARRAY_POINTER 0x8093
+#define GR_GL_V2F 0x2A20
+#define GR_GL_V3F 0x2A21
+#define GR_GL_C4UB_V2F 0x2A22
+#define GR_GL_C4UB_V3F 0x2A23
+#define GR_GL_C3F_V3F 0x2A24
+#define GR_GL_N3F_V3F 0x2A25
+#define GR_GL_C4F_N3F_V3F 0x2A26
+#define GR_GL_T2F_V3F 0x2A27
+#define GR_GL_T4F_V4F 0x2A28
+#define GR_GL_T2F_C4UB_V3F 0x2A29
+#define GR_GL_T2F_C3F_V3F 0x2A2A
+#define GR_GL_T2F_N3F_V3F 0x2A2B
+#define GR_GL_T2F_C4F_N3F_V3F 0x2A2C
+#define GR_GL_T4F_C4F_N3F_V4F 0x2A2D
+
+/* Vertex Buffer Object */
+#define GR_GL_WRITE_ONLY 0x88B9
+#define GR_GL_BUFFER_MAPPED 0x88BC
+/* Read Format */
+#define GR_GL_IMPLEMENTATION_COLOR_READ_TYPE 0x8B9A
+#define GR_GL_IMPLEMENTATION_COLOR_READ_FORMAT 0x8B9B
+
+/* Shader Source */
+#define GR_GL_COMPILE_STATUS 0x8B81
+#define GR_GL_INFO_LOG_LENGTH 0x8B84
+#define GR_GL_SHADER_SOURCE_LENGTH 0x8B88
+#define GR_GL_SHADER_COMPILER 0x8DFA
+
+/* Shader Binary */
+#define GR_GL_SHADER_BINARY_FORMATS 0x8DF8
+#define GR_GL_NUM_SHADER_BINARY_FORMATS 0x8DF9
+
+/* Shader Precision-Specified Types */
+#define GR_GL_LOW_FLOAT 0x8DF0
+#define GR_GL_MEDIUM_FLOAT 0x8DF1
+#define GR_GL_HIGH_FLOAT 0x8DF2
+#define GR_GL_LOW_INT 0x8DF3
+#define GR_GL_MEDIUM_INT 0x8DF4
+#define GR_GL_HIGH_INT 0x8DF5
+
+/* Framebuffer Object. */
+#define GR_GL_FRAMEBUFFER 0x8D40
+#define GR_GL_READ_FRAMEBUFFER 0x8CA8
+#define GR_GL_DRAW_FRAMEBUFFER 0x8CA9
+
+#define GR_GL_RENDERBUFFER 0x8D41
+
+#define GR_GL_RGBA4 0x8056
+#define GR_GL_RGB5_A1 0x8057
+#define GR_GL_RGB565 0x8D62
+#define GR_GL_RGBA8 0x8058
+#define GR_GL_RGB8 0x8051
+#define GR_GL_SRGB 0x8C40
+#define GR_GL_SRGB8 0x8C41
+#define GR_GL_SRGB_ALPHA 0x8C42
+#define GR_GL_SRGB8_ALPHA8 0x8C43
+#define GR_GL_DEPTH_COMPONENT16 0x81A5
+#define GR_GL_STENCIL_INDEX 0x1901
+#define GR_GL_STENCIL_INDEX4 0x8D47
+#define GR_GL_STENCIL_INDEX8 0x8D48
+#define GR_GL_STENCIL_INDEX16 0x8D49
+#define GR_GL_DEPTH_STENCIL 0x84F9
+#define GR_GL_DEPTH24_STENCIL8 0x88F0
+
+#define GR_GL_MAX_SAMPLES 0x8D57
+
+#define GR_GL_RENDERBUFFER_WIDTH 0x8D42
+#define GR_GL_RENDERBUFFER_HEIGHT 0x8D43
+#define GR_GL_RENDERBUFFER_INTERNAL_FORMAT 0x8D44
+#define GR_GL_RENDERBUFFER_RED_SIZE 0x8D50
+#define GR_GL_RENDERBUFFER_GREEN_SIZE 0x8D51
+#define GR_GL_RENDERBUFFER_BLUE_SIZE 0x8D52
+#define GR_GL_RENDERBUFFER_ALPHA_SIZE 0x8D53
+#define GR_GL_RENDERBUFFER_DEPTH_SIZE 0x8D54
+#define GR_GL_RENDERBUFFER_STENCIL_SIZE 0x8D55
+
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE 0x8CD0
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME 0x8CD1
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL 0x8CD2
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE 0x8CD3
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216
+#define GR_GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217
+
+#define GR_GL_COLOR_ATTACHMENT0 0x8CE0
+#define GR_GL_DEPTH_ATTACHMENT 0x8D00
+#define GR_GL_STENCIL_ATTACHMENT 0x8D20
+#define GR_GL_DEPTH_STENCIL_ATTACHMENT 0x821A
+
+#define GR_GL_NONE 0
+
+#define GR_GL_FRAMEBUFFER_COMPLETE 0x8CD5
+#define GR_GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 0x8CD6
+#define GR_GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT 0x8CD7
+#define GR_GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS 0x8CD9
+#define GR_GL_FRAMEBUFFER_UNSUPPORTED 0x8CDD
+
+#define GR_GL_FRAMEBUFFER_BINDING 0x8CA6
+#define GR_GL_RENDERBUFFER_BINDING 0x8CA7
+#define GR_GL_MAX_RENDERBUFFER_SIZE 0x84E8
+
+#define GR_GL_INVALID_FRAMEBUFFER_OPERATION 0x0506
+
+#endif
diff --git a/include/gpu/GrGLInterface.h b/include/gpu/GrGLInterface.h
new file mode 100644
index 0000000000..8271dcbe93
--- /dev/null
+++ b/include/gpu/GrGLInterface.h
@@ -0,0 +1,414 @@
+
+/*
+ * 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 GrGLInterface_DEFINED
+#define GrGLInterface_DEFINED
+
+#include "GrGLConfig.h"
+#include "GrRefCnt.h"
+
+#if !defined(GR_GL_FUNCTION_TYPE)
+ #define GR_GL_FUNCTION_TYPE
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Helpers for glGetString()
+ */
+
+typedef uint32_t GrGLVersion;
+typedef uint32_t GrGLSLVersion;
+
+#define GR_GL_VER(major, minor) ((static_cast<int>(major) << 16) | \
+ static_cast<int>(minor))
+#define GR_GLSL_VER(major, minor) ((static_cast<int>(major) << 16) | \
+ static_cast<int>(minor))
+
+// these variants assume caller already has a string from glGetString()
+GrGLVersion GrGLGetVersionFromString(const char* versionString);
+GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
+bool GrGLHasExtensionFromString(const char* ext, const char* extensionString);
+
+// these variants call glGetString()
+bool GrGLGetString(const GrGLInterface*, const char* ext);
+GrGLVersion GrGLGetVersion(const GrGLInterface*);
+GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Rather than depend on platform-specific GL headers and libraries, we require
+ * the client to provide a struct of GL function pointers. This struct can be
+ * specified per-GrContext as a parameter to GrContext::Create. If NULL is
+ * passed to Create then the "default" GL interface is used. If the default is
+ * also NULL GrContext creation will fail.
+ *
+ * The default interface is returned by GrGLDefaultInterface. This function's
+ * implementation is platform-specifc. Several have been provided, along with an
+ * implementation that simply returns NULL. It is implementation-specific
+ * whether the same GrGLInterface is returned or whether a new one is created
+ * at each call. Some platforms may not be able to use a single GrGLInterface
+ * because extension function ptrs vary across contexts. Note that GrGLInterface
+ * is ref-counted. So if the same object is returned by multiple calls to
+ * GrGLDefaultInterface, each should bump the ref count.
+ *
+ * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
+ * callback function that will be called prior to each GL function call. See
+ * comments in GrGLConfig.h
+ */
+
+struct GrGLInterface;
+
+const GrGLInterface* GrGLDefaultInterface();
+
+typedef unsigned int GrGLenum;
+typedef unsigned char GrGLboolean;
+typedef unsigned int GrGLbitfield;
+typedef signed char GrGLbyte;
+typedef char GrGLchar;
+typedef short GrGLshort;
+typedef int GrGLint;
+typedef int GrGLsizei;
+typedef unsigned char GrGLubyte;
+typedef unsigned short GrGLushort;
+typedef unsigned int GrGLuint;
+typedef float GrGLfloat;
+typedef float GrGLclampf;
+typedef double GrGLdouble;
+typedef double GrGLclampd;
+typedef void GrGLvoid;
+typedef long GrGLintptr;
+typedef long GrGLsizeiptr;
+
+enum GrGLBinding {
+ kDesktop_GrGLBinding = 0x01,
+ kES1_GrGLBinding = 0x02,
+ kES2_GrGLBinding = 0x04
+};
+
+extern "C" {
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLActiveTextureProc)(GrGLenum texture);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLAttachShaderProc)(GrGLuint program, GrGLuint shader);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindAttribLocationProc)(GrGLuint program, GrGLuint index, const char* name);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindBufferProc)(GrGLenum target, GrGLuint buffer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindTextureProc)(GrGLenum target, GrGLuint texture);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationProc)(GrGLuint program, GrGLuint colorNumber, const GrGLchar* name);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlendFuncProc)(GrGLenum sfactor, GrGLenum dfactor);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferDataProc)(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, GrGLenum usage);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBufferSubDataProc)(GrGLenum target, GrGLintptr offset, GrGLsizeiptr size, const GrGLvoid* data);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearProc)(GrGLbitfield mask);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearColorProc)(GrGLclampf red, GrGLclampf green, GrGLclampf blue, GrGLclampf alpha);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClearStencilProc)(GrGLint s);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLClientActiveTextureProc)(GrGLenum texture);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColor4ubProc)(GrGLubyte red, GrGLubyte green, GrGLubyte blue, GrGLubyte alpha);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorMaskProc)(GrGLboolean red, GrGLboolean green, GrGLboolean blue, GrGLboolean alpha);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLColorPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompileShaderProc)(GrGLuint shader);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCompressedTexImage2DProc)(GrGLenum target, GrGLint level, GrGLenum internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLsizei imageSize, const GrGLvoid* data);
+ typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateProgramProc)(void);
+ typedef GrGLuint (GR_GL_FUNCTION_TYPE *GrGLCreateShaderProc)(GrGLenum type);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLCullFaceProc)(GrGLenum mode);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteBuffersProc)(GrGLsizei n, const GrGLuint* buffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteProgramProc)(GrGLuint program);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteShaderProc)(GrGLuint shader);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteTexturesProc)(GrGLsizei n, const GrGLuint* textures);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDepthMaskProc)(GrGLboolean flag);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableProc)(GrGLenum cap);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableClientStateProc)(GrGLenum array);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDisableVertexAttribArrayProc)(GrGLuint index);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawArraysProc)(GrGLenum mode, GrGLint first, GrGLsizei count);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBufferProc)(GrGLenum mode);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawBuffersProc)(GrGLsizei n, const GrGLenum* bufs);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDrawElementsProc)(GrGLenum mode, GrGLsizei count, GrGLenum type, const GrGLvoid* indices);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableProc)(GrGLenum cap);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableClientStateProc)(GrGLenum cap);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLEnableVertexAttribArrayProc)(GrGLuint index);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFrontFaceProc)(GrGLenum mode);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetBufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
+ typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLGetErrorProc)(void);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetIntegervProc)(GrGLenum pname, GrGLint* params);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramInfoLogProc)(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetProgramivProc)(GrGLuint program, GrGLenum pname, GrGLint* params);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderInfoLogProc)(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, char* infolog);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetShaderivProc)(GrGLuint shader, GrGLenum pname, GrGLint* params);
+ typedef const GrGLubyte* (GR_GL_FUNCTION_TYPE *GrGLGetStringProc)(GrGLenum name);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetTexLevelParameteriv)(GrGLenum target, GrGLint level, GrGLenum pname, GrGLint* params);
+ typedef GrGLint (GR_GL_FUNCTION_TYPE *GrGLGetUniformLocationProc)(GrGLuint program, const char* name);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLineWidthProc)(GrGLfloat width);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLinkProgramProc)(GrGLuint program);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLLoadMatrixfProc)(const GrGLfloat* m);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLMatrixModeProc)(GrGLenum mode);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPixelStoreiProc)(GrGLenum pname, GrGLint param);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLPointSizeProc)(GrGLfloat size);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadBufferProc)(GrGLenum src);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLReadPixelsProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, GrGLvoid* pixels);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLScissorProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShadeModelProc)(GrGLenum mode);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLShaderSourceProc)(GrGLuint shader, GrGLsizei count, const char** str, const GrGLint* length);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncProc)(GrGLenum func, GrGLint ref, GrGLuint mask);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilFuncSeparateProc)(GrGLenum face, GrGLenum func, GrGLint ref, GrGLuint mask);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskProc)(GrGLuint mask);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilMaskSeparateProc)(GrGLenum face, GrGLuint mask);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpProc)(GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLStencilOpSeparateProc)(GrGLenum face, GrGLenum fail, GrGLenum zfail, GrGLenum zpass);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexCoordPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexEnviProc)(GrGLenum target, GrGLenum pname, GrGLint param);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexImage2DProc)(GrGLenum target, GrGLint level, GrGLint internalformat, GrGLsizei width, GrGLsizei height, GrGLint border, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexParameteriProc)(GrGLenum target, GrGLenum pname, GrGLint param);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLTexSubImage2DProc)(GrGLenum target, GrGLint level, GrGLint xoffset, GrGLint yoffset, GrGLsizei width, GrGLsizei height, GrGLenum format, GrGLenum type, const GrGLvoid* pixels);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fProc)(GrGLint location, GrGLfloat v0);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1iProc)(GrGLint location, GrGLint v0);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform1ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2iProc)(GrGLint location, GrGLint v0, GrGLint v1);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform2ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform3ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fProc)(GrGLint location, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2, GrGLfloat v3);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4iProc)(GrGLint location, GrGLint v0, GrGLint v1, GrGLint v2, GrGLint v3);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4fvProc)(GrGLint location, GrGLsizei count, const GrGLfloat* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniform4ivProc)(GrGLint location, GrGLsizei count, const GrGLint* v);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix2fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix3fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUniformMatrix4fvProc)(GrGLint location, GrGLsizei count, GrGLboolean transpose, const GrGLfloat* value);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLUseProgramProc)(GrGLuint program);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttrib4fvProc)(GrGLuint indx, const GrGLfloat* values);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexAttribPointerProc)(GrGLuint indx, GrGLint size, GrGLenum type, GrGLboolean normalized, GrGLsizei stride, const GrGLvoid* ptr);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLVertexPointerProc)(GrGLint size, GrGLenum type, GrGLsizei stride, const GrGLvoid* pointer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLViewportProc)(GrGLint x, GrGLint y, GrGLsizei width, GrGLsizei height);
+
+ // FBO Extension Functions
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFramebufferProc)(GrGLenum target, GrGLuint framebuffer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindRenderbufferProc)(GrGLenum target, GrGLuint renderbuffer);
+ typedef GrGLenum (GR_GL_FUNCTION_TYPE *GrGLCheckFramebufferStatusProc)(GrGLenum target);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteFramebuffersProc)(GrGLsizei n, const GrGLuint *framebuffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLDeleteRenderbuffersProc)(GrGLsizei n, const GrGLuint *renderbuffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferRenderbufferProc)(GrGLenum target, GrGLenum attachment, GrGLenum renderbuffertarget, GrGLuint renderbuffer);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLFramebufferTexture2DProc)(GrGLenum target, GrGLenum attachment, GrGLenum textarget, GrGLuint texture, GrGLint level);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetFramebufferAttachmentParameterivProc)(GrGLenum target, GrGLenum attachment, GrGLenum pname, GrGLint* params);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLGetRenderbufferParameterivProc)(GrGLenum target, GrGLenum pname, GrGLint* params);
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageProc)(GrGLenum target, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
+
+ // Multisampling Extension Functions
+ // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLRenderbufferStorageMultisampleProc)(GrGLenum target, GrGLsizei samples, GrGLenum internalformat, GrGLsizei width, GrGLsizei height);
+ // desktop: ext_fbo_blit, arb_fbo, gl 3.0
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBlitFramebufferProc)(GrGLint srcX0, GrGLint srcY0, GrGLint srcX1, GrGLint srcY1, GrGLint dstX0, GrGLint dstY0, GrGLint dstX1, GrGLint dstY1, GrGLbitfield mask, GrGLenum filter);
+ // apple's es extension
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLResolveMultisampleFramebufferProc)();
+
+ // Buffer mapping (extension in ES).
+ typedef GrGLvoid* (GR_GL_FUNCTION_TYPE *GrGLMapBufferProc)(GrGLenum target, GrGLenum access);
+ typedef GrGLboolean (GR_GL_FUNCTION_TYPE *GrGLUnmapBufferProc)(GrGLenum target);
+
+ // Dual source blending
+ typedef GrGLvoid (GR_GL_FUNCTION_TYPE *GrGLBindFragDataLocationIndexedProc)(GrGLuint program, GrGLuint colorNumber, GrGLuint index, const GrGLchar * name);
+} // extern "C"
+
+#if GR_GL_PER_GL_FUNC_CALLBACK
+typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
+typedef intptr_t GrGLInterfaceCallbackData;
+#endif
+
+
+enum GrGLCapability {
+ kProbe_GrGLCapability = -1
+};
+
+/*
+ * The following interface exports the OpenGL entry points used by the system.
+ * Use of OpenGL calls is disallowed. All calls should be invoked through
+ * the global instance of this struct, defined above.
+ *
+ * IMPORTANT NOTE: The OpenGL entry points exposed here include both core GL
+ * functions, and extensions. The system assumes that the address of the
+ * extension pointer will be valid across contexts.
+ */
+struct GR_API GrGLInterface : public GrRefCnt {
+
+ GrGLInterface();
+
+ bool validate(GrEngine engine) const;
+ bool supportsDesktop() const {
+ return 0 != (kDesktop_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES1() const {
+ return 0 != (kES1_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES2() const {
+ return 0 != (kES2_GrGLBinding & fBindingsExported);
+ }
+ bool supportsES() const {
+ return 0 != ((kES1_GrGLBinding | kES2_GrGLBinding) &
+ fBindingsExported);
+ }
+
+ // Indicator variable specifying the type of GL implementation
+ // exported: GLES{1|2} or Desktop.
+ GrGLBinding fBindingsExported;
+
+ /// Does this GL support NPOT textures on FBOs?
+ /// boolean value, or kProbe_GrGLCapability to probe (slowly) at context creation.
+ int fNPOTRenderTargetSupport;
+
+ /// Some GL implementations (PowerVR SGX devices like the iPhone 4)
+ /// have restrictions on the size of small render targets.
+ /// kProbe_GrGLCapability to probe (slowly) at context creation.
+ int fMinRenderTargetHeight;
+ int fMinRenderTargetWidth;
+
+ GrGLActiveTextureProc fActiveTexture;
+ GrGLAttachShaderProc fAttachShader;
+ GrGLBindAttribLocationProc fBindAttribLocation;
+ GrGLBindBufferProc fBindBuffer;
+ GrGLBindFragDataLocationProc fBindFragDataLocation;
+ GrGLBindTextureProc fBindTexture;
+ GrGLBlendColorProc fBlendColor;
+ GrGLBlendFuncProc fBlendFunc;
+ GrGLBufferDataProc fBufferData;
+ GrGLBufferSubDataProc fBufferSubData;
+ GrGLClearProc fClear;
+ GrGLClearColorProc fClearColor;
+ GrGLClearStencilProc fClearStencil;
+ GrGLClientActiveTextureProc fClientActiveTexture;
+ GrGLColor4ubProc fColor4ub;
+ GrGLColorMaskProc fColorMask;
+ GrGLColorPointerProc fColorPointer;
+ GrGLCompileShaderProc fCompileShader;
+ GrGLCompressedTexImage2DProc fCompressedTexImage2D;
+ GrGLCreateProgramProc fCreateProgram;
+ GrGLCreateShaderProc fCreateShader;
+ GrGLCullFaceProc fCullFace;
+ GrGLDeleteBuffersProc fDeleteBuffers;
+ GrGLDeleteProgramProc fDeleteProgram;
+ GrGLDeleteShaderProc fDeleteShader;
+ GrGLDeleteTexturesProc fDeleteTextures;
+ GrGLDepthMaskProc fDepthMask;
+ GrGLDisableProc fDisable;
+ GrGLDisableClientStateProc fDisableClientState;
+ GrGLDisableVertexAttribArrayProc fDisableVertexAttribArray;
+ GrGLDrawArraysProc fDrawArrays;
+ GrGLDrawBufferProc fDrawBuffer;
+ GrGLDrawBuffersProc fDrawBuffers;
+ GrGLDrawElementsProc fDrawElements;
+ GrGLEnableProc fEnable;
+ GrGLEnableClientStateProc fEnableClientState;
+ GrGLEnableVertexAttribArrayProc fEnableVertexAttribArray;
+ GrGLFrontFaceProc fFrontFace;
+ GrGLGenBuffersProc fGenBuffers;
+ GrGLGenTexturesProc fGenTextures;
+ GrGLGetBufferParameterivProc fGetBufferParameteriv;
+ GrGLGetErrorProc fGetError;
+ GrGLGetIntegervProc fGetIntegerv;
+ GrGLGetProgramInfoLogProc fGetProgramInfoLog;
+ GrGLGetProgramivProc fGetProgramiv;
+ GrGLGetShaderInfoLogProc fGetShaderInfoLog;
+ GrGLGetShaderivProc fGetShaderiv;
+ GrGLGetStringProc fGetString;
+ GrGLGetTexLevelParameteriv fGetTexLevelParameteriv;
+ GrGLGetUniformLocationProc fGetUniformLocation;
+ GrGLLineWidthProc fLineWidth;
+ GrGLLinkProgramProc fLinkProgram;
+ GrGLLoadMatrixfProc fLoadMatrixf;
+ GrGLMatrixModeProc fMatrixMode;
+ GrGLPixelStoreiProc fPixelStorei;
+ GrGLPointSizeProc fPointSize;
+ GrGLReadBufferProc fReadBuffer;
+ GrGLReadPixelsProc fReadPixels;
+ GrGLScissorProc fScissor;
+ GrGLShadeModelProc fShadeModel;
+ GrGLShaderSourceProc fShaderSource;
+ GrGLStencilFuncProc fStencilFunc;
+ GrGLStencilFuncSeparateProc fStencilFuncSeparate;
+ GrGLStencilMaskProc fStencilMask;
+ GrGLStencilMaskSeparateProc fStencilMaskSeparate;
+ GrGLStencilOpProc fStencilOp;
+ GrGLStencilOpSeparateProc fStencilOpSeparate;
+ GrGLTexCoordPointerProc fTexCoordPointer;
+ GrGLTexEnviProc fTexEnvi;
+ GrGLTexImage2DProc fTexImage2D;
+ GrGLTexParameteriProc fTexParameteri;
+ GrGLTexSubImage2DProc fTexSubImage2D;
+ GrGLUniform1fProc fUniform1f;
+ GrGLUniform1iProc fUniform1i;
+ GrGLUniform1fvProc fUniform1fv;
+ GrGLUniform1ivProc fUniform1iv;
+ GrGLUniform2fProc fUniform2f;
+ GrGLUniform2iProc fUniform2i;
+ GrGLUniform2fvProc fUniform2fv;
+ GrGLUniform2ivProc fUniform2iv;
+ GrGLUniform3fProc fUniform3f;
+ GrGLUniform3iProc fUniform3i;
+ GrGLUniform3fvProc fUniform3fv;
+ GrGLUniform3ivProc fUniform3iv;
+ GrGLUniform4fProc fUniform4f;
+ GrGLUniform4iProc fUniform4i;
+ GrGLUniform4fvProc fUniform4fv;
+ GrGLUniform4ivProc fUniform4iv;
+ GrGLUniformMatrix2fvProc fUniformMatrix2fv;
+ GrGLUniformMatrix3fvProc fUniformMatrix3fv;
+ GrGLUniformMatrix4fvProc fUniformMatrix4fv;
+ GrGLUseProgramProc fUseProgram;
+ GrGLVertexAttrib4fvProc fVertexAttrib4fv;
+ GrGLVertexAttribPointerProc fVertexAttribPointer;
+ GrGLVertexPointerProc fVertexPointer;
+ GrGLViewportProc fViewport;
+
+ // FBO Extension Functions
+ GrGLBindFramebufferProc fBindFramebuffer;
+ GrGLBindRenderbufferProc fBindRenderbuffer;
+ GrGLCheckFramebufferStatusProc fCheckFramebufferStatus;
+ GrGLDeleteFramebuffersProc fDeleteFramebuffers;
+ GrGLDeleteRenderbuffersProc fDeleteRenderbuffers;
+ GrGLFramebufferRenderbufferProc fFramebufferRenderbuffer;
+ GrGLFramebufferTexture2DProc fFramebufferTexture2D;
+ GrGLGenFramebuffersProc fGenFramebuffers;
+ GrGLGenRenderbuffersProc fGenRenderbuffers;
+ GrGLGetFramebufferAttachmentParameterivProc fGetFramebufferAttachmentParameteriv;
+ GrGLGetRenderbufferParameterivProc fGetRenderbufferParameteriv;
+ GrGLRenderbufferStorageProc fRenderbufferStorage;
+
+ // Multisampling Extension Functions
+ // same prototype for ARB_FBO, EXT_FBO, GL 3.0, & Apple ES extension
+ GrGLRenderbufferStorageMultisampleProc fRenderbufferStorageMultisample;
+ // desktop: ext_fbo_blit, arb_fbo, gl 3.0
+ GrGLBlitFramebufferProc fBlitFramebuffer;
+ // apple's es extension
+ GrGLResolveMultisampleFramebufferProc fResolveMultisampleFramebuffer;
+
+ // Buffer mapping (extension in ES).
+ GrGLMapBufferProc fMapBuffer;
+ GrGLUnmapBufferProc fUnmapBuffer;
+
+ // Dual Source Blending
+ GrGLBindFragDataLocationIndexedProc fBindFragDataLocationIndexed;
+
+ // Per-GL func callback
+#if GR_GL_PER_GL_FUNC_CALLBACK
+ GrGLInterfaceCallbackProc fCallback;
+ GrGLInterfaceCallbackData fCallbackData;
+#endif
+
+private:
+ bool validateShaderFunctions() const;
+ bool validateFixedFunctions() const;
+};
+
+#endif
diff --git a/include/gpu/GrGlyph.h b/include/gpu/GrGlyph.h
new file mode 100644
index 0000000000..a0d81a1f35
--- /dev/null
+++ b/include/gpu/GrGlyph.h
@@ -0,0 +1,82 @@
+
+/*
+ * 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 GrGlyph_DEFINED
+#define GrGlyph_DEFINED
+
+#include "GrPath.h"
+#include "GrRect.h"
+
+class GrAtlas;
+
+/* Need this to be quad-state:
+ - complete w/ image
+ - just metrics
+ - failed to get image, but has metrics
+ - failed to get metrics
+ */
+struct GrGlyph {
+ typedef uint32_t PackedID;
+
+ GrAtlas* fAtlas;
+ GrPath* fPath;
+ PackedID fPackedID;
+ GrIRect16 fBounds;
+ GrIPoint16 fAtlasLocation;
+
+ void init(GrGlyph::PackedID packed, const GrIRect& bounds) {
+ fAtlas = NULL;
+ fPath = NULL;
+ fPackedID = packed;
+ fBounds.set(bounds);
+ fAtlasLocation.set(0, 0);
+ }
+
+ void free() {
+ if (fPath) {
+ delete fPath;
+ fPath = NULL;
+ }
+ }
+
+ int width() const { return fBounds.width(); }
+ int height() const { return fBounds.height(); }
+ bool isEmpty() const { return fBounds.isEmpty(); }
+ uint16_t glyphID() const { return UnpackID(fPackedID); }
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ static inline unsigned ExtractSubPixelBitsFromFixed(GrFixed pos) {
+ // two most significant fraction bits from fixed-point
+ return (pos >> 14) & 3;
+ }
+
+ static inline PackedID Pack(uint16_t glyphID, GrFixed x, GrFixed y) {
+ x = ExtractSubPixelBitsFromFixed(x);
+ y = ExtractSubPixelBitsFromFixed(y);
+ return (x << 18) | (y << 16) | glyphID;
+ }
+
+ static inline GrFixed UnpackFixedX(PackedID packed) {
+ return ((packed >> 18) & 3) << 14;
+ }
+
+ static inline GrFixed UnpackFixedY(PackedID packed) {
+ return ((packed >> 16) & 3) << 14;
+ }
+
+ static inline uint16_t UnpackID(PackedID packed) {
+ return (uint16_t)packed;
+ }
+};
+
+
+#endif
+
diff --git a/include/gpu/GrGpuVertex.h b/include/gpu/GrGpuVertex.h
new file mode 100644
index 0000000000..2abc2f407e
--- /dev/null
+++ b/include/gpu/GrGpuVertex.h
@@ -0,0 +1,97 @@
+
+/*
+ * 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 GrGpuVertex_DEFINED
+#define GrGpuVertex_DEFINED
+
+#include "GrGLConfig.h"
+#include "GrPoint.h"
+
+#if GR_TEXT_SCALAR_IS_USHORT
+ typedef uint16_t GrTextScalar;
+ #define GrIntToTextScalar(x) ((uint16_t)x)
+ #define GrFixedToTextScalar(x) (x)
+#elif GR_TEXT_SCALAR_IS_FIXED
+ typedef GrFixed GrTextScalar;
+ #define GrIntToTextScalar(x) GrIntToFixed(x)
+ #define GrFixedToTextScalar(x) (x)
+#elif GR_TEXT_SCALAR_IS_FLOAT
+ typedef float GrTextScalar;
+ #define GrIntToTextScalar(x) ((GrTextScalar)x)
+ #define GrFixedToTextScalar(x) GrFixedToFloat(x)
+#else
+ #error "Text scalar type not defined"
+#endif
+
+// text has its own vertex class, since it may want to be in fixed point (given)
+// that it starts with all integers) even when the default vertices are floats
+struct GrGpuTextVertex {
+ GrTextScalar fX;
+ GrTextScalar fY;
+
+ void set(GrTextScalar x, GrTextScalar y) {
+ fX = x;
+ fY = y;
+ }
+
+ void setI(int x, int y) {
+ fX = GrIntToTextScalar(x);
+ fY = GrIntToTextScalar(y);
+ }
+
+ void setX(GrFixed x, GrFixed y) {
+ fX = GrFixedToTextScalar(x);
+ fY = GrFixedToTextScalar(y);
+ }
+
+ // rect fan is counter-clockwise
+
+ void setRectFan(GrTextScalar l, GrTextScalar t, GrTextScalar r,
+ GrTextScalar b) {
+ GrGpuTextVertex* v = this;
+ v[0].set(l, t);
+ v[1].set(l, b);
+ v[2].set(r, b);
+ v[3].set(r, t);
+ }
+
+ void setIRectFan(int l, int t, int r, int b) {
+ this->setRectFan(GrIntToTextScalar(l), GrIntToTextScalar(t),
+ GrIntToTextScalar(r), GrIntToTextScalar(b));
+ }
+
+ void setIRectFan(int l, int t, int r, int b, size_t stride) {
+ GrAssert(stride > sizeof(GrGpuTextVertex));
+ char* v = (char*)this;
+ ((GrGpuTextVertex*)(v + 0*stride))->setI(l, t);
+ ((GrGpuTextVertex*)(v + 1*stride))->setI(l, b);
+ ((GrGpuTextVertex*)(v + 2*stride))->setI(r, b);
+ ((GrGpuTextVertex*)(v + 3*stride))->setI(r, t);
+ }
+
+ // counter-clockwise fan
+ void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b) {
+ this->setRectFan(GrFixedToTextScalar(l), GrFixedToTextScalar(t),
+ GrFixedToTextScalar(r), GrFixedToTextScalar(b));
+ }
+
+ void setXRectFan(GrFixed l, GrFixed t, GrFixed r, GrFixed b, size_t stride) {
+ GrAssert(stride > sizeof(GrGpuTextVertex));
+ char* v = (char*)this;
+ ((GrGpuTextVertex*)(v + 0*stride))->setX(l, t);
+ ((GrGpuTextVertex*)(v + 1*stride))->setX(l, b);
+ ((GrGpuTextVertex*)(v + 2*stride))->setX(r, b);
+ ((GrGpuTextVertex*)(v + 3*stride))->setX(r, t);
+ }
+
+};
+
+#endif
+
diff --git a/include/gpu/GrIPoint.h b/include/gpu/GrIPoint.h
new file mode 100644
index 0000000000..9471054f06
--- /dev/null
+++ b/include/gpu/GrIPoint.h
@@ -0,0 +1,28 @@
+
+/*
+ * 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 GrIPoint_DEFINED
+#define GrIPoint_DEFINED
+
+#include "GrTypes.h"
+
+struct GrIPoint {
+public:
+ int32_t fX, fY;
+
+ GrIPoint(int32_t x, int32_t y) : fX(x), fY(y) {}
+
+ void set(int32_t x, int32_t y) {
+ fX = x;
+ fY = y;
+ }
+};
+
+#endif
diff --git a/include/gpu/GrInstanceCounter.h b/include/gpu/GrInstanceCounter.h
new file mode 100644
index 0000000000..b3e21d22d4
--- /dev/null
+++ b/include/gpu/GrInstanceCounter.h
@@ -0,0 +1,40 @@
+
+/*
+ * 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 GrInstanceCounter_DEFINED
+#define GrInstanceCounter_DEFINED
+
+#include "GrTypes.h"
+
+template <typename T> class GrInstanceCounter {
+public:
+ GrInstanceCounter() {
+ ++gCounter;
+ GrPrintf("+ %s %d\n", T::InstanceCounterClassName(), gCounter);
+ }
+
+ ~GrInstanceCounter() {
+ --gCounter;
+ GrPrintf("- %s %d\n", T::InstanceCounterClassName(), gCounter);
+ }
+
+private:
+ static int gCounter;
+};
+
+template <typename T> int GrInstanceCounter<T>::gCounter;
+
+#define DECLARE_INSTANCE_COUNTER(T) \
+ static const char* InstanceCounterClassName() { return #T; } \
+ friend class GrInstanceCounter<T>; \
+ GrInstanceCounter<T> fInstanceCounter
+
+#endif
+
diff --git a/include/gpu/GrKey.h b/include/gpu/GrKey.h
new file mode 100644
index 0000000000..813d82d920
--- /dev/null
+++ b/include/gpu/GrKey.h
@@ -0,0 +1,40 @@
+
+/*
+ * 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 GrKey_DEFINED
+#define GrKey_DEFINED
+
+#include "GrRefCnt.h"
+
+class GrKey : public GrRefCnt {
+public:
+ typedef intptr_t Hash;
+
+ explicit GrKey(Hash hash) : fHash(hash) {}
+
+ intptr_t getHash() const { return fHash; }
+
+ bool operator<(const GrKey& rh) const {
+ return fHash < rh.fHash || (fHash == rh.fHash && this->lt(rh));
+ }
+ bool operator==(const GrKey& rh) const {
+ return fHash == rh.fHash && this->eq(rh);
+ }
+
+protected:
+ virtual bool lt(const GrKey& rh) const = 0;
+ virtual bool eq(const GrKey& rh) const = 0;
+
+private:
+ const Hash fHash;
+};
+
+#endif
+
diff --git a/include/gpu/GrMatrix.h b/include/gpu/GrMatrix.h
new file mode 100644
index 0000000000..055680ac40
--- /dev/null
+++ b/include/gpu/GrMatrix.h
@@ -0,0 +1,19 @@
+
+/*
+ * 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 GrMatrix_DEFINED
+#define GrMatrix_DEFINED
+
+#include "GrRect.h"
+#include "SkMatrix.h"
+
+typedef SkMatrix GrMatrix;
+
+#endif
diff --git a/include/gpu/GrMesh.h b/include/gpu/GrMesh.h
new file mode 100644
index 0000000000..122613264f
--- /dev/null
+++ b/include/gpu/GrMesh.h
@@ -0,0 +1,49 @@
+
+/*
+ * 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 GrMesh_DEFINED
+#define GrMesh_DEFINED
+
+#include "SkRect.h"
+#include "SkPoint.h"
+
+class SkCanvas;
+class SkPaint;
+
+class GrMesh {
+public:
+ GrMesh();
+ ~GrMesh();
+
+ GrMesh& operator=(const GrMesh& src);
+
+ void init(const SkRect& bounds, int rows, int cols,
+ const SkRect& texture);
+
+ const SkRect& bounds() const { return fBounds; }
+
+ int rows() const { return fRows; }
+ int cols() const { return fCols; }
+ SkPoint& pt(int row, int col) {
+ return fPts[row * (fRows + 1) + col];
+ }
+
+ void draw(SkCanvas*, const SkPaint&);
+ void drawWireframe(SkCanvas* canvas, const SkPaint& paint);
+
+private:
+ SkRect fBounds;
+ int fRows, fCols;
+ SkPoint* fPts;
+ SkPoint* fTex; // just points into fPts, not separately allocated
+ int fCount;
+ uint16_t* fIndices;
+ int fIndexCount;
+};
+
+#endif
+
diff --git a/include/gpu/GrNoncopyable.h b/include/gpu/GrNoncopyable.h
new file mode 100644
index 0000000000..cad722f6f4
--- /dev/null
+++ b/include/gpu/GrNoncopyable.h
@@ -0,0 +1,31 @@
+
+/*
+ * 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 GrNoncopyable_DEFINED
+#define GrNoncopyable_DEFINED
+
+#include "GrTypes.h"
+
+/**
+ * Base for classes that want to disallow copying themselves. It makes its
+ * copy-constructor and assignment operators private (and unimplemented).
+ */
+class GR_API GrNoncopyable {
+public:
+ GrNoncopyable() {}
+
+private:
+ // illegal
+ GrNoncopyable(const GrNoncopyable&);
+ GrNoncopyable& operator=(const GrNoncopyable&);
+};
+
+#endif
+
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
new file mode 100644
index 0000000000..3b4b849fd7
--- /dev/null
+++ b/include/gpu/GrPaint.h
@@ -0,0 +1,254 @@
+
+/*
+ * 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 GrPaint_DEFINED
+#define GrPaint_DEFINED
+
+#include "GrTexture.h"
+#include "GrColor.h"
+#include "GrSamplerState.h"
+
+#include "SkXfermode.h"
+
+/**
+ * The paint describes how pixels are colored when the context draws to
+ * them. TODO: Make this a "real" class with getters and setters, default
+ * values, and documentation.
+ */
+class GrPaint {
+public:
+ enum {
+ kMaxTextures = 1,
+ kMaxMasks = 1,
+ };
+
+ // All the paint fields are public except textures/samplers
+ GrBlendCoeff fSrcBlendCoeff;
+ GrBlendCoeff fDstBlendCoeff;
+ bool fAntiAlias;
+ bool fDither;
+
+ GrColor fColor;
+
+ GrColor fColorFilterColor;
+ SkXfermode::Mode fColorFilterXfermode;
+
+ void setTexture(int i, GrTexture* texture) {
+ GrAssert((unsigned)i < kMaxTextures);
+ GrSafeRef(texture);
+ GrSafeUnref(fTextures[i]);
+ fTextures[i] = texture;
+ }
+
+ GrTexture* getTexture(int i) const {
+ GrAssert((unsigned)i < kMaxTextures);
+ return fTextures[i];
+ }
+
+ GrSamplerState* getTextureSampler(int i) {
+ GrAssert((unsigned)i < kMaxTextures);
+ return fTextureSamplers + i;
+ }
+
+ const GrSamplerState* getTextureSampler(int i) const {
+ GrAssert((unsigned)i < kMaxTextures);
+ return fTextureSamplers + i;
+ }
+
+ // The mask can be alpha-only or per channel. It is applied
+ // after the colorfilter
+ void setMask(int i, GrTexture* mask) {
+ GrAssert((unsigned)i < kMaxMasks);
+ GrSafeRef(mask);
+ GrSafeUnref(fMaskTextures[i]);
+ fMaskTextures[i] = mask;
+ }
+
+ GrTexture* getMask(int i) const {
+ GrAssert((unsigned)i < kMaxMasks);
+ return fMaskTextures[i];
+ }
+
+ // mask's sampler matrix is always applied to the positions
+ // (i.e. no explicit texture coordinates)
+ GrSamplerState* getMaskSampler(int i) {
+ GrAssert((unsigned)i < kMaxMasks);
+ return fMaskSamplers + i;
+ }
+
+ const GrSamplerState* getMaskSampler(int i) const {
+ GrAssert((unsigned)i < kMaxMasks);
+ return fMaskSamplers + i;
+ }
+
+ // pre-concats sampler matrices for non-NULL textures and masks
+ void preConcatActiveSamplerMatrices(const GrMatrix& matrix) {
+ for (int i = 0; i < kMaxTextures; ++i) {
+ fTextureSamplers[i].preConcatMatrix(matrix);
+ }
+ for (int i = 0; i < kMaxMasks; ++i) {
+ fMaskSamplers[i].preConcatMatrix(matrix);
+ }
+ }
+
+ // uninitialized
+ GrPaint() {
+ for (int i = 0; i < kMaxTextures; ++i) {
+ fTextures[i] = NULL;
+ }
+ for (int i = 0; i < kMaxMasks; ++i) {
+ fMaskTextures[i] = NULL;
+ }
+ }
+
+ GrPaint(const GrPaint& paint) {
+ for (int i = 0; i < kMaxTextures; ++i) {
+ fTextures[i] = NULL;
+ }
+ for (int i = 0; i < kMaxMasks; ++i) {
+ fMaskTextures[i] = NULL;
+ }
+ *this = paint;
+ }
+
+ GrPaint& operator=(const GrPaint& paint) {
+ fSrcBlendCoeff = paint.fSrcBlendCoeff;
+ fDstBlendCoeff = paint.fDstBlendCoeff;
+ fAntiAlias = paint.fAntiAlias;
+ fDither = paint.fDither;
+
+ fColor = paint.fColor;
+
+ fColorFilterColor = paint.fColorFilterColor;
+ fColorFilterXfermode = paint.fColorFilterXfermode;
+
+ for (int i = 0; i < kMaxTextures; ++i) {
+ GrSafeUnref(fTextures[i]);
+ fTextureSamplers[i] = paint.fTextureSamplers[i];
+ fTextures[i] = paint.fTextures[i];
+ GrSafeRef(fTextures[i]);
+ }
+ for (int i = 0; i < kMaxMasks; ++i) {
+ GrSafeUnref(fMaskTextures[i]);
+ fMaskSamplers[i] = paint.fMaskSamplers[i];
+ fMaskTextures[i] = paint.fMaskTextures[i];
+ GrSafeRef(fMaskTextures[i]);
+ }
+ return *this;
+ }
+
+ ~GrPaint() {
+ for (int i = 0; i < kMaxTextures; ++i) {
+ GrSafeUnref(fTextures[i]);
+ }
+ for (int i = 0; i < kMaxMasks; ++i) {
+ GrSafeUnref(fMaskTextures[i]);
+ }
+ }
+
+ // sets paint to src-over, solid white, no texture, no mask
+ void reset() {
+ this->resetBlend();
+ this->resetOptions();
+ this->resetColor();
+ this->resetTextures();
+ this->resetColorFilter();
+ this->resetMasks();
+ }
+
+ void resetColorFilter() {
+ fColorFilterXfermode = SkXfermode::kDst_Mode;
+ fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
+ }
+
+ bool hasTexture() const {
+ return 0 != this->getActiveTextureStageMask();
+ }
+
+ bool hasMask() const {
+ return 0 != this->getActiveMaskStageMask();
+ }
+
+ bool hasTextureOrMask() const {
+ return this->hasTexture() || this->hasMask();
+ }
+
+ // helpers for GrContext, GrTextContext
+ int getActiveTextureStageMask() const {
+ int mask = 0;
+ for (int i = 0; i < kMaxTextures; ++i) {
+ if (NULL != fTextures[i]) {
+ mask |= 1 << (i + kFirstTextureStage);
+ }
+ }
+ return mask;
+ }
+
+ int getActiveMaskStageMask() const {
+ int mask = 0;
+ for (int i = 0; i < kMaxMasks; ++i) {
+ if (NULL != fMaskTextures[i]) {
+ mask |= 1 << (i + kFirstMaskStage);
+ }
+ }
+ return mask;
+ }
+
+ int getActiveStageMask() const {
+ return this->getActiveTextureStageMask() |
+ this->getActiveMaskStageMask();
+ }
+
+ // internal use
+ // GrPaint's textures and masks map to the first N stages
+ // of GrDrawTarget in that order (textures followed by masks)
+ enum {
+ kFirstTextureStage = 0,
+ kFirstMaskStage = kMaxTextures,
+ kTotalStages = kMaxTextures + kMaxMasks,
+ };
+
+private:
+
+ GrSamplerState fTextureSamplers[kMaxTextures];
+ GrSamplerState fMaskSamplers[kMaxMasks];
+
+ GrTexture* fTextures[kMaxTextures];
+ GrTexture* fMaskTextures[kMaxMasks];
+
+ void resetBlend() {
+ fSrcBlendCoeff = kOne_BlendCoeff;
+ fDstBlendCoeff = kZero_BlendCoeff;
+ }
+
+ void resetOptions() {
+ fAntiAlias = false;
+ fDither = false;
+ }
+
+ void resetColor() {
+ fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
+ }
+
+ void resetTextures() {
+ for (int i = 0; i < kMaxTextures; ++i) {
+ this->setTexture(i, NULL);
+ fTextureSamplers[i].setClampNoFilter();
+ }
+ }
+
+ void resetMasks() {
+ for (int i = 0; i < kMaxMasks; ++i) {
+ this->setMask(i, NULL);
+ fMaskSamplers[i].setClampNoFilter();
+ }
+ }
+};
+
+#endif
diff --git a/include/gpu/GrPath.h b/include/gpu/GrPath.h
new file mode 100644
index 0000000000..7da0d48082
--- /dev/null
+++ b/include/gpu/GrPath.h
@@ -0,0 +1,20 @@
+
+/*
+ * 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 GrPath_DEFINED
+#define GrPath_DEFINED
+
+#include "GrTypes.h"
+#include "SkPath.h"
+
+typedef SkPath GrPath;
+
+#endif
+
diff --git a/include/gpu/GrPathSink.h b/include/gpu/GrPathSink.h
new file mode 100644
index 0000000000..ed71387e7f
--- /dev/null
+++ b/include/gpu/GrPathSink.h
@@ -0,0 +1,29 @@
+
+/*
+ * 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 GrPathSink_DEFINED
+#define GrPathSink_DEFINED
+
+#include "GrScalar.h"
+
+class GrPathSink {
+public:
+ virtual ~GrPathSink() {}
+
+ virtual void moveTo(GrScalar x, GrScalar y) = 0;
+ virtual void lineTo(GrScalar x, GrScalar y) = 0;
+ virtual void quadTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1) = 0;
+ virtual void cubicTo(GrScalar x0, GrScalar y0, GrScalar x1, GrScalar y1,
+ GrScalar x2, GrScalar y2) = 0;
+ virtual void close() = 0;
+};
+
+#endif
+
diff --git a/include/gpu/GrPlotMgr.h b/include/gpu/GrPlotMgr.h
new file mode 100644
index 0000000000..0e631a9ade
--- /dev/null
+++ b/include/gpu/GrPlotMgr.h
@@ -0,0 +1,77 @@
+
+/*
+ * 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 GrPlotMgr_DEFINED
+#define GrPlotMgr_DEFINED
+
+#include "GrTypes.h"
+#include "GrPoint.h"
+
+class GrPlotMgr : GrNoncopyable {
+public:
+ GrPlotMgr(int width, int height) {
+ fDim.set(width, height);
+ size_t needed = width * height;
+ if (needed <= sizeof(fStorage)) {
+ fBusy = fStorage;
+ } else {
+ fBusy = new char[needed];
+ }
+ this->reset();
+ }
+
+ ~GrPlotMgr() {
+ if (fBusy != fStorage) {
+ delete[] fBusy;
+ }
+ }
+
+ void reset() {
+ Gr_bzero(fBusy, fDim.fX * fDim.fY);
+ }
+
+ bool newPlot(GrIPoint16* loc) {
+ char* busy = fBusy;
+ for (int y = 0; y < fDim.fY; y++) {
+ for (int x = 0; x < fDim.fX; x++) {
+ if (!*busy) {
+ *busy = true;
+ loc->set(x, y);
+ return true;
+ }
+ busy++;
+ }
+ }
+ return false;
+ }
+
+ bool isBusy(int x, int y) const {
+ GrAssert((unsigned)x < (unsigned)fDim.fX);
+ GrAssert((unsigned)y < (unsigned)fDim.fY);
+ return fBusy[y * fDim.fX + x] != 0;
+ }
+
+ void freePlot(int x, int y) {
+ GrAssert((unsigned)x < (unsigned)fDim.fX);
+ GrAssert((unsigned)y < (unsigned)fDim.fY);
+ fBusy[y * fDim.fX + x] = false;
+ }
+
+private:
+ enum {
+ STORAGE = 64
+ };
+ char fStorage[STORAGE];
+ char* fBusy;
+ GrIPoint16 fDim;
+};
+
+#endif
+
diff --git a/include/gpu/GrPoint.h b/include/gpu/GrPoint.h
new file mode 100644
index 0000000000..b32123b568
--- /dev/null
+++ b/include/gpu/GrPoint.h
@@ -0,0 +1,31 @@
+
+/*
+ * 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 GrPoint_DEFINED
+#define GrPoint_DEFINED
+
+#include "GrTypes.h"
+#include "GrScalar.h"
+#include "SkPoint.h"
+
+#define GrPoint SkPoint
+#define GrVec SkVector
+
+struct GrIPoint16 {
+ int16_t fX, fY;
+
+ void set(intptr_t x, intptr_t y) {
+ fX = GrToS16(x);
+ fY = GrToS16(y);
+ }
+};
+
+#endif
+
diff --git a/include/gpu/GrRandom.h b/include/gpu/GrRandom.h
new file mode 100644
index 0000000000..c98a8fbd94
--- /dev/null
+++ b/include/gpu/GrRandom.h
@@ -0,0 +1,55 @@
+
+/*
+ * 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 GrRandom_DEFINED
+#define GrRandom_DEFINED
+
+class GrRandom {
+public:
+ GrRandom() : fSeed(0) {}
+ GrRandom(uint32_t seed) : fSeed(seed) {}
+
+ uint32_t seed() const { return fSeed; }
+
+ uint32_t nextU() {
+ fSeed = fSeed * kMUL + kADD;
+ return fSeed;
+ }
+
+ int32_t nextS() { return (int32_t)this->nextU(); }
+
+ /**
+ * Returns value [0...1) as a float
+ */
+ float nextF() {
+ // const is 1 / (2^32 - 1)
+ return (float)(this->nextU() * 2.32830644e-10);
+ }
+
+ /**
+ * Returns value [min...max) as a float
+ */
+ float nextF(float min, float max) {
+ return min + this->nextF() * (max - min);
+ }
+
+private:
+ /*
+ * These constants taken from "Numerical Recipes in C", reprinted 1999
+ */
+ enum {
+ kMUL = 1664525,
+ kADD = 1013904223
+ };
+ uint32_t fSeed;
+};
+
+#endif
+
diff --git a/include/gpu/GrRect.h b/include/gpu/GrRect.h
new file mode 100644
index 0000000000..60a4773820
--- /dev/null
+++ b/include/gpu/GrRect.h
@@ -0,0 +1,37 @@
+
+/*
+ * 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 GrRect_DEFINED
+#define GrRect_DEFINED
+
+#include "GrPoint.h"
+#include "SkRect.h"
+
+typedef SkIRect GrIRect;
+typedef SkRect GrRect;
+
+struct GrIRect16 {
+ int16_t fLeft, fTop, fRight, fBottom;
+
+ int width() const { return fRight - fLeft; }
+ int height() const { return fBottom - fTop; }
+ int area() const { return this->width() * this->height(); }
+ bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+
+ void set(const GrIRect& r) {
+ fLeft = SkToS16(r.fLeft);
+ fTop = SkToS16(r.fTop);
+ fRight = SkToS16(r.fRight);
+ fBottom = SkToS16(r.fBottom);
+ }
+};
+
+#endif
+
diff --git a/include/gpu/GrRectanizer.h b/include/gpu/GrRectanizer.h
new file mode 100644
index 0000000000..d1f5033259
--- /dev/null
+++ b/include/gpu/GrRectanizer.h
@@ -0,0 +1,57 @@
+
+/*
+ * 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 GrRectanizer_DEFINED
+#define GrRectanizer_DEFINED
+
+#include "GrRect.h"
+#include "GrTDArray.h"
+
+class GrRectanizerPurgeListener {
+public:
+ virtual ~GrRectanizerPurgeListener() {}
+
+ virtual void notifyPurgeStrip(void*, int yCoord) = 0;
+};
+
+class GrRectanizer {
+public:
+ GrRectanizer(int width, int height) : fWidth(width), fHeight(height) {
+ GrAssert(width >= 0);
+ GrAssert(height >= 0);
+ }
+
+ virtual ~GrRectanizer() {}
+
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+
+ virtual bool addRect(int width, int height, GrIPoint16* loc) = 0;
+ virtual float percentFull() const = 0;
+
+ // return the Y-coordinate of a strip that should be purged, given height
+ // i.e. return the oldest such strip, or some other criteria. Return -1
+ // if there is no candidate
+ virtual int stripToPurge(int height) const = 0;
+ virtual void purgeStripAtY(int yCoord) = 0;
+
+ /**
+ * Our factory, which returns the subclass du jour
+ */
+ static GrRectanizer* Factory(int width, int height);
+
+private:
+ int fWidth;
+ int fHeight;
+};
+
+#endif
+
+
diff --git a/include/gpu/GrRefCnt.h b/include/gpu/GrRefCnt.h
new file mode 100644
index 0000000000..50c32c6560
--- /dev/null
+++ b/include/gpu/GrRefCnt.h
@@ -0,0 +1,34 @@
+
+/*
+ * 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 GrRefCnt_DEFINED
+#define GrRefCnt_DEFINED
+
+#include "GrTypes.h"
+#include "SkRefCnt.h"
+
+typedef SkRefCnt GrRefCnt;
+typedef SkAutoRef GrAutoRef;
+typedef SkAutoUnref GrAutoUnref;
+
+#define GrSafeRef SkSafeRef
+#define GrSafeUnref SkSafeUnref
+#define GrSafeAssign(a, b) SkRefCnt_SafeAssign(a, b)
+
+template<typename T>
+static inline void GrSafeSetNull(T*& obj) {
+ if (NULL != obj) {
+ obj->unref();
+ obj = NULL;
+ }
+}
+
+#endif
+
diff --git a/include/gpu/GrRenderTarget.h b/include/gpu/GrRenderTarget.h
new file mode 100644
index 0000000000..dd7a371dcb
--- /dev/null
+++ b/include/gpu/GrRenderTarget.h
@@ -0,0 +1,209 @@
+/*
+ Copyright 2011 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+
+#ifndef GrRenderTarget_DEFINED
+#define GrRenderTarget_DEFINED
+
+#include "GrRect.h"
+#include "GrResource.h"
+
+class GrStencilBuffer;
+class GrTexture;
+
+/**
+ * GrRenderTarget represents a 2D buffer of pixels that can be rendered to.
+ * A context's render target is set by setRenderTarget(). Render targets are
+ * created by a createTexture with the kRenderTarget_TextureFlag flag.
+ * Additionally, GrContext provides methods for creating GrRenderTargets
+ * that wrap externally created render targets.
+ */
+class GrRenderTarget : public GrResource {
+public:
+
+ /**
+ * @return the width of the rendertarget
+ */
+ int width() const { return fWidth; }
+ /**
+ * @return the height of the rendertarget
+ */
+ int height() const { return fHeight; }
+
+ /**
+ * Retrieves the allocated width. It may differ from width for
+ * NPOT or min-RT size reasons.
+ * @return allocated width in pixels
+ */
+ int allocatedWidth() const { return fAllocatedWidth; }
+
+ /**
+ * Retrieves the allocated height. It may differ from height for
+ * NPOT or min-RT size reasons.
+ * @return allocated height in pixels
+ */
+ int allocatedHeight() const { return fAllocatedHeight; }
+
+ /**
+ * @return the pixel config. Can be kUnknown_GrPixelConfig
+ * if client asked us to render to a target that has a pixel
+ * config that isn't equivalent with one of our configs.
+ */
+ GrPixelConfig config() const { return fConfig; }
+
+ /**
+ * @return the texture associated with the rendertarget, may be NULL.
+ */
+ GrTexture* asTexture() {return fTexture;}
+
+ /**
+ * If this RT is multisampled, this is the multisample buffer
+ * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
+ */
+ virtual intptr_t getRenderTargetHandle() const = 0;
+
+ /**
+ * If this RT is multisampled, this is the buffer it is resolved to.
+ * Otherwise, same as getRenderTargetHandle().
+ * (In GL a separate FBO ID is used for the msaa and resolved buffers)
+ * @return the 3D API's handle to this object (e.g. FBO ID in OpenGL)
+ */
+ virtual intptr_t getRenderTargetResolvedHandle() const = 0;
+
+ /**
+ * @return true if the render target is multisampled, false otherwise
+ */
+ bool isMultisampled() const { return 0 != fSampleCnt; }
+
+ /**
+ * @return the number of samples-per-pixel or zero if non-MSAA.
+ */
+ int numSamples() const { return fSampleCnt; }
+
+ /**
+ * Call to indicate the multisample contents were modified such that the
+ * render target needs to be resolved before it can be used as texture. Gr
+ * tracks this for its own drawing and thus this only needs to be called
+ * when the render target has been modified outside of Gr. Only meaningful
+ * for Gr-created RT/Textures and Platform RT/Textures created with the
+ * kGrCanResolve flag.
+ * @param rect a rect bounding the area needing resolve. NULL indicates
+ * the whole RT needs resolving.
+ */
+ void flagAsNeedingResolve(const GrIRect* rect = NULL);
+
+ /**
+ * Call to override the region that needs to be resolved.
+ */
+ void overrideResolveRect(const GrIRect rect);
+
+ /**
+ * Call to indicate that GrRenderTarget was externally resolved. This may
+ * allow Gr to skip a redundant resolve step.
+ */
+ void flagAsResolved() { fResolveRect.setLargestInverted(); }
+
+ /**
+ * @return true if the GrRenderTarget requires MSAA resolving
+ */
+ bool needsResolve() const { return !fResolveRect.isEmpty(); }
+
+ /**
+ * Returns a rect bounding the region needing resolving.
+ */
+ const GrIRect& getResolveRect() const { return fResolveRect; }
+
+ // GrResource overrides
+ virtual size_t sizeInBytes() const;
+
+ /**
+ * Reads a rectangle of pixels from the render target.
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ *
+ * @return true if the read succeeded, false if not. The read can fail
+ * because of a unsupported pixel config.
+ */
+ bool readPixels(int left, int top, int width, int height,
+ GrPixelConfig config, void* buffer);
+
+ // a MSAA RT may require explicit resolving , it may auto-resolve (e.g. FBO
+ // 0 in GL), or be unresolvable because the client didn't give us the
+ // resolve destination.
+ enum ResolveType {
+ kCanResolve_ResolveType,
+ kAutoResolves_ResolveType,
+ kCantResolve_ResolveType,
+ };
+ virtual ResolveType getResolveType() const = 0;
+
+ /**
+ * GrStencilBuffer is not part of the public API.
+ */
+ GrStencilBuffer* getStencilBuffer() const { return fStencilBuffer; }
+ void setStencilBuffer(GrStencilBuffer* stencilBuffer);
+
+protected:
+ GrRenderTarget(GrGpu* gpu,
+ GrTexture* texture,
+ int width,
+ int height,
+ int allocatedWidth,
+ int allocatedHeight,
+ GrPixelConfig config,
+ int sampleCnt)
+ : INHERITED(gpu)
+ , fStencilBuffer(NULL)
+ , fTexture(texture)
+ , fWidth(width)
+ , fHeight(height)
+ , fAllocatedWidth(allocatedWidth)
+ , fAllocatedHeight(allocatedHeight)
+ , fConfig(config)
+ , fSampleCnt(sampleCnt) {
+ fResolveRect.setLargestInverted();
+ }
+
+ friend class GrTexture;
+ // When a texture unrefs an owned rendertarget this func
+ // removes the back pointer. This could be done called from
+ // texture's destructor but would have to be done in derived
+ // class. By the time of texture base destructor it has already
+ // lost its pointer to the rt.
+ void onTextureReleaseRenderTarget() {
+ GrAssert(NULL != fTexture);
+ fTexture = NULL;
+ }
+
+private:
+ GrStencilBuffer* fStencilBuffer;
+ GrTexture* fTexture; // not ref'ed
+ int fWidth;
+ int fHeight;
+ int fAllocatedWidth;
+ int fAllocatedHeight;
+ GrPixelConfig fConfig;
+ int fSampleCnt;
+ GrIRect fResolveRect;
+
+ typedef GrResource INHERITED;
+};
+
+#endif
diff --git a/include/gpu/GrResource.h b/include/gpu/GrResource.h
new file mode 100644
index 0000000000..0d15fe9c00
--- /dev/null
+++ b/include/gpu/GrResource.h
@@ -0,0 +1,78 @@
+
+/*
+ * 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 GrResource_DEFINED
+#define GrResource_DEFINED
+
+#include "GrRefCnt.h"
+
+class GrGpu;
+
+class GrResource : public GrRefCnt {
+public:
+ explicit GrResource(GrGpu* gpu);
+
+ virtual ~GrResource() {
+ // subclass should have released this.
+ GrAssert(!isValid());
+ }
+
+ /**
+ * Frees the resource in the underlying 3D API. It must be safe to call this
+ * when the resource has been previously abandoned.
+ */
+ void release();
+
+ /**
+ * Removes references to objects in the underlying 3D API without freeing
+ * them. Used when the API context has been torn down before the GrContext.
+ */
+ void abandon();
+
+ /**
+ * Tests whether a resource has been abandoned or released. All resources
+ * will be in this state after their creating GrContext is destroyed or has
+ * contextLost called. It's up to the client to test isValid() before
+ * attempting to use a resource if it holds refs on resources across
+ * ~GrContext, freeResources with the force flag, or contextLost.
+ *
+ * @return true if the resource has been released or abandoned,
+ * false otherwise.
+ */
+ bool isValid() const { return NULL != fGpu; }
+
+ /**
+ * Retrieves the size of the object in GPU memory. This is approximate since
+ * we aren't aware of additional padding or copies made by the driver.
+ *
+ * @return the size of the buffer in bytes
+ */
+ virtual size_t sizeInBytes() const = 0;
+
+protected:
+
+ virtual void onRelease() = 0;
+ virtual void onAbandon() = 0;
+
+ GrGpu* getGpu() const { return fGpu; }
+
+private:
+ GrResource(); // unimpl
+
+ GrGpu* fGpu; // not reffed. This can outlive the GrGpu.
+
+ friend class GrGpu; // GrGpu manages list of resources.
+
+ GrResource* fNext; // dl-list of resources per-GrGpu
+ GrResource* fPrevious;
+
+ typedef GrRefCnt INHERITED;
+};
+
+#endif
diff --git a/include/gpu/GrSamplerState.h b/include/gpu/GrSamplerState.h
new file mode 100644
index 0000000000..324472c972
--- /dev/null
+++ b/include/gpu/GrSamplerState.h
@@ -0,0 +1,265 @@
+
+/*
+ * 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 GrSamplerState_DEFINED
+#define GrSamplerState_DEFINED
+
+#include "GrTypes.h"
+#include "GrMatrix.h"
+
+#define MAX_KERNEL_WIDTH 25
+
+class GrSamplerState {
+public:
+ enum Filter {
+ /**
+ * Read the closest src texel to the sample position
+ */
+ kNearest_Filter,
+ /**
+ * Blend between closest 4 src texels to sample position (tent filter)
+ */
+ kBilinear_Filter,
+ /**
+ * Average of 4 bilinear filterings spaced +/- 1 texel from sample
+ * position in x and y. Intended for averaging 16 texels in a downsample
+ * pass. (rasterizing such that texture samples fall exactly halfway
+ * between texels in x and y spaced 4 texels apart.) Only supported
+ * on shader backends.
+ */
+ k4x4Downsample_Filter,
+ /**
+ * Apply a separable convolution kernel.
+ */
+ kConvolution_Filter
+ };
+
+ /**
+ * The intepretation of the texture matrix depends on the sample mode. The
+ * texture matrix is applied both when the texture coordinates are explicit
+ * and when vertex positions are used as texture coordinates. In the latter
+ * case the texture matrix is applied to the pre-view-matrix position
+ * values.
+ *
+ * kNormal_SampleMode
+ * The post-matrix texture coordinates are in normalize space with (0,0) at
+ * the top-left and (1,1) at the bottom right.
+ * kRadial_SampleMode
+ * The matrix specifies the radial gradient parameters.
+ * (0,0) in the post-matrix space is center of the radial gradient.
+ * kRadial2_SampleMode
+ * Matrix transforms to space where first circle is centered at the
+ * origin. The second circle will be centered (x, 0) where x may be
+ * 0 and is provided by setRadial2Params. The post-matrix space is
+ * normalized such that 1 is the second radius - first radius.
+ * kSweepSampleMode
+ * The angle from the origin of texture coordinates in post-matrix space
+ * determines the gradient value.
+ */
+ enum SampleMode {
+ kNormal_SampleMode, //!< sample color directly
+ kRadial_SampleMode, //!< treat as radial gradient
+ kRadial2_SampleMode, //!< treat as 2-point radial gradient
+ kSweep_SampleMode, //!< treat as sweep gradient
+ };
+
+ /**
+ * Describes how a texture is sampled when coordinates are outside the
+ * texture border
+ */
+ enum WrapMode {
+ kClamp_WrapMode,
+ kRepeat_WrapMode,
+ kMirror_WrapMode
+ };
+
+ /**
+ * Default sampler state is set to clamp, use normal sampling mode, be
+ * unfiltered, and use identity matrix.
+ */
+ GrSamplerState()
+ : fRadial2CenterX1()
+ , fRadial2Radius0()
+ , fRadial2PosRoot() {
+ this->setClampNoFilter();
+ }
+
+ explicit GrSamplerState(Filter filter)
+ : fRadial2CenterX1()
+ , fRadial2Radius0()
+ , fRadial2PosRoot() {
+ fWrapX = kClamp_WrapMode;
+ fWrapY = kClamp_WrapMode;
+ fSampleMode = kNormal_SampleMode;
+ fFilter = filter;
+ fMatrix.setIdentity();
+ fTextureDomain.setEmpty();
+ }
+
+ GrSamplerState(WrapMode wx, WrapMode wy, Filter filter)
+ : fRadial2CenterX1()
+ , fRadial2Radius0()
+ , fRadial2PosRoot() {
+ fWrapX = wx;
+ fWrapY = wy;
+ fSampleMode = kNormal_SampleMode;
+ fFilter = filter;
+ fMatrix.setIdentity();
+ fTextureDomain.setEmpty();
+ }
+
+ GrSamplerState(WrapMode wx, WrapMode wy,
+ const GrMatrix& matrix, Filter filter)
+ : fRadial2CenterX1()
+ , fRadial2Radius0()
+ , fRadial2PosRoot() {
+ fWrapX = wx;
+ fWrapY = wy;
+ fSampleMode = kNormal_SampleMode;
+ fFilter = filter;
+ fMatrix = matrix;
+ fTextureDomain.setEmpty();
+ }
+
+ GrSamplerState(WrapMode wx, WrapMode wy, SampleMode sample,
+ const GrMatrix& matrix, Filter filter)
+ : fRadial2CenterX1()
+ , fRadial2Radius0()
+ , fRadial2PosRoot() {
+ fWrapX = wx;
+ fWrapY = wy;
+ fSampleMode = sample;
+ fMatrix = matrix;
+ fFilter = filter;
+ fTextureDomain.setEmpty();
+ }
+
+ WrapMode getWrapX() const { return fWrapX; }
+ WrapMode getWrapY() const { return fWrapY; }
+ SampleMode getSampleMode() const { return fSampleMode; }
+ const GrMatrix& getMatrix() const { return fMatrix; }
+ const GrRect& getTextureDomain() const { return fTextureDomain; }
+ bool hasTextureDomain() const {return SkIntToScalar(0) != fTextureDomain.right();}
+ Filter getFilter() const { return fFilter; }
+ int getKernelWidth() const { return fKernelWidth; }
+ const float* getKernel() const { return fKernel; }
+ const float* getImageIncrement() const { return fImageIncrement; }
+
+ bool isGradient() const {
+ return kRadial_SampleMode == fSampleMode ||
+ kRadial2_SampleMode == fSampleMode ||
+ kSweep_SampleMode == fSampleMode;
+ }
+
+ void setWrapX(WrapMode mode) { fWrapX = mode; }
+ void setWrapY(WrapMode mode) { fWrapY = mode; }
+ void setSampleMode(SampleMode mode) { fSampleMode = mode; }
+
+ /**
+ * Sets the sampler's matrix. See SampleMode for explanation of
+ * relationship between the matrix and sample mode.
+ * @param matrix the matrix to set
+ */
+ void setMatrix(const GrMatrix& matrix) { fMatrix = matrix; }
+
+ /**
+ * Sets the sampler's texture coordinate domain to a
+ * custom rectangle, rather than the default (0,1).
+ * This option is currently only supported with kClamp_WrapMode
+ */
+ void setTextureDomain(const GrRect& textureDomain) { fTextureDomain = textureDomain; }
+
+ /**
+ * Multiplies the current sampler matrix a matrix
+ *
+ * After this call M' = M*m where M is the old matrix, m is the parameter
+ * to this function, and M' is the new matrix. (We consider points to
+ * be column vectors so tex cood vector t is transformed by matrix X as
+ * t' = X*t.)
+ *
+ * @param matrix the matrix used to modify the matrix.
+ */
+ void preConcatMatrix(const GrMatrix& matrix) { fMatrix.preConcat(matrix); }
+
+ /**
+ * Sets filtering type.
+ * @param filter type of filtering to apply
+ */
+ void setFilter(Filter filter) { fFilter = filter; }
+
+ void setClampNoFilter() {
+ fWrapX = kClamp_WrapMode;
+ fWrapY = kClamp_WrapMode;
+ fSampleMode = kNormal_SampleMode;
+ fFilter = kNearest_Filter;
+ fMatrix.setIdentity();
+ fTextureDomain.setEmpty();
+ }
+
+ GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
+ GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
+ bool isRadial2PosRoot() const { return fRadial2PosRoot; }
+ // do the radial gradient params lead to a linear (rather than quadratic)
+ // equation.
+ bool radial2IsDegenerate() const { return GR_Scalar1 == fRadial2CenterX1; }
+
+ /**
+ * Sets the parameters for kRadial2_SampleMode. The texture
+ * matrix must be set so that the first point is at (0,0) and the second
+ * point lies on the x-axis. The second radius minus the first is 1 unit.
+ * The additional parameters to define the gradient are specified by this
+ * function.
+ */
+ void setRadial2Params(GrScalar centerX1, GrScalar radius0, bool posRoot) {
+ fRadial2CenterX1 = centerX1;
+ fRadial2Radius0 = radius0;
+ fRadial2PosRoot = posRoot;
+ }
+
+ void setConvolutionParams(int kernelWidth, const float* kernel, float imageIncrement[2]) {
+ GrAssert(kernelWidth >= 0 && kernelWidth <= MAX_KERNEL_WIDTH);
+ fKernelWidth = kernelWidth;
+ if (NULL != kernel) {
+ memcpy(fKernel, kernel, kernelWidth * sizeof(float));
+ }
+ if (NULL != imageIncrement) {
+ memcpy(fImageIncrement, imageIncrement, sizeof(fImageIncrement));
+ } else {
+ memset(fImageIncrement, 0, sizeof(fImageIncrement));
+ }
+ }
+
+ static const GrSamplerState& ClampNoFilter() {
+ return gClampNoFilter;
+ }
+
+private:
+ WrapMode fWrapX;
+ WrapMode fWrapY;
+ SampleMode fSampleMode;
+ Filter fFilter;
+ GrMatrix fMatrix;
+ GrRect fTextureDomain;
+
+ // these are undefined unless fSampleMode == kRadial2_SampleMode
+ GrScalar fRadial2CenterX1;
+ GrScalar fRadial2Radius0;
+ bool fRadial2PosRoot;
+
+ // These are undefined unless fFilter == kConvolution_Filter
+ int fKernelWidth;
+ float fKernel[MAX_KERNEL_WIDTH];
+ float fImageIncrement[2];
+
+ static const GrSamplerState gClampNoFilter;
+};
+
+#endif
+
diff --git a/include/gpu/GrScalar.h b/include/gpu/GrScalar.h
new file mode 100644
index 0000000000..4ffc4cabe0
--- /dev/null
+++ b/include/gpu/GrScalar.h
@@ -0,0 +1,49 @@
+
+/*
+ * 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 GrScalar_DEFINED
+#define GrScalar_DEFINED
+
+#include "GrTypes.h"
+#include "SkScalar.h"
+
+#define GR_Int32Min SK_NaN32
+#define GR_Int32Max SK_MaxS32
+
+#define GR_Fixed1 SK_Fixed1
+#define GR_FixedHalf SK_FixedHalf
+#define GrIntToFixed(a) SkIntToFixed(a)
+#define GrFixedToFloat(a) SkFixedToFloat(a)
+#define GrFixedFloorToInt(a) SkFixedFloor(a)
+
+#define GrScalar SkScalar
+#define GR_Scalar1 SK_Scalar1
+#define GR_ScalarHalf SK_ScalarHalf
+#define GR_ScalarMin SK_ScalarMin
+#define GR_ScalarMax SK_ScalarMax
+
+#define GrIntToScalar(a) SkIntToScalar(a)
+#define GrScalarHalf(a) SkScalarHalf(a)
+#define GrScalarAve(a,b) SkScalarAve(a,b)
+#define GrMul(a,b) SkScalarMul(a,b) // deprecated, prefer GrScalarMul
+#define GrScalarMul(a,b) SkScalarMul(a,b)
+#define GrScalarDiv(a,b) SkScalarDiv(a, b)
+#define GrScalarToFloat(a) SkScalarToFloat(a)
+#define GrFloatToScalar(a) SkScalarToFloat(a)
+#define GrIntToScalar(a) SkIntToScalar(a)
+#define GrScalarAbs(a) SkScalarAbs(a)
+#define GrScalarIsInt(a) SkScalarIsInt(a)
+#define GrScalarMax(a,b) SkScalarMax(a,b)
+#define GrScalarFloorToInt(a) SkScalarFloor(a)
+#define GrScalarCeilToInt(a) SkScalarCeil(a)
+#define GrFixedToScalar(a) SkFixedToScalar(a)
+
+#endif
+
diff --git a/include/gpu/GrStencil.h b/include/gpu/GrStencil.h
new file mode 100644
index 0000000000..b8610f2017
--- /dev/null
+++ b/include/gpu/GrStencil.h
@@ -0,0 +1,211 @@
+
+/*
+ * 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 GrStencil_DEFINED
+#define GrStencil_DEFINED
+
+#include "GrTypes.h"
+/**
+ * Gr uses the stencil buffer to implement complex clipping inside the
+ * GrDrawTarget class. The GrDrawTarget makes a subset of the stencil buffer
+ * bits available for other uses by external code (clients). Client code can
+ * modify these bits. GrDrawTarget will ignore ref, mask, and writemask bits
+ * provided by clients that overlap the bits used to implement clipping.
+ *
+ * When code outside the GrDrawTarget class uses the stencil buffer the contract
+ * is as follows:
+ *
+ * > Normal stencil funcs allow the client to pass / fail regardless of the
+ * reserved clip bits.
+ * > Additional functions allow a test against the clip along with a limited
+ * set of tests against the client bits.
+ * > Client can assume all client bits are zero initially.
+ * > Client must ensure that after all its passes are finished it has only
+ * written to the color buffer in the region inside the clip. Furthermore, it
+ * must zero all client bits that were modifed (both inside and outside the
+ * clip).
+ */
+
+/**
+ * Determines which pixels pass / fail the stencil test.
+ * Stencil test passes if (ref & mask) FUNC (stencil & mask) is true
+ */
+enum GrStencilFunc {
+ kAlways_StencilFunc = 0,
+ kNever_StencilFunc,
+ kGreater_StencilFunc,
+ kGEqual_StencilFunc,
+ kLess_StencilFunc,
+ kLEqual_StencilFunc,
+ kEqual_StencilFunc,
+ kNotEqual_StencilFunc,
+
+ // Gr stores the current clip in the
+ // stencil buffer in the high bits that
+ // are not directly accessible modifiable
+ // via the GrDrawTarget interface. The below
+ // stencil funcs test against the current
+ // clip in addition to the GrDrawTarget
+ // client's stencil bits.
+
+ // pass if inside the clip
+ kAlwaysIfInClip_StencilFunc,
+ kEqualIfInClip_StencilFunc,
+ kLessIfInClip_StencilFunc,
+ kLEqualIfInClip_StencilFunc,
+ kNonZeroIfInClip_StencilFunc, // this one forces the ref to be 0
+
+ // counts
+ kStencilFuncCount,
+ kClipStencilFuncCount = kNonZeroIfInClip_StencilFunc -
+ kAlwaysIfInClip_StencilFunc + 1,
+ kBasicStencilFuncCount = kStencilFuncCount - kClipStencilFuncCount
+};
+
+/**
+ * Operations to perform based on whether stencil test passed failed.
+ */
+enum GrStencilOp {
+ kKeep_StencilOp = 0, // preserve existing stencil value
+ kReplace_StencilOp, // replace with reference value from stencl test
+ kIncWrap_StencilOp, // increment and wrap at max
+ kIncClamp_StencilOp, // increment and clamp at max
+ kDecWrap_StencilOp, // decrement and wrap at 0
+ kDecClamp_StencilOp, // decrement and clamp at 0
+ kZero_StencilOp, // zero stencil bits
+ kInvert_StencilOp, // invert stencil bits
+
+ kStencilOpCount
+};
+
+/**
+ * Struct representing stencil state.
+ */
+struct GrStencilSettings {
+ GrStencilOp fFrontPassOp; // op to perform when front faces pass
+ GrStencilOp fBackPassOp; // op to perform when back faces pass
+ GrStencilOp fFrontFailOp; // op to perform when front faces fail
+ GrStencilOp fBackFailOp; // op to perform when back faces fail
+ GrStencilFunc fFrontFunc; // test function for front faces
+ GrStencilFunc fBackFunc; // test function for back faces
+ unsigned int fFrontFuncMask; // mask for front face test
+ unsigned int fBackFuncMask; // mask for back face test
+ unsigned int fFrontFuncRef; // reference value for front face test
+ unsigned int fBackFuncRef; // reference value for back face test
+ unsigned int fFrontWriteMask; // stencil write mask for front faces
+ unsigned int fBackWriteMask; // stencil write mask for back faces
+
+ bool operator == (const GrStencilSettings& s) const {
+ // make sure this is tightly packed.
+ GR_STATIC_ASSERT(0 == sizeof(GrStencilOp)%4);
+ GR_STATIC_ASSERT(0 == sizeof(GrStencilFunc)%4);
+ GR_STATIC_ASSERT(sizeof(GrStencilSettings) ==
+ 4*sizeof(GrStencilOp) +
+ 2*sizeof(GrStencilFunc) +
+ 6*sizeof(unsigned int));
+ return 0 == memcmp(this, &s, sizeof(GrStencilSettings));
+ }
+
+ bool operator != (const GrStencilSettings& s) const {
+ return !(*this == s);
+ }
+
+ GrStencilSettings& operator =(const GrStencilSettings& s) {
+ memcpy(this, &s, sizeof(GrStencilSettings));
+ return *this;
+ }
+
+ void setSame(GrStencilOp passOp,
+ GrStencilOp failOp,
+ GrStencilFunc func,
+ unsigned int funcMask,
+ unsigned int funcRef,
+ unsigned int writeMask) {
+ fFrontPassOp = passOp;
+ fBackPassOp = passOp;
+ fFrontFailOp = failOp;
+ fBackFailOp = failOp;
+ fFrontFunc = func;
+ fBackFunc = func;
+ fFrontFuncMask = funcMask;
+ fBackFuncMask = funcMask;
+ fFrontFuncRef = funcRef;
+ fBackFuncRef = funcRef;
+ fFrontWriteMask = writeMask;
+ fBackWriteMask = writeMask;
+ }
+
+ // canonical value for disabled stenciling
+ static const GrStencilSettings gDisabled;
+ void setDisabled() {
+ *this = gDisabled;
+ }
+ bool isDisabled() const {
+ return kKeep_StencilOp == fFrontPassOp &&
+ kKeep_StencilOp == fBackPassOp &&
+ kKeep_StencilOp == fFrontFailOp &&
+ kKeep_StencilOp == fBackFailOp &&
+ kAlways_StencilFunc == fFrontFunc &&
+ kAlways_StencilFunc == fBackFunc;
+ }
+ bool doesWrite() const {
+ return !((kNever_StencilFunc == fFrontFunc ||
+ kKeep_StencilOp == fFrontPassOp) &&
+ (kNever_StencilFunc == fBackFunc ||
+ kKeep_StencilOp == fBackPassOp) &&
+ (kAlways_StencilFunc == fFrontFunc ||
+ kKeep_StencilOp == fFrontFailOp) &&
+ (kAlways_StencilFunc == fBackFunc ||
+ kKeep_StencilOp == fBackFailOp));
+ }
+ void invalidate() {
+ // just write an illegal value to the first member
+ fFrontPassOp = (GrStencilOp)-1;
+ }
+
+private:
+ friend class GrGpu;
+
+ enum {
+ kMaxStencilClipPasses = 2 // maximum number of passes to add a clip
+ // element to the stencil buffer.
+ };
+
+ /**
+ * Given a thing to draw into the stencil clip, a fill type, and a set op
+ * this function determines:
+ * 1. Whether the thing can be draw directly to the stencil clip or
+ * needs to be drawn to the client portion of the stencil first.
+ * 2. How many passes are needed.
+ * 3. What those passes are.
+ * 4. The fill rule that should actually be used to render (will
+ * always be non-inverted).
+ *
+ * @param op the set op to combine this element with the
+ * existing clip
+ * @param stencilClipMask mask with just the stencil bit used for clipping
+ * enabled.
+ * @param invertedFill is this path inverted
+ * @param numPasses out: the number of passes needed to add the
+ * element to the clip.
+ * @param settings out: the stencil settings to use for each pass
+ *
+ * @return true if the clip element's geometry can be drawn directly to the
+ * stencil clip bit. Will only be true if canBeDirect is true.
+ * numPasses will be 1 if return value is true.
+ */
+ static bool GetClipPasses(GrSetOp op,
+ bool canBeDirect,
+ unsigned int stencilClipMask,
+ bool invertedFill,
+ int* numPasses,
+ GrStencilSettings settings[kMaxStencilClipPasses]);
+};
+
+#endif
diff --git a/include/gpu/GrStopwatch.h b/include/gpu/GrStopwatch.h
new file mode 100644
index 0000000000..7ac3fd0d42
--- /dev/null
+++ b/include/gpu/GrStopwatch.h
@@ -0,0 +1,128 @@
+
+/*
+ * 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 GrStopwatch_DEFINED
+#define GrStopwatch_DEFINED
+
+#include "GrTypes.h"
+
+template <typename PLATFORM_TIMER>
+/**
+ * Base class for stopwatch. Relies on PLATFORM_TIMER for platform-specific
+ * timer functions. PLATFORM_TIMER provides:
+ * - typename TIMESTAMP : a timestamp value that can be used with Diff()
+ * - static TIMESTAMP Now() : gets current timestamp
+ * - static double Diff(const TIMESTAMP& begin, const TIMESTAMP& end) :
+ * computes delta in seconds between two timestamps
+ */
+class GrStopwatchBase {
+public:
+ /**
+ * Contructor - implicit reset()
+ */
+ GrStopwatchBase() {
+ fRunning = false;
+ fTotalElapsed = 0.0;
+ }
+
+ /**
+ * begins a new lap
+ */
+ void start() {
+ double lastLap = lapTime();
+ fTotalElapsed += lastLap;
+ fRunning = true;
+ fLastStart = PLATFORM_TIMER::Now();
+ }
+
+ /**
+ * ends current lap (or no effect if lap not started)
+ */
+ void stop() {
+ double lastLap = lapTime();
+ fTotalElapsed += lastLap;
+ fRunning = false;
+ }
+
+ /**
+ * ends current lap, resets total time
+ */
+ void reset() {
+ fRunning = false;
+ fTotalElapsed = 0.f;
+ }
+
+ /**
+ * Computes the time of all laps since last reset() including current lap
+ * if lap is still running.
+ *
+ * @return the sum time in seconds of all laps since last reset().
+ */
+ double totalTime() const {
+ return fTotalElapsed + lapTime();
+ }
+
+ /**
+ * Current lap time.
+ *
+ * @return time in seconds of current lap if one is running otherwise 0.
+ */
+ double lapTime() const {
+ if (fRunning) {
+ PLATFORM_TIMER::Timestamp now = PLATFORM_TIMER::Now();
+ return PLATFORM_TIMER::Elapsed(fLastStart, now);
+ }
+ return 0.0;
+ }
+
+private:
+ double fTotalElapsed;
+
+ typename PLATFORM_TIMER::Timestamp fLastStart;
+ bool fRunning;
+};
+
+#if GR_WIN32_BUILD
+
+ #include <Windows.h>
+
+ class GrWin32Timer {
+ public:
+ typedef LARGE_INTEGER Timestamp;
+
+ static Timestamp Now() {
+ LARGE_INTEGER now;
+ QueryPerformanceCounter(&now);
+ return now;
+ }
+
+ static double Elapsed(const Timestamp& begin, const Timestamp& end) {
+ double diff = (double)(end.QuadPart - begin.QuadPart);
+ return diff * Scale();
+ }
+ private:
+ static double Scale() {
+ static double scale;
+ if (0.0 == scale) {
+ LARGE_INTEGER freq;
+ QueryPerformanceFrequency(&freq);
+ GrAssert(0 != freq.QuadPart);
+ scale = 1 / (double) freq.QuadPart;
+ }
+ return scale;
+ }
+ };
+ typedef GrStopwatchBase<GrWin32Timer> GrStopwatch;
+#else
+ #error "Implement platform timer for stopwatch"
+#endif
+
+
+#endif
diff --git a/include/gpu/GrStringBuilder.h b/include/gpu/GrStringBuilder.h
new file mode 100644
index 0000000000..558d0419c0
--- /dev/null
+++ b/include/gpu/GrStringBuilder.h
@@ -0,0 +1,19 @@
+
+/*
+ * 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 GrStringBuilder_DEFINED
+#define GrStringBuilder_DEFINED
+
+#include "SkString.h"
+
+typedef SkString GrStringBuilder;
+
+#endif
+
diff --git a/include/gpu/GrTBSearch.h b/include/gpu/GrTBSearch.h
new file mode 100644
index 0000000000..2697f3733b
--- /dev/null
+++ b/include/gpu/GrTBSearch.h
@@ -0,0 +1,46 @@
+
+/*
+ * 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 GrTBSearch_DEFINED
+#define GrTBSearch_DEFINED
+
+template <typename ELEM, typename KEY>
+int GrTBSearch(const ELEM array[], int count, KEY target) {
+ GrAssert(count >= 0);
+ if (0 == count) {
+ // we should insert it at 0
+ return ~0;
+ }
+
+ int high = count - 1;
+ int low = 0;
+ while (high > low) {
+ int index = (low + high) >> 1;
+ if (LT(array[index], target)) {
+ low = index + 1;
+ } else {
+ high = index;
+ }
+ }
+
+ // check if we found it
+ if (EQ(array[high], target)) {
+ return high;
+ }
+
+ // now return the ~ of where we should insert it
+ if (LT(array[high], target)) {
+ high += 1;
+ }
+ return ~high;
+}
+
+#endif
+
diff --git a/include/gpu/GrTDArray.h b/include/gpu/GrTDArray.h
new file mode 100644
index 0000000000..731001a8c9
--- /dev/null
+++ b/include/gpu/GrTDArray.h
@@ -0,0 +1,216 @@
+
+/*
+ * 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 GrTDArray_DEFINED
+#define GrTDArray_DEFINED
+
+#include "GrTypes.h"
+#include "GrRefCnt.h"
+
+static int GrInitialArrayAllocationCount() {
+ return 4;
+}
+
+static int GrNextArrayAllocationCount(int count) {
+ return count + ((count + 1) >> 1);
+}
+
+template <typename T> class GrTDArray {
+public:
+ GrTDArray() : fArray(NULL), fAllocated(0), fCount(0) {}
+ GrTDArray(const GrTDArray& src) {
+ fCount = fAllocated = src.fCount;
+ fArray = (T*)GrMalloc(fAllocated * sizeof(T));
+ memcpy(fArray, src.fArray, fCount * sizeof(T));
+ }
+ ~GrTDArray() {
+ if (fArray) {
+ GrFree(fArray);
+ }
+ }
+
+ bool isEmpty() const { return 0 == fCount; }
+ int count() const { return fCount; }
+
+ const T& at(int index) const {
+ GrAssert((unsigned)index < (unsigned)fCount);
+ return fArray[index];
+ }
+ T& at(int index) {
+ GrAssert((unsigned)index < (unsigned)fCount);
+ return fArray[index];
+ }
+
+ const T& operator[](int index) const { return this->at(index); }
+ T& operator[](int index) { return this->at(index); }
+
+ GrTDArray& operator=(const GrTDArray& src) {
+ if (fAllocated < src.fCount) {
+ fAllocated = src.fCount;
+ GrFree(fArray);
+ fArray = (T*)GrMalloc(fAllocated * sizeof(T));
+ }
+ fCount = src.fCount;
+ memcpy(fArray, src.fArray, fCount * sizeof(T));
+ return *this;
+ }
+
+ void reset() {
+ if (fArray) {
+ GrFree(fArray);
+ fArray = NULL;
+ }
+ fAllocated = fCount = 0;
+ }
+
+ T* begin() const { return fArray; }
+ T* end() const { return fArray + fCount; }
+ T* back() const { GrAssert(fCount); return fArray + (fCount - 1); }
+
+ T* prepend() {
+ this->growAt(0);
+ return fArray;
+ }
+
+ T* append() {
+ this->growAt(fCount);
+ return fArray + fCount - 1;
+ }
+
+ /**
+ * index may be [0..count], so that you can insert at the end (like append)
+ */
+ T* insert(int index) {
+ GrAssert((unsigned)index <= (unsigned)fCount);
+ this->growAt(index);
+ return fArray + index;
+ }
+
+ void remove(int index) {
+ GrAssert((unsigned)index < (unsigned)fCount);
+ fCount -= 1;
+ if (index < fCount) {
+ int remaining = fCount - index;
+ memmove(fArray + index, fArray + index + 1, remaining * sizeof(T));
+ }
+ }
+
+ void removeShuffle(int index) {
+ GrAssert((unsigned)index < (unsigned)fCount);
+ fCount -= 1;
+ if (index < fCount) {
+ memmove(fArray + index, fArray + fCount, sizeof(T));
+ }
+ }
+
+ // Utility iterators
+
+ /**
+ * Calls GrFree() on each element. Assumes each is NULL or was allocated
+ * with GrMalloc().
+ */
+ void freeAll() {
+ T* stop = this->end();
+ for (T* curr = this->begin(); curr < stop; curr++) {
+ GrFree(*curr);
+ }
+ this->reset();
+ }
+
+ /**
+ * Calls delete on each element. Assumes each is NULL or was allocated
+ * with new.
+ */
+ void deleteAll() {
+ T* stop = this->end();
+ for (T* curr = this->begin(); curr < stop; curr++) {
+ delete *curr;
+ }
+ this->reset();
+ }
+
+ /**
+ * Calls GrSafeUnref() on each element. Assumes each is NULL or is a
+ * subclass of GrRefCnt.
+ */
+ void unrefAll() {
+ T* stop = this->end();
+ for (T* curr = this->begin(); curr < stop; curr++) {
+ GrSafeUnref(*curr);
+ }
+ this->reset();
+ }
+
+ void visit(void visitor(T&)) const {
+ T* stop = this->end();
+ for (T* curr = this->begin(); curr < stop; curr++) {
+ if (*curr) {
+ visitor(*curr);
+ }
+ }
+ }
+
+ int find(const T& elem) const {
+ int count = this->count();
+ T* curr = this->begin();
+ for (int i = 0; i < count; i++) {
+ if (elem == curr[i]) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ friend bool operator==(const GrTDArray<T>& a, const GrTDArray<T>& b) {
+ return a.count() == b.count() &&
+ (0 == a.count() ||
+ 0 == memcmp(a.begin(), b.begin(), a.count() * sizeof(T)));
+ }
+ friend bool operator!=(const GrTDArray<T>& a, const GrTDArray<T>& b) {
+ return !(a == b);
+ }
+
+private:
+ T* fArray;
+ int fAllocated, fCount;
+
+ // growAt will increment fCount, reallocate fArray (as needed), and slide
+ // the contents of fArray to make a hole for new data at index.
+ void growAt(int index) {
+ GrAssert(fCount <= fAllocated);
+ if (0 == fAllocated) {
+ fAllocated = GrInitialArrayAllocationCount();
+ fArray = (T*)GrMalloc(fAllocated * sizeof(T));
+ } else if (fCount == fAllocated) {
+ fAllocated = GrNextArrayAllocationCount(fAllocated);
+ T* newArray = (T*)GrMalloc(fAllocated * sizeof(T));
+ memcpy(newArray, fArray, index * sizeof(T));
+ memcpy(newArray + index + 1, fArray + index,
+ (fCount - index) * sizeof(T));
+ GrFree(fArray);
+ fArray = newArray;
+ } else {
+ // check that we're not just appending
+ if (index < fCount) {
+ memmove(fArray + index + 1, fArray + index,
+ (fCount - index) * sizeof(T));
+ }
+ }
+ GrAssert(fCount < fAllocated);
+ fCount += 1;
+ }
+};
+
+extern void* GrTDArray_growAt(void*, int* allocated, int& count, int index,
+ size_t);
+
+
+#endif
+
diff --git a/include/gpu/GrTHashCache.h b/include/gpu/GrTHashCache.h
new file mode 100644
index 0000000000..8651c35c22
--- /dev/null
+++ b/include/gpu/GrTHashCache.h
@@ -0,0 +1,219 @@
+
+/*
+ * 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 GrTHashCache_DEFINED
+#define GrTHashCache_DEFINED
+
+#include "GrTDArray.h"
+
+/**
+ * Key needs
+ * static bool EQ(const Entry&, const HashKey&);
+ * static bool LT(const Entry&, const HashKey&);
+ * uint32_t getHash() const;
+ *
+ * Allows duplicate key entries but on find you may get
+ * any of the duplicate entries returned.
+ */
+template <typename T, typename Key, size_t kHashBits> class GrTHashTable {
+public:
+ GrTHashTable() { Gr_bzero(fHash, sizeof(fHash)); }
+ ~GrTHashTable() {}
+
+ int count() const { return fSorted.count(); }
+ T* find(const Key&) const;
+ // return true if key was unique when inserted.
+ bool insert(const Key&, T*);
+ void remove(const Key&, const T*);
+ T* removeAt(int index, uint32_t hash);
+ void removeAll();
+ void deleteAll();
+ void unrefAll();
+
+ /**
+ * Return the index for the element, using a linear search.
+ */
+ int slowFindIndex(T* elem) const { return fSorted.find(elem); }
+
+#if GR_DEBUG
+ void validate() const;
+ bool contains(T*) const;
+#endif
+
+ // testing
+ const GrTDArray<T*>& getArray() const { return fSorted; }
+private:
+ enum {
+ kHashCount = 1 << kHashBits,
+ kHashMask = kHashCount - 1
+ };
+ static unsigned hash2Index(uint32_t hash) {
+ hash ^= hash >> 16;
+ if (kHashBits <= 8) {
+ hash ^= hash >> 8;
+ }
+ return hash & kHashMask;
+ }
+
+ mutable T* fHash[kHashCount];
+ GrTDArray<T*> fSorted;
+
+ // search fSorted, and return the found index, or ~index of where it
+ // should be inserted
+ int searchArray(const Key&) const;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+template <typename T, typename Key, size_t kHashBits>
+int GrTHashTable<T, Key, kHashBits>::searchArray(const Key& key) const {
+ int count = fSorted.count();
+ if (0 == count) {
+ // we should insert it at 0
+ return ~0;
+ }
+
+ const T* const* array = fSorted.begin();
+ int high = count - 1;
+ int low = 0;
+ while (high > low) {
+ int index = (low + high) >> 1;
+ if (Key::LT(*array[index], key)) {
+ low = index + 1;
+ } else {
+ high = index;
+ }
+ }
+
+ // check if we found it
+ if (Key::EQ(*array[high], key)) {
+ // above search should have found the first occurrence if there
+ // are multiple.
+ GrAssert(0 == high || Key::LT(*array[high - 1], key));
+ return high;
+ }
+
+ // now return the ~ of where we should insert it
+ if (Key::LT(*array[high], key)) {
+ high += 1;
+ }
+ return ~high;
+}
+
+template <typename T, typename Key, size_t kHashBits>
+T* GrTHashTable<T, Key, kHashBits>::find(const Key& key) const {
+ int hashIndex = hash2Index(key.getHash());
+ T* elem = fHash[hashIndex];
+
+ if (NULL == elem || !Key::EQ(*elem, key)) {
+ // bsearch for the key in our sorted array
+ int index = this->searchArray(key);
+ if (index < 0) {
+ return NULL;
+ }
+ elem = fSorted[index];
+ // update the hash
+ fHash[hashIndex] = elem;
+ }
+ return elem;
+}
+
+template <typename T, typename Key, size_t kHashBits>
+bool GrTHashTable<T, Key, kHashBits>::insert(const Key& key, T* elem) {
+ int index = this->searchArray(key);
+ bool first = index < 0;
+ if (first) {
+ // turn it into the actual index
+ index = ~index;
+ }
+ // add it to our array
+ *fSorted.insert(index) = elem;
+ // update our hash table (overwrites any dupe's position in the hash)
+ fHash[hash2Index(key.getHash())] = elem;
+ return first;
+}
+
+template <typename T, typename Key, size_t kHashBits>
+void GrTHashTable<T, Key, kHashBits>::remove(const Key& key, const T* elem) {
+ int index = hash2Index(key.getHash());
+ if (fHash[index] == elem) {
+ fHash[index] = NULL;
+ }
+
+ // remove from our sorted array
+ index = this->searchArray(key);
+ GrAssert(index >= 0);
+ // if there are multiple matches searchArray will give us the first match
+ // march forward until we find elem.
+ while (elem != fSorted[index]) {
+ ++index;
+ GrAssert(index < fSorted.count());
+ }
+ GrAssert(elem == fSorted[index]);
+ fSorted.remove(index);
+}
+
+template <typename T, typename Key, size_t kHashBits>
+T* GrTHashTable<T, Key, kHashBits>::removeAt(int elemIndex, uint32_t hash) {
+ int hashIndex = hash2Index(hash);
+ if (fHash[hashIndex] == fSorted[elemIndex]) {
+ fHash[hashIndex] = NULL;
+ }
+ // remove from our sorted array
+ T* elem = fSorted[elemIndex];
+ fSorted.remove(elemIndex);
+ return elem;
+}
+
+template <typename T, typename Key, size_t kHashBits>
+void GrTHashTable<T, Key, kHashBits>::removeAll() {
+ fSorted.reset();
+ Gr_bzero(fHash, sizeof(fHash));
+}
+
+template <typename T, typename Key, size_t kHashBits>
+void GrTHashTable<T, Key, kHashBits>::deleteAll() {
+ fSorted.deleteAll();
+ Gr_bzero(fHash, sizeof(fHash));
+}
+
+template <typename T, typename Key, size_t kHashBits>
+void GrTHashTable<T, Key, kHashBits>::unrefAll() {
+ fSorted.unrefAll();
+ Gr_bzero(fHash, sizeof(fHash));
+}
+
+#if GR_DEBUG
+template <typename T, typename Key, size_t kHashBits>
+void GrTHashTable<T, Key, kHashBits>::validate() const {
+ for (size_t i = 0; i < GR_ARRAY_COUNT(fHash); i++) {
+ if (fHash[i]) {
+ unsigned hashIndex = hash2Index(Key::GetHash(*fHash[i]));
+ GrAssert(hashIndex == i);
+ }
+ }
+
+ int count = fSorted.count();
+ for (int i = 1; i < count; i++) {
+ GrAssert(Key::LT(*fSorted[i - 1], *fSorted[i]) ||
+ Key::EQ(*fSorted[i - 1], *fSorted[i]));
+ }
+}
+
+template <typename T, typename Key, size_t kHashBits>
+bool GrTHashTable<T, Key, kHashBits>::contains(T* elem) const {
+ int index = fSorted.find(elem);
+ return index >= 0;
+}
+
+#endif
+
+#endif
+
diff --git a/include/gpu/GrTLList.h b/include/gpu/GrTLList.h
new file mode 100644
index 0000000000..ea310ac20e
--- /dev/null
+++ b/include/gpu/GrTLList.h
@@ -0,0 +1,54 @@
+
+/*
+ * 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 GrTLList_DEFINED
+#define GrTLList_DEFINED
+
+#include "GrNoncopyable.h"
+
+template <typename T> class GrTLList : GrNoncopyable {
+public:
+ class Entry {
+ Entry* fPrev;
+ Entry* fNext;
+ };
+
+ GrTLList() : fHead(NULL), fTail(NULL) {}
+#if GR_DEBUG
+ ~GrTLList() {
+ GrAssert(NULL == fHead);
+ GrAssert(NULL == ftail);
+ }
+#endif
+
+ T* head() const { return fHead; }
+ T* tail() const { return fTail; }
+
+ void addToHead(T*);
+ void addToTail(T*);
+ void removeFromList(T*);
+
+private:
+ Entry* fHead;
+ Entry* fTail;
+
+ friend class Entry;
+};
+
+
+class Parent {
+ GrTDLList<Child> fList;
+};
+
+class Child : public GrTLList::Entry<Child> {
+};
+
+#endif
+
diff --git a/include/gpu/GrTemplates.h b/include/gpu/GrTemplates.h
new file mode 100644
index 0000000000..63e43eed01
--- /dev/null
+++ b/include/gpu/GrTemplates.h
@@ -0,0 +1,69 @@
+
+/*
+ * 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 GrTemplates_DEFINED
+#define GrTemplates_DEFINED
+
+#include "GrNoncopyable.h"
+
+/**
+ * Use to cast a ptr to a different type, and maintain strict-aliasing
+ */
+template <typename Dst, typename Src> Dst GrTCast(Src src) {
+ union {
+ Src src;
+ Dst dst;
+ } data;
+ data.src = src;
+ return data.dst;
+}
+
+/**
+ * saves value of T* in and restores in destructor
+ * e.g.:
+ * {
+ * GrAutoTPtrValueRestore<int*> autoCountRestore;
+ * if (useExtra) {
+ * autoCountRestore.save(&fCount);
+ * fCount += fExtraCount;
+ * }
+ * ...
+ * } // fCount is restored
+ */
+template <typename T> class GrAutoTPtrValueRestore : public GrNoncopyable {
+public:
+ GrAutoTPtrValueRestore() : fPtr(NULL), fVal() {}
+
+ GrAutoTPtrValueRestore(T* ptr) {
+ fPtr = ptr;
+ if (NULL != ptr) {
+ fVal = *ptr;
+ }
+ }
+
+ ~GrAutoTPtrValueRestore() {
+ if (NULL != fPtr) {
+ *fPtr = fVal;
+ }
+ }
+
+ // restores previously saved value (if any) and saves value for passed T*
+ void save(T* ptr) {
+ if (NULL != fPtr) {
+ *fPtr = fVal;
+ }
+ fPtr = ptr;
+ fVal = *ptr;
+ }
+private:
+ T* fPtr;
+ T fVal;
+};
+
+#endif
diff --git a/include/gpu/GrTextContext.h b/include/gpu/GrTextContext.h
new file mode 100644
index 0000000000..5983e358c8
--- /dev/null
+++ b/include/gpu/GrTextContext.h
@@ -0,0 +1,68 @@
+
+/*
+ * 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 GrTextContext_DEFINED
+#define GrTextContext_DEFINED
+
+#include "GrGlyph.h"
+#include "GrPaint.h"
+#include "GrMatrix.h"
+
+struct GrGpuTextVertex;
+class GrContext;
+class GrTextStrike;
+class GrFontScaler;
+class GrDrawTarget;
+
+class GrTextContext {
+public:
+ GrTextContext(GrContext*,
+ const GrPaint& paint,
+ const GrMatrix* extMatrix = NULL);
+ ~GrTextContext();
+
+ void drawPackedGlyph(GrGlyph::PackedID, GrFixed left, GrFixed top,
+ GrFontScaler*);
+
+ void flush(); // optional; automatically called by destructor
+
+private:
+ GrPaint fPaint;
+ GrVertexLayout fVertexLayout;
+ GrContext* fContext;
+ GrDrawTarget* fDrawTarget;
+
+ GrMatrix fExtMatrix;
+ GrFontScaler* fScaler;
+ GrTextStrike* fStrike;
+
+ inline void flushGlyphs();
+ void setupDrawTarget();
+
+ enum {
+ kMinRequestedGlyphs = 1,
+ kDefaultRequestedGlyphs = 64,
+ kMinRequestedVerts = kMinRequestedGlyphs * 4,
+ kDefaultRequestedVerts = kDefaultRequestedGlyphs * 4,
+ };
+
+ GrGpuTextVertex* fVertices;
+
+ int32_t fMaxVertices;
+ GrTexture* fCurrTexture;
+ int fCurrVertex;
+
+ GrIRect fClipRect;
+ GrMatrix fOrigViewMatrix; // restore previous viewmatrix
+};
+
+#endif
+
+
diff --git a/include/gpu/GrTextStrike.h b/include/gpu/GrTextStrike.h
new file mode 100644
index 0000000000..701acea7ab
--- /dev/null
+++ b/include/gpu/GrTextStrike.h
@@ -0,0 +1,115 @@
+
+/*
+ * 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 GrTextStrike_DEFINED
+#define GrTextStrike_DEFINED
+
+#include "GrAllocPool.h"
+#include "GrFontScaler.h"
+#include "GrTHashCache.h"
+#include "GrPoint.h"
+#include "GrGlyph.h"
+
+class GrAtlasMgr;
+class GrFontCache;
+class GrGpu;
+class GrFontPurgeListener;
+
+/**
+ * The textcache maps a hostfontscaler instance to a dictionary of
+ * glyphid->strike
+ */
+class GrTextStrike {
+public:
+ GrTextStrike(GrFontCache*, const GrKey* fontScalerKey, GrMaskFormat,
+ GrAtlasMgr*);
+ ~GrTextStrike();
+
+ const GrKey* getFontScalerKey() const { return fFontScalerKey; }
+ GrFontCache* getFontCache() const { return fFontCache; }
+ GrMaskFormat getMaskFormat() const { return fMaskFormat; }
+
+ inline GrGlyph* getGlyph(GrGlyph::PackedID, GrFontScaler*);
+ bool getGlyphAtlas(GrGlyph*, GrFontScaler*);
+
+ // testing
+ int countGlyphs() const { return fCache.getArray().count(); }
+ const GrGlyph* glyphAt(int index) const {
+ return fCache.getArray()[index];
+ }
+ GrAtlas* getAtlas() const { return fAtlas; }
+
+public:
+ // for LRU
+ GrTextStrike* fPrev;
+ GrTextStrike* fNext;
+
+private:
+ class Key;
+ GrTHashTable<GrGlyph, Key, 7> fCache;
+ const GrKey* fFontScalerKey;
+ GrTAllocPool<GrGlyph> fPool;
+
+ GrFontCache* fFontCache;
+ GrAtlasMgr* fAtlasMgr;
+ GrAtlas* fAtlas; // linklist
+
+ GrMaskFormat fMaskFormat;
+
+ GrGlyph* generateGlyph(GrGlyph::PackedID packed, GrFontScaler* scaler);
+ // returns true if after the purge, the strike is empty
+ bool purgeAtlasAtY(GrAtlas* atlas, int yCoord);
+
+ friend class GrFontCache;
+};
+
+class GrFontCache {
+public:
+ GrFontCache(GrGpu*);
+ ~GrFontCache();
+
+ inline GrTextStrike* getStrike(GrFontScaler*);
+
+ void freeAll();
+
+ void purgeExceptFor(GrTextStrike*);
+
+ // testing
+ int countStrikes() const { return fCache.getArray().count(); }
+ const GrTextStrike* strikeAt(int index) const {
+ return fCache.getArray()[index];
+ }
+ GrTextStrike* getHeadStrike() const { return fHead; }
+
+#if GR_DEBUG
+ void validate() const;
+#else
+ void validate() const {}
+#endif
+
+private:
+ friend class GrFontPurgeListener;
+
+ class Key;
+ GrTHashTable<GrTextStrike, Key, 8> fCache;
+ // for LRU
+ GrTextStrike* fHead;
+ GrTextStrike* fTail;
+
+ GrGpu* fGpu;
+ GrAtlasMgr* fAtlasMgr;
+
+
+ GrTextStrike* generateStrike(GrFontScaler*, const Key&);
+ inline void detachStrikeFromList(GrTextStrike*);
+};
+
+#endif
+
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
new file mode 100644
index 0000000000..5a86b0881b
--- /dev/null
+++ b/include/gpu/GrTexture.h
@@ -0,0 +1,183 @@
+
+/*
+ * 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 GrTexture_DEFINED
+#define GrTexture_DEFINED
+
+#include "GrResource.h"
+
+class GrRenderTarget;
+
+class GrTexture : public GrResource {
+
+public:
+ /**
+ * Retrieves the width of the texture.
+ *
+ * @return the width in texels
+ */
+ int width() const { return fWidth; }
+
+ /**
+ * Retrieves the height of the texture.
+ *
+ * @return the height in texels
+ */
+ int height() const { return fHeight; }
+
+ /**
+ * Retrieves the allocated width. It may differ from width for
+ * NPOT or min-RT size reasons.
+ * @return allocated width in texels
+ */
+ int allocatedWidth() const { return fAllocatedWidth; }
+
+ /**
+ * Retrieves the allocated height. It may differ from height for
+ * NPOT or min-RT size reasons.
+ * @return allocated height in texels
+ */
+ int allocatedHeight() const { return fAllocatedHeight; }
+
+ /**
+ * Convert from texels to normalized texture coords for POT textures
+ * only.
+ */
+ GrFixed normalizeFixedX(GrFixed x) const { GrAssert(GrIsPow2(fWidth));
+ return x >> fShiftFixedX; }
+ GrFixed normalizeFixedY(GrFixed y) const { GrAssert(GrIsPow2(fHeight));
+ return y >> fShiftFixedY; }
+
+ /**
+ * Retrieves the pixel config specified when the texture was created.
+ */
+ GrPixelConfig config() const { return fConfig; }
+
+ /**
+ * Approximate number of bytes used by the texture
+ */
+ virtual size_t sizeInBytes() const {
+ return (size_t) fAllocatedWidth *
+ fAllocatedHeight *
+ GrBytesPerPixel(fConfig);
+ }
+
+ /**
+ * Updates a subrectangle of texels in the texture.
+ *
+ * @param x left edge of rectangle to update
+ * @param y top edge of rectangle to update
+ * @param width width of rectangle to update
+ * @param height height of rectangle to update
+ * @param srcData width*height texels of data in same format that was
+ * used at texture creation.
+ * @param rowBytes number of bytes per row in srcData, 0 means rows are
+ * packed
+ */
+ virtual void uploadTextureData(int x,
+ int y,
+ int width,
+ int height,
+ const void* srcData,
+ size_t rowBytes) = 0;
+
+ /**
+ * Reads a rectangle of pixels from the texture.
+ * @param left left edge of the rectangle to read (inclusive)
+ * @param top top edge of the rectangle to read (inclusive)
+ * @param width width of rectangle to read in pixels.
+ * @param height height of rectangle to read in pixels.
+ * @param config the pixel config of the destination buffer
+ * @param buffer memory to read the rectangle into.
+ *
+ * @return true if the read succeeded, false if not. The read can fail
+ * because of a unsupported pixel config.
+ */
+ bool readPixels(int left, int top, int width, int height,
+ GrPixelConfig config, void* buffer);
+
+ /**
+ * Retrieves the render target underlying this texture that can be passed to
+ * GrGpu::setRenderTarget().
+ *
+ * @return handle to render target or NULL if the texture is not a
+ * render target
+ */
+ GrRenderTarget* asRenderTarget() { return fRenderTarget; }
+
+ /**
+ * Removes the reference on the associated GrRenderTarget held by this
+ * texture. Afterwards asRenderTarget() will return NULL. The
+ * GrRenderTarget survives the release if another ref is held on it.
+ */
+ void releaseRenderTarget();
+
+ /**
+ * Return the native ID or handle to the texture, depending on the
+ * platform. e.g. on opengl, return the texture ID.
+ */
+ virtual intptr_t getTextureHandle() const = 0;
+
+#if GR_DEBUG
+ void validate() const {
+ this->INHERITED::validate();
+ }
+#else
+ void validate() const {}
+#endif
+
+protected:
+ GrRenderTarget* fRenderTarget; // texture refs its rt representation
+ // base class cons sets to NULL
+ // subclass cons can create and set
+
+ GrTexture(GrGpu* gpu,
+ int width,
+ int height,
+ int allocatedWidth,
+ int allocatedHeight,
+ GrPixelConfig config)
+ : INHERITED(gpu)
+ , fRenderTarget(NULL)
+ , fWidth(width)
+ , fHeight(height)
+ , fAllocatedWidth(allocatedWidth)
+ , fAllocatedHeight(allocatedHeight)
+ , fConfig(config) {
+ // only make sense if alloc size is pow2
+ fShiftFixedX = 31 - Gr_clz(fWidth);
+ fShiftFixedY = 31 - Gr_clz(fHeight);
+ }
+
+ // GrResource overrides
+ virtual void onRelease() {
+ this->releaseRenderTarget();
+ }
+
+ virtual void onAbandon();
+
+private:
+ int fWidth;
+ int fHeight;
+ int fAllocatedWidth;
+ int fAllocatedHeight;
+
+ // these two shift a fixed-point value into normalized coordinates
+ // for this texture if the texture is power of two sized.
+ int fShiftFixedX;
+ int fShiftFixedY;
+
+ GrPixelConfig fConfig;
+
+ typedef GrResource INHERITED;
+};
+
+#endif
+
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
new file mode 100644
index 0000000000..e1ab3d4e3a
--- /dev/null
+++ b/include/gpu/GrTypes.h
@@ -0,0 +1,637 @@
+
+/*
+ * 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 GrTypes_DEFINED
+#define GrTypes_DEFINED
+
+#include "SkTypes.h"
+#include "GrConfig.h"
+
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Defines overloaded bitwise operators to make it easier to use an enum as a
+ * bitfield.
+ */
+#define GR_MAKE_BITFIELD_OPS(X) \
+ inline X operator | (X a, X b) { \
+ return (X) (+a | +b); \
+ } \
+ \
+ inline X operator & (X a, X b) { \
+ return (X) (+a & +b); \
+ } \
+ template <typename T> \
+ inline X operator & (T a, X b) { \
+ return (X) (+a & +b); \
+ } \
+ template <typename T> \
+ inline X operator & (X a, T b) { \
+ return (X) (+a & +b); \
+ } \
+
+#define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
+ friend X operator | (X a, X b); \
+ \
+ friend X operator & (X a, X b); \
+ \
+ template <typename T> \
+ friend X operator & (T a, X b); \
+ \
+ template <typename T> \
+ friend X operator & (X a, T b); \
+////////////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Macro to round n up to the next multiple of 4, or return it unchanged if
+ * n is already a multiple of 4
+ */
+#define GrALIGN4(n) SkAlign4(n)
+#define GrIsALIGN4(n) (((n) & 3) == 0)
+
+template <typename T> const T& GrMin(const T& a, const T& b) {
+ return (a < b) ? a : b;
+}
+
+template <typename T> const T& GrMax(const T& a, const T& b) {
+ return (b < a) ? a : b;
+}
+
+// compile time versions of min/max
+#define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b))
+#define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a))
+
+/**
+ * divide, rounding up
+ */
+static inline int32_t GrIDivRoundUp(int x, int y) {
+ GrAssert(y > 0);
+ return (x + (y-1)) / y;
+}
+static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) {
+ return (x + (y-1)) / y;
+}
+static inline size_t GrSizeDivRoundUp(size_t x, uint32_t y) {
+ return (x + (y-1)) / y;
+}
+
+/**
+ * align up
+ */
+static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) {
+ return GrUIDivRoundUp(x, alignment) * alignment;
+}
+static inline uint32_t GrSizeAlignUp(size_t x, uint32_t alignment) {
+ return GrSizeDivRoundUp(x, alignment) * alignment;
+}
+
+/**
+ * amount of pad needed to align up
+ */
+static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) {
+ return (alignment - x % alignment) % alignment;
+}
+static inline size_t GrSizeAlignUpPad(size_t x, uint32_t alignment) {
+ return (alignment - x % alignment) % alignment;
+}
+
+/**
+ * align down
+ */
+static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) {
+ return (x / alignment) * alignment;
+}
+static inline uint32_t GrSizeAlignDown(size_t x, uint32_t alignment) {
+ return (x / alignment) * alignment;
+}
+
+/**
+ * Count elements in an array
+ */
+#define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array)
+
+//!< allocate a block of memory, will never return NULL
+extern void* GrMalloc(size_t bytes);
+
+//!< free block allocated by GrMalloc. ptr may be NULL
+extern void GrFree(void* ptr);
+
+static inline void Gr_bzero(void* dst, size_t size) {
+ memset(dst, 0, size);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Return the number of leading zeros in n
+ */
+extern int Gr_clz(uint32_t n);
+
+/**
+ * Return true if n is a power of 2
+ */
+static inline bool GrIsPow2(unsigned n) {
+ return n && 0 == (n & (n - 1));
+}
+
+/**
+ * Return the next power of 2 >= n.
+ */
+static inline uint32_t GrNextPow2(uint32_t n) {
+ return n ? (1 << (32 - Gr_clz(n - 1))) : 1;
+}
+
+static inline int GrNextPow2(int n) {
+ GrAssert(n >= 0); // this impl only works for non-neg.
+ return n ? (1 << (32 - Gr_clz(n - 1))) : 1;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * 16.16 fixed point type
+ */
+typedef int32_t GrFixed;
+
+#if GR_DEBUG
+
+static inline int16_t GrToS16(intptr_t x) {
+ GrAssert((int16_t)x == x);
+ return (int16_t)x;
+}
+
+#else
+
+#define GrToS16(x) x
+
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Possible 3D APIs that may be used by Ganesh.
+ */
+enum GrEngine {
+ kOpenGL_Shaders_GrEngine,
+ kOpenGL_Fixed_GrEngine,
+};
+
+/**
+ * Engine-specific 3D context handle
+ * GrGLInterface* for OpenGL. If NULL will use the default GL interface.
+ */
+typedef intptr_t GrPlatform3DContext;
+
+///////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Type used to describe format of vertices in arrays
+ * Values are defined in GrDrawTarget
+ */
+typedef int GrVertexLayout;
+
+/**
+* Geometric primitives used for drawing.
+*/
+enum GrPrimitiveType {
+ kTriangles_PrimitiveType,
+ kTriangleStrip_PrimitiveType,
+ kTriangleFan_PrimitiveType,
+ kPoints_PrimitiveType,
+ kLines_PrimitiveType, // 1 pix wide only
+ kLineStrip_PrimitiveType // 1 pix wide only
+};
+
+static inline bool GrIsPrimTypeLines(GrPrimitiveType type) {
+ return kLines_PrimitiveType == type || kLineStrip_PrimitiveType == type;
+}
+
+static inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
+ return kTriangles_PrimitiveType == type ||
+ kTriangleStrip_PrimitiveType == type ||
+ kTriangleFan_PrimitiveType == type;
+}
+
+/**
+ * Coeffecients for alpha-blending.
+ */
+enum GrBlendCoeff {
+ kZero_BlendCoeff, //<! 0
+ kOne_BlendCoeff, //<! 1
+ kSC_BlendCoeff, //<! src color
+ kISC_BlendCoeff, //<! one minus src color
+ kDC_BlendCoeff, //<! dst color
+ kIDC_BlendCoeff, //<! one minus dst color
+ kSA_BlendCoeff, //<! src alpha
+ kISA_BlendCoeff, //<! one minus src alpha
+ kDA_BlendCoeff, //<! dst alpha
+ kIDA_BlendCoeff, //<! one minus dst alpha
+ kConstC_BlendCoeff, //<! constant color
+ kIConstC_BlendCoeff, //<! one minus constant color
+ kConstA_BlendCoeff, //<! constant color alpha
+ kIConstA_BlendCoeff, //<! one minus constant color alpha
+
+ kPublicBlendCoeffCount
+};
+
+/**
+ * Formats for masks, used by the font cache.
+ * Important that these are 0-based.
+ */
+enum GrMaskFormat {
+ kA8_GrMaskFormat, //!< 1-byte per pixel
+ kA565_GrMaskFormat, //!< 2-bytes per pixel
+ kA888_GrMaskFormat, //!< 4-bytes per pixel
+
+ kCount_GrMaskFormats //!< used to allocate arrays sized for mask formats
+};
+
+/**
+ * Return the number of bytes-per-pixel for the specified mask format.
+ */
+static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
+ GrAssert((unsigned)format <= 2);
+ // kA8 (0) -> 1
+ // kA565 (1) -> 2
+ // kA888 (2) -> 4
+ return 1 << (int)format;
+}
+
+/**
+ * Pixel configurations.
+ */
+enum GrPixelConfig {
+ kUnknown_GrPixelConfig,
+ kAlpha_8_GrPixelConfig,
+ kIndex_8_GrPixelConfig,
+ kRGB_565_GrPixelConfig,
+ kRGBA_4444_GrPixelConfig, //!< premultiplied
+ kRGBA_8888_GrPixelConfig, //!< premultiplied
+ kRGBX_8888_GrPixelConfig, //!< treat the alpha channel as opaque
+};
+
+static inline size_t GrBytesPerPixel(GrPixelConfig config) {
+ switch (config) {
+ case kAlpha_8_GrPixelConfig:
+ case kIndex_8_GrPixelConfig:
+ return 1;
+ case kRGB_565_GrPixelConfig:
+ case kRGBA_4444_GrPixelConfig:
+ return 2;
+ case kRGBA_8888_GrPixelConfig:
+ case kRGBX_8888_GrPixelConfig:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
+static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
+ switch (config) {
+ case kRGB_565_GrPixelConfig:
+ case kRGBX_8888_GrPixelConfig:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
+ switch (config) {
+ case kAlpha_8_GrPixelConfig:
+ return true;
+ default:
+ return false;
+ }
+}
+
+/**
+ * Used to control the level of antialiasing available for a rendertarget.
+ * Anti-alias quality levels depend on the underlying API/GPU capabilities.
+ */
+enum GrAALevels {
+ kNone_GrAALevel, //<! No antialiasing available.
+ kLow_GrAALevel, //<! Low quality antialiased rendering. Actual
+ // interpretation is platform-dependent.
+ kMed_GrAALevel, //<! Medium quality antialiased rendering. Actual
+ // interpretation is platform-dependent.
+ kHigh_GrAALevel, //<! High quality antialiased rendering. Actual
+ // interpretation is platform-dependent.
+};
+
+/**
+ * Optional bitfield flags that can be passed to createTexture.
+ */
+enum GrTextureFlags {
+ kNone_GrTextureFlags = 0x0,
+ /**
+ * Creates a texture that can be rendered to as a GrRenderTarget. Use
+ * GrTexture::asRenderTarget() to access.
+ */
+ kRenderTarget_GrTextureFlagBit = 0x1,
+ /**
+ * By default all render targets have an associated stencil buffer that
+ * may be required for path filling. This flag overrides stencil buffer
+ * creation.
+ * MAKE THIS PRIVATE?
+ */
+ kNoStencil_GrTextureFlagBit = 0x2,
+ /**
+ * Hint that the CPU may modify this texture after creation.
+ */
+ kDynamicUpdate_GrTextureFlagBit = 0x4,
+};
+
+GR_MAKE_BITFIELD_OPS(GrTextureFlags)
+
+enum {
+ /**
+ * For Index8 pixel config, the colortable must be 256 entries
+ */
+ kGrColorTableSize = 256 * 4 //sizeof(GrColor)
+};
+
+/**
+ * Describes a texture to be created.
+ */
+struct GrTextureDesc {
+ GrTextureFlags fFlags; //!< bitfield of TextureFlags
+ /**
+ * The level of antialiasing available for a rendertarget texture. Only used
+ * fFlags contains kRenderTarget_GrTextureFlag.
+ */
+ GrAALevels fAALevel;
+ int fWidth; //!< Width of the texture
+ int fHeight; //!< Height of the texture
+ /**
+ * Format of source data of the texture. Not guaraunteed to be the same as
+ * internal format used by 3D API.
+ */
+ GrPixelConfig fFormat;
+};
+
+/**
+ * Set Operations used to construct clips.
+ */
+enum GrSetOp {
+ kReplace_SetOp,
+ kIntersect_SetOp,
+ kUnion_SetOp,
+ kXor_SetOp,
+ kDifference_SetOp,
+ kReverseDifference_SetOp,
+};
+
+/**
+ * Clips are composed from these objects.
+ */
+enum GrClipType {
+ kRect_ClipType,
+ kPath_ClipType
+};
+
+/**
+ * Commands used to describe a path. Each command
+ * is accompanied by some number of points.
+ */
+enum GrPathCmd {
+ kMove_PathCmd, //!< Starts a new subpath at
+ // at the returned point
+ // 1 point
+ kLine_PathCmd, //!< Adds a line segment
+ // 2 points
+ kQuadratic_PathCmd, //!< Adds a quadratic segment
+ // 3 points
+ kCubic_PathCmd, //!< Adds a cubic segment
+ // 4 points
+ kClose_PathCmd, //!< Closes the current subpath
+ // by connecting a line to the
+ // starting point.
+ // 0 points
+ kEnd_PathCmd //!< Indicates the end of the last subpath
+ // when iterating
+ // 0 points.
+};
+
+/**
+ * Gets the number of points associated with a path command.
+ */
+static int inline NumPathCmdPoints(GrPathCmd cmd) {
+ static const int gNumPoints[] = {
+ 1, 2, 3, 4, 0, 0
+ };
+ return gNumPoints[cmd];
+}
+
+/**
+ * Path filling rules
+ */
+enum GrPathFill {
+ kWinding_PathFill,
+ kEvenOdd_PathFill,
+ kInverseWinding_PathFill,
+ kInverseEvenOdd_PathFill,
+ kHairLine_PathFill,
+
+ kPathFillCount
+};
+
+static inline GrPathFill GrNonInvertedFill(GrPathFill fill) {
+ static const GrPathFill gNonInvertedFills[] = {
+ kWinding_PathFill, // kWinding_PathFill
+ kEvenOdd_PathFill, // kEvenOdd_PathFill
+ kWinding_PathFill, // kInverseWinding_PathFill
+ kEvenOdd_PathFill, // kInverseEvenOdd_PathFill
+ kHairLine_PathFill,// kHairLine_PathFill
+ };
+ GR_STATIC_ASSERT(0 == kWinding_PathFill);
+ GR_STATIC_ASSERT(1 == kEvenOdd_PathFill);
+ GR_STATIC_ASSERT(2 == kInverseWinding_PathFill);
+ GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill);
+ GR_STATIC_ASSERT(4 == kHairLine_PathFill);
+ GR_STATIC_ASSERT(5 == kPathFillCount);
+ return gNonInvertedFills[fill];
+}
+
+static inline bool GrIsFillInverted(GrPathFill fill) {
+ static const bool gIsFillInverted[] = {
+ false, // kWinding_PathFill
+ false, // kEvenOdd_PathFill
+ true, // kInverseWinding_PathFill
+ true, // kInverseEvenOdd_PathFill
+ false, // kHairLine_PathFill
+ };
+ GR_STATIC_ASSERT(0 == kWinding_PathFill);
+ GR_STATIC_ASSERT(1 == kEvenOdd_PathFill);
+ GR_STATIC_ASSERT(2 == kInverseWinding_PathFill);
+ GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill);
+ GR_STATIC_ASSERT(4 == kHairLine_PathFill);
+ GR_STATIC_ASSERT(5 == kPathFillCount);
+ return gIsFillInverted[fill];
+}
+
+/**
+ * Hints provided about a path's convexity (or lack thereof).
+ */
+enum GrConvexHint {
+ kNone_ConvexHint, //<! No hint about convexity
+ // of the path
+ kConvex_ConvexHint, //<! Path is one convex piece
+ kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces,
+ // pieces are known to be
+ // disjoint
+ kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces,
+ // may or may not intersect,
+ // either all wind cw or all
+ // wind ccw.
+ kConcave_ConvexHint //<! Path is known to be
+ // concave
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+enum GrPlatformSurfaceType {
+ /**
+ * Specifies that the object being created is a render target.
+ */
+ kRenderTarget_GrPlatformSurfaceType,
+ /**
+ * Specifies that the object being created is a texture.
+ */
+ kTexture_GrPlatformSurfaceType,
+ /**
+ * Specifies that the object being created is a texture and a render
+ * target.
+ */
+ kTextureRenderTarget_GrPlatformSurfaceType,
+};
+
+enum GrPlatformRenderTargetFlags {
+ kNone_GrPlatformRenderTargetFlagBit = 0x0,
+
+ /**
+ * Gives permission to Gr to perform the downsample-resolve of a
+ * multisampled render target. If this is not set then read pixel
+ * operations may fail. If the object is both a texture and render target
+ * then this *must* be set. Otherwise, if the client wants do its own
+ * resolves it must create separate GrRenderTarget and GrTexture objects
+ * and insert appropriate flushes and resolves betweeen data hazards.
+ * GrRenderTarget has a flagForResolve()
+ */
+ kGrCanResolve_GrPlatformRenderTargetFlagBit = 0x2,
+};
+
+GR_MAKE_BITFIELD_OPS(GrPlatformRenderTargetFlags)
+
+// opaque type for 3D API object handles
+typedef intptr_t GrPlatform3DObject;
+
+/**
+ * Description of platform surface to create. See below for GL example.
+ */
+struct GrPlatformSurfaceDesc {
+ GrPlatformSurfaceType fSurfaceType; // type of surface to create
+ /**
+ * Flags for kRenderTarget and kTextureRenderTarget surface types
+ */
+ GrPlatformRenderTargetFlags fRenderTargetFlags;
+
+ int fWidth; // width in pixels
+ int fHeight; // height in pixels
+ GrPixelConfig fConfig; // color format
+ /**
+ * Number of per sample stencil buffer. Only relevant if kIsRenderTarget is
+ * set in fFlags.
+ */
+ int fStencilBits;
+
+ /**
+ * Number of samples per-pixel. Only relevant if kIsRenderTarget is set in
+ * fFlags.
+ */
+ int fSampleCnt;
+
+ /**
+ * Texture object in 3D API. Only relevant if fSurfaceType is kTexture or
+ * kTextureRenderTarget.
+ * GL: this is a texture object (glGenTextures)
+ */
+ GrPlatform3DObject fPlatformTexture;
+ /**
+ * Render target object in 3D API. Only relevant if fSurfaceType is
+ * kRenderTarget or kTextureRenderTarget
+ * GL: this is a FBO object (glGenFramebuffers)
+ */
+ GrPlatform3DObject fPlatformRenderTarget;
+ /**
+ * 3D API object used as destination of resolve. Only relevant if
+ * fSurfaceType is kRenderTarget or kTextureRenderTarget and
+ * kGrCanResolve is set in fRenderTargetFlags.
+ * fFlags.
+ * GL: this is a FBO object (glGenFramebuffers)
+ */
+ GrPlatform3DObject fPlatformResolveDestination;
+
+ void reset() { memset(this, 0, sizeof(GrPlatformSurfaceDesc)); }
+};
+
+/**
+ * Example of how to wrap render-to-texture-with-MSAA GL objects with a GrPlatformSurace
+ *
+ * GLint colorBufferID;
+ * glGenRenderbuffers(1, &colorID);
+ * glBindRenderbuffer(GL_RENDERBUFFER, colorBufferID);
+ * glRenderbufferStorageMultisample(GL_RENDERBUFFER, S, GL_RGBA, W, H);
+ *
+ * GLint stencilBufferID;
+ * glGenRenderBuffers(1, &stencilBufferID);
+ * glBindRenderbuffer(GL_RENDERBUFFER, stencilBufferID);
+ * glRenderbufferStorageMultisample(GL_RENDERBUFFER, S, GL_STENCIL_INDEX8, W, H);
+ *
+ * GLint drawFBOID;
+ * glGenFramebuffers(1, &drawFBOID);
+ * glBindFramebuffer(GL_FRAMEBUFFER, drawFBOID);
+ * glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBufferID);
+ * glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilBufferID);
+ *
+ * GLint textureID;
+ * glGenTextures(1, &textureID);
+ * glBindTexture(GL_TEXTURE_2D, textureID);
+ * glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, ...);
+ *
+ * GLint readFBOID;
+ * glGenFramebuffers(1, &readFBOID);
+ * glBindFramebuffer(GL_FRAMEBUFFER, readFBOID);
+ * glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureID, 0);
+ *
+ * GrPlatformSurfaceDesc renderTargetTextureDesc;
+ * renderTargetTextureDesc.fSurfaceType = kTextureRenderTarget_GrPlatformSurfaceType;
+ * renderTargetTextureDesc.fRenderTargetFlags = kGrCanResolve_GrPlatformRenderTargetFlagBit;
+ * renderTargetTextureDesc.fWidth = W;
+ * renderTargetTextureDesc.fHeight = H;
+ * renderTargetTextureDesc.fConfig = kRGBA_8888_GrPixelConfig
+ * renderTargetTextureDesc.fStencilBits = 8;
+ * renderTargetTextureDesc.fSampleCnt = S;
+ * renderTargetTextureDesc.fPlatformTexture = textureID;
+ * renderTargetTextureDesc.fPlatformRenderTarget = drawFBOID;
+ * renderTargetTextureDesc.fPlatformResolveDestination = readFBOID;
+ *
+ * GrTexture* texture = static_cast<GrTexture*>(grContext->createPlatrformSurface(renderTargetTextureDesc));
+ */
+
+
+///////////////////////////////////////////////////////////////////////////////
+
+// this is included only to make it easy to use this debugging facility
+#include "GrInstanceCounter.h"
+
+#endif
diff --git a/include/gpu/GrUserConfig.h b/include/gpu/GrUserConfig.h
new file mode 100644
index 0000000000..9f616388cf
--- /dev/null
+++ b/include/gpu/GrUserConfig.h
@@ -0,0 +1,83 @@
+
+/*
+ * 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 GrUserConfig_DEFINED
+#define GrUserConfig_DEFINED
+
+#if defined(GR_USER_CONFIG_FILE)
+ #error "default user config pulled in but GR_USER_CONFIG_FILE is defined."
+#endif
+
+#if 0
+ #undef GR_RELEASE
+ #undef GR_DEBUG
+ #define GR_RELEASE 0
+ #define GR_DEBUG 1
+#endif
+
+/*
+ * The default 32bit pixel config for texture upload is GL_RGBA on all
+ * platforms except on Windows where it is GL_BGRA. If your bitmaps map to a
+ * different GL enum, specify that with this define. For portability use
+ * GR_BGRA rather than GL_BGRA for platforms where this format is an
+ * extension.
+ */
+//#define GR_GL_32BPP_COLOR_FORMAT GL_RGBA
+
+/*
+ * To diagnose texture cache performance, define this to 1 if you want to see
+ * a log statement everytime we upload an image to create a texture.
+ */
+//#define GR_DUMP_TEXTURE_UPLOAD 1
+
+/*
+ * To log all GL calls define this. Can be turned on and off at runtime by
+ * gPrintGL global variable.
+ */
+//#define GR_GL_LOG_CALLS 1
+
+/*
+ * When drawing rects this causes Ganesh to use a vertex buffer containing
+ * a unit square that is positioned by a matrix. Enable on systems where
+ * emitting per-rect-draw verts is more expensive than constant/matrix
+ * updates. Defaults to 0.
+ */
+//#define GR_STATIC_RECT_VB 1
+
+/*
+ * This causes more aggressive shader optimization. May hurt performance if
+ * switching shaders is expensive.
+ */
+//#define GR_AGGRESSIVE_SHADER_OPTS 1
+
+/*
+ * This gives a threshold in bytes of when to lock a GrGeometryBuffer vs using
+ * updateData. (Note the depending on the underlying 3D API the update functions
+ * may always be implemented using a lock)
+ */
+//#define GR_GEOM_BUFFER_LOCK_THRESHOLD (1<<15)
+
+///////////////////////////////////////////////////////////////////////////////
+/*
+ * temporary flags (may go away soon)
+ */
+
+///////////////////////////////////////////////////////////////////////////////
+// Decide Ganesh types
+
+#define GR_SCALAR_IS_FIXED 0
+#define GR_SCALAR_IS_FLOAT 1
+
+#define GR_TEXT_SCALAR_IS_USHORT 0
+#define GR_TEXT_SCALAR_IS_FIXED 0
+#define GR_TEXT_SCALAR_IS_FLOAT 1
+
+#endif
+
+
diff --git a/include/gpu/SkUIView.h b/include/gpu/SkUIView.h
new file mode 100644
index 0000000000..b5a4cd8ed8
--- /dev/null
+++ b/include/gpu/SkUIView.h
@@ -0,0 +1,65 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#import <UIKit/UIKit.h>
+
+#include "SkMatrix.h"
+#include "FlingState.h"
+
+#import <OpenGLES/EAGL.h>
+#import <OpenGLES/ES1/gl.h>
+#import <OpenGLES/ES1/glext.h>
+
+class SkOSWindow;
+class SkEvent;
+
+@interface SkUIView : UIView <UIAccelerometerDelegate> {
+ BOOL fRedrawRequestPending;
+ SkMatrix fMatrix, fLocalMatrix;
+ bool fNeedGestureEnded;
+
+ SkMatrix fRotateMatrix;
+
+ float fFirstPinchX, fFirstPinchY;
+ bool fNeedFirstPinch;
+
+ float fZoomAroundX, fZoomAroundY;
+ bool fZoomAround;
+
+ FlingState fFlingState;
+
+ GrAnimateFloat fWarpState;
+ bool fUseWarp;
+
+ struct {
+ EAGLContext* fContext;
+ GLuint fRenderbuffer;
+ GLuint fStencilbuffer;
+ GLuint fFramebuffer;
+ GLint fWidth;
+ GLint fHeight;
+ } fGL;
+
+ UINavigationItem* fTitle;
+ SkOSWindow* fWind;
+}
+
+@property (nonatomic, assign) SkOSWindow *fWind;
+@property (nonatomic, retain) UINavigationItem* fTitle;
+@property (nonatomic, assign) Backend fBackend;
+@property (nonatomic, assign) bool fComplexClip;
+@property (nonatomic, assign, setter=setWarpState) bool fUseWarp;
+
+- (void)initGestures;
+- (void)flushLocalMatrix;
+
+- (void)setSkTitle:(const char*)title;
+- (void)postInvalWithRect:(const SkIRect*)rectOrNil;
+- (BOOL)onHandleEvent:(const SkEvent&)event;
+
+@end
+