summaryrefslogtreecommitdiffstats
path: root/libs/hwui/OpenGLRenderer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/OpenGLRenderer.h')
-rwxr-xr-xlibs/hwui/OpenGLRenderer.h182
1 files changed, 112 insertions, 70 deletions
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index e1c3d10..fde9e0f 100755
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -38,6 +38,7 @@
#include <androidfw/ResourceTypes.h>
+#include "CanvasState.h"
#include "Debug.h"
#include "Extensions.h"
#include "Matrix.h"
@@ -45,11 +46,9 @@
#include "Rect.h"
#include "Renderer.h"
#include "Snapshot.h"
-#include "StatefulBaseRenderer.h"
#include "UvMapper.h"
#include "Vertex.h"
#include "Caches.h"
-#include "CanvasProperty.h"
class SkShader;
@@ -72,11 +71,6 @@ struct DrawModifiers {
}
float mOverrideLayerAlpha;
-
- // Draw filters
- bool mHasDrawFilter;
- int mPaintFilterClearBits;
- int mPaintFilterSetBits;
};
enum StateDeferFlags {
@@ -123,7 +117,7 @@ enum ModelViewMode {
/**
* OpenGL Renderer implementation.
*/
-class OpenGLRenderer : public StatefulBaseRenderer {
+class OpenGLRenderer : public Renderer, public CanvasStateClient {
public:
OpenGLRenderer(RenderState& renderState);
virtual ~OpenGLRenderer();
@@ -132,11 +126,13 @@ public:
void initLight(const Vector3& lightCenter, float lightRadius,
uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
- virtual void onViewportInitialized();
- virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
- virtual void finish();
+ virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
+ virtual void prepare(bool opaque) {
+ prepareDirty(0.0f, 0.0f, mState.getWidth(), mState.getHeight(), opaque);
+ }
+ virtual bool finish();
- virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
+ virtual void callDrawGLFunction(Functor* functor, Rect& dirty);
void pushLayerUpdate(Layer* layer);
void cancelLayerUpdate(Layer* layer);
@@ -156,56 +152,53 @@ public:
int saveLayerDeferred(float left, float top, float right, float bottom,
const SkPaint* paint, int flags);
- virtual status_t drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
- virtual status_t drawLayer(Layer* layer, float x, float y);
- virtual status_t drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
- status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
+ virtual void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
+ virtual void drawLayer(Layer* layer, float x, float y);
+ virtual void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
+ void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
- virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
+ virtual void drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, const SkPaint* paint);
- virtual status_t drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint);
- virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
+ virtual void drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint);
+ virtual void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint);
- status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
+ void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
- virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
+ virtual void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
float left, float top, float right, float bottom, const SkPaint* paint);
- status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
+ void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
float left, float top, float right, float bottom, const SkPaint* paint);
- virtual status_t drawColor(int color, SkXfermode::Mode mode);
- virtual status_t drawRect(float left, float top, float right, float bottom,
+ virtual void drawColor(int color, SkXfermode::Mode mode);
+ virtual void drawRect(float left, float top, float right, float bottom,
const SkPaint* paint);
- virtual status_t drawRoundRect(float left, float top, float right, float bottom,
+ virtual void drawRoundRect(float left, float top, float right, float bottom,
float rx, float ry, const SkPaint* paint);
- virtual status_t drawCircle(float x, float y, float radius, const SkPaint* paint);
- virtual status_t drawOval(float left, float top, float right, float bottom,
+ virtual void drawCircle(float x, float y, float radius, const SkPaint* paint);
+ virtual void drawOval(float left, float top, float right, float bottom,
const SkPaint* paint);
- virtual status_t drawArc(float left, float top, float right, float bottom,
+ virtual void drawArc(float left, float top, float right, float bottom,
float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
- virtual status_t drawPath(const SkPath* path, const SkPaint* paint);
- virtual status_t drawLines(const float* points, int count, const SkPaint* paint);
- virtual status_t drawPoints(const float* points, int count, const SkPaint* paint);
- virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
+ virtual void drawPath(const SkPath* path, const SkPaint* paint);
+ virtual void drawLines(const float* points, int count, const SkPaint* paint);
+ virtual void drawPoints(const float* points, int count, const SkPaint* paint);
+ virtual void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
float hOffset, float vOffset, const SkPaint* paint);
- virtual status_t drawPosText(const char* text, int bytesCount, int count,
+ virtual void drawPosText(const char* text, int bytesCount, int count,
const float* positions, const SkPaint* paint);
- virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
+ virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
DrawOpMode drawOpMode = kDrawOpMode_Immediate);
- virtual status_t drawRects(const float* rects, int count, const SkPaint* paint);
+ virtual void drawRects(const float* rects, int count, const SkPaint* paint);
- status_t drawShadow(float casterAlpha,
+ void drawShadow(float casterAlpha,
const VertexBuffer* ambientShadowVertexBuffer, const VertexBuffer* spotShadowVertexBuffer);
- virtual void resetPaintFilter();
- virtual void setupPaintFilter(int clearBits, int setBits);
+ virtual void setDrawFilter(SkDrawFilter* filter);
// If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer)
void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; }
- const SkPaint* filterPaint(const SkPaint* paint);
-
/**
* Store the current display state (most importantly, the current clip and transform), and
* additionally map the state's bounds from local to window coordinates.
@@ -228,20 +221,16 @@ public:
}
// simple rect clip
- bool isCurrentClipSimple() {
- return mSnapshot->clipRegion->isEmpty();
- }
+ bool isCurrentClipSimple() { return mState.isCurrentClipSimple(); }
- int getViewportWidth() { return currentSnapshot()->getViewportWidth(); }
- int getViewportHeight() { return currentSnapshot()->getViewportHeight(); }
+ int getViewportWidth() { return mState.getViewportWidth(); }
+ int getViewportHeight() { return mState.getViewportHeight(); }
/**
* Scales the alpha on the current snapshot. This alpha value will be modulated
* with other alpha values when drawing primitives.
*/
- void scaleAlpha(float alpha) {
- mSnapshot->alpha *= alpha;
- }
+ void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); }
/**
* Inserts a named event marker in the stream of GL commands.
@@ -334,14 +323,67 @@ public:
drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
if (stencilWasEnabled) mCaches.stencil.enableTest();
+ mDirty = true;
}
#endif
- const Vector3& getLightCenter() const { return currentSnapshot()->getRelativeLightCenter(); }
+ const Vector3& getLightCenter() const { return mState.currentLightCenter(); }
float getLightRadius() const { return mLightRadius; }
uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; }
uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; }
+ ///////////////////////////////////////////////////////////////////
+ /// State manipulation
+
+ virtual void setViewport(int width, int height) { mState.setViewport(width, height); }
+
+ virtual int getSaveCount() const;
+ virtual int save(int flags);
+ virtual void restore();
+ virtual void restoreToCount(int saveCount);
+
+ virtual void getMatrix(SkMatrix* outMatrix) const { mState.getMatrix(outMatrix); }
+ virtual void setMatrix(const SkMatrix& matrix) { mState.setMatrix(matrix); }
+ virtual void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); }
+
+ virtual void translate(float dx, float dy, float dz = 0.0f);
+ virtual void rotate(float degrees);
+ virtual void scale(float sx, float sy);
+ virtual void skew(float sx, float sy);
+
+ void setMatrix(const Matrix4& matrix); // internal only convenience method
+ void concatMatrix(const Matrix4& matrix); // internal only convenience method
+
+ virtual const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); }
+ const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
+ virtual bool quickRejectConservative(float left, float top, float right, float bottom) const {
+ return mState.quickRejectConservative(left, top, right, bottom);
+ }
+
+ virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
+ virtual bool clipPath(const SkPath* path, SkRegion::Op op);
+ virtual bool clipRegion(const SkRegion* region, SkRegion::Op op);
+
+ /**
+ * Does not support different clipping Ops (that is, every call to setClippingOutline is
+ * effectively using SkRegion::kReplaceOp)
+ *
+ * The clipping outline is independent from the regular clip.
+ */
+ void setClippingOutline(LinearAllocator& allocator, const Outline* outline);
+ void setClippingRoundRect(LinearAllocator& allocator,
+ const Rect& rect, float radius, bool highPriority = true);
+
+ inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); }
+ inline const mat4* currentTransform() const { return mState.currentTransform(); }
+
+ ///////////////////////////////////////////////////////////////////
+ /// CanvasStateClient interface
+
+ virtual void onViewportInitialized();
+ virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored);
+ virtual GLuint onGetTargetFbo() const { return 0; }
+
protected:
/**
* Perform the setup specific to a frame. This method does not
@@ -353,12 +395,12 @@ protected:
* Indicates the start of rendering. This method will setup the
* initial OpenGL state (viewport, clearing the buffer, etc.)
*/
- status_t startFrame();
+ void startFrame();
/**
* Clears the underlying surface if needed.
*/
- virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
+ virtual void clear(float left, float top, float right, float bottom, bool opaque);
/**
* Call this method after updating a layer during a drawing pass.
@@ -405,22 +447,16 @@ protected:
* Returns the region of the current layer.
*/
virtual Region* getRegion() const {
- return mSnapshot->region;
+ return mState.currentRegion();
}
/**
* Indicates whether rendering is currently targeted at a layer.
*/
virtual bool hasLayer() const {
- return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
+ return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion();
}
- /**
- * Returns the name of the FBO this renderer is rendering into.
- */
- virtual GLuint getTargetFbo() const {
- return 0;
- }
/**
* Renders the specified layer as a textured quad.
@@ -473,6 +509,8 @@ protected:
inline RenderState& renderState() { return mRenderState; }
+ CanvasState mState;
+
private:
/**
* Discards the content of the framebuffer if supported by the driver.
@@ -508,8 +546,6 @@ private:
*/
void endTiling();
- void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored);
-
/**
* Sets the clipping rectangle using glScissor. The clip is defined by
* the current snapshot's clipRect member.
@@ -623,7 +659,7 @@ private:
* @param dirty True if calling this method should dirty the current layer
* @param clip True if the rects should be clipped, false otherwise
*/
- status_t drawColorRects(const float* rects, int count, const SkPaint* paint,
+ void drawColorRects(const float* rects, int count, const SkPaint* paint,
bool ignoreTransform = false, bool dirty = true, bool clip = true);
/**
@@ -637,7 +673,7 @@ private:
* @param texture The texture reprsenting the shape
* @param paint The paint to draw the shape with
*/
- status_t drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
+ void drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
/**
* Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
@@ -657,15 +693,15 @@ private:
* @param paint The paint to render with
* @param flags flags with which to draw
*/
- status_t drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
+ void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
const SkPaint* paint, int flags = 0);
/**
* Convenience for translating method
*/
- status_t drawVertexBuffer(const VertexBuffer& vertexBuffer,
+ void drawVertexBuffer(const VertexBuffer& vertexBuffer,
const SkPaint* paint, int flags = 0) {
- return drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
+ drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
}
/**
@@ -674,7 +710,7 @@ private:
* @param path The hull of the path to draw
* @param paint The paint to render with
*/
- status_t drawConvexPath(const SkPath& path, const SkPaint* paint);
+ void drawConvexPath(const SkPath& path, const SkPaint* paint);
/**
* Draws a textured rectangle with the specified texture. The specified coordinates
@@ -925,9 +961,7 @@ private:
/**
* Should be invoked every time the glScissor is modified.
*/
- inline void dirtyClip() {
- mDirtyClip = true;
- }
+ inline void dirtyClip() { mState.setDirtyClip(true); }
inline const UvMapper& getMapper(const Texture* texture) {
return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
@@ -940,6 +974,10 @@ private:
*/
Texture* getTexture(const SkBitmap* bitmap);
+ bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; }
+ inline Snapshot* writableSnapshot() { return mState.writableSnapshot(); }
+ inline const Snapshot* currentSnapshot() const { return mState.currentSnapshot(); }
+
/**
* Model-view matrix used to position/size objects
*
@@ -1008,6 +1046,10 @@ private:
bool mSkipOutlineClip;
+ // True if anything has been drawn since the last call to
+ // reportAndClearDirty()
+ bool mDirty;
+
// Lighting + shadows
Vector3 mLightCenter;
float mLightRadius;