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