Skip to content

Commit 19de9ef

Browse files
Romain GuyAndroid (Google) Code Review
authored andcommitted
Merge "Reduce the size of libhwui by 50%"
2 parents dc8f432 + 7953745 commit 19de9ef

File tree

11 files changed

+111
-88
lines changed

11 files changed

+111
-88
lines changed

include/utils/Singleton.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
#include <stdint.h>
2121
#include <sys/types.h>
2222
#include <utils/threads.h>
23+
#include <cutils/compiler.h>
2324

2425
namespace android {
2526
// ---------------------------------------------------------------------------
2627

2728
template <typename TYPE>
28-
class Singleton
29+
class ANDROID_API Singleton
2930
{
3031
public:
3132
static TYPE& getInstance() {

libs/hwui/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ifeq ($(USE_OPENGL_RENDERER),true)
3939
external/skia/include/utils
4040

4141
LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER
42+
LOCAL_CFLAGS += -fvisibility=hidden
4243
LOCAL_MODULE_CLASS := SHARED_LIBRARIES
4344
LOCAL_SHARED_LIBRARIES := libcutils libutils libGLESv2 libskia libui
4445
LOCAL_MODULE := libhwui

libs/hwui/Caches.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#include <utils/Singleton.h>
2525

26+
#include <cutils/compiler.h>
27+
2628
#include "Extensions.h"
2729
#include "FontRenderer.h"
2830
#include "GammaFontRenderer.h"
@@ -82,7 +84,7 @@ struct CacheLogger {
8284
// Caches
8385
///////////////////////////////////////////////////////////////////////////////
8486

85-
class Caches: public Singleton<Caches> {
87+
class ANDROID_API Caches: public Singleton<Caches> {
8688
Caches();
8789
~Caches();
8890

libs/hwui/DisplayListLogBuffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define ANDROID_HWUI_DISPLAY_LIST_LOG_BUFFER_H
1919

2020
#include <utils/Singleton.h>
21+
2122
#include <stdio.h>
2223

2324
namespace android {

libs/hwui/DisplayListRenderer.h

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <SkTDArray.h>
2727
#include <SkTSearch.h>
2828

29+
#include <cutils/compiler.h>
30+
2931
#include "DisplayListLogBuffer.h"
3032
#include "OpenGLRenderer.h"
3133
#include "utils/Functor.h"
@@ -58,7 +60,7 @@ class DisplayListRenderer;
5860
class DisplayList {
5961
public:
6062
DisplayList(const DisplayListRenderer& recorder);
61-
~DisplayList();
63+
ANDROID_API ~DisplayList();
6264

6365
// IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
6466
// when modifying this file
@@ -107,13 +109,13 @@ class DisplayList {
107109

108110
void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
109111

110-
size_t getSize();
112+
ANDROID_API size_t getSize();
111113

112114
bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0);
113115

114116
void output(OpenGLRenderer& renderer, uint32_t level = 0);
115117

116-
static void outputLogBuffer(int fd);
118+
ANDROID_API static void outputLogBuffer(int fd);
117119

118120
void setRenderable(bool renderable) {
119121
mIsRenderable = renderable;
@@ -230,75 +232,76 @@ class DisplayList {
230232
*/
231233
class DisplayListRenderer: public OpenGLRenderer {
232234
public:
233-
DisplayListRenderer();
234-
~DisplayListRenderer();
235+
ANDROID_API DisplayListRenderer();
236+
virtual ~DisplayListRenderer();
235237

236-
DisplayList* getDisplayList(DisplayList* displayList);
238+
ANDROID_API DisplayList* getDisplayList(DisplayList* displayList);
237239

238-
void setViewport(int width, int height);
239-
void prepareDirty(float left, float top, float right, float bottom, bool opaque);
240-
void finish();
240+
virtual void setViewport(int width, int height);
241+
virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
242+
virtual void finish();
241243

242-
bool callDrawGLFunction(Functor *functor, Rect& dirty);
244+
virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
243245

244-
void interrupt();
245-
void resume();
246+
virtual void interrupt();
247+
virtual void resume();
246248

247-
int save(int flags);
248-
void restore();
249-
void restoreToCount(int saveCount);
249+
virtual int save(int flags);
250+
virtual void restore();
251+
virtual void restoreToCount(int saveCount);
250252

251-
int saveLayer(float left, float top, float right, float bottom,
253+
virtual int saveLayer(float left, float top, float right, float bottom,
252254
SkPaint* p, int flags);
253-
int saveLayerAlpha(float left, float top, float right, float bottom,
255+
virtual int saveLayerAlpha(float left, float top, float right, float bottom,
254256
int alpha, int flags);
255257

256-
void translate(float dx, float dy);
257-
void rotate(float degrees);
258-
void scale(float sx, float sy);
259-
void skew(float sx, float sy);
258+
virtual void translate(float dx, float dy);
259+
virtual void rotate(float degrees);
260+
virtual void scale(float sx, float sy);
261+
virtual void skew(float sx, float sy);
260262

261-
void setMatrix(SkMatrix* matrix);
262-
void concatMatrix(SkMatrix* matrix);
263+
virtual void setMatrix(SkMatrix* matrix);
264+
virtual void concatMatrix(SkMatrix* matrix);
263265

264-
bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
266+
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
265267

266-
bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
268+
virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
267269
Rect& dirty, uint32_t level = 0);
268-
void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
269-
void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
270-
void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
271-
void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
270+
virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
271+
virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
272+
virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
273+
virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
272274
float srcRight, float srcBottom, float dstLeft, float dstTop,
273275
float dstRight, float dstBottom, SkPaint* paint);
274-
void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
276+
virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
275277
float* vertices, int* colors, SkPaint* paint);
276-
void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
278+
virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
277279
const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
278280
float left, float top, float right, float bottom, SkPaint* paint);
279-
void drawColor(int color, SkXfermode::Mode mode);
280-
void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
281-
void drawRoundRect(float left, float top, float right, float bottom,
281+
virtual void drawColor(int color, SkXfermode::Mode mode);
282+
virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
283+
virtual void drawRoundRect(float left, float top, float right, float bottom,
282284
float rx, float ry, SkPaint* paint);
283-
void drawCircle(float x, float y, float radius, SkPaint* paint);
284-
void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
285-
void drawArc(float left, float top, float right, float bottom,
285+
virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
286+
virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
287+
virtual void drawArc(float left, float top, float right, float bottom,
286288
float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
287-
void drawPath(SkPath* path, SkPaint* paint);
288-
void drawLines(float* points, int count, SkPaint* paint);
289-
void drawPoints(float* points, int count, SkPaint* paint);
290-
void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint);
289+
virtual void drawPath(SkPath* path, SkPaint* paint);
290+
virtual void drawLines(float* points, int count, SkPaint* paint);
291+
virtual void drawPoints(float* points, int count, SkPaint* paint);
292+
virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
293+
SkPaint* paint);
291294

292-
void resetShader();
293-
void setupShader(SkiaShader* shader);
295+
virtual void resetShader();
296+
virtual void setupShader(SkiaShader* shader);
294297

295-
void resetColorFilter();
296-
void setupColorFilter(SkiaColorFilter* filter);
298+
virtual void resetColorFilter();
299+
virtual void setupColorFilter(SkiaColorFilter* filter);
297300

298-
void resetShadow();
299-
void setupShadow(float radius, float dx, float dy, int color);
301+
virtual void resetShadow();
302+
virtual void setupShadow(float radius, float dx, float dy, int color);
300303

301-
void reset();
304+
ANDROID_API void reset();
302305

303306
const SkWriter32& writeStream() const {
304307
return mWriter;

libs/hwui/LayerRenderer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ namespace uirenderer {
3131
// Rendering
3232
///////////////////////////////////////////////////////////////////////////////
3333

34+
LayerRenderer::LayerRenderer(Layer* layer): mLayer(layer) {
35+
}
36+
37+
LayerRenderer::~LayerRenderer() {
38+
}
39+
3440
void LayerRenderer::prepareDirty(float left, float top, float right, float bottom, bool opaque) {
3541
LAYER_RENDERER_LOGD("Rendering into layer, fbo = %d", mLayer->getFbo());
3642

libs/hwui/LayerRenderer.h

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef ANDROID_HWUI_LAYER_RENDERER_H
1818
#define ANDROID_HWUI_LAYER_RENDERER_H
1919

20+
#include <cutils/compiler.h>
21+
2022
#include "OpenGLRenderer.h"
2123
#include "Layer.h"
2224

@@ -42,27 +44,24 @@ namespace uirenderer {
4244

4345
class LayerRenderer: public OpenGLRenderer {
4446
public:
45-
LayerRenderer(Layer* layer): mLayer(layer) {
46-
}
47-
48-
~LayerRenderer() {
49-
}
47+
ANDROID_API LayerRenderer(Layer* layer);
48+
virtual ~LayerRenderer();
5049

51-
void prepareDirty(float left, float top, float right, float bottom, bool opaque);
52-
void finish();
50+
virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
51+
virtual void finish();
5352

54-
bool hasLayer();
55-
Region* getRegion();
56-
GLint getTargetFbo();
53+
virtual bool hasLayer();
54+
virtual Region* getRegion();
55+
virtual GLint getTargetFbo();
5756

58-
static Layer* createTextureLayer(bool isOpaque);
59-
static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false);
60-
static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height);
61-
static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height,
57+
ANDROID_API static Layer* createTextureLayer(bool isOpaque);
58+
ANDROID_API static Layer* createLayer(uint32_t width, uint32_t height, bool isOpaque = false);
59+
ANDROID_API static bool resizeLayer(Layer* layer, uint32_t width, uint32_t height);
60+
ANDROID_API static void updateTextureLayer(Layer* layer, uint32_t width, uint32_t height,
6261
bool isOpaque, GLenum renderTarget, float* transform);
63-
static void destroyLayer(Layer* layer);
64-
static void destroyLayerDeferred(Layer* layer);
65-
static bool copyLayer(Layer* layer, SkBitmap* bitmap);
62+
ANDROID_API static void destroyLayer(Layer* layer);
63+
ANDROID_API static void destroyLayerDeferred(Layer* layer);
64+
ANDROID_API static bool copyLayer(Layer* layer, SkBitmap* bitmap);
6665

6766
private:
6867
void generateMesh();

libs/hwui/OpenGLRenderer.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <utils/RefBase.h>
3232
#include <utils/Vector.h>
3333

34+
#include <cutils/compiler.h>
35+
3436
#include "Debug.h"
3537
#include "Extensions.h"
3638
#include "Matrix.h"
@@ -57,12 +59,12 @@ class DisplayList;
5759
*/
5860
class OpenGLRenderer {
5961
public:
60-
OpenGLRenderer();
62+
ANDROID_API OpenGLRenderer();
6163
virtual ~OpenGLRenderer();
6264

6365
virtual void setViewport(int width, int height);
6466

65-
void prepare(bool opaque);
67+
ANDROID_API void prepare(bool opaque);
6668
virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
6769
virtual void finish();
6870

@@ -72,7 +74,7 @@ class OpenGLRenderer {
7274

7375
virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
7476

75-
int getSaveCount() const;
77+
ANDROID_API int getSaveCount() const;
7678
virtual int save(int flags);
7779
virtual void restore();
7880
virtual void restoreToCount(int saveCount);
@@ -87,12 +89,12 @@ class OpenGLRenderer {
8789
virtual void scale(float sx, float sy);
8890
virtual void skew(float sx, float sy);
8991

90-
void getMatrix(SkMatrix* matrix);
92+
ANDROID_API void getMatrix(SkMatrix* matrix);
9193
virtual void setMatrix(SkMatrix* matrix);
9294
virtual void concatMatrix(SkMatrix* matrix);
9395

94-
const Rect& getClipBounds();
95-
bool quickReject(float left, float top, float right, float bottom);
96+
ANDROID_API const Rect& getClipBounds();
97+
ANDROID_API bool quickReject(float left, float top, float right, float bottom);
9698
virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
9799

98100
virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,

libs/hwui/ResourceCache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef ANDROID_HWUI_RESOURCE_CACHE_H
1818
#define ANDROID_HWUI_RESOURCE_CACHE_H
1919

20+
#include <cutils/compiler.h>
21+
2022
#include <SkBitmap.h>
2123
#include <SkiaColorFilter.h>
2224
#include <SkiaShader.h>
@@ -49,7 +51,7 @@ class ResourceReference {
4951
ResourceType resourceType;
5052
};
5153

52-
class ResourceCache {
54+
class ANDROID_API ResourceCache {
5355
KeyedVector<void *, ResourceReference *>* mCache;
5456
public:
5557
ResourceCache();

libs/hwui/SkiaColorFilter.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <GLES2/gl2.h>
2121
#include <SkColorFilter.h>
2222

23+
#include <cutils/compiler.h>
24+
2325
#include "ProgramCache.h"
2426
#include "Extensions.h"
2527

@@ -45,7 +47,7 @@ struct SkiaColorFilter {
4547
kBlend,
4648
};
4749

48-
SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend);
50+
ANDROID_API SkiaColorFilter(SkColorFilter *skFilter, Type type, bool blend);
4951
virtual ~SkiaColorFilter();
5052

5153
virtual void describe(ProgramDescription& description, const Extensions& extensions) = 0;
@@ -79,7 +81,7 @@ struct SkiaColorFilter {
7981
* A color filter that multiplies the source color with a matrix and adds a vector.
8082
*/
8183
struct SkiaColorMatrixFilter: public SkiaColorFilter {
82-
SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector);
84+
ANDROID_API SkiaColorMatrixFilter(SkColorFilter *skFilter, float* matrix, float* vector);
8385
~SkiaColorMatrixFilter();
8486

8587
void describe(ProgramDescription& description, const Extensions& extensions);
@@ -95,7 +97,7 @@ struct SkiaColorMatrixFilter: public SkiaColorFilter {
9597
* another fixed value. Ignores the alpha channel of both arguments.
9698
*/
9799
struct SkiaLightingFilter: public SkiaColorFilter {
98-
SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add);
100+
ANDROID_API SkiaLightingFilter(SkColorFilter *skFilter, int multiply, int add);
99101

100102
void describe(ProgramDescription& description, const Extensions& extensions);
101103
void setupProgram(Program* program);
@@ -110,7 +112,7 @@ struct SkiaLightingFilter: public SkiaColorFilter {
110112
* and PorterDuff blending mode.
111113
*/
112114
struct SkiaBlendFilter: public SkiaColorFilter {
113-
SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode);
115+
ANDROID_API SkiaBlendFilter(SkColorFilter *skFilter, int color, SkXfermode::Mode mode);
114116

115117
void describe(ProgramDescription& description, const Extensions& extensions);
116118
void setupProgram(Program* program);

0 commit comments

Comments
 (0)