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