Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |
| 18 | #define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 19 | |
| 20 | #include <SkChunkAlloc.h> |
| 21 | #include <SkFlattenable.h> |
| 22 | #include <SkMatrix.h> |
| 23 | #include <SkPaint.h> |
| 24 | #include <SkPath.h> |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 25 | #include <SkRefCnt.h> |
| 26 | #include <SkTDArray.h> |
| 27 | #include <SkTSearch.h> |
| 28 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 29 | #include <cutils/compiler.h> |
| 30 | |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 31 | #include "DisplayListLogBuffer.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 32 | #include "OpenGLRenderer.h" |
Romain Guy | 7d7b549 | 2011-01-24 16:33:45 -0800 | [diff] [blame] | 33 | #include "utils/Functor.h" |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | namespace uirenderer { |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////////// |
| 39 | // Defines |
| 40 | /////////////////////////////////////////////////////////////////////////////// |
| 41 | |
Romain Guy | 6d7475d | 2011-07-27 16:28:21 -0700 | [diff] [blame] | 42 | #define MIN_WRITER_SIZE 4096 |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 43 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 44 | // Debug |
| 45 | #if DEBUG_DISPLAY_LIST |
Steve Block | 5baa3a6 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 46 | #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__) |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 47 | #else |
| 48 | #define DISPLAY_LIST_LOGD(...) |
| 49 | #endif |
| 50 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 51 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 52 | // Display list |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 53 | /////////////////////////////////////////////////////////////////////////////// |
| 54 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 55 | class DisplayListRenderer; |
| 56 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 57 | /** |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 58 | * Replays recorded drawing commands. |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 59 | */ |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 60 | class DisplayList { |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 61 | public: |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 62 | DisplayList(const DisplayListRenderer& recorder); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 63 | ANDROID_API ~DisplayList(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 64 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 65 | // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file |
| 66 | // when modifying this file |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 67 | enum Op { |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 68 | // Non-drawing operations |
Romain Guy | 2b1847e | 2011-01-26 13:43:01 -0800 | [diff] [blame] | 69 | Save = 0, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 70 | Restore, |
| 71 | RestoreToCount, |
| 72 | SaveLayer, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 73 | SaveLayerAlpha, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 74 | Translate, |
| 75 | Rotate, |
| 76 | Scale, |
Romain Guy | 807daf7 | 2011-01-18 11:19:19 -0800 | [diff] [blame] | 77 | Skew, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 78 | SetMatrix, |
| 79 | ConcatMatrix, |
| 80 | ClipRect, |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 81 | // Drawing operations |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 82 | DrawDisplayList, |
Romain Guy | 6c319ca | 2011-01-11 14:29:25 -0800 | [diff] [blame] | 83 | DrawLayer, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 84 | DrawBitmap, |
| 85 | DrawBitmapMatrix, |
| 86 | DrawBitmapRect, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 87 | DrawBitmapMesh, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 88 | DrawPatch, |
| 89 | DrawColor, |
| 90 | DrawRect, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 91 | DrawRoundRect, |
| 92 | DrawCircle, |
Romain Guy | c1cd9ba3 | 2011-01-23 14:18:41 -0800 | [diff] [blame] | 93 | DrawOval, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 94 | DrawArc, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 95 | DrawPath, |
| 96 | DrawLines, |
Romain Guy | ed6fcb0 | 2011-03-21 13:11:28 -0700 | [diff] [blame] | 97 | DrawPoints, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 98 | DrawText, |
| 99 | ResetShader, |
| 100 | SetupShader, |
| 101 | ResetColorFilter, |
| 102 | SetupColorFilter, |
| 103 | ResetShadow, |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 104 | SetupShadow, |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 105 | DrawGLFunction, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Romain Guy | ffac7fc | 2011-01-13 17:21:49 -0800 | [diff] [blame] | 108 | static const char* OP_NAMES[]; |
| 109 | |
Chet Haase | d63cbd1 | 2011-02-03 16:32:46 -0800 | [diff] [blame] | 110 | void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 111 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 112 | ANDROID_API size_t getSize(); |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 113 | |
Romain Guy | cabfcc1 | 2011-03-07 18:06:46 -0800 | [diff] [blame] | 114 | bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 115 | |
Chet Haase | ed30fd8 | 2011-04-22 16:18:45 -0700 | [diff] [blame] | 116 | void output(OpenGLRenderer& renderer, uint32_t level = 0); |
| 117 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 118 | ANDROID_API static void outputLogBuffer(int fd); |
Chet Haase | 9c1e23b | 2011-03-24 10:51:31 -0700 | [diff] [blame] | 119 | |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 120 | void setRenderable(bool renderable) { |
| 121 | mIsRenderable = renderable; |
| 122 | } |
| 123 | |
| 124 | bool isRenderable() const { |
| 125 | return mIsRenderable; |
| 126 | } |
| 127 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 128 | private: |
| 129 | void init(); |
| 130 | |
Chet Haase | d63cbd1 | 2011-02-03 16:32:46 -0800 | [diff] [blame] | 131 | void clearResources(); |
| 132 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 133 | class TextContainer { |
| 134 | public: |
| 135 | size_t length() const { |
| 136 | return mByteLength; |
| 137 | } |
| 138 | |
| 139 | const char* text() const { |
| 140 | return (const char*) mText; |
| 141 | } |
| 142 | |
| 143 | size_t mByteLength; |
| 144 | const char* mText; |
| 145 | }; |
| 146 | |
| 147 | SkBitmap* getBitmap() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 148 | return (SkBitmap*) getInt(); |
| 149 | } |
| 150 | |
| 151 | SkiaShader* getShader() { |
| 152 | return (SkiaShader*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 155 | SkiaColorFilter* getColorFilter() { |
| 156 | return (SkiaColorFilter*) getInt(); |
| 157 | } |
| 158 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 159 | inline int getIndex() { |
| 160 | return mReader.readInt(); |
| 161 | } |
| 162 | |
| 163 | inline int getInt() { |
| 164 | return mReader.readInt(); |
| 165 | } |
| 166 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 167 | inline uint32_t getUInt() { |
| 168 | return mReader.readU32(); |
| 169 | } |
| 170 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 171 | SkMatrix* getMatrix() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 172 | return (SkMatrix*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | SkPath* getPath() { |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 176 | return (SkPath*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | SkPaint* getPaint() { |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 180 | return (SkPaint*) getInt(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 183 | DisplayList* getDisplayList() { |
| 184 | return (DisplayList*) getInt(); |
| 185 | } |
| 186 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 187 | inline float getFloat() { |
| 188 | return mReader.readScalar(); |
| 189 | } |
| 190 | |
| 191 | int32_t* getInts(uint32_t& count) { |
| 192 | count = getInt(); |
| 193 | return (int32_t*) mReader.skip(count * sizeof(int32_t)); |
| 194 | } |
| 195 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 196 | uint32_t* getUInts(int8_t& count) { |
| 197 | count = getInt(); |
| 198 | return (uint32_t*) mReader.skip(count * sizeof(uint32_t)); |
| 199 | } |
| 200 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 201 | float* getFloats(int& count) { |
| 202 | count = getInt(); |
| 203 | return (float*) mReader.skip(count * sizeof(float)); |
| 204 | } |
| 205 | |
| 206 | void getText(TextContainer* text) { |
| 207 | size_t length = text->mByteLength = getInt(); |
| 208 | text->mText = (const char*) mReader.skip(length); |
| 209 | } |
| 210 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 211 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 212 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 213 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 214 | Vector<SkPaint*> mPaints; |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 215 | Vector<SkPath*> mPaths; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 216 | Vector<SkMatrix*> mMatrices; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 217 | Vector<SkiaShader*> mShaders; |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 218 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 219 | mutable SkFlattenableReadBuffer mReader; |
Romain Guy | 65b345f | 2011-07-27 18:51:50 -0700 | [diff] [blame] | 220 | |
| 221 | size_t mSize; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 222 | |
| 223 | bool mIsRenderable; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | /////////////////////////////////////////////////////////////////////////////// |
| 227 | // Renderer |
| 228 | /////////////////////////////////////////////////////////////////////////////// |
| 229 | |
| 230 | /** |
| 231 | * Records drawing commands in a display list for latter playback. |
| 232 | */ |
| 233 | class DisplayListRenderer: public OpenGLRenderer { |
| 234 | public: |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 235 | ANDROID_API DisplayListRenderer(); |
| 236 | virtual ~DisplayListRenderer(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 237 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 238 | ANDROID_API DisplayList* getDisplayList(DisplayList* displayList); |
Chet Haase | 5977baa | 2011-01-05 18:01:22 -0800 | [diff] [blame] | 239 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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(); |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 243 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 244 | virtual bool callDrawGLFunction(Functor *functor, Rect& dirty); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 245 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 246 | virtual void interrupt(); |
| 247 | virtual void resume(); |
Chet Haase | daf98e9 | 2011-01-10 14:10:36 -0800 | [diff] [blame] | 248 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 249 | virtual int save(int flags); |
| 250 | virtual void restore(); |
| 251 | virtual void restoreToCount(int saveCount); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 252 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 253 | virtual int saveLayer(float left, float top, float right, float bottom, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 254 | SkPaint* p, int flags); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 255 | virtual int saveLayerAlpha(float left, float top, float right, float bottom, |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 256 | int alpha, int flags); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 257 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 262 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 263 | virtual void setMatrix(SkMatrix* matrix); |
| 264 | virtual void concatMatrix(SkMatrix* matrix); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 265 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 266 | virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 267 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 268 | virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height, |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 269 | Rect& dirty, uint32_t level = 0); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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, |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 274 | float srcRight, float srcBottom, float dstLeft, float dstTop, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 275 | float dstRight, float dstBottom, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 276 | virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, |
Romain Guy | 5a7b466 | 2011-01-20 19:09:30 -0800 | [diff] [blame] | 277 | float* vertices, int* colors, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 278 | virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 279 | const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 280 | float left, float top, float right, float bottom, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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, |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 284 | float rx, float ry, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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, |
Romain Guy | 8b2f526 | 2011-01-23 16:15:02 -0800 | [diff] [blame] | 288 | float startAngle, float sweepAngle, bool useCenter, SkPaint* paint); |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 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, |
Romain Guy | 8f9a9f6 | 2011-12-05 11:53:26 -0800 | [diff] [blame] | 293 | SkPaint* paint, float length = 1.0f); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 294 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 295 | virtual void resetShader(); |
| 296 | virtual void setupShader(SkiaShader* shader); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 297 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 298 | virtual void resetColorFilter(); |
| 299 | virtual void setupColorFilter(SkiaColorFilter* filter); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 300 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 301 | virtual void resetShadow(); |
| 302 | virtual void setupShadow(float radius, float dx, float dy, int color); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 303 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 304 | ANDROID_API void reset(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 305 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 306 | const SkWriter32& writeStream() const { |
| 307 | return mWriter; |
| 308 | } |
| 309 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 310 | const Vector<SkBitmap*>& getBitmapResources() const { |
| 311 | return mBitmapResources; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 314 | const Vector<SkiaColorFilter*>& getFilterResources() const { |
| 315 | return mFilterResources; |
| 316 | } |
| 317 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 318 | const Vector<SkiaShader*>& getShaders() const { |
| 319 | return mShaders; |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 322 | const Vector<SkPaint*>& getPaints() const { |
| 323 | return mPaints; |
| 324 | } |
| 325 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 326 | const Vector<SkPath*>& getPaths() const { |
| 327 | return mPaths; |
| 328 | } |
| 329 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 330 | const Vector<SkMatrix*>& getMatrices() const { |
| 331 | return mMatrices; |
| 332 | } |
| 333 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 334 | private: |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 335 | void insertRestoreToCount() { |
| 336 | if (mRestoreSaveCount >= 0) { |
| 337 | mWriter.writeInt(DisplayList::RestoreToCount); |
| 338 | addInt(mRestoreSaveCount); |
| 339 | mRestoreSaveCount = -1; |
| 340 | } |
| 341 | } |
| 342 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 343 | inline void addOp(DisplayList::Op drawOp) { |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 344 | insertRestoreToCount(); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 345 | mWriter.writeInt(drawOp); |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 346 | mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | inline void addInt(int value) { |
| 350 | mWriter.writeInt(value); |
| 351 | } |
| 352 | |
Romain Guy | 7b5b6ab | 2011-03-14 18:05:08 -0700 | [diff] [blame] | 353 | inline void addSize(uint32_t w, uint32_t h) { |
| 354 | mWriter.writeInt(w); |
| 355 | mWriter.writeInt(h); |
| 356 | } |
| 357 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 358 | void addInts(const int32_t* values, uint32_t count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 359 | mWriter.writeInt(count); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 360 | for (uint32_t i = 0; i < count; i++) { |
| 361 | mWriter.writeInt(values[i]); |
| 362 | } |
| 363 | } |
| 364 | |
Romain Guy | 4bb9420 | 2010-10-12 15:59:26 -0700 | [diff] [blame] | 365 | void addUInts(const uint32_t* values, int8_t count) { |
| 366 | mWriter.writeInt(count); |
| 367 | for (int8_t i = 0; i < count; i++) { |
| 368 | mWriter.writeInt(values[i]); |
| 369 | } |
| 370 | } |
| 371 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 372 | inline void addFloat(float value) { |
| 373 | mWriter.writeScalar(value); |
| 374 | } |
| 375 | |
| 376 | void addFloats(const float* values, int count) { |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 377 | mWriter.writeInt(count); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 378 | for (int i = 0; i < count; i++) { |
| 379 | mWriter.writeScalar(values[i]); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | inline void addPoint(float x, float y) { |
| 384 | mWriter.writeScalar(x); |
| 385 | mWriter.writeScalar(y); |
| 386 | } |
| 387 | |
| 388 | inline void addBounds(float left, float top, float right, float bottom) { |
| 389 | mWriter.writeScalar(left); |
| 390 | mWriter.writeScalar(top); |
| 391 | mWriter.writeScalar(right); |
| 392 | mWriter.writeScalar(bottom); |
| 393 | } |
| 394 | |
| 395 | inline void addText(const void* text, size_t byteLength) { |
| 396 | mWriter.writeInt(byteLength); |
| 397 | mWriter.writePad(text, byteLength); |
| 398 | } |
| 399 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 400 | inline void addPath(SkPath* path) { |
| 401 | if (!path) { |
| 402 | addInt((int) NULL); |
| 403 | return; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 404 | } |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 405 | |
| 406 | SkPath* pathCopy = mPathMap.valueFor(path); |
| 407 | if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) { |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 408 | pathCopy = new SkPath(*path); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 409 | mPathMap.add(path, pathCopy); |
Romain Guy | b29cfbf | 2011-03-18 16:24:19 -0700 | [diff] [blame] | 410 | mPaths.add(pathCopy); |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | addInt((int) pathCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 416 | inline void addPaint(SkPaint* paint) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 417 | if (!paint) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 418 | addInt((int) NULL); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 419 | return; |
| 420 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 421 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 422 | SkPaint* paintCopy = mPaintMap.valueFor(paint); |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 423 | if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) { |
| 424 | paintCopy = new SkPaint(*paint); |
| 425 | mPaintMap.add(paint, paintCopy); |
| 426 | mPaints.add(paintCopy); |
| 427 | } |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 428 | |
| 429 | addInt((int) paintCopy); |
| 430 | } |
| 431 | |
| 432 | inline void addDisplayList(DisplayList* displayList) { |
| 433 | // TODO: To be safe, the display list should be ref-counted in the |
| 434 | // resources cache, but we rely on the caller (UI toolkit) to |
| 435 | // do the right thing for now |
| 436 | addInt((int) displayList); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 439 | inline void addMatrix(SkMatrix* matrix) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 440 | // Copying the matrix is cheap and prevents against the user changing the original |
| 441 | // matrix before the operation that uses it |
Romain Guy | f6a63ae | 2011-06-22 15:13:09 -0700 | [diff] [blame] | 442 | SkMatrix* copy = new SkMatrix(*matrix); |
| 443 | addInt((int) copy); |
| 444 | mMatrices.add(copy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 447 | inline void addBitmap(SkBitmap* bitmap) { |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 448 | // Note that this assumes the bitmap is immutable. There are cases this won't handle |
| 449 | // correctly, such as creating the bitmap from scratch, drawing with it, changing its |
| 450 | // contents, and drawing again. The only fix would be to always copy it the first time, |
| 451 | // which doesn't seem worth the extra cycles for this unlikely case. |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 452 | addInt((int) bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 453 | mBitmapResources.add(bitmap); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 454 | Caches::getInstance().resourceCache.incrementRefcount(bitmap); |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 455 | } |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 456 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 457 | inline void addShader(SkiaShader* shader) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 458 | if (!shader) { |
| 459 | addInt((int) NULL); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | SkiaShader* shaderCopy = mShaderMap.valueFor(shader); |
| 464 | // TODO: We also need to handle generation ID changes in compose shaders |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 465 | if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) { |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 466 | shaderCopy = shader->copy(); |
| 467 | mShaderMap.add(shader, shaderCopy); |
Romain Guy | 1f1fcb7 | 2011-01-14 15:37:54 -0800 | [diff] [blame] | 468 | mShaders.add(shaderCopy); |
Romain Guy | 43ccf46 | 2011-01-14 18:51:01 -0800 | [diff] [blame] | 469 | Caches::getInstance().resourceCache.incrementRefcount(shaderCopy); |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | addInt((int) shaderCopy); |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 475 | inline void addColorFilter(SkiaColorFilter* colorFilter) { |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 476 | addInt((int) colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 477 | mFilterResources.add(colorFilter); |
Romain Guy | d586ad9 | 2011-06-22 16:14:36 -0700 | [diff] [blame] | 478 | Caches::getInstance().resourceCache.incrementRefcount(colorFilter); |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 481 | Vector<SkBitmap*> mBitmapResources; |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 482 | Vector<SkiaColorFilter*> mFilterResources; |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 483 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 484 | Vector<SkPaint*> mPaints; |
Romain Guy | 0fe478e | 2010-11-08 12:08:41 -0800 | [diff] [blame] | 485 | DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap; |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 486 | |
Romain Guy | 2fc941e | 2011-02-03 15:06:05 -0800 | [diff] [blame] | 487 | Vector<SkPath*> mPaths; |
| 488 | DefaultKeyedVector<SkPath*, SkPath*> mPathMap; |
| 489 | |
Romain Guy | 24c0021 | 2011-01-14 15:31:00 -0800 | [diff] [blame] | 490 | Vector<SkiaShader*> mShaders; |
| 491 | DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap; |
| 492 | |
Chet Haase | d98aa2d | 2010-10-25 15:47:32 -0700 | [diff] [blame] | 493 | Vector<SkMatrix*> mMatrices; |
| 494 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 495 | SkWriter32 mWriter; |
| 496 | |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 497 | int mRestoreSaveCount; |
Romain Guy | 04c9d8c | 2011-08-25 14:01:48 -0700 | [diff] [blame] | 498 | bool mHasDrawOps; |
Romain Guy | 27454a4 | 2011-01-23 12:01:41 -0800 | [diff] [blame] | 499 | |
Romain Guy | b051e89 | 2010-09-28 19:09:36 -0700 | [diff] [blame] | 500 | friend class DisplayList; |
| 501 | |
Romain Guy | 4aa9057 | 2010-09-26 18:40:37 -0700 | [diff] [blame] | 502 | }; // class DisplayListRenderer |
| 503 | |
| 504 | }; // namespace uirenderer |
| 505 | }; // namespace android |
| 506 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 507 | #endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H |