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 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 80 | virtual void output(int level, uint32_t logFlags = 0) const = 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; |
| 85 | }; |
| 86 | |
| 87 | class StateOp : public DisplayListOp { |
| 88 | public: |
| 89 | StateOp() {}; |
| 90 | |
| 91 | virtual ~StateOp() {} |
| 92 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 93 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 94 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 95 | // default behavior only affects immediate, deferrable state, issue directly to renderer |
| 96 | applyState(deferStruct.mRenderer, saveCount); |
| 97 | } |
| 98 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 99 | /** |
| 100 | * State operations are applied directly to the renderer, but can cause the deferred drawing op |
| 101 | * list to flush |
| 102 | */ |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 103 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 104 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 105 | applyState(replayStruct.mRenderer, saveCount); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 106 | } |
| 107 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 108 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const = 0; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | class DrawOp : public DisplayListOp { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 112 | friend class MergingDrawBatch; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 113 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 114 | DrawOp(const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 115 | : mPaint(paint), mQuickRejected(false) {} |
| 116 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 117 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 118 | bool useQuickReject) { |
| 119 | if (mQuickRejected && CC_LIKELY(useQuickReject)) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 120 | return; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 123 | deferStruct.mDeferredList.addDrawOp(deferStruct.mRenderer, this); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 126 | virtual void replay(ReplayStateStruct& replayStruct, 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; |
| 130 | } |
| 131 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 132 | replayStruct.mDrawGlStatus |= applyDraw(replayStruct.mRenderer, replayStruct.mDirty); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 135 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) = 0; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 136 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 137 | /** |
| 138 | * Draw multiple instances of an operation, must be overidden for operations that merge |
| 139 | * |
| 140 | * Currently guarantees certain similarities between ops (see MergingDrawBatch::canMergeWith), |
| 141 | * and pure translation transformations. Other guarantees of similarity should be enforced by |
| 142 | * reducing which operations are tagged as mergeable. |
| 143 | */ |
| 144 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 145 | const Vector<OpStatePair>& ops, const Rect& bounds) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 146 | status_t status = DrawGlInfo::kStatusDone; |
| 147 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 148 | renderer.restoreDisplayState(*(ops[i].state), true); |
| 149 | status |= ops[i].op->applyDraw(renderer, dirty); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 150 | } |
| 151 | return status; |
| 152 | } |
| 153 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 154 | /** |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 155 | * When this method is invoked the state field is initialized to have the |
| 156 | * final rendering state. We can thus use it to process data as it will be |
| 157 | * used at draw time. |
| 158 | * |
| 159 | * Additionally, this method allows subclasses to provide defer-time preferences for batching |
| 160 | * and merging. |
| 161 | * |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 162 | * 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] | 163 | */ |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 164 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 165 | const DeferredDisplayState& state) {} |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 166 | |
Chris Craik | 5e49b30 | 2013-07-30 19:05:20 -0700 | [diff] [blame] | 167 | /** |
| 168 | * Query the conservative, local bounds (unmapped) bounds of the op. |
| 169 | * |
| 170 | * returns true if bounds exist |
| 171 | */ |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 172 | virtual bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) { |
| 173 | return false; |
| 174 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 175 | |
| 176 | // TODO: better refine localbounds usage |
| 177 | void setQuickRejected(bool quickRejected) { mQuickRejected = quickRejected; } |
| 178 | bool getQuickRejected() { return mQuickRejected; } |
| 179 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 180 | inline int getPaintAlpha() const { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 181 | return OpenGLRenderer::getAlphaDirect(mPaint); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 182 | } |
| 183 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 184 | inline float strokeWidthOutset() { |
Chris Craik | f0a5907 | 2013-11-19 18:00:46 -0800 | [diff] [blame] | 185 | // since anything AA stroke with less than 1.0 pixel width is drawn with an alpha-reduced |
| 186 | // 1.0 stroke, treat 1.0 as minimum. |
| 187 | |
| 188 | // TODO: it would be nice if this could take scale into account, but scale isn't stable |
| 189 | // since higher levels of the view hierarchy can change scale out from underneath it. |
| 190 | return fmaxf(mPaint->getStrokeWidth(), 1) * 0.5f; |
Chris Craik | e7c69c6 | 2013-04-03 09:55:48 -0700 | [diff] [blame] | 191 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 192 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 193 | protected: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 194 | const SkPaint* getPaint(OpenGLRenderer& renderer) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 195 | return renderer.filterPaint(mPaint); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 198 | // Helper method for determining op opaqueness. Assumes op fills its bounds in local |
| 199 | // coordinates, and that paint's alpha is used |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 200 | inline bool isOpaqueOverBounds(const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 201 | // ensure that local bounds cover mapped bounds |
| 202 | if (!state.mMatrix.isSimple()) return false; |
| 203 | |
| 204 | // check state/paint for transparency |
| 205 | if (state.mDrawModifiers.mShader || |
| 206 | state.mAlpha != 1.0f || |
| 207 | (mPaint && mPaint->getAlpha() != 0xFF)) return false; |
| 208 | |
| 209 | SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint); |
| 210 | return (mode == SkXfermode::kSrcOver_Mode || |
| 211 | mode == SkXfermode::kSrc_Mode); |
| 212 | |
| 213 | } |
| 214 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 215 | const SkPaint* mPaint; // should be accessed via getPaint() when applying |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 216 | bool mQuickRejected; |
| 217 | }; |
| 218 | |
| 219 | class DrawBoundedOp : public DrawOp { |
| 220 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 221 | DrawBoundedOp(float left, float top, float right, float bottom, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 222 | : DrawOp(paint), mLocalBounds(left, top, right, bottom) {} |
| 223 | |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 224 | DrawBoundedOp(const Rect& localBounds, const SkPaint* paint) |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 225 | : DrawOp(paint), mLocalBounds(localBounds) {} |
| 226 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 227 | // Calculates bounds as smallest rect encompassing all points |
| 228 | // NOTE: requires at least 1 vertex, and doesn't account for stroke size (should be handled in |
| 229 | // subclass' constructor) |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 230 | DrawBoundedOp(const float* points, int count, const SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 231 | : DrawOp(paint), mLocalBounds(points[0], points[1], points[0], points[1]) { |
| 232 | for (int i = 2; i < count; i += 2) { |
| 233 | mLocalBounds.left = fminf(mLocalBounds.left, points[i]); |
| 234 | mLocalBounds.right = fmaxf(mLocalBounds.right, points[i]); |
| 235 | mLocalBounds.top = fminf(mLocalBounds.top, points[i + 1]); |
| 236 | mLocalBounds.bottom = fmaxf(mLocalBounds.bottom, points[i + 1]); |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | // default empty constructor for bounds, to be overridden in child constructor body |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 241 | DrawBoundedOp(const SkPaint* paint): DrawOp(paint) { } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 242 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 243 | bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 244 | localBounds.set(mLocalBounds); |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 245 | if (drawModifiers.mHasShadow) { |
| 246 | // TODO: inspect paint's looper directly |
Romain Guy | 9b5a1a2 | 2013-08-09 14:06:29 -0700 | [diff] [blame] | 247 | Rect shadow(mLocalBounds); |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 248 | shadow.translate(drawModifiers.mShadowDx, drawModifiers.mShadowDy); |
| 249 | shadow.outset(drawModifiers.mShadowRadius); |
Romain Guy | 9b5a1a2 | 2013-08-09 14:06:29 -0700 | [diff] [blame] | 250 | localBounds.unionWith(shadow); |
| 251 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
| 255 | protected: |
| 256 | Rect mLocalBounds; // displayed area in LOCAL coord. doesn't incorporate stroke, so check paint |
| 257 | }; |
| 258 | |
| 259 | /////////////////////////////////////////////////////////////////////////////// |
| 260 | // STATE OPERATIONS - these may affect the state of the canvas/renderer, but do |
| 261 | // not directly draw or alter output |
| 262 | /////////////////////////////////////////////////////////////////////////////// |
| 263 | |
| 264 | class SaveOp : public StateOp { |
| 265 | public: |
| 266 | SaveOp(int flags) |
| 267 | : mFlags(flags) {} |
| 268 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 269 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 270 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 271 | int newSaveCount = deferStruct.mRenderer.save(mFlags); |
| 272 | deferStruct.mDeferredList.addSave(deferStruct.mRenderer, this, newSaveCount); |
| 273 | } |
| 274 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 275 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 276 | renderer.save(mFlags); |
| 277 | } |
| 278 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 279 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 280 | OP_LOG("Save flags %x", mFlags); |
| 281 | } |
| 282 | |
| 283 | virtual const char* name() { return "Save"; } |
| 284 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 285 | int getFlags() const { return mFlags; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 286 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 287 | SaveOp() {} |
| 288 | DisplayListOp* reinit(int flags) { |
| 289 | mFlags = flags; |
| 290 | return this; |
| 291 | } |
| 292 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 293 | int mFlags; |
| 294 | }; |
| 295 | |
| 296 | class RestoreToCountOp : public StateOp { |
| 297 | public: |
| 298 | RestoreToCountOp(int count) |
| 299 | : mCount(count) {} |
| 300 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 301 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 302 | bool useQuickReject) { |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 303 | deferStruct.mDeferredList.addRestoreToCount(deferStruct.mRenderer, |
| 304 | this, saveCount + mCount); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 305 | deferStruct.mRenderer.restoreToCount(saveCount + mCount); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 308 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 309 | renderer.restoreToCount(saveCount + mCount); |
| 310 | } |
| 311 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 312 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 313 | OP_LOG("Restore to count %d", mCount); |
| 314 | } |
| 315 | |
| 316 | virtual const char* name() { return "RestoreToCount"; } |
| 317 | |
| 318 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 319 | RestoreToCountOp() {} |
| 320 | DisplayListOp* reinit(int count) { |
| 321 | mCount = count; |
| 322 | return this; |
| 323 | } |
| 324 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 325 | int mCount; |
| 326 | }; |
| 327 | |
| 328 | class SaveLayerOp : public StateOp { |
| 329 | public: |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 330 | SaveLayerOp(float left, float top, float right, float bottom, int alpha, int flags) |
| 331 | : mArea(left, top, right, bottom), mPaint(&mCachedPaint), mFlags(flags) { |
| 332 | mCachedPaint.setAlpha(alpha); |
| 333 | } |
| 334 | |
| 335 | SaveLayerOp(float left, float top, float right, float bottom, const SkPaint* paint, int flags) |
| 336 | : mArea(left, top, right, bottom), mPaint(paint), mFlags(flags) {} |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 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, |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 347 | mPaint, 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 { |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 351 | renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom, mPaint, mFlags); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 354 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 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: |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 364 | bool isSaveLayerAlpha() const { |
| 365 | SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint); |
| 366 | int alpha = OpenGLRenderer::getAlphaDirect(mPaint); |
| 367 | return alpha < 255 && mode == SkXfermode::kSrcOver_Mode; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 370 | Rect mArea; |
Derek Sollenberger | d44fbe5 | 2014-02-05 16:47:00 -0500 | [diff] [blame] | 371 | const SkPaint* mPaint; |
| 372 | SkPaint mCachedPaint; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 373 | int mFlags; |
| 374 | }; |
| 375 | |
| 376 | class TranslateOp : public StateOp { |
| 377 | public: |
| 378 | TranslateOp(float dx, float dy) |
| 379 | : mDx(dx), mDy(dy) {} |
| 380 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 381 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 382 | renderer.translate(mDx, mDy); |
| 383 | } |
| 384 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 385 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 386 | OP_LOG("Translate by %f %f", mDx, mDy); |
| 387 | } |
| 388 | |
| 389 | virtual const char* name() { return "Translate"; } |
| 390 | |
| 391 | private: |
| 392 | float mDx; |
| 393 | float mDy; |
| 394 | }; |
| 395 | |
| 396 | class RotateOp : public StateOp { |
| 397 | public: |
| 398 | RotateOp(float degrees) |
| 399 | : mDegrees(degrees) {} |
| 400 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 401 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 402 | renderer.rotate(mDegrees); |
| 403 | } |
| 404 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 405 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 406 | OP_LOG("Rotate by %f degrees", mDegrees); |
| 407 | } |
| 408 | |
| 409 | virtual const char* name() { return "Rotate"; } |
| 410 | |
| 411 | private: |
| 412 | float mDegrees; |
| 413 | }; |
| 414 | |
| 415 | class ScaleOp : public StateOp { |
| 416 | public: |
| 417 | ScaleOp(float sx, float sy) |
| 418 | : mSx(sx), mSy(sy) {} |
| 419 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 420 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 421 | renderer.scale(mSx, mSy); |
| 422 | } |
| 423 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 424 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 425 | OP_LOG("Scale by %f %f", mSx, mSy); |
| 426 | } |
| 427 | |
| 428 | virtual const char* name() { return "Scale"; } |
| 429 | |
| 430 | private: |
| 431 | float mSx; |
| 432 | float mSy; |
| 433 | }; |
| 434 | |
| 435 | class SkewOp : public StateOp { |
| 436 | public: |
| 437 | SkewOp(float sx, float sy) |
| 438 | : mSx(sx), mSy(sy) {} |
| 439 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 440 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 441 | renderer.skew(mSx, mSy); |
| 442 | } |
| 443 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 444 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 445 | OP_LOG("Skew by %f %f", mSx, mSy); |
| 446 | } |
| 447 | |
| 448 | virtual const char* name() { return "Skew"; } |
| 449 | |
| 450 | private: |
| 451 | float mSx; |
| 452 | float mSy; |
| 453 | }; |
| 454 | |
| 455 | class SetMatrixOp : public StateOp { |
| 456 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 457 | SetMatrixOp(const SkMatrix* matrix) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 458 | : mMatrix(matrix) {} |
| 459 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 460 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 461 | renderer.setMatrix(mMatrix); |
| 462 | } |
| 463 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 464 | virtual void output(int level, uint32_t logFlags) const { |
Romain Guy | 4e7b772 | 2013-07-16 13:47:01 -0700 | [diff] [blame] | 465 | if (mMatrix) { |
Chris Craik | 629f677 | 2014-02-05 13:00:24 -0800 | [diff] [blame] | 466 | OP_LOG("SetMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(mMatrix)); |
Romain Guy | 4e7b772 | 2013-07-16 13:47:01 -0700 | [diff] [blame] | 467 | } else { |
| 468 | OP_LOGS("SetMatrix (reset)"); |
| 469 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | virtual const char* name() { return "SetMatrix"; } |
| 473 | |
| 474 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 475 | const SkMatrix* mMatrix; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 476 | }; |
| 477 | |
| 478 | class ConcatMatrixOp : public StateOp { |
| 479 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 480 | ConcatMatrixOp(const SkMatrix* matrix) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 481 | : mMatrix(matrix) {} |
| 482 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 483 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 484 | renderer.concatMatrix(mMatrix); |
| 485 | } |
| 486 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 487 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 629f677 | 2014-02-05 13:00:24 -0800 | [diff] [blame] | 488 | OP_LOG("ConcatMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(mMatrix)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | virtual const char* name() { return "ConcatMatrix"; } |
| 492 | |
| 493 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 494 | const SkMatrix* mMatrix; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 495 | }; |
| 496 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 497 | class ClipOp : public StateOp { |
| 498 | public: |
| 499 | ClipOp(SkRegion::Op op) : mOp(op) {} |
| 500 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 501 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 502 | bool useQuickReject) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 503 | // NOTE: must defer op BEFORE applying state, since it may read clip |
| 504 | deferStruct.mDeferredList.addClip(deferStruct.mRenderer, this); |
| 505 | |
| 506 | // TODO: Can we avoid applying complex clips at defer time? |
| 507 | applyState(deferStruct.mRenderer, saveCount); |
| 508 | } |
| 509 | |
| 510 | bool canCauseComplexClip() { |
| 511 | return ((mOp != SkRegion::kIntersect_Op) && (mOp != SkRegion::kReplace_Op)) || !isRect(); |
| 512 | } |
| 513 | |
| 514 | protected: |
| 515 | ClipOp() {} |
| 516 | virtual bool isRect() { return false; } |
| 517 | |
| 518 | SkRegion::Op mOp; |
| 519 | }; |
| 520 | |
| 521 | class ClipRectOp : public ClipOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 522 | public: |
| 523 | ClipRectOp(float left, float top, float right, float bottom, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 524 | : ClipOp(op), mArea(left, top, right, bottom) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 525 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 526 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 527 | renderer.clipRect(mArea.left, mArea.top, mArea.right, mArea.bottom, mOp); |
| 528 | } |
| 529 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 530 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 531 | OP_LOG("ClipRect " RECT_STRING, RECT_ARGS(mArea)); |
| 532 | } |
| 533 | |
| 534 | virtual const char* name() { return "ClipRect"; } |
| 535 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 536 | protected: |
| 537 | virtual bool isRect() { return true; } |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 538 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 539 | private: |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 540 | ClipRectOp() {} |
| 541 | DisplayListOp* reinit(float left, float top, float right, float bottom, SkRegion::Op op) { |
| 542 | mOp = op; |
| 543 | mArea.set(left, top, right, bottom); |
| 544 | return this; |
Chris Craik | b98a016 | 2013-02-21 11:30:22 -0800 | [diff] [blame] | 545 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 546 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 547 | Rect mArea; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 548 | }; |
| 549 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 550 | class ClipPathOp : public ClipOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 551 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 552 | ClipPathOp(const SkPath* path, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 553 | : ClipOp(op), mPath(path) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 554 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 555 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 556 | renderer.clipPath(mPath, mOp); |
| 557 | } |
| 558 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 559 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 560 | SkRect bounds = mPath->getBounds(); |
| 561 | OP_LOG("ClipPath bounds " RECT_STRING, |
| 562 | bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); |
| 563 | } |
| 564 | |
| 565 | virtual const char* name() { return "ClipPath"; } |
| 566 | |
| 567 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 568 | const SkPath* mPath; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 569 | }; |
| 570 | |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 571 | class ClipRegionOp : public ClipOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 572 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 573 | ClipRegionOp(const SkRegion* region, SkRegion::Op op) |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 574 | : ClipOp(op), mRegion(region) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 575 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 576 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 577 | renderer.clipRegion(mRegion, mOp); |
| 578 | } |
| 579 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 580 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 581 | SkIRect bounds = mRegion->getBounds(); |
| 582 | OP_LOG("ClipRegion bounds %d %d %d %d", |
| 583 | bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); |
| 584 | } |
| 585 | |
| 586 | virtual const char* name() { return "ClipRegion"; } |
| 587 | |
| 588 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 589 | const SkRegion* mRegion; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 590 | }; |
| 591 | |
| 592 | class ResetShaderOp : public StateOp { |
| 593 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 594 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 595 | renderer.resetShader(); |
| 596 | } |
| 597 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 598 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 599 | OP_LOGS("ResetShader"); |
| 600 | } |
| 601 | |
| 602 | virtual const char* name() { return "ResetShader"; } |
| 603 | }; |
| 604 | |
| 605 | class SetupShaderOp : public StateOp { |
| 606 | public: |
| 607 | SetupShaderOp(SkiaShader* shader) |
| 608 | : mShader(shader) {} |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 609 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 610 | renderer.setupShader(mShader); |
| 611 | } |
| 612 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 613 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 614 | OP_LOG("SetupShader, shader %p", mShader); |
| 615 | } |
| 616 | |
| 617 | virtual const char* name() { return "SetupShader"; } |
| 618 | |
| 619 | private: |
| 620 | SkiaShader* mShader; |
| 621 | }; |
| 622 | |
| 623 | class ResetColorFilterOp : public StateOp { |
| 624 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 625 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 626 | renderer.resetColorFilter(); |
| 627 | } |
| 628 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 629 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 630 | OP_LOGS("ResetColorFilter"); |
| 631 | } |
| 632 | |
| 633 | virtual const char* name() { return "ResetColorFilter"; } |
| 634 | }; |
| 635 | |
| 636 | class SetupColorFilterOp : public StateOp { |
| 637 | public: |
| 638 | SetupColorFilterOp(SkiaColorFilter* colorFilter) |
| 639 | : mColorFilter(colorFilter) {} |
| 640 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 641 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 642 | renderer.setupColorFilter(mColorFilter); |
| 643 | } |
| 644 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 645 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 646 | OP_LOG("SetupColorFilter, filter %p", mColorFilter); |
| 647 | } |
| 648 | |
| 649 | virtual const char* name() { return "SetupColorFilter"; } |
| 650 | |
| 651 | private: |
| 652 | SkiaColorFilter* mColorFilter; |
| 653 | }; |
| 654 | |
| 655 | class ResetShadowOp : public StateOp { |
| 656 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 657 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 658 | renderer.resetShadow(); |
| 659 | } |
| 660 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 661 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 662 | OP_LOGS("ResetShadow"); |
| 663 | } |
| 664 | |
| 665 | virtual const char* name() { return "ResetShadow"; } |
| 666 | }; |
| 667 | |
| 668 | class SetupShadowOp : public StateOp { |
| 669 | public: |
| 670 | SetupShadowOp(float radius, float dx, float dy, int color) |
| 671 | : mRadius(radius), mDx(dx), mDy(dy), mColor(color) {} |
| 672 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 673 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 674 | renderer.setupShadow(mRadius, mDx, mDy, mColor); |
| 675 | } |
| 676 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 677 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 678 | OP_LOG("SetupShadow, radius %f, %f, %f, color %#x", mRadius, mDx, mDy, mColor); |
| 679 | } |
| 680 | |
| 681 | virtual const char* name() { return "SetupShadow"; } |
| 682 | |
| 683 | private: |
| 684 | float mRadius; |
| 685 | float mDx; |
| 686 | float mDy; |
| 687 | int mColor; |
| 688 | }; |
| 689 | |
| 690 | class ResetPaintFilterOp : public StateOp { |
| 691 | public: |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 692 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 693 | renderer.resetPaintFilter(); |
| 694 | } |
| 695 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 696 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 697 | OP_LOGS("ResetPaintFilter"); |
| 698 | } |
| 699 | |
| 700 | virtual const char* name() { return "ResetPaintFilter"; } |
| 701 | }; |
| 702 | |
| 703 | class SetupPaintFilterOp : public StateOp { |
| 704 | public: |
| 705 | SetupPaintFilterOp(int clearBits, int setBits) |
| 706 | : mClearBits(clearBits), mSetBits(setBits) {} |
| 707 | |
Chris Craik | 7273daa | 2013-03-28 11:25:24 -0700 | [diff] [blame] | 708 | virtual void applyState(OpenGLRenderer& renderer, int saveCount) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 709 | renderer.setupPaintFilter(mClearBits, mSetBits); |
| 710 | } |
| 711 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 712 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 713 | OP_LOG("SetupPaintFilter, clear %#x, set %#x", mClearBits, mSetBits); |
| 714 | } |
| 715 | |
| 716 | virtual const char* name() { return "SetupPaintFilter"; } |
| 717 | |
| 718 | private: |
| 719 | int mClearBits; |
| 720 | int mSetBits; |
| 721 | }; |
| 722 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 723 | /////////////////////////////////////////////////////////////////////////////// |
| 724 | // DRAW OPERATIONS - these are operations that can draw to the canvas's device |
| 725 | /////////////////////////////////////////////////////////////////////////////// |
| 726 | |
| 727 | class DrawBitmapOp : public DrawBoundedOp { |
| 728 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 729 | DrawBitmapOp(const SkBitmap* bitmap, float left, float top, const SkPaint* paint) |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 730 | : DrawBoundedOp(left, top, left + bitmap->width(), top + bitmap->height(), paint), |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 731 | mBitmap(bitmap), mAtlas(Caches::getInstance().assetAtlas) { |
| 732 | mEntry = mAtlas.getEntry(bitmap); |
| 733 | if (mEntry) { |
| 734 | mEntryGenerationId = mAtlas.getGenerationId(); |
| 735 | mUvMapper = mEntry->uvMapper; |
| 736 | } |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 737 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 738 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 739 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 740 | return renderer.drawBitmap(mBitmap, mLocalBounds.left, mLocalBounds.top, |
| 741 | getPaint(renderer)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 744 | AssetAtlas::Entry* getAtlasEntry() { |
| 745 | // The atlas entry is stale, let's get a new one |
| 746 | if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) { |
| 747 | mEntryGenerationId = mAtlas.getGenerationId(); |
| 748 | mEntry = mAtlas.getEntry(mBitmap); |
| 749 | mUvMapper = mEntry->uvMapper; |
| 750 | } |
| 751 | return mEntry; |
| 752 | } |
| 753 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 754 | #define SET_TEXTURE(ptr, posRect, offsetRect, texCoordsRect, xDim, yDim) \ |
| 755 | TextureVertex::set(ptr++, posRect.xDim - offsetRect.left, posRect.yDim - offsetRect.top, \ |
| 756 | texCoordsRect.xDim, texCoordsRect.yDim) |
| 757 | |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 758 | /** |
| 759 | * This multi-draw operation builds a mesh on the stack by generating a quad |
| 760 | * for each bitmap in the batch. This method is also responsible for dirtying |
| 761 | * the current layer, if any. |
| 762 | */ |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 763 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 764 | const Vector<OpStatePair>& ops, const Rect& bounds) { |
| 765 | const DeferredDisplayState& firstState = *(ops[0].state); |
| 766 | renderer.restoreDisplayState(firstState, true); // restore all but the clip |
| 767 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 768 | TextureVertex vertices[6 * ops.size()]; |
| 769 | TextureVertex* vertex = &vertices[0]; |
| 770 | |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 771 | const bool hasLayer = renderer.hasLayer(); |
Chris Craik | 996fe65 | 2013-09-20 17:13:18 -0700 | [diff] [blame] | 772 | bool pureTranslate = true; |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 773 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 774 | // TODO: manually handle rect clip for bitmaps by adjusting texCoords per op, |
| 775 | // and allowing them to be merged in getBatchId() |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 776 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 777 | const DeferredDisplayState& state = *(ops[i].state); |
| 778 | const Rect& opBounds = state.mBounds; |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 779 | // When we reach multiDraw(), the matrix can be either |
| 780 | // pureTranslate or simple (translate and/or scale). |
| 781 | // If the matrix is not pureTranslate, then we have a scale |
Chris Craik | 996fe65 | 2013-09-20 17:13:18 -0700 | [diff] [blame] | 782 | pureTranslate &= state.mMatrix.isPureTranslate(); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 783 | |
| 784 | Rect texCoords(0, 0, 1, 1); |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 785 | ((DrawBitmapOp*) ops[i].op)->mUvMapper.map(texCoords); |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 786 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 787 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top); |
| 788 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top); |
| 789 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom); |
| 790 | |
| 791 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom); |
| 792 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top); |
| 793 | SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, bottom); |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 794 | |
| 795 | if (hasLayer) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 796 | renderer.dirtyLayer(opBounds.left, opBounds.top, opBounds.right, opBounds.bottom); |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 797 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 798 | } |
| 799 | |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 800 | return renderer.drawBitmaps(mBitmap, mEntry, ops.size(), &vertices[0], |
Chris Craik | 996fe65 | 2013-09-20 17:13:18 -0700 | [diff] [blame] | 801 | pureTranslate, bounds, mPaint); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 804 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 805 | OP_LOG("Draw bitmap %p at %f %f", mBitmap, mLocalBounds.left, mLocalBounds.top); |
| 806 | } |
| 807 | |
| 808 | virtual const char* name() { return "DrawBitmap"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 809 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 810 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 811 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 812 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | d965bc5 | 2013-09-16 14:47:13 -0700 | [diff] [blame] | 813 | deferInfo.mergeId = getAtlasEntry() ? |
| 814 | (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap; |
Romain Guy | 2db5e99 | 2013-05-21 15:29:59 -0700 | [diff] [blame] | 815 | |
Chris Craik | d965bc5 | 2013-09-16 14:47:13 -0700 | [diff] [blame] | 816 | // Don't merge non-simply transformed or neg scale ops, SET_TEXTURE doesn't handle rotation |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 817 | // Don't merge A8 bitmaps - the paint's color isn't compared by mergeId, or in |
| 818 | // MergingDrawBatch::canMergeWith() |
| 819 | // TODO: support clipped bitmaps by handling them in SET_TEXTURE |
Chris Craik | d965bc5 | 2013-09-16 14:47:13 -0700 | [diff] [blame] | 820 | deferInfo.mergeable = state.mMatrix.isSimple() && state.mMatrix.positiveScale() && |
| 821 | !state.mClipSideFlags && |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 822 | OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode && |
| 823 | (mBitmap->getConfig() != SkBitmap::kA8_Config); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 824 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 825 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 826 | const SkBitmap* bitmap() { return mBitmap; } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 827 | protected: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 828 | const SkBitmap* mBitmap; |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 829 | const AssetAtlas& mAtlas; |
| 830 | uint32_t mEntryGenerationId; |
| 831 | AssetAtlas::Entry* mEntry; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 832 | UvMapper mUvMapper; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 833 | }; |
| 834 | |
| 835 | class DrawBitmapMatrixOp : public DrawBoundedOp { |
| 836 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 837 | DrawBitmapMatrixOp(const SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 838 | : DrawBoundedOp(paint), mBitmap(bitmap), mMatrix(matrix) { |
| 839 | mLocalBounds.set(0, 0, bitmap->width(), bitmap->height()); |
| 840 | const mat4 transform(*matrix); |
| 841 | transform.mapRect(mLocalBounds); |
| 842 | } |
| 843 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 844 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 845 | return renderer.drawBitmap(mBitmap, mMatrix, getPaint(renderer)); |
| 846 | } |
| 847 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 848 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 629f677 | 2014-02-05 13:00:24 -0800 | [diff] [blame] | 849 | OP_LOG("Draw bitmap %p matrix " SK_MATRIX_STRING, mBitmap, SK_MATRIX_ARGS(mMatrix)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 852 | virtual const char* name() { return "DrawBitmapMatrix"; } |
| 853 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 854 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 855 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 856 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 857 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 858 | |
| 859 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 860 | const SkBitmap* mBitmap; |
| 861 | const SkMatrix* mMatrix; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 862 | }; |
| 863 | |
| 864 | class DrawBitmapRectOp : public DrawBoundedOp { |
| 865 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 866 | DrawBitmapRectOp(const SkBitmap* bitmap, |
| 867 | float srcLeft, float srcTop, float srcRight, float srcBottom, |
| 868 | float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 869 | : DrawBoundedOp(dstLeft, dstTop, dstRight, dstBottom, paint), |
| 870 | mBitmap(bitmap), mSrc(srcLeft, srcTop, srcRight, srcBottom) {} |
| 871 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 872 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 873 | return renderer.drawBitmap(mBitmap, mSrc.left, mSrc.top, mSrc.right, mSrc.bottom, |
| 874 | mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom, |
| 875 | getPaint(renderer)); |
| 876 | } |
| 877 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 878 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 879 | OP_LOG("Draw bitmap %p src="RECT_STRING", dst="RECT_STRING, |
| 880 | mBitmap, RECT_ARGS(mSrc), RECT_ARGS(mLocalBounds)); |
| 881 | } |
| 882 | |
| 883 | virtual const char* name() { return "DrawBitmapRect"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 884 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 885 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 886 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 887 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 888 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 889 | |
| 890 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 891 | const SkBitmap* mBitmap; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 892 | Rect mSrc; |
| 893 | }; |
| 894 | |
| 895 | class DrawBitmapDataOp : public DrawBitmapOp { |
| 896 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 897 | DrawBitmapDataOp(const SkBitmap* bitmap, float left, float top, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 898 | : DrawBitmapOp(bitmap, left, top, paint) {} |
| 899 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 900 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 901 | return renderer.drawBitmapData(mBitmap, mLocalBounds.left, |
| 902 | mLocalBounds.top, getPaint(renderer)); |
| 903 | } |
| 904 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 905 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 906 | OP_LOG("Draw bitmap %p", mBitmap); |
| 907 | } |
| 908 | |
| 909 | virtual const char* name() { return "DrawBitmapData"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 910 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 911 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 912 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 913 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 914 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 915 | }; |
| 916 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 917 | class DrawBitmapMeshOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 918 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 919 | DrawBitmapMeshOp(const SkBitmap* bitmap, int meshWidth, int meshHeight, |
| 920 | const float* vertices, const int* colors, const SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 921 | : DrawBoundedOp(vertices, 2 * (meshWidth + 1) * (meshHeight + 1), paint), |
| 922 | mBitmap(bitmap), mMeshWidth(meshWidth), mMeshHeight(meshHeight), |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 923 | mVertices(vertices), mColors(colors) {} |
| 924 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 925 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 926 | return renderer.drawBitmapMesh(mBitmap, mMeshWidth, mMeshHeight, |
| 927 | mVertices, mColors, getPaint(renderer)); |
| 928 | } |
| 929 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 930 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 931 | OP_LOG("Draw bitmap %p mesh %d x %d", mBitmap, mMeshWidth, mMeshHeight); |
| 932 | } |
| 933 | |
| 934 | virtual const char* name() { return "DrawBitmapMesh"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 935 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 936 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 937 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 938 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 939 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 940 | |
| 941 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 942 | const SkBitmap* mBitmap; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 943 | int mMeshWidth; |
| 944 | int mMeshHeight; |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 945 | const float* mVertices; |
| 946 | const int* mColors; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 947 | }; |
| 948 | |
| 949 | class DrawPatchOp : public DrawBoundedOp { |
| 950 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 951 | DrawPatchOp(const SkBitmap* bitmap, const Res_png_9patch* patch, |
| 952 | float left, float top, float right, float bottom, const SkPaint* paint) |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 953 | : DrawBoundedOp(left, top, right, bottom, paint), |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 954 | mBitmap(bitmap), mPatch(patch), mGenerationId(0), mMesh(NULL), |
| 955 | mAtlas(Caches::getInstance().assetAtlas) { |
| 956 | mEntry = mAtlas.getEntry(bitmap); |
| 957 | if (mEntry) { |
| 958 | mEntryGenerationId = mAtlas.getGenerationId(); |
| 959 | } |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 960 | }; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 961 | |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 962 | AssetAtlas::Entry* getAtlasEntry() { |
| 963 | // The atlas entry is stale, let's get a new one |
| 964 | if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) { |
| 965 | mEntryGenerationId = mAtlas.getGenerationId(); |
| 966 | mEntry = mAtlas.getEntry(mBitmap); |
| 967 | } |
| 968 | return mEntry; |
| 969 | } |
| 970 | |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 971 | const Patch* getMesh(OpenGLRenderer& renderer) { |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 972 | if (!mMesh || renderer.getCaches().patchCache.getGenerationId() != mGenerationId) { |
| 973 | PatchCache& cache = renderer.getCaches().patchCache; |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 974 | mMesh = cache.get(getAtlasEntry(), mBitmap->width(), mBitmap->height(), |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 975 | mLocalBounds.getWidth(), mLocalBounds.getHeight(), mPatch); |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 976 | mGenerationId = cache.getGenerationId(); |
| 977 | } |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 978 | return mMesh; |
| 979 | } |
| 980 | |
| 981 | /** |
| 982 | * This multi-draw operation builds an indexed mesh on the stack by copying |
| 983 | * and transforming the vertices of each 9-patch in the batch. This method |
| 984 | * is also responsible for dirtying the current layer, if any. |
| 985 | */ |
| 986 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 987 | const Vector<OpStatePair>& ops, const Rect& bounds) { |
| 988 | const DeferredDisplayState& firstState = *(ops[0].state); |
| 989 | renderer.restoreDisplayState(firstState, true); // restore all but the clip |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 990 | |
| 991 | // Batches will usually contain a small number of items so it's |
| 992 | // worth performing a first iteration to count the exact number |
| 993 | // of vertices we need in the new mesh |
| 994 | uint32_t totalVertices = 0; |
| 995 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 996 | totalVertices += ((DrawPatchOp*) ops[i].op)->getMesh(renderer)->verticesCount; |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | const bool hasLayer = renderer.hasLayer(); |
| 1000 | |
| 1001 | uint32_t indexCount = 0; |
| 1002 | |
| 1003 | TextureVertex vertices[totalVertices]; |
| 1004 | TextureVertex* vertex = &vertices[0]; |
| 1005 | |
| 1006 | // Create a mesh that contains the transformed vertices for all the |
| 1007 | // 9-patch objects that are part of the batch. Note that onDefer() |
| 1008 | // enforces ops drawn by this function to have a pure translate or |
| 1009 | // identity matrix |
| 1010 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1011 | DrawPatchOp* patchOp = (DrawPatchOp*) ops[i].op; |
| 1012 | const DeferredDisplayState* state = ops[i].state; |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1013 | const Patch* opMesh = patchOp->getMesh(renderer); |
| 1014 | uint32_t vertexCount = opMesh->verticesCount; |
| 1015 | if (vertexCount == 0) continue; |
| 1016 | |
| 1017 | // We use the bounds to know where to translate our vertices |
| 1018 | // Using patchOp->state.mBounds wouldn't work because these |
| 1019 | // bounds are clipped |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1020 | const float tx = (int) floorf(state->mMatrix.getTranslateX() + |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1021 | patchOp->mLocalBounds.left + 0.5f); |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1022 | const float ty = (int) floorf(state->mMatrix.getTranslateY() + |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1023 | patchOp->mLocalBounds.top + 0.5f); |
| 1024 | |
| 1025 | // Copy & transform all the vertices for the current operation |
| 1026 | TextureVertex* opVertices = opMesh->vertices; |
| 1027 | for (uint32_t j = 0; j < vertexCount; j++, opVertices++) { |
| 1028 | TextureVertex::set(vertex++, |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame] | 1029 | opVertices->x + tx, opVertices->y + ty, |
| 1030 | opVertices->u, opVertices->v); |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | // Dirty the current layer if possible. When the 9-patch does not |
| 1034 | // contain empty quads we can take a shortcut and simply set the |
| 1035 | // dirty rect to the object's bounds. |
| 1036 | if (hasLayer) { |
| 1037 | if (!opMesh->hasEmptyQuads) { |
| 1038 | renderer.dirtyLayer(tx, ty, |
| 1039 | tx + patchOp->mLocalBounds.getWidth(), |
| 1040 | ty + patchOp->mLocalBounds.getHeight()); |
| 1041 | } else { |
| 1042 | const size_t count = opMesh->quads.size(); |
| 1043 | for (size_t i = 0; i < count; i++) { |
| 1044 | const Rect& quadBounds = opMesh->quads[i]; |
| 1045 | const float x = tx + quadBounds.left; |
| 1046 | const float y = ty + quadBounds.top; |
| 1047 | renderer.dirtyLayer(x, y, |
| 1048 | x + quadBounds.getWidth(), y + quadBounds.getHeight()); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | |
| 1053 | indexCount += opMesh->indexCount; |
| 1054 | } |
| 1055 | |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 1056 | return renderer.drawPatches(mBitmap, getAtlasEntry(), |
| 1057 | &vertices[0], indexCount, getPaint(renderer)); |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 1061 | // We're not calling the public variant of drawPatch() here |
| 1062 | // This method won't perform the quickReject() since we've already done it at this point |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 1063 | return renderer.drawPatch(mBitmap, getMesh(renderer), getAtlasEntry(), |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1064 | mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom, |
| 1065 | getPaint(renderer)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1068 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1069 | OP_LOG("Draw patch "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 1070 | } |
| 1071 | |
| 1072 | virtual const char* name() { return "DrawPatch"; } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1073 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1074 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1075 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1076 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch; |
Romain Guy | 7f6d6b0 | 2013-08-06 13:49:28 -0700 | [diff] [blame] | 1077 | deferInfo.mergeId = getAtlasEntry() ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap; |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1078 | deferInfo.mergeable = state.mMatrix.isPureTranslate() && |
| 1079 | OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode; |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1080 | deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && mBitmap->isOpaque(); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1081 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1082 | |
| 1083 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1084 | const SkBitmap* mBitmap; |
| 1085 | const Res_png_9patch* mPatch; |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 1086 | |
Romain Guy | 4c2547f | 2013-06-11 16:19:24 -0700 | [diff] [blame] | 1087 | uint32_t mGenerationId; |
| 1088 | const Patch* mMesh; |
Romain Guy | 03c00b5 | 2013-06-20 18:30:28 -0700 | [diff] [blame] | 1089 | |
Romain Guy | 55b6f95 | 2013-06-27 15:27:09 -0700 | [diff] [blame] | 1090 | const AssetAtlas& mAtlas; |
| 1091 | uint32_t mEntryGenerationId; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 1092 | AssetAtlas::Entry* mEntry; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1093 | }; |
| 1094 | |
| 1095 | class DrawColorOp : public DrawOp { |
| 1096 | public: |
| 1097 | DrawColorOp(int color, SkXfermode::Mode mode) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1098 | : DrawOp(NULL), mColor(color), mMode(mode) {}; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1099 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1100 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1101 | return renderer.drawColor(mColor, mMode); |
| 1102 | } |
| 1103 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1104 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1105 | OP_LOG("Draw color %#x, mode %d", mColor, mMode); |
| 1106 | } |
| 1107 | |
| 1108 | virtual const char* name() { return "DrawColor"; } |
| 1109 | |
| 1110 | private: |
| 1111 | int mColor; |
| 1112 | SkXfermode::Mode mMode; |
| 1113 | }; |
| 1114 | |
| 1115 | class DrawStrokableOp : public DrawBoundedOp { |
| 1116 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1117 | DrawStrokableOp(float left, float top, float right, float bottom, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1118 | : DrawBoundedOp(left, top, right, bottom, paint) {}; |
| 1119 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1120 | bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1121 | localBounds.set(mLocalBounds); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1122 | if (mPaint && mPaint->getStyle() != SkPaint::kFill_Style) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1123 | localBounds.outset(strokeWidthOutset()); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1124 | } |
| 1125 | return true; |
| 1126 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1127 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1128 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1129 | const DeferredDisplayState& state) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1130 | if (mPaint->getPathEffect()) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1131 | deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1132 | } else { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1133 | deferInfo.batchId = mPaint->isAntiAlias() ? |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1134 | DeferredDisplayList::kOpBatch_AlphaVertices : |
| 1135 | DeferredDisplayList::kOpBatch_Vertices; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1136 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1137 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1138 | }; |
| 1139 | |
| 1140 | class DrawRectOp : public DrawStrokableOp { |
| 1141 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1142 | DrawRectOp(float left, float top, float right, float bottom, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1143 | : DrawStrokableOp(left, top, right, bottom, paint) {} |
| 1144 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1145 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1146 | return renderer.drawRect(mLocalBounds.left, mLocalBounds.top, |
| 1147 | mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); |
| 1148 | } |
| 1149 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1150 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1151 | OP_LOG("Draw Rect "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 1152 | } |
| 1153 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1154 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1155 | const DeferredDisplayState& state) { |
| 1156 | DrawStrokableOp::onDefer(renderer, deferInfo, state); |
| 1157 | deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1158 | mPaint->getStyle() == SkPaint::kFill_Style; |
| 1159 | } |
| 1160 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1161 | virtual const char* name() { return "DrawRect"; } |
| 1162 | }; |
| 1163 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1164 | class DrawRectsOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1165 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1166 | DrawRectsOp(const float* rects, int count, const SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1167 | : DrawBoundedOp(rects, count, paint), |
| 1168 | mRects(rects), mCount(count) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1169 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1170 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1171 | return renderer.drawRects(mRects, mCount, getPaint(renderer)); |
| 1172 | } |
| 1173 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1174 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1175 | OP_LOG("Draw Rects count %d", mCount); |
| 1176 | } |
| 1177 | |
| 1178 | virtual const char* name() { return "DrawRects"; } |
| 1179 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1180 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1181 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1182 | deferInfo.batchId = DeferredDisplayList::kOpBatch_Vertices; |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1185 | private: |
| 1186 | const float* mRects; |
| 1187 | int mCount; |
| 1188 | }; |
| 1189 | |
| 1190 | class DrawRoundRectOp : public DrawStrokableOp { |
| 1191 | public: |
| 1192 | DrawRoundRectOp(float left, float top, float right, float bottom, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1193 | float rx, float ry, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1194 | : DrawStrokableOp(left, top, right, bottom, paint), mRx(rx), mRy(ry) {} |
| 1195 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1196 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1197 | return renderer.drawRoundRect(mLocalBounds.left, mLocalBounds.top, |
| 1198 | mLocalBounds.right, mLocalBounds.bottom, mRx, mRy, getPaint(renderer)); |
| 1199 | } |
| 1200 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1201 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1202 | OP_LOG("Draw RoundRect "RECT_STRING", rx %f, ry %f", RECT_ARGS(mLocalBounds), mRx, mRy); |
| 1203 | } |
| 1204 | |
| 1205 | virtual const char* name() { return "DrawRoundRect"; } |
| 1206 | |
| 1207 | private: |
| 1208 | float mRx; |
| 1209 | float mRy; |
| 1210 | }; |
| 1211 | |
| 1212 | class DrawCircleOp : public DrawStrokableOp { |
| 1213 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1214 | DrawCircleOp(float x, float y, float radius, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1215 | : DrawStrokableOp(x - radius, y - radius, x + radius, y + radius, paint), |
| 1216 | mX(x), mY(y), mRadius(radius) {} |
| 1217 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1218 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1219 | return renderer.drawCircle(mX, mY, mRadius, getPaint(renderer)); |
| 1220 | } |
| 1221 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1222 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1223 | OP_LOG("Draw Circle x %f, y %f, r %f", mX, mY, mRadius); |
| 1224 | } |
| 1225 | |
| 1226 | virtual const char* name() { return "DrawCircle"; } |
| 1227 | |
| 1228 | private: |
| 1229 | float mX; |
| 1230 | float mY; |
| 1231 | float mRadius; |
| 1232 | }; |
| 1233 | |
| 1234 | class DrawOvalOp : public DrawStrokableOp { |
| 1235 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1236 | DrawOvalOp(float left, float top, float right, float bottom, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1237 | : DrawStrokableOp(left, top, right, bottom, paint) {} |
| 1238 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1239 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1240 | return renderer.drawOval(mLocalBounds.left, mLocalBounds.top, |
| 1241 | mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer)); |
| 1242 | } |
| 1243 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1244 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1245 | OP_LOG("Draw Oval "RECT_STRING, RECT_ARGS(mLocalBounds)); |
| 1246 | } |
| 1247 | |
| 1248 | virtual const char* name() { return "DrawOval"; } |
| 1249 | }; |
| 1250 | |
| 1251 | class DrawArcOp : public DrawStrokableOp { |
| 1252 | public: |
| 1253 | DrawArcOp(float left, float top, float right, float bottom, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1254 | float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1255 | : DrawStrokableOp(left, top, right, bottom, paint), |
| 1256 | mStartAngle(startAngle), mSweepAngle(sweepAngle), mUseCenter(useCenter) {} |
| 1257 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1258 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1259 | return renderer.drawArc(mLocalBounds.left, mLocalBounds.top, |
| 1260 | mLocalBounds.right, mLocalBounds.bottom, |
| 1261 | mStartAngle, mSweepAngle, mUseCenter, getPaint(renderer)); |
| 1262 | } |
| 1263 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1264 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1265 | OP_LOG("Draw Arc "RECT_STRING", start %f, sweep %f, useCenter %d", |
| 1266 | RECT_ARGS(mLocalBounds), mStartAngle, mSweepAngle, mUseCenter); |
| 1267 | } |
| 1268 | |
| 1269 | virtual const char* name() { return "DrawArc"; } |
| 1270 | |
| 1271 | private: |
| 1272 | float mStartAngle; |
| 1273 | float mSweepAngle; |
| 1274 | bool mUseCenter; |
| 1275 | }; |
| 1276 | |
| 1277 | class DrawPathOp : public DrawBoundedOp { |
| 1278 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1279 | DrawPathOp(const SkPath* path, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1280 | : DrawBoundedOp(paint), mPath(path) { |
| 1281 | float left, top, offset; |
| 1282 | uint32_t width, height; |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1283 | PathCache::computePathBounds(path, paint, left, top, offset, width, height); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1284 | left -= offset; |
| 1285 | top -= offset; |
| 1286 | mLocalBounds.set(left, top, left + width, top + height); |
| 1287 | } |
| 1288 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1289 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1290 | return renderer.drawPath(mPath, getPaint(renderer)); |
| 1291 | } |
| 1292 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1293 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1294 | const DeferredDisplayState& state) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1295 | const SkPaint* paint = getPaint(renderer); |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1296 | renderer.getCaches().pathCache.precache(mPath, paint); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1297 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1298 | deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture; |
Romain Guy | ca89e2a | 2013-03-08 17:44:20 -0800 | [diff] [blame] | 1299 | } |
| 1300 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1301 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1302 | OP_LOG("Draw Path %p in "RECT_STRING, mPath, RECT_ARGS(mLocalBounds)); |
| 1303 | } |
| 1304 | |
| 1305 | virtual const char* name() { return "DrawPath"; } |
| 1306 | |
| 1307 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1308 | const SkPath* mPath; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1309 | }; |
| 1310 | |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1311 | class DrawLinesOp : public DrawBoundedOp { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1312 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1313 | DrawLinesOp(const float* points, int count, const SkPaint* paint) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1314 | : DrawBoundedOp(points, count, paint), |
| 1315 | mPoints(points), mCount(count) { |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1316 | mLocalBounds.outset(strokeWidthOutset()); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1317 | } |
| 1318 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1319 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1320 | return renderer.drawLines(mPoints, mCount, getPaint(renderer)); |
| 1321 | } |
| 1322 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1323 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1324 | OP_LOG("Draw Lines count %d", mCount); |
| 1325 | } |
| 1326 | |
| 1327 | virtual const char* name() { return "DrawLines"; } |
| 1328 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1329 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1330 | const DeferredDisplayState& state) { |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1331 | deferInfo.batchId = mPaint->isAntiAlias() ? |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1332 | DeferredDisplayList::kOpBatch_AlphaVertices : |
| 1333 | DeferredDisplayList::kOpBatch_Vertices; |
| 1334 | } |
| 1335 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1336 | protected: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1337 | const float* mPoints; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1338 | int mCount; |
| 1339 | }; |
| 1340 | |
| 1341 | class DrawPointsOp : public DrawLinesOp { |
| 1342 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1343 | DrawPointsOp(const float* points, int count, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1344 | : DrawLinesOp(points, count, paint) {} |
| 1345 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1346 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1347 | return renderer.drawPoints(mPoints, mCount, getPaint(renderer)); |
| 1348 | } |
| 1349 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1350 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1351 | OP_LOG("Draw Points count %d", mCount); |
| 1352 | } |
| 1353 | |
| 1354 | virtual const char* name() { return "DrawPoints"; } |
| 1355 | }; |
| 1356 | |
| 1357 | class DrawSomeTextOp : public DrawOp { |
| 1358 | public: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1359 | DrawSomeTextOp(const char* text, int bytesCount, int count, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1360 | : DrawOp(paint), mText(text), mBytesCount(bytesCount), mCount(count) {}; |
| 1361 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1362 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1363 | OP_LOG("Draw some text, %d bytes", mBytesCount); |
| 1364 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1365 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1366 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1367 | const DeferredDisplayState& state) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1368 | const SkPaint* paint = getPaint(renderer); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1369 | FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint); |
| 1370 | fontRenderer.precache(paint, mText, mCount, mat4::identity()); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1371 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1372 | deferInfo.batchId = mPaint->getColor() == 0xff000000 ? |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1373 | DeferredDisplayList::kOpBatch_Text : |
| 1374 | DeferredDisplayList::kOpBatch_ColorText; |
| 1375 | } |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1376 | |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1377 | protected: |
| 1378 | const char* mText; |
| 1379 | int mBytesCount; |
| 1380 | int mCount; |
| 1381 | }; |
| 1382 | |
| 1383 | class DrawTextOnPathOp : public DrawSomeTextOp { |
| 1384 | public: |
| 1385 | DrawTextOnPathOp(const char* text, int bytesCount, int count, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1386 | const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1387 | : DrawSomeTextOp(text, bytesCount, count, paint), |
| 1388 | mPath(path), mHOffset(hOffset), mVOffset(vOffset) { |
| 1389 | /* TODO: inherit from DrawBounded and init mLocalBounds */ |
| 1390 | } |
| 1391 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1392 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1393 | return renderer.drawTextOnPath(mText, mBytesCount, mCount, mPath, |
| 1394 | mHOffset, mVOffset, getPaint(renderer)); |
| 1395 | } |
| 1396 | |
| 1397 | virtual const char* name() { return "DrawTextOnPath"; } |
| 1398 | |
| 1399 | private: |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1400 | const SkPath* mPath; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1401 | float mHOffset; |
| 1402 | float mVOffset; |
| 1403 | }; |
| 1404 | |
| 1405 | class DrawPosTextOp : public DrawSomeTextOp { |
| 1406 | public: |
| 1407 | DrawPosTextOp(const char* text, int bytesCount, int count, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1408 | const float* positions, const SkPaint* paint) |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1409 | : DrawSomeTextOp(text, bytesCount, count, paint), mPositions(positions) { |
| 1410 | /* TODO: inherit from DrawBounded and init mLocalBounds */ |
| 1411 | } |
| 1412 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1413 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1414 | return renderer.drawPosText(mText, mBytesCount, mCount, mPositions, getPaint(renderer)); |
| 1415 | } |
| 1416 | |
| 1417 | virtual const char* name() { return "DrawPosText"; } |
| 1418 | |
| 1419 | private: |
| 1420 | const float* mPositions; |
| 1421 | }; |
| 1422 | |
| 1423 | class DrawTextOp : public DrawBoundedOp { |
| 1424 | public: |
| 1425 | DrawTextOp(const char* text, int bytesCount, int count, float x, float y, |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1426 | const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds) |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1427 | : DrawBoundedOp(bounds, paint), mText(text), mBytesCount(bytesCount), mCount(count), |
| 1428 | mX(x), mY(y), mPositions(positions), mTotalAdvance(totalAdvance) { |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1429 | memset(&mPrecacheTransform.data[0], 0xff, 16 * sizeof(float)); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1432 | virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo, |
| 1433 | const DeferredDisplayState& state) { |
Chris Craik | d218a92 | 2014-01-02 17:13:34 -0800 | [diff] [blame] | 1434 | const SkPaint* paint = getPaint(renderer); |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1435 | FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint); |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1436 | const mat4& transform = renderer.findBestFontTransform(state.mMatrix); |
| 1437 | if (mPrecacheTransform != transform) { |
| 1438 | fontRenderer.precache(paint, mText, mCount, transform); |
| 1439 | mPrecacheTransform = transform; |
| 1440 | } |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1441 | deferInfo.batchId = mPaint->getColor() == 0xff000000 ? |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1442 | DeferredDisplayList::kOpBatch_Text : |
| 1443 | DeferredDisplayList::kOpBatch_ColorText; |
| 1444 | |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1445 | deferInfo.mergeId = (mergeid_t)mPaint->getColor(); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1446 | |
| 1447 | // don't merge decorated text - the decorations won't draw in order |
| 1448 | bool noDecorations = !(mPaint->getFlags() & (SkPaint::kUnderlineText_Flag | |
| 1449 | SkPaint::kStrikeThruText_Flag)); |
Chris Craik | 28ce94a | 2013-05-31 11:38:03 -0700 | [diff] [blame] | 1450 | deferInfo.mergeable = state.mMatrix.isPureTranslate() && noDecorations && |
| 1451 | OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode; |
Romain Guy | 0f66753 | 2013-03-01 14:31:04 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1454 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Romain Guy | 9b5a1a2 | 2013-08-09 14:06:29 -0700 | [diff] [blame] | 1455 | Rect bounds; |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1456 | getLocalBounds(renderer.getDrawModifiers(), bounds); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1457 | return renderer.drawText(mText, mBytesCount, mCount, mX, mY, |
Romain Guy | 9b5a1a2 | 2013-08-09 14:06:29 -0700 | [diff] [blame] | 1458 | mPositions, getPaint(renderer), mTotalAdvance, bounds); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1461 | virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty, |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1462 | const Vector<OpStatePair>& ops, const Rect& bounds) { |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1463 | status_t status = DrawGlInfo::kStatusDone; |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1464 | for (unsigned int i = 0; i < ops.size(); i++) { |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1465 | const DeferredDisplayState& state = *(ops[i].state); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1466 | DrawOpMode drawOpMode = (i == ops.size() - 1) ? kDrawOpMode_Flush : kDrawOpMode_Defer; |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1467 | renderer.restoreDisplayState(state, true); // restore all but the clip |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1468 | |
Chris Craik | c1c5f08 | 2013-09-11 16:23:37 -0700 | [diff] [blame] | 1469 | DrawTextOp& op = *((DrawTextOp*)ops[i].op); |
Romain Guy | 9b5a1a2 | 2013-08-09 14:06:29 -0700 | [diff] [blame] | 1470 | // quickReject() will not occure in drawText() so we can use mLocalBounds |
| 1471 | // directly, we do not need to account for shadow by calling getLocalBounds() |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1472 | 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] | 1473 | op.mPositions, op.getPaint(renderer), op.mTotalAdvance, op.mLocalBounds, |
| 1474 | drawOpMode); |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1475 | } |
| 1476 | return status; |
| 1477 | } |
| 1478 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1479 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1480 | OP_LOG("Draw Text of count %d, bytes %d", mCount, mBytesCount); |
| 1481 | } |
| 1482 | |
| 1483 | virtual const char* name() { return "DrawText"; } |
| 1484 | |
| 1485 | private: |
| 1486 | const char* mText; |
| 1487 | int mBytesCount; |
| 1488 | int mCount; |
| 1489 | float mX; |
| 1490 | float mY; |
| 1491 | const float* mPositions; |
Chris Craik | 4154182 | 2013-05-03 16:35:54 -0700 | [diff] [blame] | 1492 | float mTotalAdvance; |
Romain Guy | bd3055f | 2013-03-13 16:14:47 -0700 | [diff] [blame] | 1493 | mat4 mPrecacheTransform; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1494 | }; |
| 1495 | |
| 1496 | /////////////////////////////////////////////////////////////////////////////// |
| 1497 | // SPECIAL DRAW OPERATIONS |
| 1498 | /////////////////////////////////////////////////////////////////////////////// |
| 1499 | |
| 1500 | class DrawFunctorOp : public DrawOp { |
| 1501 | public: |
| 1502 | DrawFunctorOp(Functor* functor) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1503 | : DrawOp(NULL), mFunctor(functor) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1504 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1505 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1506 | renderer.startMark("GL functor"); |
| 1507 | status_t ret = renderer.callDrawGLFunction(mFunctor, dirty); |
| 1508 | renderer.endMark(); |
| 1509 | return ret; |
| 1510 | } |
| 1511 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1512 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1513 | OP_LOG("Draw Functor %p", mFunctor); |
| 1514 | } |
| 1515 | |
| 1516 | virtual const char* name() { return "DrawFunctor"; } |
| 1517 | |
| 1518 | private: |
| 1519 | Functor* mFunctor; |
| 1520 | }; |
| 1521 | |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1522 | class DrawDisplayListOp : public DrawBoundedOp { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1523 | friend class DisplayList; // grant DisplayList access to info of child |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1524 | public: |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1525 | DrawDisplayListOp(DisplayList* displayList, int flags, const mat4& transformFromParent) |
Chris Craik | 5d11676 | 2013-02-19 17:49:31 -0800 | [diff] [blame] | 1526 | : DrawBoundedOp(0, 0, displayList->getWidth(), displayList->getHeight(), 0), |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1527 | mDisplayList(displayList), mFlags(flags), mTransformFromParent(transformFromParent) {} |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1528 | |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 1529 | virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level, |
| 1530 | bool useQuickReject) { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1531 | if (mDisplayList && mDisplayList->isRenderable() && !mSkipInOrderDraw) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1532 | mDisplayList->defer(deferStruct, level + 1); |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1533 | } |
Chris Craik | c3566d0 | 2013-02-04 16:16:33 -0800 | [diff] [blame] | 1534 | } |
Chet Haase | dd67159 | 2013-04-19 14:54:34 -0700 | [diff] [blame] | 1535 | virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level, |
| 1536 | bool useQuickReject) { |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1537 | if (mDisplayList && mDisplayList->isRenderable() && !mSkipInOrderDraw) { |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1538 | mDisplayList->replay(replayStruct, level + 1); |
| 1539 | } |
| 1540 | } |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1541 | |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1542 | // NOT USED since replay() is overridden |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1543 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1544 | return DrawGlInfo::kStatusDone; |
| 1545 | } |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1546 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1547 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1548 | OP_LOG("Draw Display List %p, flags %#x", mDisplayList, mFlags); |
Chris Craik | ff78583 | 2013-03-08 13:12:16 -0800 | [diff] [blame] | 1549 | if (mDisplayList && (logFlags & kOpLogFlag_Recurse)) { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1550 | mDisplayList->output(level + 1); |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | virtual const char* name() { return "DrawDisplayList"; } |
| 1555 | |
| 1556 | private: |
| 1557 | DisplayList* mDisplayList; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1558 | const int mFlags; |
| 1559 | |
| 1560 | /////////////////////////// |
| 1561 | // Properties below are used by DisplayList::computeOrderingImpl() and iterate() |
| 1562 | /////////////////////////// |
| 1563 | /** |
| 1564 | * Records transform vs parent, used for computing total transform without rerunning DL contents |
| 1565 | */ |
| 1566 | const mat4 mTransformFromParent; |
| 1567 | |
| 1568 | /** |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 1569 | * Holds the transformation between the 3d root OR projection surface ViewGroup and this |
| 1570 | * DisplayList drawing instance. Represents any translations / transformations done within the |
| 1571 | * drawing of the compositing ancestor ViewGroup's draw, before the draw of the View represented |
| 1572 | * by this DisplayList draw instance. |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1573 | * |
| 1574 | * Note: doesn't include any transformation recorded within the DisplayList and its properties. |
| 1575 | */ |
Chris Craik | f533e94 | 2014-01-14 22:35:37 -0800 | [diff] [blame] | 1576 | mat4 mTransformFromCompositingAncestor; |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1577 | bool mSkipInOrderDraw; |
| 1578 | }; |
| 1579 | |
| 1580 | /** |
| 1581 | * Not a canvas operation, used only by 3d / z ordering logic in DisplayList::iterate() |
| 1582 | */ |
| 1583 | class DrawShadowOp : public DrawOp { |
| 1584 | public: |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 1585 | DrawShadowOp(const mat4& transform, float alpha, const SkPath* outline, |
| 1586 | float fallbackWidth, float fallbackHeight) |
| 1587 | : DrawOp(NULL), mTransform(transform), mAlpha(alpha), mOutline(outline), |
| 1588 | mFallbackWidth(fallbackWidth), mFallbackHeight(fallbackHeight) {} |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1589 | |
| 1590 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 1591 | if (!mOutline->isEmpty()) { |
| 1592 | return renderer.drawShadow(mTransform, mAlpha, mOutline); |
| 1593 | } |
| 1594 | |
| 1595 | SkPath fakeOutline; |
| 1596 | fakeOutline.addRect(0, 0, mFallbackWidth, mFallbackHeight); |
| 1597 | return renderer.drawShadow(mTransform, mAlpha, &fakeOutline); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1598 | } |
| 1599 | |
| 1600 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 1601 | OP_LOG("DrawShadow of outline %p", mOutline); |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | virtual const char* name() { return "DrawShadow"; } |
| 1605 | |
| 1606 | private: |
Chris Craik | a2fe7af | 2014-01-28 17:25:06 -0800 | [diff] [blame] | 1607 | const mat4 mTransform; |
| 1608 | const float mAlpha; |
| 1609 | const SkPath* mOutline; |
| 1610 | const float mFallbackWidth; |
| 1611 | const float mFallbackHeight; |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1612 | }; |
| 1613 | |
| 1614 | class DrawLayerOp : public DrawOp { |
| 1615 | public: |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1616 | DrawLayerOp(Layer* layer, float x, float y) |
Chris Craik | f57776b | 2013-10-25 18:30:17 -0700 | [diff] [blame] | 1617 | : DrawOp(NULL), mLayer(layer), mX(x), mY(y) {} |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1618 | |
Chris Craik | 527a3aa | 2013-03-04 10:19:31 -0800 | [diff] [blame] | 1619 | virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) { |
Chris Craik | a08f95c | 2013-03-15 17:24:33 -0700 | [diff] [blame] | 1620 | return renderer.drawLayer(mLayer, mX, mY); |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
Chris Craik | c5493fb | 2013-06-19 16:58:58 -0700 | [diff] [blame] | 1623 | virtual void output(int level, uint32_t logFlags) const { |
Chris Craik | 2af4635 | 2012-11-26 18:30:17 -0800 | [diff] [blame] | 1624 | OP_LOG("Draw Layer %p at %f %f", mLayer, mX, mY); |
| 1625 | } |
| 1626 | |
| 1627 | virtual const char* name() { return "DrawLayer"; } |
| 1628 | |
| 1629 | private: |
| 1630 | Layer* mLayer; |
| 1631 | float mX; |
| 1632 | float mY; |
| 1633 | }; |
| 1634 | |
| 1635 | }; // namespace uirenderer |
| 1636 | }; // namespace android |
| 1637 | |
| 1638 | #endif // ANDROID_HWUI_DISPLAY_OPERATION_H |