Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1 | /* |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 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 | |
| 17 | #ifndef ANDROID_HWUI_DISPLAY_OPERATION_H |
| 18 | #define ANDROID_HWUI_DISPLAY_OPERATION_H |
| 19 | |
Romain Guy | 7031ff6 | 2013-02-22 11:48:16 -0800 | [diff] [blame] | 20 | #ifndef LOG_TAG |
| 21 | #define LOG_TAG "OpenGLRenderer" |
| 22 | #endif |
| 23 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 24 | #include <SkXfermode.h> |
| 25 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 26 | #include <private/hwui/DrawGlInfo.h> |
| 27 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 28 | #include "OpenGLRenderer.h" |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 29 | #include "AssetAtlas.h" |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 30 | #include "DeferredDisplayList.h" |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 31 | #include "DisplayListRenderer.h" |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 32 | #include "UvMapper.h" |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 33 | #include "utils/LinearAllocator.h" |
| 34 | |
| 35 | #define CRASH() do { \ |
Romain Guy | 5216c3b | 2013-06-14 16:31:37 -0700 | [diff] [blame] | 36 | *(int *)(uintptr_t) 0xbbadbeef = 0; \ |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 37 | ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \ |
| 38 | } while(false) |
| 39 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 40 | // Use OP_LOG for logging with arglist, OP_LOGS if just printing char* |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 41 | #define OP_LOGS(s) OP_LOG("%s", (s)) |
Chris Craik | 3dc553b | 2013-02-04 12:45:13 -0800 | [diff] [blame] | 42 | #define OP_LOG(s, ...) ALOGD( "%*s" s, level * 2, "", __VA_ARGS__ ) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 43 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 44 | namespace android { |
| 45 | namespace uirenderer { |
| 46 | |
| 47 | /** |
| 48 | * Structure for storing canvas operations when they are recorded into a DisplayList, so that they |
| 49 | * may be replayed to an OpenGLRenderer. |
| 50 | * |
| 51 | * To avoid individual memory allocations, DisplayListOps may only be allocated into a |
| 52 | * LinearAllocator's managed memory buffers. Each pointer held by a DisplayListOp is either a |
| 53 | * pointer into memory also allocated in the LinearAllocator (mostly for text and float buffers) or |
| 54 | * references a externally refcounted object (Sk... and Skia... objects). ~DisplayListOp() is |
| 55 | * never called as LinearAllocators are simply discarded, so no memory management should be done in |
| 56 | * this class. |
| 57 | */ |
| 58 | class DisplayListOp { |
| 59 | public: |
| 60 | // These objects should always be allocated with a LinearAllocator, and never destroyed/deleted. |
| 61 | // standard new() intentionally not implemented, and delete/deconstructor should never be used. |
| 62 | virtual ~DisplayListOp() { CRASH(); } |
| 63 | static void operator delete(void* ptr) { CRASH(); } |
| 64 | /** static void* operator new(size_t size); PURPOSELY OMITTED **/ |
| 65 | static void* operator new(size_t size, LinearAllocator& allocator) { |
| 66 | return allocator.alloc(size); |
| 67 | } |
| 68 | |
| 69 | enum OpLogFlag { |
| 70 | kOpLogFlag_Recurse = 0x1, |
| 71 | kOpLogFlag_JSON = 0x2 // TODO: add? |
| 72 | }; |
| 73 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 74 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 75 | bool useQuickReject) = 0; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 76 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 77 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 78 | bool useQuickReject) = 0; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 79 | |
| 80 | virtual void output(int level, uint32_t logFlags = 0) = 0; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 81 | |
| 82 | // NOTE: it would be nice to declare constants and overriding the implementation in each op to |
| 83 | // point at the constants, but that seems to require a .cpp file |
| 84 | virtual const char* name() = 0; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Stores the relevant canvas state of the object between deferral and replay (if the canvas |
| 88 | * state supports being stored) See OpenGLRenderer::simpleClipAndState() |
| 89 | * |
| 90 | * TODO: don't reserve space for StateOps that won't be deferred |
| 91 | */ |
| 92 | DeferredDisplayState state; |
| 93 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | class StateOp : public DisplayListOp { |
| 97 | public: |
| 98 | StateOp() {}; |
| 99 | |
| 100 | virtual ~StateOp() {} |
| 101 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 102 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 103 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 104 | // default behavior only affects immediate, deferrable state, issue directly to renderer |
| 105 | applyState(deferStruct.mRenderer, saveCount); |
| 106 | } |
| 107 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 108 | /** |
| 109 | * State operations are applied directly to the renderer, but can cause the deferred drawing op |
| 110 | * list to flush |
| 111 | */ |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 112 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 113 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 114 | applyState(replayStruct.mRenderer, saveCount); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 117 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const = 0; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | class DrawOp : public DisplayListOp { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 121 | friend class MergingDrawBatch; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 122 | public: |
| 123 | DrawOp(SkPaint* paint) |
| 124 | : mPaint(paint), mQuickRejected(false) {} |
| 125 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 126 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 127 | bool useQuickReject) { |
| 128 | if (mQuickRejected && CC_LIKELY(useQuickReject)) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 129 | return; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Chris Craik | d72b73c | 2013-06-17 13:52:06 -0700 | [diff] [blame] | 132 | if (getLocalBounds(state.mBounds)) { |
| 133 | // valid empty bounds, don't bother deferring |
| 134 | if (state.mBounds.isEmpty()) return; |
| 135 | } else { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 136 | // empty bounds signify bounds can't be calculated |
| 137 | state.mBounds.setEmpty(); |
| 138 | } |
| 139 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 140 | deferStruct.mDeferredList.addDrawOp(deferStruct.mRenderer, this); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 143 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 144 | bool useQuickReject) { |
| 145 | if (mQuickRejected && CC_LIKELY(useQuickReject)) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 149 | replayStruct.mDrawGlStatus |= applyDraw(replayStruct.mRenderer, replayStruct.mDirty); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 152 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) = 0; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 153 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 154 | /** |
| 155 | * Draw multiple instances of an operation, must be overidden for operations that merge |
| 156 | * |
| 157 | * Currently guarantees certain similarities between ops (see MergingDrawBatch::canMergeWith), |
| 158 | * and pure translation transformations. Other guarantees of similarity should be enforced by |
| 159 | * reducing which operations are tagged as mergeable. |
| 160 | */ |
| 161 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
| 162 | const Vector<DrawOp*>& ops, const Rect& bounds) { |
| 163 | status_t status = DrawGlInfo::kStatusDone; |
| 164 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 165 | renderer.restoreDisplayState(ops[i]->state, true); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 166 | status |= ops[i]->applyDraw(renderer, dirty); |
| 167 | } |
| 168 | return status; |
| 169 | } |
| 170 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 171 | /** |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 172 | * When this method is invoked the state field is initialized to have the |
| 173 | * final rendering state. We can thus use it to process data as it will be |
| 174 | * used at draw time. |
| 175 | * |
| 176 | * Additionally, this method allows subclasses to provide defer-time preferences for batching |
| 177 | * and merging. |
| 178 | * |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 179 | * if a subclass can set deferInfo.mergeable to true, it should implement multiDraw() |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 180 | */ |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 181 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {} |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 182 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 183 | // returns true if bounds exist |
| 184 | virtual bool getLocalBounds(Rect& localBounds) { return false; } |
| 185 | |
| 186 | // TODO: better refine localbounds usage |
| 187 | void setQuickRejected(bool quickRejected) { mQuickRejected = quickRejected; } |
| 188 | bool getQuickRejected() { return mQuickRejected; } |
| 189 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 190 | inline int getPaintAlpha() { |
| 191 | return OpenGLRenderer::getAlphaDirect(mPaint); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 194 | inline float strokeWidthOutset() { |
Chris Craik | e7c69c6 | 2013-04-03 09:55:48 -0700 | [diff] [blame] | 195 | float width = mPaint->getStrokeWidth(); |
| 196 | if (width == 0) return 0.5f; // account for hairline |
| 197 | return width * 0.5f; |
| 198 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 199 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 200 | protected: |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 201 | SkPaint* getPaint(OpenGLRenderer& renderer) { |
| 202 | return renderer.filterPaint(mPaint); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 205 | // Helper method for determining op opaqueness. Assumes op fills its bounds in local |
| 206 | // coordinates, and that paint's alpha is used |
| 207 | inline bool isOpaqueOverBounds() { |
| 208 | // ensure that local bounds cover mapped bounds |
| 209 | if (!state.mMatrix.isSimple()) return false; |
| 210 | |
| 211 | // check state/paint for transparency |
| 212 | if (state.mDrawModifiers.mShader || |
| 213 | state.mAlpha != 1.0f || |
| 214 | (mPaint && mPaint->getAlpha() != 0xFF)) return false; |
| 215 | |
| 216 | SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint); |
| 217 | return (mode == SkXfermode::kSrcOver_Mode || |
| 218 | mode == SkXfermode::kSrc_Mode); |
| 219 | |
| 220 | } |
| 221 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 222 | SkPaint* mPaint; // should be accessed via getPaint() when applying |
| 223 | bool mQuickRejected; |
| 224 | }; |
| 225 | |
| 226 | class DrawBoundedOp : public DrawOp { |
| 227 | public: |
| 228 | DrawBoundedOp(float left, float top, float right, float bottom, SkPaint* paint) |
| 229 | : DrawOp(paint), mLocalBounds(left, top, right, bottom) {} |
| 230 | |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 231 | DrawBoundedOp(const Rect& localBounds, SkPaint* paint) |
| 232 | : DrawOp(paint), mLocalBounds(localBounds) {} |
| 233 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 234 | // Calculates bounds as smallest rect encompassing all points |
| 235 | // NOTE: requires at least 1 vertex, and doesn't account for stroke size (should be handled in |
| 236 | // subclass' constructor) |
| 237 | DrawBoundedOp(const float* points, int count, SkPaint* paint) |
| 238 | : DrawOp(paint), mLocalBounds(points[0], points[1], points[0], points[1]) { |
| 239 | for (int i = 2; i < count; i += 2) { |
| 240 | mLocalBounds.left = fminf(mLocalBounds.left, points[i]); |
| 241 | mLocalBounds.right = fmaxf(mLocalBounds.right, points[i]); |
| 242 | mLocalBounds.top = fminf(mLocalBounds.top, points[i + 1]); |
| 243 | mLocalBounds.bottom = fmaxf(mLocalBounds.bottom, points[i + 1]); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // default empty constructor for bounds, to be overridden in child constructor body |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 248 | DrawBoundedOp(SkPaint* paint) |
| 249 | : DrawOp(paint) {} |
| 250 | |
| 251 | bool getLocalBounds(Rect& localBounds) { |
| 252 | localBounds.set(mLocalBounds); |
| 253 | return true; |
| 254 | } |
| 255 | |
| 256 | protected: |
| 257 | Rect mLocalBounds; // displayed area in LOCAL coord. doesn't incorporate stroke, so check paint |
| 258 | }; |
| 259 | |
| 260 | /////////////////////////////////////////////////////////////////////////////// |
| 261 | // STATE OPERATIONS - these may affect the state of the canvas/renderer, but do |
| 262 | // not directly draw or alter output |
| 263 | /////////////////////////////////////////////////////////////////////////////// |
| 264 | |
| 265 | class SaveOp : public StateOp { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 266 | friend class DisplayList; // give DisplayList private constructor/reinit access |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 267 | public: |
| 268 | SaveOp(int flags) |
| 269 | : mFlags(flags) {} |
| 270 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 271 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 272 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 273 | int newSaveCount = deferStruct.mRenderer.save(mFlags); |
| 274 | deferStruct.mDeferredList.addSave(deferStruct.mRenderer, this, newSaveCount); |
| 275 | } |
| 276 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 277 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 278 | renderer.save(mFlags); |
| 279 | } |
| 280 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 281 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 282 | OP_LOG("Save flags %x", mFlags); |
| 283 | } |
| 284 | |
| 285 | virtual const char* name() { return "Save"; } |
| 286 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 287 | int getFlags() const { return mFlags; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 288 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 289 | SaveOp() {} |
| 290 | DisplayListOp* reinit(int flags) { |
| 291 | mFlags = flags; |
| 292 | return this; |
| 293 | } |
| 294 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 295 | int mFlags; |
| 296 | }; |
| 297 | |
| 298 | class RestoreToCountOp : public StateOp { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 299 | friend class DisplayList; // give DisplayList private constructor/reinit access |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 300 | public: |
| 301 | RestoreToCountOp(int count) |
| 302 | : mCount(count) {} |
| 303 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 304 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 305 | bool useQuickReject) { |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 306 | deferStruct.mDeferredList.addRestoreToCount(deferStruct.mRenderer, |
| 307 | this, saveCount + mCount); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 308 | deferStruct.mRenderer.restoreToCount(saveCount + mCount); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 311 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 312 | renderer.restoreToCount(saveCount + mCount); |
| 313 | } |
| 314 | |
| 315 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 316 | OP_LOG("Restore to count %d", mCount); |
| 317 | } |
| 318 | |
| 319 | virtual const char* name() { return "RestoreToCount"; } |
| 320 | |
| 321 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 322 | RestoreToCountOp() {} |
| 323 | DisplayListOp* reinit(int count) { |
| 324 | mCount = count; |
| 325 | return this; |
| 326 | } |
| 327 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 328 | int mCount; |
| 329 | }; |
| 330 | |
| 331 | class SaveLayerOp : public StateOp { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 332 | friend class DisplayList; // give DisplayList private constructor/reinit access |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 333 | public: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 334 | SaveLayerOp(float left, float top, float right, float bottom, |
| 335 | int alpha, SkXfermode::Mode mode, int flags) |
| 336 | : mArea(left, top, right, bottom), mAlpha(alpha), mMode(mode), mFlags(flags) {} |
| 337 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 338 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 339 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 340 | // NOTE: don't bother with actual saveLayer, instead issuing it at flush time |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 341 | int newSaveCount = deferStruct.mRenderer.getSaveCount(); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 342 | deferStruct.mDeferredList.addSaveLayer(deferStruct.mRenderer, this, newSaveCount); |
Chris Craik | d90144d | 2013-03-19 15:03:48 -0700 | [diff] [blame] | 343 | |
| 344 | // NOTE: don't issue full saveLayer, since that has side effects/is costly. instead just |
| 345 | // setup the snapshot for deferral, and re-issue the op at flush time |
| 346 | deferStruct.mRenderer.saveLayerDeferred(mArea.left, mArea.top, mArea.right, mArea.bottom, |
| 347 | mAlpha, mMode, mFlags); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 348 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 349 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 350 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 351 | renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom, mAlpha, mMode, mFlags); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 354 | virtual void output(int level, uint32_t logFlags) { |
| 355 | OP_LOG("SaveLayer%s of area " RECT_STRING, |
| 356 | (isSaveLayerAlpha() ? "Alpha" : ""),RECT_ARGS(mArea)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 357 | } |
| 358 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 359 | virtual const char* name() { return isSaveLayerAlpha() ? "SaveLayerAlpha" : "SaveLayer"; } |
| 360 | |
| 361 | int getFlags() { return mFlags; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 362 | |
| 363 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 364 | // Special case, reserved for direct DisplayList usage |
| 365 | SaveLayerOp() {} |
| 366 | DisplayListOp* reinit(float left, float top, float right, float bottom, |
| 367 | int alpha, SkXfermode::Mode mode, int flags) { |
| 368 | mArea.set(left, top, right, bottom); |
| 369 | mAlpha = alpha; |
| 370 | mMode = mode; |
| 371 | mFlags = flags; |
| 372 | return this; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 375 | bool isSaveLayerAlpha() { return mAlpha < 255 && mMode == SkXfermode::kSrcOver_Mode; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 376 | Rect mArea; |
| 377 | int mAlpha; |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 378 | SkXfermode::Mode mMode; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 379 | int mFlags; |
| 380 | }; |
| 381 | |
| 382 | class TranslateOp : public StateOp { |
| 383 | public: |
| 384 | TranslateOp(float dx, float dy) |
| 385 | : mDx(dx), mDy(dy) {} |
| 386 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 387 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 388 | renderer.translate(mDx, mDy); |
| 389 | } |
| 390 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 391 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 392 | OP_LOG("Translate by %f %f", mDx, mDy); |
| 393 | } |
| 394 | |
| 395 | virtual const char* name() { return "Translate"; } |
| 396 | |
| 397 | private: |
| 398 | float mDx; |
| 399 | float mDy; |
| 400 | }; |
| 401 | |
| 402 | class RotateOp : public StateOp { |
| 403 | public: |
| 404 | RotateOp(float degrees) |
| 405 | : mDegrees(degrees) {} |
| 406 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 407 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 408 | renderer.rotate(mDegrees); |
| 409 | } |
| 410 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 411 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 412 | OP_LOG("Rotate by %f degrees", mDegrees); |
| 413 | } |
| 414 | |
| 415 | virtual const char* name() { return "Rotate"; } |
| 416 | |
| 417 | private: |
| 418 | float mDegrees; |
| 419 | }; |
| 420 | |
| 421 | class ScaleOp : public StateOp { |
| 422 | public: |
| 423 | ScaleOp(float sx, float sy) |
| 424 | : mSx(sx), mSy(sy) {} |
| 425 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 426 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 427 | renderer.scale(mSx, mSy); |
| 428 | } |
| 429 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 430 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 431 | OP_LOG("Scale by %f %f", mSx, mSy); |
| 432 | } |
| 433 | |
| 434 | virtual const char* name() { return "Scale"; } |
| 435 | |
| 436 | private: |
| 437 | float mSx; |
| 438 | float mSy; |
| 439 | }; |
| 440 | |
| 441 | class SkewOp : public StateOp { |
| 442 | public: |
| 443 | SkewOp(float sx, float sy) |
| 444 | : mSx(sx), mSy(sy) {} |
| 445 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 446 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 447 | renderer.skew(mSx, mSy); |
| 448 | } |
| 449 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 450 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 451 | OP_LOG("Skew by %f %f", mSx, mSy); |
| 452 | } |
| 453 | |
| 454 | virtual const char* name() { return "Skew"; } |
| 455 | |
| 456 | private: |
| 457 | float mSx; |
| 458 | float mSy; |
| 459 | }; |
| 460 | |
| 461 | class SetMatrixOp : public StateOp { |
| 462 | public: |
| 463 | SetMatrixOp(SkMatrix* matrix) |
| 464 | : mMatrix(matrix) {} |
| 465 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 466 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 467 | renderer.setMatrix(mMatrix); |
| 468 | } |
| 469 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 470 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 471 | OP_LOG("SetMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); |
| 472 | } |
| 473 | |
| 474 | virtual const char* name() { return "SetMatrix"; } |
| 475 | |
| 476 | private: |
| 477 | SkMatrix* mMatrix; |
| 478 | }; |
| 479 | |
| 480 | class ConcatMatrixOp : public StateOp { |
| 481 | public: |
| 482 | ConcatMatrixOp(SkMatrix* matrix) |
| 483 | : mMatrix(matrix) {} |
| 484 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 485 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 486 | renderer.concatMatrix(mMatrix); |
| 487 | } |
| 488 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 489 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 490 | OP_LOG("ConcatMatrix " MATRIX_STRING, MATRIX_ARGS(mMatrix)); |
| 491 | } |
| 492 | |
| 493 | virtual const char* name() { return "ConcatMatrix"; } |
| 494 | |
| 495 | private: |
| 496 | SkMatrix* mMatrix; |
| 497 | }; |
| 498 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 499 | class ClipOp : public StateOp { |
| 500 | public: |
| 501 | ClipOp(SkRegion::Op op) : mOp(op) {} |
| 502 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 503 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 504 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 505 | // NOTE: must defer op BEFORE applying state, since it may read clip |
| 506 | deferStruct.mDeferredList.addClip(deferStruct.mRenderer, this); |
| 507 | |
| 508 | // TODO: Can we avoid applying complex clips at defer time? |
| 509 | applyState(deferStruct.mRenderer, saveCount); |
| 510 | } |
| 511 | |
| 512 | bool canCauseComplexClip() { |
| 513 | return ((mOp != SkRegion::kIntersect_Op) && (mOp != SkRegion::kReplace_Op)) || !isRect(); |
| 514 | } |
| 515 | |
| 516 | protected: |
| 517 | ClipOp() {} |
| 518 | virtual bool isRect() { return false; } |
| 519 | |
| 520 | SkRegion::Op mOp; |
| 521 | }; |
| 522 | |
| 523 | class ClipRectOp : public ClipOp { |
| 524 | friend class DisplayList; // give DisplayList private constructor/reinit access |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 525 | public: |
| 526 | ClipRectOp(float left, float top, float right, float bottom, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 527 | : ClipOp(op), mArea(left, top, right, bottom) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 528 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 529 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 530 | renderer.clipRect(mArea.left, mArea.top, mArea.right, mArea.bottom, mOp); |
| 531 | } |
| 532 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 533 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 534 | OP_LOG("ClipRect " RECT_STRING, RECT_ARGS(mArea)); |
| 535 | } |
| 536 | |
| 537 | virtual const char* name() { return "ClipRect"; } |
| 538 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 539 | protected: |
| 540 | virtual bool isRect() { return true; } |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 541 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 542 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 543 | ClipRectOp() {} |
| 544 | DisplayListOp* reinit(float left, float top, float right, float bottom, SkRegion::Op op) { |
| 545 | mOp = op; |
| 546 | mArea.set(left, top, right, bottom); |
| 547 | return this; |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 548 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 549 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 550 | Rect mArea; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 551 | }; |
| 552 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 553 | class ClipPathOp : public ClipOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 554 | public: |
| 555 | ClipPathOp(SkPath* path, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 556 | : ClipOp(op), mPath(path) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 557 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 558 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 559 | renderer.clipPath(mPath, mOp); |
| 560 | } |
| 561 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 562 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 563 | SkRect bounds = mPath->getBounds(); |
| 564 | OP_LOG("ClipPath bounds " RECT_STRING, |
| 565 | bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); |
| 566 | } |
| 567 | |
| 568 | virtual const char* name() { return "ClipPath"; } |
| 569 | |
| 570 | private: |
| 571 | SkPath* mPath; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 572 | }; |
| 573 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 574 | class ClipRegionOp : public ClipOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 575 | public: |
| 576 | ClipRegionOp(SkRegion* region, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 577 | : ClipOp(op), mRegion(region) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 578 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 579 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 580 | renderer.clipRegion(mRegion, mOp); |
| 581 | } |
| 582 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 583 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 584 | SkIRect bounds = mRegion->getBounds(); |
| 585 | OP_LOG("ClipRegion bounds %d %d %d %d", |
| 586 | bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); |
| 587 | } |
| 588 | |
| 589 | virtual const char* name() { return "ClipRegion"; } |
| 590 | |
| 591 | private: |
| 592 | SkRegion* mRegion; |
| 593 | SkRegion::Op mOp; |
| 594 | }; |
| 595 | |
| 596 | class ResetShaderOp : public StateOp { |
| 597 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 598 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 599 | renderer.resetShader(); |
| 600 | } |
| 601 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 602 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 603 | OP_LOGS("ResetShader"); |
| 604 | } |
| 605 | |
| 606 | virtual const char* name() { return "ResetShader"; } |
| 607 | }; |
| 608 | |
| 609 | class SetupShaderOp : public StateOp { |
| 610 | public: |
| 611 | SetupShaderOp(SkiaShader* shader) |
| 612 | : mShader(shader) {} |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 613 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 614 | renderer.setupShader(mShader); |
| 615 | } |
| 616 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 617 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 618 | OP_LOG("SetupShader, shader %p", mShader); |
| 619 | } |
| 620 | |
| 621 | virtual const char* name() { return "SetupShader"; } |
| 622 | |
| 623 | private: |
| 624 | SkiaShader* mShader; |
| 625 | }; |
| 626 | |
| 627 | class ResetColorFilterOp : public StateOp { |
| 628 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 629 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 630 | renderer.resetColorFilter(); |
| 631 | } |
| 632 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 633 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 634 | OP_LOGS("ResetColorFilter"); |
| 635 | } |
| 636 | |
| 637 | virtual const char* name() { return "ResetColorFilter"; } |
| 638 | }; |
| 639 | |
| 640 | class SetupColorFilterOp : public StateOp { |
| 641 | public: |
| 642 | SetupColorFilterOp(SkiaColorFilter* colorFilter) |
| 643 | : mColorFilter(colorFilter) {} |
| 644 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 645 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 646 | renderer.setupColorFilter(mColorFilter); |
| 647 | } |
| 648 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 649 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 650 | OP_LOG("SetupColorFilter, filter %p", mColorFilter); |
| 651 | } |
| 652 | |
| 653 | virtual const char* name() { return "SetupColorFilter"; } |
| 654 | |
| 655 | private: |
| 656 | SkiaColorFilter* mColorFilter; |
| 657 | }; |
| 658 | |
| 659 | class ResetShadowOp : public StateOp { |
| 660 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 661 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 662 | renderer.resetShadow(); |
| 663 | } |
| 664 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 665 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 666 | OP_LOGS("ResetShadow"); |
| 667 | } |
| 668 | |
| 669 | virtual const char* name() { return "ResetShadow"; } |
| 670 | }; |
| 671 | |
| 672 | class SetupShadowOp : public StateOp { |
| 673 | public: |
| 674 | SetupShadowOp(float radius, float dx, float dy, int color) |
| 675 | : mRadius(radius), mDx(dx), mDy(dy), mColor(color) {} |
| 676 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 677 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 678 | renderer.setupShadow(mRadius, mDx, mDy, mColor); |
| 679 | } |
| 680 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 681 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 682 | OP_LOG("SetupShadow, radius %f, %f, %f, color %#x", mRadius, mDx, mDy, mColor); |
| 683 | } |
| 684 | |
| 685 | virtual const char* name() { return "SetupShadow"; } |
| 686 | |
| 687 | private: |
| 688 | float mRadius; |
| 689 | float mDx; |
| 690 | float mDy; |
| 691 | int mColor; |
| 692 | }; |
| 693 | |
| 694 | class ResetPaintFilterOp : public StateOp { |
| 695 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 696 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 697 | renderer.resetPaintFilter(); |
| 698 | } |
| 699 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 700 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 701 | OP_LOGS("ResetPaintFilter"); |
| 702 | } |
| 703 | |
| 704 | virtual const char* name() { return "ResetPaintFilter"; } |
| 705 | }; |
| 706 | |
| 707 | class SetupPaintFilterOp : public StateOp { |
| 708 | public: |
| 709 | SetupPaintFilterOp(int clearBits, int setBits) |
| 710 | : mClearBits(clearBits), mSetBits(setBits) {} |
| 711 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 712 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 713 | renderer.setupPaintFilter(mClearBits, mSetBits); |
| 714 | } |
| 715 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 716 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 717 | OP_LOG("SetupPaintFilter, clear %#x, set %#x", mClearBits, mSetBits); |
| 718 | } |
| 719 | |
| 720 | virtual const char* name() { return "SetupPaintFilter"; } |
| 721 | |
| 722 | private: |
| 723 | int mClearBits; |
| 724 | int mSetBits; |
| 725 | }; |
| 726 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 727 | /////////////////////////////////////////////////////////////////////////////// |
| 728 | // DRAW OPERATIONS - these are operations that can draw to the canvas's device |
| 729 | /////////////////////////////////////////////////////////////////////////////// |
| 730 | |
| 731 | class DrawBitmapOp : public DrawBoundedOp { |
| 732 | public: |
| 733 | DrawBitmapOp(SkBitmap* bitmap, float left, float top, SkPaint* paint) |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 734 | : DrawBoundedOp(left, top, left + bitmap->width(), top + bitmap->height(), paint), |
| 735 | mBitmap(bitmap), mAtlasEntry(NULL) { |
| 736 | } |
| 737 | |
| 738 | DrawBitmapOp(SkBitmap* bitmap, float left, float top, SkPaint* paint, |
| 739 | const AssetAtlas::Entry* entry) |
| 740 | : DrawBoundedOp(left, top, left + bitmap->width(), top + bitmap->height(), paint), |
| 741 | mBitmap(bitmap), mAtlasEntry(entry) { |
| 742 | if (entry) mUvMapper = entry->uvMapper; |
| 743 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 744 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 745 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 746 | return renderer.drawBitmap(mBitmap, mLocalBounds.left, mLocalBounds.top, |
| 747 | getPaint(renderer)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 750 | #define SET_TEXTURE(ptr, posRect, offsetRect, texCoordsRect, xDim, yDim) \ |
| 751 | TextureVertex::set(ptr++, posRect.xDim - offsetRect.left, posRect.yDim - offsetRect.top, \ |
| 752 | texCoordsRect.xDim, texCoordsRect.yDim) |
| 753 | |
| 754 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
| 755 | const Vector<DrawOp*>& ops, const Rect& bounds) { |
| 756 | renderer.restoreDisplayState(state, true); // restore all but the clip |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 757 | TextureVertex vertices[6 * ops.size()]; |
| 758 | TextureVertex* vertex = &vertices[0]; |
| 759 | |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 760 | bool transformed = false; |
| 761 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 762 | // TODO: manually handle rect clip for bitmaps by adjusting texCoords per op, |
| 763 | // and allowing them to be merged in getBatchId() |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 764 | for (unsigned int i = 0; i < ops.size(); i++) { |
| 765 | const Rect& opBounds = ops[i]->state.mBounds; |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 766 | // When we reach multiDraw(), the matrix can be either |
| 767 | // pureTranslate or simple (translate and/or scale). |
| 768 | // If the matrix is not pureTranslate, then we have a scale |
| 769 | if (!ops[i]->state.mMatrix.isPureTranslate()) transformed = true; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 770 | |
| 771 | Rect texCoords(0, 0, 1, 1); |
| 772 | ((DrawBitmapOp*) ops[i])->mUvMapper.map(texCoords); |
| 773 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 774 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top); |
| 775 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top); |
| 776 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom); |
| 777 | |
| 778 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom); |
| 779 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top); |
| 780 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, bottom); |
| 781 | } |
| 782 | |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 783 | return renderer.drawBitmaps(mBitmap, ops.size(), &vertices[0], |
| 784 | transformed, bounds, mPaint); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 785 | } |
| 786 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 787 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 788 | OP_LOG("Draw bitmap %p at %f %f", mBitmap, mLocalBounds.left, mLocalBounds.top); |
| 789 | } |
| 790 | |
| 791 | virtual const char* name() { return "DrawBitmap"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 792 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 793 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 794 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
| 795 | deferInfo.mergeId = mAtlasEntry ? (mergeid_t) &mAtlasEntry->atlas : (mergeid_t) mBitmap; |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 796 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 797 | // Don't merge A8 bitmaps - the paint's color isn't compared by mergeId, or in |
| 798 | // MergingDrawBatch::canMergeWith() |
| 799 | // TODO: support clipped bitmaps by handling them in SET_TEXTURE |
| 800 | deferInfo.mergeable = state.mMatrix.isSimple() && !state.mClipSideFlags && |
| 801 | OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode && |
| 802 | (mBitmap->getConfig() != SkBitmap::kA8_Config); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 803 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 804 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 805 | const SkBitmap* bitmap() { return mBitmap; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 806 | protected: |
| 807 | SkBitmap* mBitmap; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 808 | const AssetAtlas::Entry* mAtlasEntry; |
| 809 | UvMapper mUvMapper; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 810 | }; |
| 811 | |
| 812 | class DrawBitmapMatrixOp : public DrawBoundedOp { |
| 813 | public: |
| 814 | DrawBitmapMatrixOp(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) |
| 815 | : DrawBoundedOp(paint), mBitmap(bitmap), mMatrix(matrix) { |
| 816 | mLocalBounds.set(0, 0, bitmap->width(), bitmap->height()); |
| 817 | const mat4 transform(*matrix); |
| 818 | transform.mapRect(mLocalBounds); |
| 819 | } |
| 820 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 821 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 822 | return renderer.drawBitmap(mBitmap, mMatrix, getPaint(renderer)); |
| 823 | } |
| 824 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 825 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 826 | OP_LOG("Draw bitmap %p matrix " MATRIX_STRING, mBitmap, MATRIX_ARGS(mMatrix)); |
| 827 | } |
| 828 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 829 | virtual const char* name() { return "DrawBitmapMatrix"; } |
| 830 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 831 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 832 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 833 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 834 | |
| 835 | private: |
| 836 | SkBitmap* mBitmap; |
| 837 | SkMatrix* mMatrix; |
| 838 | }; |
| 839 | |
| 840 | class DrawBitmapRectOp : public DrawBoundedOp { |
| 841 | public: |
| 842 | DrawBitmapRectOp(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, |
| 843 | float dstLeft, float dstTop, float dstRight, float dstBottom, SkPaint* paint) |
| 844 | : DrawBoundedOp(dstLeft, dstTop, dstRight, dstBottom, paint), |
| 845 | mBitmap(bitmap), mSrc(srcLeft, srcTop, srcRight, srcBottom) {} |
| 846 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 847 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 848 | return renderer.drawBitmap(mBitmap, mSrc.left, mSrc.top, mSrc.right, mSrc.bottom, |
| 849 | mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom, |
| 850 | getPaint(renderer)); |
| 851 | } |
| 852 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 853 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 854 | OP_LOG("Draw bitmap %p src="RECT_STRING", dst="RECT_STRING, |
| 855 | mBitmap, RECT_ARGS(mSrc), RECT_ARGS(mLocalBounds)); |
| 856 | } |
| 857 | |
| 858 | virtual const char* name() { return "DrawBitmapRect"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 859 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 860 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 861 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 862 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 863 | |
| 864 | private: |
| 865 | SkBitmap* mBitmap; |
| 866 | Rect mSrc; |
| 867 | }; |
| 868 | |
| 869 | class DrawBitmapDataOp : public DrawBitmapOp { |
| 870 | public: |
| 871 | DrawBitmapDataOp(SkBitmap* bitmap, float left, float top, SkPaint* paint) |
| 872 | : DrawBitmapOp(bitmap, left, top, paint) {} |
| 873 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 874 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 875 | return renderer.drawBitmapData(mBitmap, mLocalBounds.left, |
| 876 | mLocalBounds.top, getPaint(renderer)); |
| 877 | } |
| 878 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 879 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 880 | OP_LOG("Draw bitmap %p", mBitmap); |
| 881 | } |
| 882 | |
| 883 | virtual const char* name() { return "DrawBitmapData"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 884 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 885 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 886 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 887 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 888 | }; |
| 889 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 890 | class DrawBitmapMeshOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 891 | public: |
| 892 | DrawBitmapMeshOp(SkBitmap* bitmap, int meshWidth, int meshHeight, |
| 893 | float* vertices, int* colors, SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 894 | : DrawBoundedOp(vertices, 2 * (meshWidth + 1) * (meshHeight + 1), paint), |
| 895 | mBitmap(bitmap), mMeshWidth(meshWidth), mMeshHeight(meshHeight), |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 896 | mVertices(vertices), mColors(colors) {} |
| 897 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 898 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 899 | return renderer.drawBitmapMesh(mBitmap, mMeshWidth, mMeshHeight, |
| 900 | mVertices, mColors, getPaint(renderer)); |
| 901 | } |
| 902 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 903 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 904 | OP_LOG("Draw bitmap %p mesh %d x %d", mBitmap, mMeshWidth, mMeshHeight); |
| 905 | } |
| 906 | |
| 907 | virtual const char* name() { return "DrawBitmapMesh"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 908 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 909 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 910 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 911 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 912 | |
| 913 | private: |
| 914 | SkBitmap* mBitmap; |
| 915 | int mMeshWidth; |
| 916 | int mMeshHeight; |
| 917 | float* mVertices; |
| 918 | int* mColors; |
| 919 | }; |
| 920 | |
| 921 | class DrawPatchOp : public DrawBoundedOp { |
| 922 | public: |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 923 | DrawPatchOp(SkBitmap* bitmap, Res_png_9patch* patch, |
| 924 | float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 925 | : DrawBoundedOp(left, top, right, bottom, 0), |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 926 | mBitmap(bitmap), mPatch(patch), mAlpha(alpha), mMode(mode), |
| 927 | mGenerationId(0), mMesh(NULL) { |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 928 | mEntry = Caches::getInstance().assetAtlas.getEntry(bitmap); |
| 929 | }; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 930 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 931 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 932 | if (!mMesh || renderer.getCaches().patchCache.getGenerationId() != mGenerationId) { |
| 933 | PatchCache& cache = renderer.getCaches().patchCache; |
| 934 | mMesh = cache.get(mEntry, mBitmap->width(), mBitmap->height(), |
| 935 | mLocalBounds.right - mLocalBounds.left, mLocalBounds.bottom - mLocalBounds.top, |
| 936 | mPatch); |
| 937 | mGenerationId = cache.getGenerationId(); |
| 938 | } |
| 939 | // We're not calling the public variant of drawPatch() here |
| 940 | // This method won't perform the quickReject() since we've already done it at this point |
| 941 | return renderer.drawPatch(mBitmap, mMesh, mEntry, mLocalBounds.left, mLocalBounds.top, |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 942 | mLocalBounds.right, mLocalBounds.bottom, mAlpha, mMode); |
| 943 | } |
| 944 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 945 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 946 | OP_LOG("Draw patch "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 947 | } |
| 948 | |
| 949 | virtual const char* name() { return "DrawPatch"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 950 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 951 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 952 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch; |
Romain Guy | 5216c3b | 2013-06-14 16:31:37 -0700 | [diff] [blame] | 953 | deferInfo.mergeId = mEntry ? (mergeid_t) &mEntry->atlas : (mergeid_t) mBitmap; |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 954 | deferInfo.mergeable = true; |
Romain Guy | 5216c3b | 2013-06-14 16:31:37 -0700 | [diff] [blame] | 955 | deferInfo.opaqueOverBounds = isOpaqueOverBounds() && mBitmap->isOpaque(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 956 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 957 | |
| 958 | private: |
| 959 | SkBitmap* mBitmap; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 960 | Res_png_9patch* mPatch; |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 961 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 962 | int mAlpha; |
| 963 | SkXfermode::Mode mMode; |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 964 | |
| 965 | uint32_t mGenerationId; |
| 966 | const Patch* mMesh; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 967 | AssetAtlas::Entry* mEntry; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 968 | }; |
| 969 | |
| 970 | class DrawColorOp : public DrawOp { |
| 971 | public: |
| 972 | DrawColorOp(int color, SkXfermode::Mode mode) |
| 973 | : DrawOp(0), mColor(color), mMode(mode) {}; |
| 974 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 975 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 976 | return renderer.drawColor(mColor, mMode); |
| 977 | } |
| 978 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 979 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 980 | OP_LOG("Draw color %#x, mode %d", mColor, mMode); |
| 981 | } |
| 982 | |
| 983 | virtual const char* name() { return "DrawColor"; } |
| 984 | |
| 985 | private: |
| 986 | int mColor; |
| 987 | SkXfermode::Mode mMode; |
| 988 | }; |
| 989 | |
| 990 | class DrawStrokableOp : public DrawBoundedOp { |
| 991 | public: |
| 992 | DrawStrokableOp(float left, float top, float right, float bottom, SkPaint* paint) |
| 993 | : DrawBoundedOp(left, top, right, bottom, paint) {}; |
| 994 | |
| 995 | bool getLocalBounds(Rect& localBounds) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 996 | localBounds.set(mLocalBounds); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 997 | if (mPaint && mPaint->getStyle() != SkPaint::kFill_Style) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 998 | localBounds.outset(strokeWidthOutset()); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 999 | } |
| 1000 | return true; |
| 1001 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1002 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1003 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1004 | if (mPaint->getPathEffect()) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1005 | deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1006 | } else { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1007 | deferInfo.batchId = mPaint->isAntiAlias() ? |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1008 | DeferredDisplayList::kOpBatch_AlphaVertices : |
| 1009 | DeferredDisplayList::kOpBatch_Vertices; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1010 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1011 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1012 | }; |
| 1013 | |
| 1014 | class DrawRectOp : public DrawStrokableOp { |
| 1015 | public: |
| 1016 | DrawRectOp(float left, float top, float right, float bottom, SkPaint* paint) |
| 1017 | : DrawStrokableOp(left, top, right, bottom, paint) {} |
| 1018 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1019 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1020 | return renderer.drawRect(mLocalBounds.left, mLocalBounds.top, |
| 1021 | mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); |
| 1022 | } |
| 1023 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1024 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1025 | OP_LOG("Draw Rect "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 1026 | } |
| 1027 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1028 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 1029 | DrawStrokableOp::onDefer(renderer, deferInfo); |
| 1030 | deferInfo.opaqueOverBounds = isOpaqueOverBounds() && |
| 1031 | mPaint->getStyle() == SkPaint::kFill_Style; |
| 1032 | } |
| 1033 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1034 | virtual const char* name() { return "DrawRect"; } |
| 1035 | }; |
| 1036 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1037 | class DrawRectsOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1038 | public: |
| 1039 | DrawRectsOp(const float* rects, int count, SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1040 | : DrawBoundedOp(rects, count, paint), |
| 1041 | mRects(rects), mCount(count) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1042 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1043 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1044 | return renderer.drawRects(mRects, mCount, getPaint(renderer)); |
| 1045 | } |
| 1046 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1047 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1048 | OP_LOG("Draw Rects count %d", mCount); |
| 1049 | } |
| 1050 | |
| 1051 | virtual const char* name() { return "DrawRects"; } |
| 1052 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1053 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 1054 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Vertices; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1057 | private: |
| 1058 | const float* mRects; |
| 1059 | int mCount; |
| 1060 | }; |
| 1061 | |
| 1062 | class DrawRoundRectOp : public DrawStrokableOp { |
| 1063 | public: |
| 1064 | DrawRoundRectOp(float left, float top, float right, float bottom, |
| 1065 | float rx, float ry, SkPaint* paint) |
| 1066 | : DrawStrokableOp(left, top, right, bottom, paint), mRx(rx), mRy(ry) {} |
| 1067 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1068 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1069 | return renderer.drawRoundRect(mLocalBounds.left, mLocalBounds.top, |
| 1070 | mLocalBounds.right, mLocalBounds.bottom, mRx, mRy, getPaint(renderer)); |
| 1071 | } |
| 1072 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1073 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1074 | OP_LOG("Draw RoundRect "RECT_STRING", rx %f, ry %f", RECT_ARGS(mLocalBounds), mRx, mRy); |
| 1075 | } |
| 1076 | |
| 1077 | virtual const char* name() { return "DrawRoundRect"; } |
| 1078 | |
| 1079 | private: |
| 1080 | float mRx; |
| 1081 | float mRy; |
| 1082 | }; |
| 1083 | |
| 1084 | class DrawCircleOp : public DrawStrokableOp { |
| 1085 | public: |
| 1086 | DrawCircleOp(float x, float y, float radius, SkPaint* paint) |
| 1087 | : DrawStrokableOp(x - radius, y - radius, x + radius, y + radius, paint), |
| 1088 | mX(x), mY(y), mRadius(radius) {} |
| 1089 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1090 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1091 | return renderer.drawCircle(mX, mY, mRadius, getPaint(renderer)); |
| 1092 | } |
| 1093 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1094 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1095 | OP_LOG("Draw Circle x %f, y %f, r %f", mX, mY, mRadius); |
| 1096 | } |
| 1097 | |
| 1098 | virtual const char* name() { return "DrawCircle"; } |
| 1099 | |
| 1100 | private: |
| 1101 | float mX; |
| 1102 | float mY; |
| 1103 | float mRadius; |
| 1104 | }; |
| 1105 | |
| 1106 | class DrawOvalOp : public DrawStrokableOp { |
| 1107 | public: |
| 1108 | DrawOvalOp(float left, float top, float right, float bottom, SkPaint* paint) |
| 1109 | : DrawStrokableOp(left, top, right, bottom, paint) {} |
| 1110 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1111 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1112 | return renderer.drawOval(mLocalBounds.left, mLocalBounds.top, |
| 1113 | mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); |
| 1114 | } |
| 1115 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1116 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1117 | OP_LOG("Draw Oval "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 1118 | } |
| 1119 | |
| 1120 | virtual const char* name() { return "DrawOval"; } |
| 1121 | }; |
| 1122 | |
| 1123 | class DrawArcOp : public DrawStrokableOp { |
| 1124 | public: |
| 1125 | DrawArcOp(float left, float top, float right, float bottom, |
| 1126 | float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) |
| 1127 | : DrawStrokableOp(left, top, right, bottom, paint), |
| 1128 | mStartAngle(startAngle), mSweepAngle(sweepAngle), mUseCenter(useCenter) {} |
| 1129 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1130 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1131 | return renderer.drawArc(mLocalBounds.left, mLocalBounds.top, |
| 1132 | mLocalBounds.right, mLocalBounds.bottom, |
| 1133 | mStartAngle, mSweepAngle, mUseCenter, getPaint(renderer)); |
| 1134 | } |
| 1135 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1136 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1137 | OP_LOG("Draw Arc "RECT_STRING", start %f, sweep %f, useCenter %d", |
| 1138 | RECT_ARGS(mLocalBounds), mStartAngle, mSweepAngle, mUseCenter); |
| 1139 | } |
| 1140 | |
| 1141 | virtual const char* name() { return "DrawArc"; } |
| 1142 | |
| 1143 | private: |
| 1144 | float mStartAngle; |
| 1145 | float mSweepAngle; |
| 1146 | bool mUseCenter; |
| 1147 | }; |
| 1148 | |
| 1149 | class DrawPathOp : public DrawBoundedOp { |
| 1150 | public: |
| 1151 | DrawPathOp(SkPath* path, SkPaint* paint) |
| 1152 | : DrawBoundedOp(paint), mPath(path) { |
| 1153 | float left, top, offset; |
| 1154 | uint32_t width, height; |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1155 | PathCache::computePathBounds(path, paint, left, top, offset, width, height); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1156 | left -= offset; |
| 1157 | top -= offset; |
| 1158 | mLocalBounds.set(left, top, left + width, top + height); |
| 1159 | } |
| 1160 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1161 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1162 | return renderer.drawPath(mPath, getPaint(renderer)); |
| 1163 | } |
| 1164 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1165 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1166 | SkPaint* paint = getPaint(renderer); |
| 1167 | renderer.getCaches().pathCache.precache(mPath, paint); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1168 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1169 | deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture; |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1170 | } |
| 1171 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1172 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1173 | OP_LOG("Draw Path %p in "RECT_STRING, mPath, RECT_ARGS(mLocalBounds)); |
| 1174 | } |
| 1175 | |
| 1176 | virtual const char* name() { return "DrawPath"; } |
| 1177 | |
| 1178 | private: |
| 1179 | SkPath* mPath; |
| 1180 | }; |
| 1181 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1182 | class DrawLinesOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1183 | public: |
| 1184 | DrawLinesOp(float* points, int count, SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1185 | : DrawBoundedOp(points, count, paint), |
| 1186 | mPoints(points), mCount(count) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1187 | mLocalBounds.outset(strokeWidthOutset()); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1190 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1191 | return renderer.drawLines(mPoints, mCount, getPaint(renderer)); |
| 1192 | } |
| 1193 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1194 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1195 | OP_LOG("Draw Lines count %d", mCount); |
| 1196 | } |
| 1197 | |
| 1198 | virtual const char* name() { return "DrawLines"; } |
| 1199 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1200 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
| 1201 | deferInfo.batchId = mPaint->isAntiAlias() ? |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1202 | DeferredDisplayList::kOpBatch_AlphaVertices : |
| 1203 | DeferredDisplayList::kOpBatch_Vertices; |
| 1204 | } |
| 1205 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1206 | protected: |
| 1207 | float* mPoints; |
| 1208 | int mCount; |
| 1209 | }; |
| 1210 | |
| 1211 | class DrawPointsOp : public DrawLinesOp { |
| 1212 | public: |
| 1213 | DrawPointsOp(float* points, int count, SkPaint* paint) |
| 1214 | : DrawLinesOp(points, count, paint) {} |
| 1215 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1216 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1217 | return renderer.drawPoints(mPoints, mCount, getPaint(renderer)); |
| 1218 | } |
| 1219 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1220 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1221 | OP_LOG("Draw Points count %d", mCount); |
| 1222 | } |
| 1223 | |
| 1224 | virtual const char* name() { return "DrawPoints"; } |
| 1225 | }; |
| 1226 | |
| 1227 | class DrawSomeTextOp : public DrawOp { |
| 1228 | public: |
| 1229 | DrawSomeTextOp(const char* text, int bytesCount, int count, SkPaint* paint) |
| 1230 | : DrawOp(paint), mText(text), mBytesCount(bytesCount), mCount(count) {}; |
| 1231 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1232 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1233 | OP_LOG("Draw some text, %d bytes", mBytesCount); |
| 1234 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1235 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1236 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1237 | SkPaint* paint = getPaint(renderer); |
| 1238 | FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint); |
| 1239 | fontRenderer.precache(paint, mText, mCount, mat4::identity()); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1240 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1241 | deferInfo.batchId = mPaint->getColor() == 0xff000000 ? |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1242 | DeferredDisplayList::kOpBatch_Text : |
| 1243 | DeferredDisplayList::kOpBatch_ColorText; |
| 1244 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1245 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1246 | protected: |
| 1247 | const char* mText; |
| 1248 | int mBytesCount; |
| 1249 | int mCount; |
| 1250 | }; |
| 1251 | |
| 1252 | class DrawTextOnPathOp : public DrawSomeTextOp { |
| 1253 | public: |
| 1254 | DrawTextOnPathOp(const char* text, int bytesCount, int count, |
| 1255 | SkPath* path, float hOffset, float vOffset, SkPaint* paint) |
| 1256 | : DrawSomeTextOp(text, bytesCount, count, paint), |
| 1257 | mPath(path), mHOffset(hOffset), mVOffset(vOffset) { |
| 1258 | /* TODO: inherit from DrawBounded and init mLocalBounds */ |
| 1259 | } |
| 1260 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1261 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1262 | return renderer.drawTextOnPath(mText, mBytesCount, mCount, mPath, |
| 1263 | mHOffset, mVOffset, getPaint(renderer)); |
| 1264 | } |
| 1265 | |
| 1266 | virtual const char* name() { return "DrawTextOnPath"; } |
| 1267 | |
| 1268 | private: |
| 1269 | SkPath* mPath; |
| 1270 | float mHOffset; |
| 1271 | float mVOffset; |
| 1272 | }; |
| 1273 | |
| 1274 | class DrawPosTextOp : public DrawSomeTextOp { |
| 1275 | public: |
| 1276 | DrawPosTextOp(const char* text, int bytesCount, int count, |
| 1277 | const float* positions, SkPaint* paint) |
| 1278 | : DrawSomeTextOp(text, bytesCount, count, paint), mPositions(positions) { |
| 1279 | /* TODO: inherit from DrawBounded and init mLocalBounds */ |
| 1280 | } |
| 1281 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1282 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1283 | return renderer.drawPosText(mText, mBytesCount, mCount, mPositions, getPaint(renderer)); |
| 1284 | } |
| 1285 | |
| 1286 | virtual const char* name() { return "DrawPosText"; } |
| 1287 | |
| 1288 | private: |
| 1289 | const float* mPositions; |
| 1290 | }; |
| 1291 | |
| 1292 | class DrawTextOp : public DrawBoundedOp { |
| 1293 | public: |
| 1294 | DrawTextOp(const char* text, int bytesCount, int count, float x, float y, |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1295 | const float* positions, SkPaint* paint, float totalAdvance, const Rect& bounds) |
| 1296 | : DrawBoundedOp(bounds, paint), mText(text), mBytesCount(bytesCount), mCount(count), |
| 1297 | mX(x), mY(y), mPositions(positions), mTotalAdvance(totalAdvance) { |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1298 | memset(&mPrecacheTransform.data[0], 0xff, 16 * sizeof(float)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1301 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) { |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1302 | SkPaint* paint = getPaint(renderer); |
| 1303 | FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint); |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1304 | const mat4& transform = renderer.findBestFontTransform(state.mMatrix); |
| 1305 | if (mPrecacheTransform != transform) { |
| 1306 | fontRenderer.precache(paint, mText, mCount, transform); |
| 1307 | mPrecacheTransform = transform; |
| 1308 | } |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1309 | deferInfo.batchId = mPaint->getColor() == 0xff000000 ? |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1310 | DeferredDisplayList::kOpBatch_Text : |
| 1311 | DeferredDisplayList::kOpBatch_ColorText; |
| 1312 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1313 | deferInfo.mergeId = (mergeid_t)mPaint->getColor(); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1314 | |
| 1315 | // don't merge decorated text - the decorations won't draw in order |
| 1316 | bool noDecorations = !(mPaint->getFlags() & (SkPaint::kUnderlineText_Flag | |
| 1317 | SkPaint::kStrikeThruText_Flag)); |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1318 | deferInfo.mergeable = state.mMatrix.isPureTranslate() && noDecorations && |
| 1319 | OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1322 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1323 | return renderer.drawText(mText, mBytesCount, mCount, mX, mY, |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1324 | mPositions, getPaint(renderer), mTotalAdvance, mLocalBounds); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1327 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
| 1328 | const Vector<DrawOp*>& ops, const Rect& bounds) { |
| 1329 | status_t status = DrawGlInfo::kStatusDone; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1330 | for (unsigned int i = 0; i < ops.size(); i++) { |
| 1331 | DrawOpMode drawOpMode = (i == ops.size() - 1) ? kDrawOpMode_Flush : kDrawOpMode_Defer; |
| 1332 | renderer.restoreDisplayState(ops[i]->state, true); // restore all but the clip |
| 1333 | |
| 1334 | DrawTextOp& op = *((DrawTextOp*)ops[i]); |
| 1335 | status |= renderer.drawText(op.mText, op.mBytesCount, op.mCount, op.mX, op.mY, |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1336 | op.mPositions, op.getPaint(renderer), op.mTotalAdvance, op.mLocalBounds, |
| 1337 | drawOpMode); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1338 | } |
| 1339 | return status; |
| 1340 | } |
| 1341 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1342 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1343 | OP_LOG("Draw Text of count %d, bytes %d", mCount, mBytesCount); |
| 1344 | } |
| 1345 | |
| 1346 | virtual const char* name() { return "DrawText"; } |
| 1347 | |
| 1348 | private: |
| 1349 | const char* mText; |
| 1350 | int mBytesCount; |
| 1351 | int mCount; |
| 1352 | float mX; |
| 1353 | float mY; |
| 1354 | const float* mPositions; |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1355 | float mTotalAdvance; |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1356 | mat4 mPrecacheTransform; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1357 | }; |
| 1358 | |
| 1359 | /////////////////////////////////////////////////////////////////////////////// |
| 1360 | // SPECIAL DRAW OPERATIONS |
| 1361 | /////////////////////////////////////////////////////////////////////////////// |
| 1362 | |
| 1363 | class DrawFunctorOp : public DrawOp { |
| 1364 | public: |
| 1365 | DrawFunctorOp(Functor* functor) |
| 1366 | : DrawOp(0), mFunctor(functor) {} |
| 1367 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1368 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1369 | renderer.startMark("GL functor"); |
| 1370 | status_t ret = renderer.callDrawGLFunction(mFunctor, dirty); |
| 1371 | renderer.endMark(); |
| 1372 | return ret; |
| 1373 | } |
| 1374 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1375 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1376 | OP_LOG("Draw Functor %p", mFunctor); |
| 1377 | } |
| 1378 | |
| 1379 | virtual const char* name() { return "DrawFunctor"; } |
| 1380 | |
| 1381 | private: |
| 1382 | Functor* mFunctor; |
| 1383 | }; |
| 1384 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1385 | class DrawDisplayListOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1386 | public: |
| 1387 | DrawDisplayListOp(DisplayList* displayList, int flags) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1388 | : DrawBoundedOp(0, 0, displayList->getWidth(), displayList->getHeight(), 0), |
| 1389 | mDisplayList(displayList), mFlags(flags) {} |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1390 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 1391 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 1392 | bool useQuickReject) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1393 | if (mDisplayList && mDisplayList->isRenderable()) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1394 | mDisplayList->defer(deferStruct, level + 1); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1395 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1396 | } |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 1397 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 1398 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1399 | if (mDisplayList && mDisplayList->isRenderable()) { |
| 1400 | mDisplayList->replay(replayStruct, level + 1); |
| 1401 | } |
| 1402 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1403 | |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1404 | // NOT USED since replay() is overridden |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1405 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1406 | return DrawGlInfo::kStatusDone; |
| 1407 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1408 | |
| 1409 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1410 | OP_LOG("Draw Display List %p, flags %#x", mDisplayList, mFlags); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1411 | if (mDisplayList && (logFlags & kOpLogFlag_Recurse)) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1412 | mDisplayList->output(level + 1); |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | virtual const char* name() { return "DrawDisplayList"; } |
| 1417 | |
| 1418 | private: |
| 1419 | DisplayList* mDisplayList; |
| 1420 | int mFlags; |
| 1421 | }; |
| 1422 | |
| 1423 | class DrawLayerOp : public DrawOp { |
| 1424 | public: |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1425 | DrawLayerOp(Layer* layer, float x, float y) |
| 1426 | : DrawOp(0), mLayer(layer), mX(x), mY(y) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1427 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1428 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1429 | return renderer.drawLayer(mLayer, mX, mY); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1432 | virtual void output(int level, uint32_t logFlags) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1433 | OP_LOG("Draw Layer %p at %f %f", mLayer, mX, mY); |
| 1434 | } |
| 1435 | |
| 1436 | virtual const char* name() { return "DrawLayer"; } |
| 1437 | |
| 1438 | private: |
| 1439 | Layer* mLayer; |
| 1440 | float mX; |
| 1441 | float mY; |
| 1442 | }; |
| 1443 | |
| 1444 | }; // namespace uirenderer |
| 1445 | }; // namespace android |
| 1446 | |
| 1447 | #endif // ANDROID_HWUI_DISPLAY_OPERATION_H |