aboutsummaryrefslogtreecommitdiffhomepage
path: root/gpu/include
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-22 20:59:41 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-22 20:59:41 +0000
commit27847dedd9b5c1f48998c40842f3494c0746257f (patch)
tree3d48b806e5ad373030f0f9f07251d0e51789fa63 /gpu/include
parent46799cd9f0bded51a189d77731b25af159ab4609 (diff)
Fix line endings in Gr files and set svn eol style to LF
git-svn-id: http://skia.googlecode.com/svn/trunk@832 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gpu/include')
-rw-r--r--gpu/include/GrContext.h996
-rw-r--r--gpu/include/GrContext_impl.h270
-rw-r--r--gpu/include/GrDrawTarget.h6
-rw-r--r--gpu/include/GrGeometryBuffer.h232
-rw-r--r--gpu/include/GrPaint.h206
5 files changed, 855 insertions, 855 deletions
diff --git a/gpu/include/GrContext.h b/gpu/include/GrContext.h
index 9df7105451..caba6efcec 100644
--- a/gpu/include/GrContext.h
+++ b/gpu/include/GrContext.h
@@ -1,498 +1,498 @@
-/*
- Copyright 2010 Google Inc.
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#ifndef GrContext_DEFINED
-#define GrContext_DEFINED
-
-#include "GrClip.h"
-#include "GrGpu.h"
-#include "GrTextureCache.h"
-#include "GrPaint.h"
-
-class GrFontCache;
-class GrPathIter;
-class GrVertexBufferAllocPool;
-class GrIndexBufferAllocPool;
-class GrInOrderDrawBuffer;
-class GrPathRenderer;
-
-class GrContext : public GrRefCnt {
-public:
- /**
- * Creates a GrContext from within a 3D context.
- */
- static GrContext* Create(GrGpu::Engine engine,
- GrGpu::Platform3DContext 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();
-
- ///////////////////////////////////////////////////////////////////////////
- // Textures
-
- /**
- * Abandons all textures. Call this if you have lost the associated GPU
- * context, and thus internal texture references/IDs are now invalid.
- */
- void abandonAllTextures();
-
- /**
- * Search for an entry with the same Key. If found, "lock" it and return it.
- * If not found, return null.
- */
- GrTextureEntry* findAndLockTexture(GrTextureKey*,
- const GrSamplerState&);
-
-
- /**
- * Create a new entry, based on the specified key and texture, and return
- * its "locked" entry.
- *
- * Ownership of the texture is transferred to the Entry, which will unref()
- * it when we are purged or deleted.
- */
- GrTextureEntry* createAndLockTexture(GrTextureKey* key,
- const GrSamplerState&,
- const GrGpu::TextureDesc&,
- void* srcData, size_t rowBytes);
-
- /**
- * When done with an entry, call unlockTexture(entry) on it, which returns
- * it to the cache, where it may be purged.
- */
- void unlockTexture(GrTextureEntry* entry);
-
- /**
- * Removes an texture from the cache. This prevents the texture from
- * being found by a subsequent findAndLockTexture() until it is
- * reattached. The entry still counts against the cache's budget and should
- * be reattached when exclusive access is no longer needed.
- */
- void detachCachedTexture(GrTextureEntry*);
-
- /**
- * Reattaches a texture to the cache and unlocks it. Allows it to be found
- * by a subsequent findAndLock or be purged (provided its lock count is
- * now 0.)
- */
- void reattachAndUnlockCachedTexture(GrTextureEntry*);
-
- /**
- * Creates a texture that is outside the cache. Does not count against
- * cache's budget.
- */
- GrTexture* createUncachedTexture(const GrGpu::TextureDesc&,
- 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);
-
- /**
- * 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 getMaxTextureDimension();
-
- ///////////////////////////////////////////////////////////////////////////
- // Render targets
-
- /**
- * Wraps an externally-created rendertarget in a GrRenderTarget.
- * @param platformRenderTarget 3D API-specific render target identifier
- * e.g. in GL platforamRenderTarget is an FBO
- * id.
- * @param stencilBits the number of stencil bits that the render
- * target has.
- * @param width width of the render target.
- * @param height height of the render target.
- */
- GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
- int stencilBits,
- int width, int height);
-
- /**
- * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
- * viewport state from the underlying 3D API and wraps it in a
- * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
- * underlying object in its destructor and it is up to caller to guarantee
- * that it remains valid while the GrRenderTarget is used.
- *
- * @return the newly created GrRenderTarget
- */
- GrRenderTarget* createRenderTargetFrom3DApiState() {
- return fGpu->createRenderTargetFrom3DApiState();
- }
-
- /**
- * 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();
-
- ///////////////////////////////////////////////////////////////////////////
- // 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 { return fGpu->getClip(); }
-
- /**
- * 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
-
- /**
- * Erase the entire render target, ignoring any clips
- */
- void eraseColor(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);
-
- /**
- * Tessellates and 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,
- GrPathIter* 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);
-
- /**
- * Similar to drawVertices but caller provides objects that convert to Gr
- * types. The count of vertices is given by posSrc.
- *
- * @param paint describes how to color pixels.
- * @param primitiveType primitives type to draw.
- * @param posSrc Source of vertex positions. Must implement
- * int count() const;
- * void writeValue(int i, GrPoint* point) const;
- * count returns the total number of vertices and
- * writeValue writes a vertex position to point.
- * @param texSrc optional, pass NULL to not use explicit tex
- * coords. If present provides tex coords with
- * method:
- * void writeValue(int i, GrPoint* point) const;
- * @param texSrc optional, pass NULL to not use per-vertex colors
- * If present provides colors with method:
- * void writeValue(int i, GrColor* point) const;
- * @param indices optional, pass NULL for non-indexed drawing. If
- * present supplies indices for indexed drawing
- * with following methods:
- * int count() const;
- * void writeValue(int i, uint16_t* point) const;
- * count returns the number of indices and
- * writeValue supplies each index.
- */
- template <typename POS_SRC,
- typename TEX_SRC,
- typename COL_SRC,
- typename IDX_SRC>
- void drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc,
- const COL_SRC* colorSrc,
- const IDX_SRC* idxSrc);
- /**
- * To avoid the problem of having to create a typename for NULL parameters,
- * these reduced versions of drawCustomVertices are provided.
- */
- template <typename POS_SRC>
- void drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc);
- template <typename POS_SRC, typename TEX_SRC>
- void drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc);
- template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
- void drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc,
- const COL_SRC* colorSrc);
-
-
- ///////////////////////////////////////////////////////////////////////////
- // Misc.
-
- /**
- * Call to ensure all drawing to the context has been issued to the
- * underlying 3D API.
- * if flushRenderTarget is true then after the call the last
- * rendertarget set will be current in the underlying 3D API, otherwise
- * it may not be. It is useful to set if the caller plans to use the 3D
- * context outside of Ganesh to render into the current RT.
- */
- void flush(bool flushRenderTarget);
-
- /**
- * Return true on success, i.e. if we could copy the specified range of
- * pixels from the current render-target into the buffer, converting into
- * the specified pixel-config.
- */
- bool readPixels(int left, int top, int width, int height,
- GrTexture::PixelConfig, 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,
- GrTexture::PixelConfig, const void* buffer, size_t stride);
-
-
- ///////////////////////////////////////////////////////////////////////////
- // Statistics
-
- void resetStats();
-
- const GrGpu::Stats& getStats() const;
-
- void printStats() const;
-
- ///////////////////////////////////////////////////////////////////////////
- // 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; }
- GrFontCache* getFontCache() { return fFontCache; }
- GrDrawTarget* getTextTarget(const GrPaint& paint);
- void flushText();
- const GrIndexBuffer* getQuadIndexBuffer() const;
-
-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;
- GrTextureCache* fTextureCache;
- GrFontCache* fFontCache;
- GrPathRenderer* fPathRenderer;
-
- GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
- GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
- GrInOrderDrawBuffer* fDrawBuffer;
-
- GrContext(GrGpu* gpu);
- void flushDrawBuffer();
-
- static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
-
- bool finalizeTextureKey(GrTextureKey*, const GrSamplerState&) const;
-
- GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
-
- void drawClipIntoStencil();
-};
-
-/**
- * Save/restore the view-matrix in the context.
- */
-class GrAutoMatrix : GrNoncopyable {
-public:
- GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
- fMatrix = ctx->getMatrix();
- }
- GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
- fMatrix = ctx->getMatrix();
- ctx->setMatrix(matrix);
- }
- ~GrAutoMatrix() {
- fContext->setMatrix(fMatrix);
- }
-
-private:
- GrContext* fContext;
- GrMatrix fMatrix;
-};
-
-#endif
-
-#include "GrContext_impl.h"
+/*
+ Copyright 2010 Google Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+#ifndef GrContext_DEFINED
+#define GrContext_DEFINED
+
+#include "GrClip.h"
+#include "GrGpu.h"
+#include "GrTextureCache.h"
+#include "GrPaint.h"
+
+class GrFontCache;
+class GrPathIter;
+class GrVertexBufferAllocPool;
+class GrIndexBufferAllocPool;
+class GrInOrderDrawBuffer;
+class GrPathRenderer;
+
+class GrContext : public GrRefCnt {
+public:
+ /**
+ * Creates a GrContext from within a 3D context.
+ */
+ static GrContext* Create(GrGpu::Engine engine,
+ GrGpu::Platform3DContext 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();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Textures
+
+ /**
+ * Abandons all textures. Call this if you have lost the associated GPU
+ * context, and thus internal texture references/IDs are now invalid.
+ */
+ void abandonAllTextures();
+
+ /**
+ * Search for an entry with the same Key. If found, "lock" it and return it.
+ * If not found, return null.
+ */
+ GrTextureEntry* findAndLockTexture(GrTextureKey*,
+ const GrSamplerState&);
+
+
+ /**
+ * Create a new entry, based on the specified key and texture, and return
+ * its "locked" entry.
+ *
+ * Ownership of the texture is transferred to the Entry, which will unref()
+ * it when we are purged or deleted.
+ */
+ GrTextureEntry* createAndLockTexture(GrTextureKey* key,
+ const GrSamplerState&,
+ const GrGpu::TextureDesc&,
+ void* srcData, size_t rowBytes);
+
+ /**
+ * When done with an entry, call unlockTexture(entry) on it, which returns
+ * it to the cache, where it may be purged.
+ */
+ void unlockTexture(GrTextureEntry* entry);
+
+ /**
+ * Removes an texture from the cache. This prevents the texture from
+ * being found by a subsequent findAndLockTexture() until it is
+ * reattached. The entry still counts against the cache's budget and should
+ * be reattached when exclusive access is no longer needed.
+ */
+ void detachCachedTexture(GrTextureEntry*);
+
+ /**
+ * Reattaches a texture to the cache and unlocks it. Allows it to be found
+ * by a subsequent findAndLock or be purged (provided its lock count is
+ * now 0.)
+ */
+ void reattachAndUnlockCachedTexture(GrTextureEntry*);
+
+ /**
+ * Creates a texture that is outside the cache. Does not count against
+ * cache's budget.
+ */
+ GrTexture* createUncachedTexture(const GrGpu::TextureDesc&,
+ 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);
+
+ /**
+ * 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 getMaxTextureDimension();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Render targets
+
+ /**
+ * Wraps an externally-created rendertarget in a GrRenderTarget.
+ * @param platformRenderTarget 3D API-specific render target identifier
+ * e.g. in GL platforamRenderTarget is an FBO
+ * id.
+ * @param stencilBits the number of stencil bits that the render
+ * target has.
+ * @param width width of the render target.
+ * @param height height of the render target.
+ */
+ GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
+ int stencilBits,
+ int width, int height);
+
+ /**
+ * Reads the current target object (e.g. FBO or IDirect3DSurface9*) and
+ * viewport state from the underlying 3D API and wraps it in a
+ * GrRenderTarget. The GrRenderTarget will not attempt to delete/destroy the
+ * underlying object in its destructor and it is up to caller to guarantee
+ * that it remains valid while the GrRenderTarget is used.
+ *
+ * @return the newly created GrRenderTarget
+ */
+ GrRenderTarget* createRenderTargetFrom3DApiState() {
+ return fGpu->createRenderTargetFrom3DApiState();
+ }
+
+ /**
+ * 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();
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 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 { return fGpu->getClip(); }
+
+ /**
+ * 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
+
+ /**
+ * Erase the entire render target, ignoring any clips
+ */
+ void eraseColor(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);
+
+ /**
+ * Tessellates and 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,
+ GrPathIter* 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);
+
+ /**
+ * Similar to drawVertices but caller provides objects that convert to Gr
+ * types. The count of vertices is given by posSrc.
+ *
+ * @param paint describes how to color pixels.
+ * @param primitiveType primitives type to draw.
+ * @param posSrc Source of vertex positions. Must implement
+ * int count() const;
+ * void writeValue(int i, GrPoint* point) const;
+ * count returns the total number of vertices and
+ * writeValue writes a vertex position to point.
+ * @param texSrc optional, pass NULL to not use explicit tex
+ * coords. If present provides tex coords with
+ * method:
+ * void writeValue(int i, GrPoint* point) const;
+ * @param texSrc optional, pass NULL to not use per-vertex colors
+ * If present provides colors with method:
+ * void writeValue(int i, GrColor* point) const;
+ * @param indices optional, pass NULL for non-indexed drawing. If
+ * present supplies indices for indexed drawing
+ * with following methods:
+ * int count() const;
+ * void writeValue(int i, uint16_t* point) const;
+ * count returns the number of indices and
+ * writeValue supplies each index.
+ */
+ template <typename POS_SRC,
+ typename TEX_SRC,
+ typename COL_SRC,
+ typename IDX_SRC>
+ void drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc,
+ const COL_SRC* colorSrc,
+ const IDX_SRC* idxSrc);
+ /**
+ * To avoid the problem of having to create a typename for NULL parameters,
+ * these reduced versions of drawCustomVertices are provided.
+ */
+ template <typename POS_SRC>
+ void drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc);
+ template <typename POS_SRC, typename TEX_SRC>
+ void drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc);
+ template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
+ void drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc,
+ const COL_SRC* colorSrc);
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Misc.
+
+ /**
+ * Call to ensure all drawing to the context has been issued to the
+ * underlying 3D API.
+ * if flushRenderTarget is true then after the call the last
+ * rendertarget set will be current in the underlying 3D API, otherwise
+ * it may not be. It is useful to set if the caller plans to use the 3D
+ * context outside of Ganesh to render into the current RT.
+ */
+ void flush(bool flushRenderTarget);
+
+ /**
+ * Return true on success, i.e. if we could copy the specified range of
+ * pixels from the current render-target into the buffer, converting into
+ * the specified pixel-config.
+ */
+ bool readPixels(int left, int top, int width, int height,
+ GrTexture::PixelConfig, 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,
+ GrTexture::PixelConfig, const void* buffer, size_t stride);
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Statistics
+
+ void resetStats();
+
+ const GrGpu::Stats& getStats() const;
+
+ void printStats() const;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // 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; }
+ GrFontCache* getFontCache() { return fFontCache; }
+ GrDrawTarget* getTextTarget(const GrPaint& paint);
+ void flushText();
+ const GrIndexBuffer* getQuadIndexBuffer() const;
+
+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;
+ GrTextureCache* fTextureCache;
+ GrFontCache* fFontCache;
+ GrPathRenderer* fPathRenderer;
+
+ GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
+ GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
+ GrInOrderDrawBuffer* fDrawBuffer;
+
+ GrContext(GrGpu* gpu);
+ void flushDrawBuffer();
+
+ static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
+
+ bool finalizeTextureKey(GrTextureKey*, const GrSamplerState&) const;
+
+ GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
+
+ void drawClipIntoStencil();
+};
+
+/**
+ * Save/restore the view-matrix in the context.
+ */
+class GrAutoMatrix : GrNoncopyable {
+public:
+ GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ }
+ GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
+ fMatrix = ctx->getMatrix();
+ ctx->setMatrix(matrix);
+ }
+ ~GrAutoMatrix() {
+ fContext->setMatrix(fMatrix);
+ }
+
+private:
+ GrContext* fContext;
+ GrMatrix fMatrix;
+};
+
+#endif
+
+#include "GrContext_impl.h"
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
index c0a2107a87..fdcb2b1db0 100644
--- a/gpu/include/GrContext_impl.h
+++ b/gpu/include/GrContext_impl.h
@@ -1,135 +1,135 @@
-/*
- 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 GrContext_impl_DEFINED
-#define GrContext_impl_DEFINED
-
-template <typename POS_SRC, typename TEX_SRC,
- typename COL_SRC, typename IDX_SRC>
-inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc,
- const COL_SRC* colorSrc,
- const IDX_SRC* idxSrc) {
-
- GrVertexLayout layout = 0;
-
- GrDrawTarget::AutoReleaseGeometry geo;
-
- GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
-
- if (NULL != paint.getTexture()) {
- if (NULL != texCoordSrc) {
- layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
- } else {
- layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
- }
- }
-
- if (NULL != colorSrc) {
- layout |= GrDrawTarget::kColor_VertexLayoutBit;
- }
-
- int vertexCount = posSrc.count();
- int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;
-
- if (!geo.set(target, layout, vertexCount, indexCount)) {
- GrPrintf("Failed to get space for vertices!");
- return;
- }
-
- int texOffsets[GrDrawTarget::kMaxTexCoords];
- int colorOffset;
- int vsize = GrDrawTarget::VertexSizeAndOffsetsByIdx(layout,
- texOffsets,
- &colorOffset);
- void* curVertex = geo.vertices();
-
- for (int i = 0; i < vertexCount; ++i) {
- posSrc.writeValue(i, (GrPoint*)curVertex);
-
- if (texOffsets[0] > 0) {
- texCoordSrc->writeValue(i, (GrPoint*)((intptr_t)curVertex + texOffsets[0]));
- }
- if (colorOffset > 0) {
- colorSrc->writeValue(i, (GrColor*)((intptr_t)curVertex + colorOffset));
- }
- curVertex = (void*)((intptr_t)curVertex + vsize);
- }
-
- uint16_t* indices = (uint16_t*) geo.indices();
- for (int i = 0; i < indexCount; ++i) {
- idxSrc->writeValue(i, indices + i);
- }
-
- if (NULL == idxSrc) {
- target->drawNonIndexed(primitiveType, 0, vertexCount);
- } else {
- target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
- }
-}
-
-class GrNullTexCoordSource {
-public:
- void writeValue(int i, GrPoint* dstCoord) const { GrAssert(false); }
-};
-
-class GrNullColorSource {
-public:
- void writeValue(int i, GrColor* dstColor) const { GrAssert(false); }
-};
-
-class GrNullIndexSource {
-public:
- void writeValue(int i, uint16_t* dstIndex) const { GrAssert(false); }
- int count() const { GrAssert(false); return 0; }
-};
-
-template <typename POS_SRC>
-inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc) {
- this->drawCustomVertices<POS_SRC,
- GrNullTexCoordSource,
- GrNullColorSource,
- GrNullIndexSource>(paint, primitiveType, posSrc,
- NULL, NULL, NULL);
-}
-
-template <typename POS_SRC, typename TEX_SRC>
-inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc) {
- this->drawCustomVertices<POS_SRC, TEX_SRC,
- GrNullColorSource,
- GrNullIndexSource>(paint, primitiveType, posSrc,
- texCoordSrc, NULL, NULL);
-}
-
-template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
-inline void GrContext::drawCustomVertices(const GrPaint& paint,
- GrPrimitiveType primitiveType,
- const POS_SRC& posSrc,
- const TEX_SRC* texCoordSrc,
- const COL_SRC* colorSrc) {
- drawCustomVertices<POS_SRC, TEX_SRC, COL_SRC,
- GrNullIndexSource>(paint, primitiveType, posSrc,
- texCoordSrc, colorSrc, NULL);
-}
-
-#endif
+/*
+ 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 GrContext_impl_DEFINED
+#define GrContext_impl_DEFINED
+
+template <typename POS_SRC, typename TEX_SRC,
+ typename COL_SRC, typename IDX_SRC>
+inline void GrContext::drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc,
+ const COL_SRC* colorSrc,
+ const IDX_SRC* idxSrc) {
+
+ GrVertexLayout layout = 0;
+
+ GrDrawTarget::AutoReleaseGeometry geo;
+
+ GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
+
+ if (NULL != paint.getTexture()) {
+ if (NULL != texCoordSrc) {
+ layout |= GrDrawTarget::StageTexCoordVertexLayoutBit(0,0);
+ } else {
+ layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
+ }
+ }
+
+ if (NULL != colorSrc) {
+ layout |= GrDrawTarget::kColor_VertexLayoutBit;
+ }
+
+ int vertexCount = posSrc.count();
+ int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;
+
+ if (!geo.set(target, layout, vertexCount, indexCount)) {
+ GrPrintf("Failed to get space for vertices!");
+ return;
+ }
+
+ int texOffsets[GrDrawTarget::kMaxTexCoords];
+ int colorOffset;
+ int vsize = GrDrawTarget::VertexSizeAndOffsetsByIdx(layout,
+ texOffsets,
+ &colorOffset);
+ void* curVertex = geo.vertices();
+
+ for (int i = 0; i < vertexCount; ++i) {
+ posSrc.writeValue(i, (GrPoint*)curVertex);
+
+ if (texOffsets[0] > 0) {
+ texCoordSrc->writeValue(i, (GrPoint*)((intptr_t)curVertex + texOffsets[0]));
+ }
+ if (colorOffset > 0) {
+ colorSrc->writeValue(i, (GrColor*)((intptr_t)curVertex + colorOffset));
+ }
+ curVertex = (void*)((intptr_t)curVertex + vsize);
+ }
+
+ uint16_t* indices = (uint16_t*) geo.indices();
+ for (int i = 0; i < indexCount; ++i) {
+ idxSrc->writeValue(i, indices + i);
+ }
+
+ if (NULL == idxSrc) {
+ target->drawNonIndexed(primitiveType, 0, vertexCount);
+ } else {
+ target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount);
+ }
+}
+
+class GrNullTexCoordSource {
+public:
+ void writeValue(int i, GrPoint* dstCoord) const { GrAssert(false); }
+};
+
+class GrNullColorSource {
+public:
+ void writeValue(int i, GrColor* dstColor) const { GrAssert(false); }
+};
+
+class GrNullIndexSource {
+public:
+ void writeValue(int i, uint16_t* dstIndex) const { GrAssert(false); }
+ int count() const { GrAssert(false); return 0; }
+};
+
+template <typename POS_SRC>
+inline void GrContext::drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc) {
+ this->drawCustomVertices<POS_SRC,
+ GrNullTexCoordSource,
+ GrNullColorSource,
+ GrNullIndexSource>(paint, primitiveType, posSrc,
+ NULL, NULL, NULL);
+}
+
+template <typename POS_SRC, typename TEX_SRC>
+inline void GrContext::drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc) {
+ this->drawCustomVertices<POS_SRC, TEX_SRC,
+ GrNullColorSource,
+ GrNullIndexSource>(paint, primitiveType, posSrc,
+ texCoordSrc, NULL, NULL);
+}
+
+template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
+inline void GrContext::drawCustomVertices(const GrPaint& paint,
+ GrPrimitiveType primitiveType,
+ const POS_SRC& posSrc,
+ const TEX_SRC* texCoordSrc,
+ const COL_SRC* colorSrc) {
+ drawCustomVertices<POS_SRC, TEX_SRC, COL_SRC,
+ GrNullIndexSource>(paint, primitiveType, posSrc,
+ texCoordSrc, colorSrc, NULL);
+}
+
+#endif
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 929b9ff39b..10c6d48462 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -210,9 +210,9 @@ public:
* @param stage the stage of the sampler to set
* @param matrix the matrix to concat
*/
- void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) {
- GrAssert(stage >= 0 && stage < kNumStages);
- fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix);
+ void preConcatSamplerMatrix(int stage, const GrMatrix& matrix) {
+ GrAssert(stage >= 0 && stage < kNumStages);
+ fCurrDrawState.fSamplerStates[stage].preConcatMatrix(matrix);
}
/**
diff --git a/gpu/include/GrGeometryBuffer.h b/gpu/include/GrGeometryBuffer.h
index af6eed5f63..1447e73185 100644
--- a/gpu/include/GrGeometryBuffer.h
+++ b/gpu/include/GrGeometryBuffer.h
@@ -1,116 +1,116 @@
-/*
- 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 GrGeometryBuffer_DEFINED
-#define GrGeometryBuffer_DEFINED
-
-#include "GrRefCnt.h"
-
-/**
- * Parent class for vertex and index buffers
- */
-class GrGeometryBuffer : public GrRefCnt {
-public:
- virtual ~GrGeometryBuffer() {}
-
- /**
- * Retrieves the size of the buffer
- *
- * @return the size of the buffer in bytes
- */
- size_t size() const { return fSizeInBytes; }
-
- /**
- *Retrieves whether the buffer was created with the dynamic flag
- *
- * @return true if the buffer was created with the dynamic flag
- */
- bool dynamic() const { return fDynamic; }
-
- /**
- * Indicates that GPU context in which this veretx buffer was created is
- * destroyed and that Ganesh should not attempt to free the buffer in the
- * underlying API.
- */
- virtual void abandon() = 0;
-
- /**
- * Locks the buffer to be written by the CPU.
- *
- * The previous content of the buffer is invalidated. It is an error
- * to draw from the buffer while it is locked. It is an error to call lock
- * on an already locked buffer.
- *
- * @return a pointer to the data or NULL if the lock fails.
- */
- virtual void* lock() = 0;
-
- /**
- * Returns the same ptr that lock() returned at time of lock or NULL if the
- * is not locked.
- *
- * @return ptr to locked buffer data or undefined if buffer is not locked.
- */
- virtual void* lockPtr() const = 0;
-
- /**
- * Unlocks the buffer.
- *
- * The pointer returned by the previous lock call will no longer be valid.
- */
- virtual void unlock() = 0;
-
- /**
- Queries whether the buffer has been locked.
-
- @return true if the buffer is locked, false otherwise.
- */
- virtual bool isLocked() const = 0;
-
- /**
- * Updates the buffer data.
- *
- * The size of the buffer will be preserved. The src data will be
- * placed at the begining of the buffer and any remaining contents will
- * be undefined.
- *
- * @return returns true if the update succeeds, false otherwise.
- */
- virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
-
- /**
- * Updates a portion of the buffer data.
- *
- * The contents of the buffer outside the update region are preserved.
- *
- * @return returns true if the update succeeds, false otherwise.
- */
- virtual bool updateSubData(const void* src,
- size_t srcSizeInBytes,
- size_t offset) = 0;
-protected:
- GrGeometryBuffer(size_t sizeInBytes, bool dynamic) :
- fSizeInBytes(sizeInBytes),
- fDynamic(dynamic) {}
-
-private:
- size_t fSizeInBytes;
- bool fDynamic;
-
- typedef GrRefCnt INHERITED;
-};
-
-#endif
+/*
+ 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 GrGeometryBuffer_DEFINED
+#define GrGeometryBuffer_DEFINED
+
+#include "GrRefCnt.h"
+
+/**
+ * Parent class for vertex and index buffers
+ */
+class GrGeometryBuffer : public GrRefCnt {
+public:
+ virtual ~GrGeometryBuffer() {}
+
+ /**
+ * Retrieves the size of the buffer
+ *
+ * @return the size of the buffer in bytes
+ */
+ size_t size() const { return fSizeInBytes; }
+
+ /**
+ *Retrieves whether the buffer was created with the dynamic flag
+ *
+ * @return true if the buffer was created with the dynamic flag
+ */
+ bool dynamic() const { return fDynamic; }
+
+ /**
+ * Indicates that GPU context in which this veretx buffer was created is
+ * destroyed and that Ganesh should not attempt to free the buffer in the
+ * underlying API.
+ */
+ virtual void abandon() = 0;
+
+ /**
+ * Locks the buffer to be written by the CPU.
+ *
+ * The previous content of the buffer is invalidated. It is an error
+ * to draw from the buffer while it is locked. It is an error to call lock
+ * on an already locked buffer.
+ *
+ * @return a pointer to the data or NULL if the lock fails.
+ */
+ virtual void* lock() = 0;
+
+ /**
+ * Returns the same ptr that lock() returned at time of lock or NULL if the
+ * is not locked.
+ *
+ * @return ptr to locked buffer data or undefined if buffer is not locked.
+ */
+ virtual void* lockPtr() const = 0;
+
+ /**
+ * Unlocks the buffer.
+ *
+ * The pointer returned by the previous lock call will no longer be valid.
+ */
+ virtual void unlock() = 0;
+
+ /**
+ Queries whether the buffer has been locked.
+
+ @return true if the buffer is locked, false otherwise.
+ */
+ virtual bool isLocked() const = 0;
+
+ /**
+ * Updates the buffer data.
+ *
+ * The size of the buffer will be preserved. The src data will be
+ * placed at the begining of the buffer and any remaining contents will
+ * be undefined.
+ *
+ * @return returns true if the update succeeds, false otherwise.
+ */
+ virtual bool updateData(const void* src, size_t srcSizeInBytes) = 0;
+
+ /**
+ * Updates a portion of the buffer data.
+ *
+ * The contents of the buffer outside the update region are preserved.
+ *
+ * @return returns true if the update succeeds, false otherwise.
+ */
+ virtual bool updateSubData(const void* src,
+ size_t srcSizeInBytes,
+ size_t offset) = 0;
+protected:
+ GrGeometryBuffer(size_t sizeInBytes, bool dynamic) :
+ fSizeInBytes(sizeInBytes),
+ fDynamic(dynamic) {}
+
+private:
+ size_t fSizeInBytes;
+ bool fDynamic;
+
+ typedef GrRefCnt INHERITED;
+};
+
+#endif
diff --git a/gpu/include/GrPaint.h b/gpu/include/GrPaint.h
index a34cbaf445..9402209780 100644
--- a/gpu/include/GrPaint.h
+++ b/gpu/include/GrPaint.h
@@ -1,103 +1,103 @@
-/*
- 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 GrPaint_DEFINED
-#define GrPaint_DEFINED
-
-#include "GrTexture.h"
-#include "GrColor.h"
-#include "GrSamplerState.h"
-
-/**
- * The paint describes how pixels are colored when the context draws to
- * them.
- */
-class GrPaint {
-public:
-
- // All the paint fields are public except texture (it's ref-counted)
- GrBlendCoeff fSrcBlendCoeff;
- GrBlendCoeff fDstBlendCoeff;
- bool fAntiAlias;
- bool fDither;
-
- GrColor fColor;
-
- GrSamplerState fSampler;
-
- void setTexture(GrTexture* texture) {
- GrSafeRef(texture);
- GrSafeUnref(fTexture);
- fTexture = texture;
- }
-
- GrTexture* getTexture() const { return fTexture; }
-
- // uninitialized
- GrPaint() {
- fTexture = NULL;
- }
-
- GrPaint(const GrPaint& paint) {
- fSrcBlendCoeff = paint.fSrcBlendCoeff;
- fDstBlendCoeff = paint.fDstBlendCoeff;
- fAntiAlias = paint.fAntiAlias;
- fDither = paint.fDither;
-
- fColor = paint.fColor;
-
- fSampler = paint.fSampler;
- fTexture = paint.fTexture;
- GrSafeRef(fTexture);
- }
-
- ~GrPaint() {
- GrSafeUnref(fTexture);
- }
-
- // sets paint to src-over, solid white, no texture
- void reset() {
- resetBlend();
- resetOptions();
- resetColor();
- resetTexture();
- }
-
-private:
- GrTexture* fTexture;
-
- void resetBlend() {
- fSrcBlendCoeff = kOne_BlendCoeff;
- fDstBlendCoeff = kZero_BlendCoeff;
- }
-
- void resetOptions() {
- fAntiAlias = false;
- fDither = false;
- }
-
- void resetColor() {
- fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
- }
-
- void resetTexture() {
- setTexture(NULL);
- fSampler.setClampNoFilter();
- }
-
-};
-
-#endif
+/*
+ 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 GrPaint_DEFINED
+#define GrPaint_DEFINED
+
+#include "GrTexture.h"
+#include "GrColor.h"
+#include "GrSamplerState.h"
+
+/**
+ * The paint describes how pixels are colored when the context draws to
+ * them.
+ */
+class GrPaint {
+public:
+
+ // All the paint fields are public except texture (it's ref-counted)
+ GrBlendCoeff fSrcBlendCoeff;
+ GrBlendCoeff fDstBlendCoeff;
+ bool fAntiAlias;
+ bool fDither;
+
+ GrColor fColor;
+
+ GrSamplerState fSampler;
+
+ void setTexture(GrTexture* texture) {
+ GrSafeRef(texture);
+ GrSafeUnref(fTexture);
+ fTexture = texture;
+ }
+
+ GrTexture* getTexture() const { return fTexture; }
+
+ // uninitialized
+ GrPaint() {
+ fTexture = NULL;
+ }
+
+ GrPaint(const GrPaint& paint) {
+ fSrcBlendCoeff = paint.fSrcBlendCoeff;
+ fDstBlendCoeff = paint.fDstBlendCoeff;
+ fAntiAlias = paint.fAntiAlias;
+ fDither = paint.fDither;
+
+ fColor = paint.fColor;
+
+ fSampler = paint.fSampler;
+ fTexture = paint.fTexture;
+ GrSafeRef(fTexture);
+ }
+
+ ~GrPaint() {
+ GrSafeUnref(fTexture);
+ }
+
+ // sets paint to src-over, solid white, no texture
+ void reset() {
+ resetBlend();
+ resetOptions();
+ resetColor();
+ resetTexture();
+ }
+
+private:
+ GrTexture* fTexture;
+
+ void resetBlend() {
+ fSrcBlendCoeff = kOne_BlendCoeff;
+ fDstBlendCoeff = kZero_BlendCoeff;
+ }
+
+ void resetOptions() {
+ fAntiAlias = false;
+ fDither = false;
+ }
+
+ void resetColor() {
+ fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
+ }
+
+ void resetTexture() {
+ setTexture(NULL);
+ fSampler.setClampNoFilter();
+ }
+
+};
+
+#endif