summaryrefslogtreecommitdiffstats
path: root/libs/hwui/OpenGLRenderer.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/OpenGLRenderer.h')
-rwxr-xr-xlibs/hwui/OpenGLRenderer.h253
1 files changed, 151 insertions, 102 deletions
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 5eee2e2..9d9b3d2 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,10 @@
#include "Rect.h"
#include "Renderer.h"
#include "Snapshot.h"
-#include "StatefulBaseRenderer.h"
#include "UvMapper.h"
#include "Vertex.h"
#include "Caches.h"
-#include "CanvasProperty.h"
+#include "utils/PaintUtils.h"
class SkShader;
@@ -63,20 +63,14 @@ class TextSetupFunctor;
class VertexBuffer;
struct DrawModifiers {
- DrawModifiers() {
- reset();
- }
+ DrawModifiers()
+ : mOverrideLayerAlpha(0.0f) {}
void reset() {
- memset(this, 0, sizeof(DrawModifiers));
+ mOverrideLayerAlpha = 0.0f;
}
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,14 @@ 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) override;
+ virtual void prepare(bool opaque) override {
+ prepareDirty(0.0f, 0.0f, mState.getWidth(), mState.getHeight(), opaque);
+ }
+ virtual bool finish() override;
- virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
+ virtual void callDrawGLFunction(Functor* functor, Rect& dirty) override;
void pushLayerUpdate(Layer* layer);
void cancelLayerUpdate(Layer* layer);
@@ -144,8 +141,8 @@ public:
void markLayersAsBuildLayers();
virtual int saveLayer(float left, float top, float right, float bottom,
- const SkPaint* paint, int flags) {
- return saveLayer(left, top, right, bottom, paint, flags, NULL);
+ const SkPaint* paint, int flags) override {
+ return saveLayer(left, top, right, bottom, paint, flags, nullptr);
}
// Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if
@@ -156,56 +153,55 @@ 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) override;
+ virtual void drawLayer(Layer* layer, float x, float y);
+ virtual void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) override;
+ 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,
- const float* vertices, const int* colors, const SkPaint* paint);
- status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
+ float dstRight, float dstBottom, const SkPaint* paint) override;
+ virtual void drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) override;
+ virtual void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
+ const float* vertices, const int* colors, const SkPaint* paint) override;
+ 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,
- float left, float top, float right, float bottom, const SkPaint* paint);
- status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
+ virtual void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
+ float left, float top, float right, float bottom, const SkPaint* paint) override;
+ 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,
- const SkPaint* paint);
- virtual status_t 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,
- const SkPaint* paint);
- virtual status_t 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,
- float hOffset, float vOffset, const SkPaint* paint);
- virtual status_t 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 drawColor(int color, SkXfermode::Mode mode) override;
+ virtual void drawRect(float left, float top, float right, float bottom,
+ const SkPaint* paint) override;
+ virtual void drawRoundRect(float left, float top, float right, float bottom,
+ float rx, float ry, const SkPaint* paint) override;
+ virtual void drawCircle(float x, float y, float radius, const SkPaint* paint) override;
+ virtual void drawOval(float left, float top, float right, float bottom,
+ const SkPaint* paint) override;
+ virtual void drawArc(float left, float top, float right, float bottom,
+ float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) override;
+ virtual void drawPath(const SkPath* path, const SkPaint* paint) override;
+ virtual void drawLines(const float* points, int count, const SkPaint* paint) override;
+ virtual void drawPoints(const float* points, int count, const SkPaint* paint) override;
+ virtual void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
+ float hOffset, float vOffset, const SkPaint* paint) override;
+ virtual void drawPosText(const char* text, int bytesCount, int count,
+ const float* positions, const SkPaint* paint) override;
+ 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);
+ DrawOpMode drawOpMode = kDrawOpMode_Immediate) override;
+ virtual void drawRects(const float* rects, int count, const SkPaint* paint) override;
- status_t drawShadow(float casterAlpha,
- const VertexBuffer* ambientShadowVertexBuffer, const VertexBuffer* spotShadowVertexBuffer);
+ 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) override;
// 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 +224,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.
@@ -275,14 +267,15 @@ public:
* @param alpha Where to store the resulting alpha
* @param mode Where to store the resulting xfermode
*/
- static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
+ static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha,
+ SkXfermode::Mode* mode) {
*mode = getXfermodeDirect(paint);
*alpha = getAlphaDirect(paint);
}
static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) {
if (!paint) return SkXfermode::kSrcOver_Mode;
- return getXfermode(paint->getXfermode());
+ return PaintUtils::getXfermode(paint->getXfermode());
}
static inline int getAlphaDirect(const SkPaint* paint) {
@@ -312,7 +305,7 @@ public:
}
static inline bool hasTextShadow(const SkPaint* paint) {
- return getTextShadow(paint, NULL);
+ return getTextShadow(paint, nullptr);
}
/**
@@ -334,18 +327,74 @@ 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) override { mState.setViewport(width, height); }
+
+ virtual int getSaveCount() const override;
+ virtual int save(int flags) override;
+ virtual void restore() override;
+ virtual void restoreToCount(int saveCount) override;
+
+ virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
+ virtual void setMatrix(const SkMatrix& matrix) override { mState.setMatrix(matrix); }
+ virtual void concatMatrix(const SkMatrix& matrix) override { mState.concatMatrix(matrix); }
+
+ virtual void translate(float dx, float dy, float dz = 0.0f) override;
+ virtual void rotate(float degrees) override;
+ virtual void scale(float sx, float sy) override;
+ virtual void skew(float sx, float sy) override;
+
+ void setMatrix(const Matrix4& matrix); // internal only convenience method
+ void concatMatrix(const Matrix4& matrix); // internal only convenience method
+
+ virtual const Rect& getLocalClipBounds() const override { return mState.getLocalClipBounds(); }
+ const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
+ virtual bool quickRejectConservative(float left, float top,
+ float right, float bottom) const override {
+ return mState.quickRejectConservative(left, top, right, bottom);
+ }
+
+ virtual bool clipRect(float left, float top,
+ float right, float bottom, SkRegion::Op op) override;
+ virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
+ virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
+
+ /**
+ * 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() override;
+ virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override;
+ virtual GLuint onGetTargetFbo() const override { return 0; }
+
SkPath* allocPathForFrame() {
- SkPath* path = new SkPath();
- mTempPaths.push_back(path);
- return path;
+ std::unique_ptr<SkPath> path(new SkPath());
+ SkPath* returnPath = path.get();
+ mTempPaths.push_back(std::move(path));
+ return returnPath;
}
protected:
@@ -359,12 +408,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.
@@ -385,8 +434,8 @@ protected:
void attachStencilBufferToLayer(Layer* layer);
bool quickRejectSetupScissor(float left, float top, float right, float bottom,
- const SkPaint* paint = NULL);
- bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) {
+ const SkPaint* paint = nullptr);
+ bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = nullptr) {
return quickRejectSetupScissor(bounds.left, bounds.top,
bounds.right, bounds.bottom, paint);
}
@@ -411,22 +460,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.
@@ -459,7 +502,7 @@ protected:
* null then null is returned.
*/
static inline SkColorFilter* getColorFilter(const SkPaint* paint) {
- return paint ? paint->getColorFilter() : NULL;
+ return paint ? paint->getColorFilter() : nullptr;
}
/**
@@ -467,7 +510,7 @@ protected:
* null then null is returned.
*/
static inline const SkShader* getShader(const SkPaint* paint) {
- return paint ? paint->getShader() : NULL;
+ return paint ? paint->getShader() : nullptr;
}
/**
@@ -479,6 +522,8 @@ protected:
inline RenderState& renderState() { return mRenderState; }
+ CanvasState mState;
+
private:
/**
* Discards the content of the framebuffer if supported by the driver.
@@ -514,8 +559,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.
@@ -629,7 +672,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);
/**
@@ -643,7 +686,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
@@ -663,15 +706,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);
}
/**
@@ -680,7 +723,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
@@ -867,8 +910,8 @@ private:
* space must be scaled up and translated to fill the quad provided in (l,t,r,b). These
* transformations are stored in the modelView matrix and uploaded to the shader.
*
- * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate
- * geometry pixel positioning. See Vertex::GeometryFudgeFactor().
+ * @param offset Set to true if the the matrix should be fudged (translated) slightly to
+ * disambiguate geometry pixel positioning. See Vertex::GeometryFudgeFactor().
*
* @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space,
* currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil,
@@ -894,7 +937,7 @@ private:
void setupDrawTextureTransform();
void setupDrawTextureTransformUniforms(mat4& transform);
void setupDrawTextGammaUniforms();
- void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0);
+ void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = nullptr, GLuint vbo = 0);
void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors);
void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0);
void setupDrawIndexedVertices(GLvoid* vertices);
@@ -931,9 +974,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;
@@ -946,6 +987,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
*
@@ -985,7 +1030,7 @@ private:
RenderState& mRenderState;
// List of rectangles to clear after saveLayer() is invoked
- Vector<Rect*> mLayers;
+ std::vector<Rect> mLayers;
// List of layers to update at the beginning of a frame
Vector< sp<Layer> > mLayerUpdates;
@@ -1014,6 +1059,10 @@ private:
bool mSkipOutlineClip;
+ // True if anything has been drawn since the last call to
+ // reportAndClearDirty()
+ bool mDirty;
+
// Lighting + shadows
Vector3 mLightCenter;
float mLightRadius;
@@ -1021,7 +1070,7 @@ private:
uint8_t mSpotShadowAlpha;
// Paths kept alive for the duration of the frame
- std::vector<SkPath*> mTempPaths;
+ std::vector<std::unique_ptr<SkPath>> mTempPaths;
friend class Layer;
friend class TextSetupFunctor;