2010-12-23 15:00:45 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
#ifndef GrContext_DEFINED
|
|
|
|
#define GrContext_DEFINED
|
|
|
|
|
|
|
|
#include "GrClip.h"
|
|
|
|
#include "GrGpu.h"
|
|
|
|
#include "GrTextureCache.h"
|
2011-01-21 21:03:59 +00:00
|
|
|
#include "GrPaint.h"
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
class GrFontCache;
|
|
|
|
class GrPathIter;
|
2011-02-14 16:51:21 +00:00
|
|
|
class GrVertexBufferAllocPool;
|
|
|
|
class GrIndexBufferAllocPool;
|
|
|
|
class GrInOrderDrawBuffer;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
class GrContext : public GrRefCnt {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a GrContext from within a 3D context.
|
|
|
|
*/
|
|
|
|
static GrContext* Create(GrGpu::Engine engine,
|
|
|
|
GrGpu::Platform3DContext context3D);
|
|
|
|
|
2010-12-23 15:00:45 +00:00
|
|
|
/**
|
|
|
|
* Helper to create a opengl-shader based context
|
|
|
|
*/
|
|
|
|
static GrContext* CreateGLShaderContext();
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
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();
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Textures
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2011-01-28 21:21:49 +00:00
|
|
|
/**
|
|
|
|
* Return the max width or height of a texture supported by the current gpu
|
|
|
|
*/
|
|
|
|
int getMaxTextureDimension();
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Render targets
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
/**
|
|
|
|
* Wraps an externally-created rendertarget in a GrRenderTarget.
|
2011-02-18 16:09:55 +00:00
|
|
|
* @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.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
GrRenderTarget* createPlatformRenderTarget(intptr_t platformRenderTarget,
|
2011-02-18 16:09:55 +00:00
|
|
|
int stencilBits,
|
2010-12-22 21:39:39 +00:00
|
|
|
int width, int height);
|
|
|
|
|
2011-01-18 20:57:22 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
/**
|
2011-01-21 21:03:59 +00:00
|
|
|
* Sets the render target.
|
|
|
|
* @param target the render target to set. (should not be NULL.)
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2011-01-21 21:03:59 +00:00
|
|
|
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();
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-21 21:03:59 +00:00
|
|
|
// Matrix state
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-12-22 21:39:39 +00:00
|
|
|
const GrClip& getClip() const { return fGpu->getClip(); }
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* Sets the clip.
|
|
|
|
* @param clip the clip to set.
|
|
|
|
*/
|
|
|
|
void setClip(const GrClip& clip);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for setting the clip to a rect.
|
|
|
|
* @param rect the rect to set as the new clip.
|
|
|
|
*/
|
|
|
|
void setClip(const GrIRect& rect);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Draws
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-01-21 21:03:59 +00:00
|
|
|
* Erase the entire render target, ignoring any clips
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
|
|
|
void eraseColor(GrColor color);
|
|
|
|
|
|
|
|
/**
|
2011-01-21 21:03:59 +00:00
|
|
|
* Draw everywhere (respecting the clip) with the paint.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2011-01-21 21:03:59 +00:00
|
|
|
void drawPaint(const GrPaint& paint);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/**
|
2011-01-21 21:03:59 +00:00
|
|
|
* Draw the rect using a paint.
|
2011-02-01 19:12:40 +00:00
|
|
|
* @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
|
2011-02-14 16:51:21 +00:00
|
|
|
* strokeWidth == 0, then the stroke is always a single
|
2011-02-01 19:12:40 +00:00
|
|
|
* pixel thick.
|
2011-02-14 16:51:21 +00:00
|
|
|
* @param matrix Optional matrix applied to the rect. Applied before
|
2011-02-01 19:12:40 +00:00
|
|
|
* context's matrix or the paint's matrix.
|
2011-01-21 21:03:59 +00:00
|
|
|
* The rects coords are used to access the paint (through texture matrix)
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2011-02-14 16:51:21 +00:00
|
|
|
void drawRect(const GrPaint& paint,
|
|
|
|
const GrRect&,
|
2011-02-01 19:12:40 +00:00
|
|
|
GrScalar strokeWidth = -1,
|
|
|
|
const GrMatrix* matrix = NULL);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* Maps a rect of paint coordinates onto the a rect of destination
|
2011-02-01 19:12:40 +00:00
|
|
|
* coordinates. Each rect can optionally be transformed. The srcRect
|
2011-02-14 16:51:21 +00:00
|
|
|
* is stretched over the dstRect. The dstRect is transformed by the
|
2011-02-01 19:12:40 +00:00
|
|
|
* 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.
|
2011-01-21 21:03:59 +00:00
|
|
|
*/
|
|
|
|
void drawRectToRect(const GrPaint& paint,
|
|
|
|
const GrRect& dstRect,
|
2011-02-01 19:12:40 +00:00
|
|
|
const GrRect& srcRect,
|
|
|
|
const GrMatrix* dstMatrix = NULL,
|
|
|
|
const GrMatrix* srcMatrix = NULL);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Path filling rules
|
|
|
|
*/
|
|
|
|
enum PathFills {
|
|
|
|
kWinding_PathFill,
|
|
|
|
kEvenOdd_PathFill,
|
|
|
|
kInverseWinding_PathFill,
|
|
|
|
kInverseEvenOdd_PathFill,
|
|
|
|
kHairLine_PathFill,
|
|
|
|
|
|
|
|
kPathFillCount
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tessellates and draws a path.
|
|
|
|
*
|
2011-01-21 21:03:59 +00:00
|
|
|
* @param paint describes how to color pixels.
|
2010-12-22 21:39:39 +00:00
|
|
|
* @param path the path to draw
|
2011-01-21 21:03:59 +00:00
|
|
|
* @param fill the path filling rule to use.
|
|
|
|
* @param translate optional additional translation applied to the
|
|
|
|
* path.
|
2010-12-22 21:39:39 +00:00
|
|
|
*/
|
2011-01-21 21:03:59 +00:00
|
|
|
void drawPath(const GrPaint& paint,
|
|
|
|
GrPathIter* path,
|
2010-12-22 21:39:39 +00:00
|
|
|
PathFills fill,
|
|
|
|
const GrPoint* translate = NULL);
|
2011-01-21 21:03:59 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
GrDrawTarget::PrimitiveType 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,
|
|
|
|
GrDrawTarget::PrimitiveType 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,
|
|
|
|
GrDrawTarget::PrimitiveType primitiveType,
|
|
|
|
const POS_SRC& posSrc);
|
|
|
|
template <typename POS_SRC, typename TEX_SRC>
|
|
|
|
void drawCustomVertices(const GrPaint& paint,
|
|
|
|
GrDrawTarget::PrimitiveType primitiveType,
|
|
|
|
const POS_SRC& posSrc,
|
|
|
|
const TEX_SRC* texCoordSrc);
|
|
|
|
template <typename POS_SRC, typename TEX_SRC, typename COL_SRC>
|
|
|
|
void drawCustomVertices(const GrPaint& paint,
|
|
|
|
GrDrawTarget::PrimitiveType primitiveType,
|
|
|
|
const POS_SRC& posSrc,
|
|
|
|
const TEX_SRC* texCoordSrc,
|
|
|
|
const COL_SRC* colorSrc);
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Misc.
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Statistics
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
void resetStats();
|
|
|
|
|
|
|
|
const GrGpu::Stats& getStats() const;
|
|
|
|
|
|
|
|
void printStats() const;
|
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helpers
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
class AutoRenderTarget : ::GrNoncopyable {
|
|
|
|
public:
|
|
|
|
AutoRenderTarget(GrContext* context, GrRenderTarget* target) {
|
|
|
|
fContext = NULL;
|
2011-01-21 21:03:59 +00:00
|
|
|
fPrevTarget = context->getRenderTarget();
|
2010-12-22 21:39:39 +00:00
|
|
|
if (fPrevTarget != target) {
|
|
|
|
context->setRenderTarget(target);
|
|
|
|
fContext = context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~AutoRenderTarget() {
|
|
|
|
if (fContext) {
|
|
|
|
fContext->setRenderTarget(fPrevTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
GrContext* fContext;
|
|
|
|
GrRenderTarget* fPrevTarget;
|
|
|
|
};
|
|
|
|
|
2011-01-18 21:50:41 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Functions intended for internal use only.
|
2010-12-22 21:39:39 +00:00
|
|
|
GrGpu* getGpu() { return fGpu; }
|
|
|
|
GrFontCache* getFontCache() { return fFontCache; }
|
2011-01-21 21:03:59 +00:00
|
|
|
GrDrawTarget* getTextTarget(const GrPaint& paint);
|
2010-12-22 21:39:39 +00:00
|
|
|
void flushText();
|
2011-02-16 16:12:19 +00:00
|
|
|
const GrIndexBuffer* getQuadIndexBuffer() const;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
private:
|
2011-02-16 16:12:19 +00:00
|
|
|
// 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;
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
GrGpu* fGpu;
|
|
|
|
GrTextureCache* fTextureCache;
|
|
|
|
GrFontCache* fFontCache;
|
|
|
|
|
2011-02-16 16:12:19 +00:00
|
|
|
GrVertexBufferAllocPool* fDrawBufferVBAllocPool;
|
|
|
|
GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
|
|
|
|
GrInOrderDrawBuffer* fDrawBuffer;
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
GrContext(GrGpu* gpu);
|
2011-02-16 16:12:19 +00:00
|
|
|
void flushDrawBuffer();
|
2011-01-21 21:03:59 +00:00
|
|
|
|
|
|
|
static void SetPaint(const GrPaint& paint, GrDrawTarget* target);
|
|
|
|
|
2010-12-22 21:39:39 +00:00
|
|
|
bool finalizeTextureKey(GrTextureKey*, const GrSamplerState&) const;
|
2011-02-16 16:12:19 +00:00
|
|
|
|
|
|
|
GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
|
2010-12-22 21:39:39 +00:00
|
|
|
|
|
|
|
void drawClipIntoStencil();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save/restore the view-matrix in the context.
|
|
|
|
*/
|
2011-01-21 21:03:59 +00:00
|
|
|
class GrAutoMatrix : GrNoncopyable {
|
2010-12-22 21:39:39 +00:00
|
|
|
public:
|
2011-01-21 21:03:59 +00:00
|
|
|
GrAutoMatrix(GrContext* ctx) : fContext(ctx) {
|
|
|
|
fMatrix = ctx->getMatrix();
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
2011-01-21 21:03:59 +00:00
|
|
|
GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) {
|
|
|
|
fMatrix = ctx->getMatrix();
|
|
|
|
ctx->setMatrix(matrix);
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
2011-01-21 21:03:59 +00:00
|
|
|
~GrAutoMatrix() {
|
|
|
|
fContext->setMatrix(fMatrix);
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrContext* fContext;
|
|
|
|
GrMatrix fMatrix;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2010-12-23 15:00:45 +00:00
|
|
|
|
2011-01-21 21:03:59 +00:00
|
|
|
#include "GrContext_impl.h"
|