Merge "Reduce the size of libhwui by 50%"

This commit is contained in:
Romain Guy
2011-10-12 13:50:11 -07:00
committed by Android (Google) Code Review
11 changed files with 111 additions and 88 deletions

View File

@@ -20,12 +20,13 @@
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
#include <utils/threads.h> #include <utils/threads.h>
#include <cutils/compiler.h>
namespace android { namespace android {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
template <typename TYPE> template <typename TYPE>
class Singleton class ANDROID_API Singleton
{ {
public: public:
static TYPE& getInstance() { static TYPE& getInstance() {

View File

@@ -39,6 +39,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)
external/skia/include/utils external/skia/include/utils
LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER
LOCAL_CFLAGS += -fvisibility=hidden
LOCAL_MODULE_CLASS := SHARED_LIBRARIES LOCAL_MODULE_CLASS := SHARED_LIBRARIES
LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
LOCAL_MODULE := libhwui LOCAL_MODULE := libhwui

View File

@@ -23,6 +23,8 @@
#include <utils/Singleton.h> #include <utils/Singleton.h>
#include <cutils/compiler.h>
#include "Extensions.h" #include "Extensions.h"
#include "FontRenderer.h" #include "FontRenderer.h"
#include "GammaFontRenderer.h" #include "GammaFontRenderer.h"
@@ -82,7 +84,7 @@ struct CacheLogger {
// Caches // Caches
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class Caches: public Singleton<Caches> { class ANDROID_API Caches: public Singleton<Caches> {
Caches(); Caches();
~Caches(); ~Caches();

View File

@@ -18,6 +18,7 @@
#define ANDROID_HWUI_DISPLAY_LIST_LOG_BUFFER_H #define ANDROID_HWUI_DISPLAY_LIST_LOG_BUFFER_H
#include <utils/Singleton.h> #include <utils/Singleton.h>
#include <stdio.h> #include <stdio.h>
namespace android { namespace android {

View File

@@ -26,6 +26,8 @@
#include <SkTDArray.h> #include <SkTDArray.h>
#include <SkTSearch.h> #include <SkTSearch.h>
#include <cutils/compiler.h>
#include "DisplayListLogBuffer.h" #include "DisplayListLogBuffer.h"
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "utils/Functor.h" #include "utils/Functor.h"
@@ -58,7 +60,7 @@ class DisplayListRenderer;
class DisplayList { class DisplayList {
public: public:
DisplayList(const DisplayListRenderer& recorder); DisplayList(const DisplayListRenderer& recorder);
~DisplayList(); ANDROID_API ~DisplayList();
// IMPORTANT: Update the intialization of OP_NAMES in the .cpp file // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
// when modifying this file // when modifying this file
@@ -107,13 +109,13 @@ public:
void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
size_t getSize(); ANDROID_API size_t getSize();
bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0); bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0);
void output(OpenGLRenderer& renderer, uint32_t level = 0); void output(OpenGLRenderer& renderer, uint32_t level = 0);
static void outputLogBuffer(int fd); ANDROID_API static void outputLogBuffer(int fd);
void setRenderable(bool renderable) { void setRenderable(bool renderable) {
mIsRenderable = renderable; mIsRenderable = renderable;
@@ -230,75 +232,76 @@ private:
*/ */
class DisplayListRenderer: public OpenGLRenderer { class DisplayListRenderer: public OpenGLRenderer {
public: public:
DisplayListRenderer(); ANDROID_API DisplayListRenderer();
~DisplayListRenderer(); virtual ~DisplayListRenderer();
DisplayList* getDisplayList(DisplayList* displayList); ANDROID_API DisplayList* getDisplayList(DisplayList* displayList);
void setViewport(int width, int height); virtual void setViewport(int width, int height);
void prepareDirty(float left, float top, float right, float bottom, bool opaque); virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
void finish(); virtual void finish();
bool callDrawGLFunction(Functor *functor, Rect& dirty); virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
void interrupt(); virtual void interrupt();
void resume(); virtual void resume();
int save(int flags); virtual int save(int flags);
void restore(); virtual void restore();
void restoreToCount(int saveCount); virtual void restoreToCount(int saveCount);
int saveLayer(float left, float top, float right, float bottom, virtual int saveLayer(float left, float top, float right, float bottom,
SkPaint* p, int flags); SkPaint* p, int flags);
int saveLayerAlpha(float left, float top, float right, float bottom, virtual int saveLayerAlpha(float left, float top, float right, float bottom,
int alpha, int flags); int alpha, int flags);
void translate(float dx, float dy); virtual void translate(float dx, float dy);
void rotate(float degrees); virtual void rotate(float degrees);
void scale(float sx, float sy); virtual void scale(float sx, float sy);
void skew(float sx, float sy); virtual void skew(float sx, float sy);
void setMatrix(SkMatrix* matrix); virtual void setMatrix(SkMatrix* matrix);
void concatMatrix(SkMatrix* matrix); virtual void concatMatrix(SkMatrix* matrix);
bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
Rect& dirty, uint32_t level = 0); Rect& dirty, uint32_t level = 0);
void drawLayer(Layer* layer, float x, float y, SkPaint* paint); virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint); virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint); virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop, float srcRight, float srcBottom, float dstLeft, float dstTop,
float dstRight, float dstBottom, SkPaint* paint); float dstRight, float dstBottom, SkPaint* paint);
void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
float* vertices, int* colors, SkPaint* paint); float* vertices, int* colors, SkPaint* paint);
void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
float left, float top, float right, float bottom, SkPaint* paint); float left, float top, float right, float bottom, SkPaint* paint);
void drawColor(int color, SkXfermode::Mode mode); virtual void drawColor(int color, SkXfermode::Mode mode);
void drawRect(float left, float top, float right, float bottom, SkPaint* paint); virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
void drawRoundRect(float left, float top, float right, float bottom, virtual void drawRoundRect(float left, float top, float right, float bottom,
float rx, float ry, SkPaint* paint); float rx, float ry, SkPaint* paint);
void drawCircle(float x, float y, float radius, SkPaint* paint); virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
void drawOval(float left, float top, float right, float bottom, SkPaint* paint); virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
void 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, SkPaint* paint); float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
void drawPath(SkPath* path, SkPaint* paint); virtual void drawPath(SkPath* path, SkPaint* paint);
void drawLines(float* points, int count, SkPaint* paint); virtual void drawLines(float* points, int count, SkPaint* paint);
void drawPoints(float* points, int count, SkPaint* paint); virtual void drawPoints(float* points, int count, SkPaint* paint);
void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint); virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
SkPaint* paint);
void resetShader(); virtual void resetShader();
void setupShader(SkiaShader* shader); virtual void setupShader(SkiaShader* shader);
void resetColorFilter(); virtual void resetColorFilter();
void setupColorFilter(SkiaColorFilter* filter); virtual void setupColorFilter(SkiaColorFilter* filter);
void resetShadow(); virtual void resetShadow();
void setupShadow(float radius, float dx, float dy, int color); virtual void setupShadow(float radius, float dx, float dy, int color);
void reset(); ANDROID_API void reset();
const SkWriter32& writeStream() const { const SkWriter32& writeStream() const {
return mWriter; return mWriter;

View File

@@ -31,6 +31,12 @@ namespace uirenderer {
// Rendering // Rendering
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
LayerRenderer::LayerRenderer(Layer* layer): mLayer(layer) {
}
LayerRenderer::~LayerRenderer() {
}
void LayerRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) { void LayerRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) {
LAYER_RENDERER_LOGD("Rendering into layer, fbo = %d", mLayer->getFbo()); LAYER_RENDERER_LOGD("Rendering into layer, fbo = %d", mLayer->getFbo());

View File

@@ -17,6 +17,8 @@
#ifndef ANDROID_HWUI_LAYER_RENDERER_H #ifndef ANDROID_HWUI_LAYER_RENDERER_H
#define ANDROID_HWUI_LAYER_RENDERER_H #define ANDROID_HWUI_LAYER_RENDERER_H
#include <cutils/compiler.h>
#include "OpenGLRenderer.h" #include "OpenGLRenderer.h"
#include "Layer.h" #include "Layer.h"
@@ -42,27 +44,24 @@ namespace uirenderer {
class LayerRenderer: public OpenGLRenderer { class LayerRenderer: public OpenGLRenderer {
public: public:
LayerRenderer(Layer* layer): mLayer(layer) { ANDROID_API LayerRenderer(Layer* layer);
} virtual ~LayerRenderer();
~LayerRenderer() { virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
} virtual void finish();
void prepareDirty(float left, float top, float right, float bottom, bool opaque); virtual bool hasLayer();
void finish(); virtual Region* getRegion();
virtual GLint getTargetFbo();
bool hasLayer(); ANDROID_API static Layer* createTextureLayer(bool isOpaque);
Region* getRegion(); ANDROID_API static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false);
GLint getTargetFbo(); ANDROID_API static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height);
ANDROID_API static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height,
static Layer* createTextureLayer(bool isOpaque);
static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false);
static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height);
static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height,
bool isOpaque, GLenum renderTarget, float* transform); bool isOpaque, GLenum renderTarget, float* transform);
static void destroyLayer(Layer* layer); ANDROID_API static void destroyLayer(Layer* layer);
static void destroyLayerDeferred(Layer* layer); ANDROID_API static void destroyLayerDeferred(Layer* layer);
static bool copyLayer(Layer* layer, SkBitmap* bitmap); ANDROID_API static bool copyLayer(Layer* layer, SkBitmap* bitmap);
private: private:
void generateMesh(); void generateMesh();

View File

@@ -31,6 +31,8 @@
#include <utils/RefBase.h> #include <utils/RefBase.h>
#include <utils/Vector.h> #include <utils/Vector.h>
#include <cutils/compiler.h>
#include "Debug.h" #include "Debug.h"
#include "Extensions.h" #include "Extensions.h"
#include "Matrix.h" #include "Matrix.h"
@@ -57,12 +59,12 @@ class DisplayList;
*/ */
class OpenGLRenderer { class OpenGLRenderer {
public: public:
OpenGLRenderer(); ANDROID_API OpenGLRenderer();
virtual ~OpenGLRenderer(); virtual ~OpenGLRenderer();
virtual void setViewport(int width, int height); virtual void setViewport(int width, int height);
void prepare(bool opaque); ANDROID_API void prepare(bool opaque);
virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque); virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
virtual void finish(); virtual void finish();
@@ -72,7 +74,7 @@ public:
virtual bool callDrawGLFunction(Functor *functor, Rect& dirty); virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
int getSaveCount() const; ANDROID_API int getSaveCount() const;
virtual int save(int flags); virtual int save(int flags);
virtual void restore(); virtual void restore();
virtual void restoreToCount(int saveCount); virtual void restoreToCount(int saveCount);
@@ -87,12 +89,12 @@ public:
virtual void scale(float sx, float sy); virtual void scale(float sx, float sy);
virtual void skew(float sx, float sy); virtual void skew(float sx, float sy);
void getMatrix(SkMatrix* matrix); ANDROID_API void getMatrix(SkMatrix* matrix);
virtual void setMatrix(SkMatrix* matrix); virtual void setMatrix(SkMatrix* matrix);
virtual void concatMatrix(SkMatrix* matrix); virtual void concatMatrix(SkMatrix* matrix);
const Rect& getClipBounds(); ANDROID_API const Rect& getClipBounds();
bool quickReject(float left, float top, float right, float bottom); ANDROID_API bool quickReject(float left, float top, float right, float bottom);
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,

View File

@@ -17,6 +17,8 @@
#ifndef ANDROID_HWUI_RESOURCE_CACHE_H #ifndef ANDROID_HWUI_RESOURCE_CACHE_H
#define ANDROID_HWUI_RESOURCE_CACHE_H #define ANDROID_HWUI_RESOURCE_CACHE_H
#include <cutils/compiler.h>
#include <SkBitmap.h> #include <SkBitmap.h>
#include <SkiaColorFilter.h> #include <SkiaColorFilter.h>
#include <SkiaShader.h> #include <SkiaShader.h>
@@ -49,7 +51,7 @@ public:
ResourceType resourceType; ResourceType resourceType;
}; };
class ResourceCache { class ANDROID_API ResourceCache {
KeyedVector<void *, ResourceReference *>* mCache; KeyedVector<void *, ResourceReference *>* mCache;
public: public:
ResourceCache(); ResourceCache();

View File

@@ -20,6 +20,8 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <SkColorFilter.h> #include <SkColorFilter.h>
#include <cutils/compiler.h>
#include "ProgramCache.h" #include "ProgramCache.h"
#include "Extensions.h" #include "Extensions.h"
@@ -45,7 +47,7 @@ struct SkiaColorFilter {
kBlend, kBlend,
}; };
SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend); ANDROID_API SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend);
virtual ~SkiaColorFilter(); virtual ~SkiaColorFilter();
virtual void describe(ProgramDescription& description, const Extensions& extensions) = 0; virtual void describe(ProgramDescription& description, const Extensions& extensions) = 0;
@@ -79,7 +81,7 @@ private:
* A color filter that multiplies the source color with a matrix and adds a vector. * A color filter that multiplies the source color with a matrix and adds a vector.
*/ */
struct SkiaColorMatrixFilter: public SkiaColorFilter { struct SkiaColorMatrixFilter: public SkiaColorFilter {
SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector); ANDROID_API SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector);
~SkiaColorMatrixFilter(); ~SkiaColorMatrixFilter();
void describe(ProgramDescription& description, const Extensions& extensions); void describe(ProgramDescription& description, const Extensions& extensions);
@@ -95,7 +97,7 @@ private:
* another fixed value. Ignores the alpha channel of both arguments. * another fixed value. Ignores the alpha channel of both arguments.
*/ */
struct SkiaLightingFilter: public SkiaColorFilter { struct SkiaLightingFilter: public SkiaColorFilter {
SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add); ANDROID_API SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add);
void describe(ProgramDescription& description, const Extensions& extensions); void describe(ProgramDescription& description, const Extensions& extensions);
void setupProgram(Program* program); void setupProgram(Program* program);
@@ -110,7 +112,7 @@ private:
* and PorterDuff blending mode. * and PorterDuff blending mode.
*/ */
struct SkiaBlendFilter: public SkiaColorFilter { struct SkiaBlendFilter: public SkiaColorFilter {
SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode); ANDROID_API SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode);
void describe(ProgramDescription& description, const Extensions& extensions); void describe(ProgramDescription& description, const Extensions& extensions);
void setupProgram(Program* program); void setupProgram(Program* program);

