diff options
| author | 2013-12-30 21:55:47 +0000 | |
|---|---|---|
| committer | 2013-12-30 21:55:47 +0000 | |
| commit | 539394ec3aee7b5868c14e5e692684c8a875a3d4 (patch) | |
| tree | 06e255c1d3f11f750f567bf22453957b1062d648 | |
| parent | aa161c600dc17cd33c7276e61fb258dca6aa293d (diff) | |
| parent | b458942bb6e6cf13c68341dda35ef5cee060f5ae (diff) | |
Merge "Create abstract base class for OpenGLRenderer"
| -rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/DisplayList.cpp | 3 | ||||
| -rw-r--r-- | libs/hwui/DisplayListRenderer.cpp | 9 | ||||
| -rw-r--r-- | libs/hwui/DisplayListRenderer.h | 4 | ||||
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 28 | ||||
| -rw-r--r-- | libs/hwui/OpenGLRenderer.h | 112 | ||||
| -rw-r--r-- | libs/hwui/Renderer.h | 267 |
7 files changed, 294 insertions, 131 deletions
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 09003fd9999c..b0b5a5c865e1 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -498,7 +498,7 @@ static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz, renderer->drawBitmapData(bitmap, left, top, paint); // If the renderer is a deferred renderer it will own the bitmap - if (!renderer->isDeferred()) { + if (!renderer->isRecording()) { delete bitmap; } } diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp index 3853d31a144b..caed2b17f723 100644 --- a/libs/hwui/DisplayList.cpp +++ b/libs/hwui/DisplayList.cpp @@ -417,8 +417,7 @@ void DisplayList::setViewProperties(OpenGLRenderer& renderer, T& handler, } if (mMatrixFlags != 0) { if (mMatrixFlags == TRANSLATION) { - renderer.translate(mTranslationX, mTranslationY); - renderer.translateZ(mTranslationZ); + renderer.translate(mTranslationX, mTranslationY, mTranslationZ); } else { if (Caches::getInstance().propertyEnable3d) { renderer.concatMatrix(mTransform); diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp index 19a027df7be6..31a7db6461c6 100644 --- a/libs/hwui/DisplayListRenderer.cpp +++ b/libs/hwui/DisplayListRenderer.cpp @@ -116,10 +116,6 @@ DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) { return displayList; } -bool DisplayListRenderer::isDeferred() { - return true; -} - void DisplayListRenderer::setViewport(int width, int height) { // TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1); @@ -188,12 +184,13 @@ int DisplayListRenderer::saveLayer(float left, float top, float right, float bot return OpenGLRenderer::save(flags); } -void DisplayListRenderer::translate(float dx, float dy) { +void DisplayListRenderer::translate(float dx, float dy, float dz) { + // ignore dz, not used at defer time mHasTranslate = true; mTranslateX += dx; mTranslateY += dy; insertRestoreToCount(); - OpenGLRenderer::translate(dx, dy); + OpenGLRenderer::translate(dx, dy, dz); } void DisplayListRenderer::rotate(float degrees) { diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h index 726937829818..b6244e43fe4b 100644 --- a/libs/hwui/DisplayListRenderer.h +++ b/libs/hwui/DisplayListRenderer.h @@ -63,7 +63,7 @@ public: ANDROID_API DisplayList* getDisplayList(DisplayList* displayList); - virtual bool isDeferred(); + virtual bool isRecording() { return true; } virtual void setViewport(int width, int height); virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque); @@ -81,7 +81,7 @@ public: virtual int saveLayer(float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode, int flags); - virtual void translate(float dx, float dy); + virtual void translate(float dx, float dy, float dz); virtual void rotate(float degrees); virtual void scale(float sx, float sy); virtual void skew(float sx, float sy); diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index cdef94e29a8e..c30d86fbd773 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -156,22 +156,6 @@ void OpenGLRenderer::initProperties() { // Setup /////////////////////////////////////////////////////////////////////////////// -void OpenGLRenderer::setName(const char* name) { - if (name) { - mName.setTo(name); - } else { - mName.clear(); - } -} - -const char* OpenGLRenderer::getName() const { - return mName.string(); -} - -bool OpenGLRenderer::isDeferred() { - return false; -} - void OpenGLRenderer::setViewport(int width, int height) { initViewport(width, height); @@ -1524,8 +1508,8 @@ void OpenGLRenderer::setupMergedMultiDraw(const Rect* clipRect) { // Transforms /////////////////////////////////////////////////////////////////////////////// -void OpenGLRenderer::translate(float dx, float dy) { - currentTransform().translate(dx, dy); +void OpenGLRenderer::translate(float dx, float dy, float dz) { + currentTransform().translate(dx, dy, dz); } void OpenGLRenderer::rotate(float degrees) { @@ -1552,7 +1536,7 @@ bool OpenGLRenderer::hasRectToRectTransform() { return CC_LIKELY(currentTransform().rectToRect()); } -void OpenGLRenderer::getMatrix(SkMatrix* matrix) { +void OpenGLRenderer::getMatrix(SkMatrix* matrix) const { currentTransform().copyTo(*matrix); } @@ -1642,7 +1626,7 @@ void OpenGLRenderer::setStencilFromClip() { } } -const Rect& OpenGLRenderer::getClipBounds() { +const Rect& OpenGLRenderer::getClipBounds() const { return mSnapshot->getLocalClip(); } @@ -1728,7 +1712,7 @@ bool OpenGLRenderer::quickRejectSetupScissor(float left, float top, float right, return true; } - if (!isDeferred()) { + if (!isRecording()) { // not quick rejected, so enable the scissor if clipRequired mCaches.setScissorEnabled(mScissorOptimizationDisabled || clipRequired); } @@ -1737,7 +1721,7 @@ bool OpenGLRenderer::quickRejectSetupScissor(float left, float top, float right, void OpenGLRenderer::debugClip() { #if DEBUG_CLIP_REGIONS - if (!isDeferred() && !mSnapshot->clipRegion->isEmpty()) { + if (!isRecording() && !mSnapshot->clipRegion->isEmpty()) { drawRegionRects(*mSnapshot->clipRegion, 0x7f00ff00, SkXfermode::kSrcOver_Mode); } #endif diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h index 60465315c65a..2d6a7e995995 100644 --- a/libs/hwui/OpenGLRenderer.h +++ b/libs/hwui/OpenGLRenderer.h @@ -41,16 +41,22 @@ #include "Matrix.h" #include "Program.h" #include "Rect.h" -#include "Snapshot.h" -#include "Vertex.h" -#include "SkiaShader.h" +#include "Renderer.h" #include "SkiaColorFilter.h" +#include "Snapshot.h" #include "UvMapper.h" +#include "Vertex.h" #include "Caches.h" namespace android { namespace uirenderer { +class DeferredDisplayState; +class DisplayList; +class TextSetupFunctor; +class VertexBuffer; +class SkiaShader; + struct DrawModifiers { DrawModifiers() { reset(); @@ -82,12 +88,6 @@ enum StateDeferFlags { kStateDeferFlag_Clip = 0x2 }; -enum DrawOpMode { - kDrawOpMode_Immediate, - kDrawOpMode_Defer, - kDrawOpMode_Flush -}; - enum ClipSideFlags { kClipSide_None = 0x0, kClipSide_Left = 0x1, @@ -119,102 +119,24 @@ enum ModelViewMode { /////////////////////////////////////////////////////////////////////////////// // Renderer /////////////////////////////////////////////////////////////////////////////// - -class DeferredDisplayState; -class DisplayList; -class TextSetupFunctor; -class VertexBuffer; - /** * OpenGL renderer used to draw accelerated 2D graphics. The API is a * simplified version of Skia's Canvas API. */ -class OpenGLRenderer { +class OpenGLRenderer : public Renderer { public: ANDROID_API OpenGLRenderer(); virtual ~OpenGLRenderer(); - /** - * Sets the name of this renderer. The name is optional and - * empty by default. If the pointer is null the name is set - * to the empty string. - */ - ANDROID_API void setName(const char* name); - - /** - * Returns the name of this renderer as UTF8 string. - * The returned pointer is never null. - */ - ANDROID_API const char* getName() const; - - /** - * Read externally defined properties to control the behavior - * of the renderer. - */ ANDROID_API void initProperties(); - /** - * Indicates whether this renderer executes drawing commands immediately. - * If this method returns true, the drawing commands will be executed - * later. - */ - virtual bool isDeferred(); - - /** - * Sets the dimension of the underlying drawing surface. This method must - * be called at least once every time the drawing surface changes size. - * - * @param width The width in pixels of the underlysing surface - * @param height The height in pixels of the underlysing surface - */ virtual void setViewport(int width, int height); - /** - * Prepares the renderer to draw a frame. This method must be invoked - * at the beginning of each frame. When this method is invoked, the - * entire drawing surface is assumed to be redrawn. - * - * @param opaque If true, the target surface is considered opaque - * and will not be cleared. If false, the target surface - * will be cleared - */ - ANDROID_API status_t prepare(bool opaque); - - /** - * Prepares the renderer to draw a frame. This method must be invoked - * at the beginning of each frame. Only the specified rectangle of the - * frame is assumed to be dirty. A clip will automatically be set to - * the specified rectangle. - * - * @param left The left coordinate of the dirty rectangle - * @param top The top coordinate of the dirty rectangle - * @param right The right coordinate of the dirty rectangle - * @param bottom The bottom coordinate of the dirty rectangle - * @param opaque If true, the target surface is considered opaque - * and will not be cleared. If false, the target surface - * will be cleared in the specified dirty rectangle - */ + virtual status_t prepare(bool opaque); virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque); - /** - * Indicates the end of a frame. This method must be invoked whenever - * the caller is done rendering a frame. - */ virtual void finish(); - - /** - * This method must be invoked before handing control over to a draw functor. - * See callDrawGLFunction() for instance. - * - * This command must not be recorded inside display lists. - */ virtual void interrupt(); - - /** - * This method must be invoked after getting control back from a draw functor. - * - * This command must not be recorded inside display lists. - */ virtual void resume(); ANDROID_API void setCountOverdrawEnabled(bool enabled) { @@ -256,23 +178,20 @@ public: int saveLayerDeferred(float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode, int flags); - virtual void translate(float dx, float dy); + virtual void translate(float dx, float dy, float dz = 0); virtual void rotate(float degrees); virtual void scale(float sx, float sy); virtual void skew(float sx, float sy); bool hasRectToRectTransform(); - ANDROID_API void getMatrix(SkMatrix* matrix); + ANDROID_API void getMatrix(SkMatrix* matrix) const; virtual void setMatrix(SkMatrix* matrix); virtual void concatMatrix(SkMatrix* matrix); virtual void concatMatrix(Matrix4& matrix) { currentTransform().multiply(matrix); } - void translateZ(float z) { - currentTransform().translate(0,0,z); - } - ANDROID_API const Rect& getClipBounds(); + ANDROID_API const Rect& getClipBounds() const; ANDROID_API bool quickRejectConservative(float left, float top, float right, float bottom) const; @@ -1161,9 +1080,6 @@ private: bool mCountOverdraw; float mOverdraw; - // Optional name of the renderer - String8 mName; - friend class DisplayListRenderer; friend class Layer; friend class TextSetupFunctor; diff --git a/libs/hwui/Renderer.h b/libs/hwui/Renderer.h new file mode 100644 index 000000000000..ac216fe4e6e8 --- /dev/null +++ b/libs/hwui/Renderer.h @@ -0,0 +1,267 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * 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 ANDROID_HWUI_RENDERER_H +#define ANDROID_HWUI_RENDERER_H + +#include "AssetAtlas.h" +#include "SkPaint.h" + +namespace android { +namespace uirenderer { + +class DisplayList; +class Layer; +class Matrix4; +class SkiaColorFilter; +class SkiaShader; +class Patch; + +enum DrawOpMode { + kDrawOpMode_Immediate, + kDrawOpMode_Defer, + kDrawOpMode_Flush +}; + +/** + * Hwui's abstract version of Canvas. + * + * Provides methods for frame state operations, as well as the SkCanvas style transform/clip state, + * and varied drawing operations. + * + * Should at some point interact with native SkCanvas. + */ +class ANDROID_API Renderer { +public: + virtual ~Renderer() {} + + /** + * Sets the name of this renderer. The name is optional and empty by default, for debugging + * purposes only. If the pointer is null the name is set to the empty string. + */ + void setName(const char * name) { + if (name) { + mName.setTo(name); + } else { + mName.clear(); + } + } + + /** + * Returns the name of this renderer as UTF8 string. + * The returned pointer is never null. + */ + const char* getName() const { + return mName.string(); + } + + /** + * Indicates whether this renderer is recording drawing commands for later playback. + * If this method returns true, the drawing commands are deferred. + */ + virtual bool isRecording() const { + return false; + } + + /** + * Safely retrieves the mode from the specified xfermode. If the specified + * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode. + */ + static inline SkXfermode::Mode getXfermode(SkXfermode* mode) { + SkXfermode::Mode resultMode; + if (!SkXfermode::AsMode(mode, &resultMode)) { + resultMode = SkXfermode::kSrcOver_Mode; + } + return resultMode; + } + +// ---------------------------------------------------------------------------- +// Frame state operations +// ---------------------------------------------------------------------------- + /** + * Sets the dimension of the underlying drawing surface. This method must + * be called at least once every time the drawing surface changes size. + * + * @param width The width in pixels of the underlysing surface + * @param height The height in pixels of the underlysing surface + */ + virtual void setViewport(int width, int height) = 0; + + /** + * Prepares the renderer to draw a frame. This method must be invoked + * at the beginning of each frame. When this method is invoked, the + * entire drawing surface is assumed to be redrawn. + * + * @param opaque If true, the target surface is considered opaque + * and will not be cleared. If false, the target surface + * will be cleared + */ + virtual status_t prepare(bool opaque) = 0; + + /** + * Prepares the renderer to draw a frame. This method must be invoked + * at the beginning of each frame. Only the specified rectangle of the + * frame is assumed to be dirty. A clip will automatically be set to + * the specified rectangle. + * + * @param left The left coordinate of the dirty rectangle + * @param top The top coordinate of the dirty rectangle + * @param right The right coordinate of the dirty rectangle + * @param bottom The bottom coordinate of the dirty rectangle + * @param opaque If true, the target surface is considered opaque + * and will not be cleared. If false, the target surface + * will be cleared in the specified dirty rectangle + */ + virtual status_t prepareDirty(float left, float top, float right, float bottom, + bool opaque) = 0; + + /** + * Indicates the end of a frame. This method must be invoked whenever + * the caller is done rendering a frame. + */ + virtual void finish() = 0; + + /** + * This method must be invoked before handing control over to a draw functor. + * See callDrawGLFunction() for instance. + * + * This command must not be recorded inside display lists. + */ + virtual void interrupt() = 0; + + /** + * This method must be invoked after getting control back from a draw functor. + * + * This command must not be recorded inside display lists. + */ + virtual void resume() = 0; + +// ---------------------------------------------------------------------------- +// Canvas state operations +// ---------------------------------------------------------------------------- + // getters + virtual int getSaveCount() const = 0; + virtual void getMatrix(SkMatrix* outMatrix) const = 0; + virtual const Rect& getClipBounds() const = 0; + + // save (layer) + virtual int save(int flags) = 0; + virtual void restore() = 0; + virtual void restoreToCount(int saveCount) = 0; + + int saveLayer(float left, float top, float right, float bottom, + const SkPaint* paint, int flags) { + SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode; + int alpha = 255; + if (paint) { + mode = getXfermode(paint->getXfermode()); + alpha = paint->getAlpha(); + } + return saveLayer(left, top, right, bottom, alpha, mode, flags); + } + int saveLayerAlpha(float left, float top, float right, float bottom, + int alpha, int flags) { + return saveLayer(left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags); + } + virtual int saveLayer(float left, float top, float right, float bottom, + int alpha, SkXfermode::Mode mode, int flags) = 0; + + // Matrix + virtual void translate(float dx, float dy, float dz = 0.0f) = 0; + virtual void rotate(float degrees) = 0; + virtual void scale(float sx, float sy) = 0; + virtual void skew(float sx, float sy) = 0; + + virtual void setMatrix(SkMatrix* matrix) = 0; + virtual void concatMatrix(SkMatrix* matrix) = 0; + virtual void concatMatrix(Matrix4& matrix) = 0; + + // Clip + virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) = 0; + virtual bool clipPath(SkPath* path, SkRegion::Op op) = 0; + virtual bool clipRegion(SkRegion* region, SkRegion::Op op) = 0; + + // Misc - should be implemented with SkPaint inspection + virtual void resetShader() = 0; + virtual void setupShader(SkiaShader* shader) = 0; + + virtual void resetColorFilter() = 0; + virtual void setupColorFilter(SkiaColorFilter* filter) = 0; + + virtual void resetShadow() = 0; + virtual void setupShadow(float radius, float dx, float dy, int color) = 0; + + virtual void resetPaintFilter() = 0; + virtual void setupPaintFilter(int clearBits, int setBits) = 0; + +// ---------------------------------------------------------------------------- +// Canvas draw operations +// ---------------------------------------------------------------------------- + virtual status_t drawColor(int color, SkXfermode::Mode mode) = 0; + + // Bitmap-based + virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) = 0; + virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) = 0; + virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, + float srcRight, float srcBottom, float dstLeft, float dstTop, + float dstRight, float dstBottom, SkPaint* paint) = 0; + virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint) = 0; + virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, + float* vertices, int* colors, SkPaint* paint) = 0; + virtual status_t drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, + float left, float top, float right, float bottom, SkPaint* paint) = 0; + + // Shapes + virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint) = 0; + virtual status_t drawRects(const float* rects, int count, SkPaint* paint) = 0; + virtual status_t drawRoundRect(float left, float top, float right, float bottom, + float rx, float ry, SkPaint* paint) = 0; + virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint) = 0; + virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint) = 0; + virtual status_t drawArc(float left, float top, float right, float bottom, + float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) = 0; + virtual status_t drawPath(SkPath* path, SkPaint* paint) = 0; + virtual status_t drawLines(float* points, int count, SkPaint* paint) = 0; + virtual status_t drawPoints(float* points, int count, SkPaint* paint) = 0; + + // Text + virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y, + const float* positions, SkPaint* paint, float totalAdvance, const Rect& bounds, + DrawOpMode drawOpMode = kDrawOpMode_Immediate) = 0; + virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path, + float hOffset, float vOffset, SkPaint* paint) = 0; + virtual status_t drawPosText(const char* text, int bytesCount, int count, + const float* positions, SkPaint* paint) = 0; + +// ---------------------------------------------------------------------------- +// Canvas draw operations - special +// ---------------------------------------------------------------------------- + virtual status_t drawLayer(Layer* layer, float x, float y) = 0; + virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, + int32_t replayFlags) = 0; + + // TODO: rename for consistency + virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty) = 0; + +private: + // Optional name of the renderer + String8 mName; +}; // class Renderer + +}; // namespace uirenderer +}; // namespace android + +#endif // ANDROID_HWUI_RENDERER_H |