View File

@@ -22,6 +22,8 @@
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <cutils/compiler.h>
#include "Extensions.h" #include "Extensions.h"
#include "ProgramCache.h" #include "ProgramCache.h"
#include "TextureCache.h" #include "TextureCache.h"
@@ -52,8 +54,8 @@ struct SkiaShader {
kCompose kCompose
}; };
SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX, SkShader::TileMode tileY, ANDROID_API SkiaShader(Type type, SkShader* key, SkShader::TileMode tileX,
SkMatrix* matrix, bool blend); SkShader::TileMode tileY, SkMatrix* matrix, bool blend);
virtual ~SkiaShader(); virtual ~SkiaShader();
virtual SkiaShader* copy() = 0; virtual SkiaShader* copy() = 0;
@@ -139,7 +141,7 @@ private:
* A shader that draws a bitmap. * A shader that draws a bitmap.
*/ */
struct SkiaBitmapShader: public SkiaShader { struct SkiaBitmapShader: public SkiaShader {
SkiaBitmapShader(SkBitmap* bitmap, SkShader* key, SkShader::TileMode tileX, ANDROID_API SkiaBitmapShader(SkBitmap* bitmap, SkShader* key, SkShader::TileMode tileX,
SkShader::TileMode tileY, SkMatrix* matrix, bool blend); SkShader::TileMode tileY, SkMatrix* matrix, bool blend);
SkiaShader* copy(); SkiaShader* copy();
@@ -169,8 +171,8 @@ private:
* A shader that draws a linear gradient. * A shader that draws a linear gradient.
*/ */
struct SkiaLinearGradientShader: public SkiaShader { struct SkiaLinearGradientShader: public SkiaShader {
SkiaLinearGradientShader(float* bounds, uint32_t* colors, float* positions, int count, ANDROID_API SkiaLinearGradientShader(float* bounds, uint32_t* colors, float* positions,
SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend); int count, SkShader* key, SkShader::TileMode tileMode, SkMatrix* matrix, bool blend);
~SkiaLinearGradientShader(); ~SkiaLinearGradientShader();
SkiaShader* copy(); SkiaShader* copy();
@@ -193,8 +195,8 @@ private:
* A shader that draws a sweep gradient. * A shader that draws a sweep gradient.
*/ */
struct SkiaSweepGradientShader: public SkiaShader { struct SkiaSweepGradientShader: public SkiaShader {
SkiaSweepGradientShader(float x, float y, uint32_t* colors, float* positions, int count, ANDROID_API SkiaSweepGradientShader(float x, float y, uint32_t* colors, float* positions,
SkShader* key, SkMatrix* matrix, bool blend); int count, SkShader* key, SkMatrix* matrix, bool blend);
~SkiaSweepGradientShader(); ~SkiaSweepGradientShader();
SkiaShader* copy(); SkiaShader* copy();
@@ -218,8 +220,9 @@ protected:
* A shader that draws a circular gradient. * A shader that draws a circular gradient.
*/ */
struct SkiaCircularGradientShader: public SkiaSweepGradientShader { struct SkiaCircularGradientShader: public SkiaSweepGradientShader {
SkiaCircularGradientShader(float x, float y, float radius, uint32_t* colors, float* positions, ANDROID_API SkiaCircularGradientShader(float x, float y, float radius, uint32_t* colors,
int count, SkShader* key,SkShader::TileMode tileMode, SkMatrix* matrix, bool blend); float* positions, int count, SkShader* key,SkShader::TileMode tileMode,
SkMatrix* matrix, bool blend);
SkiaShader* copy(); SkiaShader* copy();
void describe(ProgramDescription& description, const Extensions& extensions); void describe(ProgramDescription& description, const Extensions& extensions);
@@ -233,7 +236,8 @@ private:
* A shader that draws two shaders, composited with an xfermode. * A shader that draws two shaders, composited with an xfermode.
*/ */
struct SkiaComposeShader: public SkiaShader { struct SkiaComposeShader: public SkiaShader {
SkiaComposeShader(SkiaShader* first, SkiaShader* second, SkXfermode::Mode mode, SkShader* key); ANDROID_API SkiaComposeShader(SkiaShader* first, SkiaShader* second, SkXfermode::Mode mode,
SkShader* key);
~SkiaComposeShader(); ~SkiaComposeShader();
SkiaShader* copy(); SkiaShader* copy();