blob: 46016d99273ddb6d0644a4265d31e2711ed55962 [file] [log] [blame]
Chris Craik2af46352012-11-26 18:30:17 -08001/*
Romain Guy7031ff62013-02-22 11:48:16 -08002 * Copyright (C) 2013 The Android Open Source Project
Chris Craik2af46352012-11-26 18:30:17 -08003 *
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 Guy7031ff62013-02-22 11:48:16 -080020#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
23
Chris Craik98d608d2014-07-17 12:25:11 -070024#include <SkColor.h>
Chris Craik8c271ca2014-03-25 10:33:01 -070025#include <SkPath.h>
26#include <SkPathOps.h>
Chris Craik2af46352012-11-26 18:30:17 -080027#include <SkXfermode.h>
28
Chris Craik0776a602013-02-14 15:36:01 -080029#include <private/hwui/DrawGlInfo.h>
30
Chris Craik2af46352012-11-26 18:30:17 -080031#include "OpenGLRenderer.h"
Romain Guy3b748a42013-04-17 18:54:38 -070032#include "AssetAtlas.h"
Chris Craikc3566d02013-02-04 16:16:33 -080033#include "DeferredDisplayList.h"
Chris Craik2af46352012-11-26 18:30:17 -080034#include "DisplayListRenderer.h"
Romain Guy3b748a42013-04-17 18:54:38 -070035#include "UvMapper.h"
Chris Craik2af46352012-11-26 18:30:17 -080036#include "utils/LinearAllocator.h"
37
38#define CRASH() do { \
Romain Guy5216c3b2013-06-14 16:31:37 -070039 *(int *)(uintptr_t) 0xbbadbeef = 0; \
Chris Craik2af46352012-11-26 18:30:17 -080040 ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \
41} while(false)
42
Chris Craik2af46352012-11-26 18:30:17 -080043// Use OP_LOG for logging with arglist, OP_LOGS if just printing char*
Chris Craik28ce94a2013-05-31 11:38:03 -070044#define OP_LOGS(s) OP_LOG("%s", (s))
Chris Craik3dc553b2013-02-04 12:45:13 -080045#define OP_LOG(s, ...) ALOGD( "%*s" s, level * 2, "", __VA_ARGS__ )
Chris Craik2af46352012-11-26 18:30:17 -080046
Chris Craik2af46352012-11-26 18:30:17 -080047namespace android {
48namespace 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 */
61class DisplayListOp {
62public:
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(); }
Andreas Gampe42ddc182014-11-21 09:49:08 -080066 static void operator delete(void* /* ptr */) { CRASH(); }
Chris Craik2af46352012-11-26 18:30:17 -080067 /** 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 Haasedd671592013-04-19 14:54:34 -070077 virtual void defer(DeferStateStruct& deferStruct, int saveCount, int level,
78 bool useQuickReject) = 0;
Chris Craikc3566d02013-02-04 16:16:33 -080079
Chet Haasedd671592013-04-19 14:54:34 -070080 virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int level,
81 bool useQuickReject) = 0;
Chris Craikff785832013-03-08 13:12:16 -080082
Chris Craikc5493fb2013-06-19 16:58:58 -070083 virtual void output(int level, uint32_t logFlags = 0) const = 0;
Chris Craik2af46352012-11-26 18:30:17 -080084
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
90class StateOp : public DisplayListOp {
91public:
92 StateOp() {};
93
94 virtual ~StateOp() {}
95
Andreas Gampe42ddc182014-11-21 09:49:08 -080096 virtual void defer(DeferStateStruct& deferStruct, int saveCount, int /* level */,
97 bool /* useQuickReject */) {
Chris Craikff785832013-03-08 13:12:16 -080098 // default behavior only affects immediate, deferrable state, issue directly to renderer
99 applyState(deferStruct.mRenderer, saveCount);
100 }
101
Chris Craikc3566d02013-02-04 16:16:33 -0800102 /**
103 * State operations are applied directly to the renderer, but can cause the deferred drawing op
104 * list to flush
105 */
Andreas Gampe42ddc182014-11-21 09:49:08 -0800106 virtual void replay(ReplayStateStruct& replayStruct, int saveCount, int /* level */,
107 bool /* useQuickReject */) {
Chris Craikff785832013-03-08 13:12:16 -0800108 applyState(replayStruct.mRenderer, saveCount);
Chris Craikc3566d02013-02-04 16:16:33 -0800109 }
110
Chris Craik7273daa2013-03-28 11:25:24 -0700111 virtual void applyState(OpenGLRenderer& renderer, int saveCount) const = 0;
Chris Craik2af46352012-11-26 18:30:17 -0800112};
113
114class DrawOp : public DisplayListOp {
Chris Craik527a3aa2013-03-04 10:19:31 -0800115friend class MergingDrawBatch;
Chris Craik2af46352012-11-26 18:30:17 -0800116public:
Chris Craikd218a922014-01-02 17:13:34 -0800117 DrawOp(const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -0800118 : mPaint(paint), mQuickRejected(false) {}
119
Andreas Gampe42ddc182014-11-21 09:49:08 -0800120 virtual void defer(DeferStateStruct& deferStruct, int /* saveCount */, int /* level */,
Chet Haasedd671592013-04-19 14:54:34 -0700121 bool useQuickReject) {
122 if (mQuickRejected && CC_LIKELY(useQuickReject)) {
Chris Craikff785832013-03-08 13:12:16 -0800123 return;
Chris Craikc3566d02013-02-04 16:16:33 -0800124 }
125
Chris Craikff785832013-03-08 13:12:16 -0800126 deferStruct.mDeferredList.addDrawOp(deferStruct.mRenderer, this);
Chris Craikc3566d02013-02-04 16:16:33 -0800127 }
128
Andreas Gampe42ddc182014-11-21 09:49:08 -0800129 virtual void replay(ReplayStateStruct& replayStruct, int /* saveCount */, int /* level */,
Chet Haasedd671592013-04-19 14:54:34 -0700130 bool useQuickReject) {
131 if (mQuickRejected && CC_LIKELY(useQuickReject)) {
Chris Craikff785832013-03-08 13:12:16 -0800132 return;
133 }
134
Chris Craik527a3aa2013-03-04 10:19:31 -0800135 replayStruct.mDrawGlStatus |= applyDraw(replayStruct.mRenderer, replayStruct.mDirty);
Chris Craikff785832013-03-08 13:12:16 -0800136 }
137
Chris Craik527a3aa2013-03-04 10:19:31 -0800138 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) = 0;
Chris Craik2af46352012-11-26 18:30:17 -0800139
Chris Craik527a3aa2013-03-04 10:19:31 -0800140 /**
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,
Andreas Gampe42ddc182014-11-21 09:49:08 -0800148 const Vector<OpStatePair>& ops, const Rect& /* bounds */) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800149 status_t status = DrawGlInfo::kStatusDone;
150 for (unsigned int i = 0; i < ops.size(); i++) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700151 renderer.restoreDisplayState(*(ops[i].state), true);
152 status |= ops[i].op->applyDraw(renderer, dirty);
Chris Craik527a3aa2013-03-04 10:19:31 -0800153 }
154 return status;
155 }
156
Chris Craik28ce94a2013-05-31 11:38:03 -0700157 /**
Chris Craik527a3aa2013-03-04 10:19:31 -0800158 * 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 Craik28ce94a2013-05-31 11:38:03 -0700165 * if a subclass can set deferInfo.mergeable to true, it should implement multiDraw()
Chris Craik527a3aa2013-03-04 10:19:31 -0800166 */
Andreas Gampe42ddc182014-11-21 09:49:08 -0800167 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& /* deferInfo */,
168 const DeferredDisplayState& /* state */) {}
Romain Guy0f667532013-03-01 14:31:04 -0800169
Chris Craik5e49b302013-07-30 19:05:20 -0700170 /**
171 * Query the conservative, local bounds (unmapped) bounds of the op.
172 *
173 * returns true if bounds exist
174 */
Andreas Gampe42ddc182014-11-21 09:49:08 -0800175 virtual bool getLocalBounds(Rect& /* localBounds */) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700176 return false;
177 }
Chris Craik2af46352012-11-26 18:30:17 -0800178
179 // TODO: better refine localbounds usage
180 void setQuickRejected(bool quickRejected) { mQuickRejected = quickRejected; }
181 bool getQuickRejected() { return mQuickRejected; }
182
Chris Craikc1c5f082013-09-11 16:23:37 -0700183 inline int getPaintAlpha() const {
Chris Craik527a3aa2013-03-04 10:19:31 -0800184 return OpenGLRenderer::getAlphaDirect(mPaint);
Chris Craikc3566d02013-02-04 16:16:33 -0800185 }
186
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -0400187 virtual bool hasTextShadow() const {
188 return false;
189 }
190
Chris Craik527a3aa2013-03-04 10:19:31 -0800191 inline float strokeWidthOutset() {
Chris Craikf0a59072013-11-19 18:00:46 -0800192 // 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 Craike7c69c62013-04-03 09:55:48 -0700198 }
Chris Craikc3566d02013-02-04 16:16:33 -0800199
Chris Craik2af46352012-11-26 18:30:17 -0800200protected:
Chris Craikd218a922014-01-02 17:13:34 -0800201 const SkPaint* getPaint(OpenGLRenderer& renderer) {
Chris Craika08f95c2013-03-15 17:24:33 -0700202 return renderer.filterPaint(mPaint);
Chris Craik2af46352012-11-26 18:30:17 -0800203 }
204
Chris Craik28ce94a2013-05-31 11:38:03 -0700205 // Helper method for determining op opaqueness. Assumes op fills its bounds in local
206 // coordinates, and that paint's alpha is used
Chris Craikc1c5f082013-09-11 16:23:37 -0700207 inline bool isOpaqueOverBounds(const DeferredDisplayState& state) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700208 // ensure that local bounds cover mapped bounds
209 if (!state.mMatrix.isSimple()) return false;
210
Chris Craik2262abb2014-08-18 19:55:36 -0700211 if (state.mRoundRectClipState) return false;
212
Chris Craik28ce94a2013-05-31 11:38:03 -0700213 // check state/paint for transparency
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400214 if (mPaint) {
Chris Craikc5b5f052014-10-01 16:40:16 -0700215 if (mPaint->getAlpha() != 0xFF) {
216 return false;
217 }
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400218 if (mPaint->getShader() && !mPaint->getShader()->isOpaque()) {
219 return false;
220 }
Chris Craikc5b5f052014-10-01 16:40:16 -0700221 if (Renderer::isBlendedColorFilter(mPaint->getColorFilter())) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400222 return false;
223 }
224 }
225
226 if (state.mAlpha != 1.0f) return false;
Chris Craik28ce94a2013-05-31 11:38:03 -0700227
228 SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint);
229 return (mode == SkXfermode::kSrcOver_Mode ||
230 mode == SkXfermode::kSrc_Mode);
231
232 }
233
Chris Craikd218a922014-01-02 17:13:34 -0800234 const SkPaint* mPaint; // should be accessed via getPaint() when applying
Chris Craik2af46352012-11-26 18:30:17 -0800235 bool mQuickRejected;
236};
237
238class DrawBoundedOp : public DrawOp {
239public:
Chris Craikd218a922014-01-02 17:13:34 -0800240 DrawBoundedOp(float left, float top, float right, float bottom, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -0800241 : DrawOp(paint), mLocalBounds(left, top, right, bottom) {}
242
Chris Craikd218a922014-01-02 17:13:34 -0800243 DrawBoundedOp(const Rect& localBounds, const SkPaint* paint)
Chris Craik41541822013-05-03 16:35:54 -0700244 : DrawOp(paint), mLocalBounds(localBounds) {}
245
Chris Craik5d116762013-02-19 17:49:31 -0800246 // Calculates bounds as smallest rect encompassing all points
247 // NOTE: requires at least 1 vertex, and doesn't account for stroke size (should be handled in
248 // subclass' constructor)
Chris Craikd218a922014-01-02 17:13:34 -0800249 DrawBoundedOp(const float* points, int count, const SkPaint* paint)
Chris Craik5d116762013-02-19 17:49:31 -0800250 : DrawOp(paint), mLocalBounds(points[0], points[1], points[0], points[1]) {
251 for (int i = 2; i < count; i += 2) {
252 mLocalBounds.left = fminf(mLocalBounds.left, points[i]);
253 mLocalBounds.right = fmaxf(mLocalBounds.right, points[i]);
254 mLocalBounds.top = fminf(mLocalBounds.top, points[i + 1]);
255 mLocalBounds.bottom = fmaxf(mLocalBounds.bottom, points[i + 1]);
256 }
257 }
258
259 // default empty constructor for bounds, to be overridden in child constructor body
Chris Craikd218a922014-01-02 17:13:34 -0800260 DrawBoundedOp(const SkPaint* paint): DrawOp(paint) { }
Chris Craik2af46352012-11-26 18:30:17 -0800261
John Reckca1b3b82014-06-27 07:21:36 -0700262 virtual bool getLocalBounds(Rect& localBounds) {
Chris Craik2af46352012-11-26 18:30:17 -0800263 localBounds.set(mLocalBounds);
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -0400264 OpenGLRenderer::TextShadow textShadow;
265 if (OpenGLRenderer::getTextShadow(mPaint, &textShadow)) {
Romain Guy9b5a1a22013-08-09 14:06:29 -0700266 Rect shadow(mLocalBounds);
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -0400267 shadow.translate(textShadow.dx, textShadow.dx);
268 shadow.outset(textShadow.radius);
Romain Guy9b5a1a22013-08-09 14:06:29 -0700269 localBounds.unionWith(shadow);
270 }
Chris Craik2af46352012-11-26 18:30:17 -0800271 return true;
272 }
273
274protected:
275 Rect mLocalBounds; // displayed area in LOCAL coord. doesn't incorporate stroke, so check paint
276};
277
278///////////////////////////////////////////////////////////////////////////////
279// STATE OPERATIONS - these may affect the state of the canvas/renderer, but do
280// not directly draw or alter output
281///////////////////////////////////////////////////////////////////////////////
282
283class SaveOp : public StateOp {
284public:
285 SaveOp(int flags)
286 : mFlags(flags) {}
287
Andreas Gampe42ddc182014-11-21 09:49:08 -0800288 virtual void defer(DeferStateStruct& deferStruct, int /* saveCount */, int /* level */,
289 bool /* useQuickReject */) {
Chris Craikff785832013-03-08 13:12:16 -0800290 int newSaveCount = deferStruct.mRenderer.save(mFlags);
291 deferStruct.mDeferredList.addSave(deferStruct.mRenderer, this, newSaveCount);
292 }
293
Andreas Gampe42ddc182014-11-21 09:49:08 -0800294 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800295 renderer.save(mFlags);
296 }
297
Andreas Gampe42ddc182014-11-21 09:49:08 -0800298 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800299 OP_LOG("Save flags %x", mFlags);
300 }
301
302 virtual const char* name() { return "Save"; }
303
Chris Craikff785832013-03-08 13:12:16 -0800304 int getFlags() const { return mFlags; }
Chris Craik2af46352012-11-26 18:30:17 -0800305private:
306 int mFlags;
307};
308
309class RestoreToCountOp : public StateOp {
310public:
311 RestoreToCountOp(int count)
312 : mCount(count) {}
313
Andreas Gampe42ddc182014-11-21 09:49:08 -0800314 virtual void defer(DeferStateStruct& deferStruct, int saveCount, int /* level */,
315 bool /* useQuickReject */) {
Chris Craik7273daa2013-03-28 11:25:24 -0700316 deferStruct.mDeferredList.addRestoreToCount(deferStruct.mRenderer,
317 this, saveCount + mCount);
Chris Craikff785832013-03-08 13:12:16 -0800318 deferStruct.mRenderer.restoreToCount(saveCount + mCount);
Chris Craik2af46352012-11-26 18:30:17 -0800319 }
320
Chris Craik7273daa2013-03-28 11:25:24 -0700321 virtual void applyState(OpenGLRenderer& renderer, int saveCount) const {
Chris Craikff785832013-03-08 13:12:16 -0800322 renderer.restoreToCount(saveCount + mCount);
323 }
324
Andreas Gampe42ddc182014-11-21 09:49:08 -0800325 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800326 OP_LOG("Restore to count %d", mCount);
327 }
328
329 virtual const char* name() { return "RestoreToCount"; }
330
331private:
332 int mCount;
333};
334
335class SaveLayerOp : public StateOp {
336public:
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500337 SaveLayerOp(float left, float top, float right, float bottom, int alpha, int flags)
Chris Craik3f0854292014-04-15 16:18:08 -0700338 : mArea(left, top, right, bottom)
339 , mPaint(&mCachedPaint)
340 , mFlags(flags)
341 , mConvexMask(NULL) {
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500342 mCachedPaint.setAlpha(alpha);
343 }
344
345 SaveLayerOp(float left, float top, float right, float bottom, const SkPaint* paint, int flags)
Chris Craik3f0854292014-04-15 16:18:08 -0700346 : mArea(left, top, right, bottom)
347 , mPaint(paint)
348 , mFlags(flags)
349 , mConvexMask(NULL)
350 {}
Chris Craikff785832013-03-08 13:12:16 -0800351
Andreas Gampe42ddc182014-11-21 09:49:08 -0800352 virtual void defer(DeferStateStruct& deferStruct, int /* saveCount */, int /* level */,
353 bool /* useQuickReject */) {
Chris Craikff785832013-03-08 13:12:16 -0800354 // NOTE: don't bother with actual saveLayer, instead issuing it at flush time
Chris Craikd90144d2013-03-19 15:03:48 -0700355 int newSaveCount = deferStruct.mRenderer.getSaveCount();
Chris Craikff785832013-03-08 13:12:16 -0800356 deferStruct.mDeferredList.addSaveLayer(deferStruct.mRenderer, this, newSaveCount);
Chris Craikd90144d2013-03-19 15:03:48 -0700357
358 // NOTE: don't issue full saveLayer, since that has side effects/is costly. instead just
359 // setup the snapshot for deferral, and re-issue the op at flush time
360 deferStruct.mRenderer.saveLayerDeferred(mArea.left, mArea.top, mArea.right, mArea.bottom,
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500361 mPaint, mFlags);
Chris Craikff785832013-03-08 13:12:16 -0800362 }
Chris Craik2af46352012-11-26 18:30:17 -0800363
Andreas Gampe42ddc182014-11-21 09:49:08 -0800364 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik3f0854292014-04-15 16:18:08 -0700365 renderer.saveLayer(mArea.left, mArea.top, mArea.right, mArea.bottom,
366 mPaint, mFlags, mConvexMask);
Chris Craik2af46352012-11-26 18:30:17 -0800367 }
368
Andreas Gampe42ddc182014-11-21 09:49:08 -0800369 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craikff785832013-03-08 13:12:16 -0800370 OP_LOG("SaveLayer%s of area " RECT_STRING,
371 (isSaveLayerAlpha() ? "Alpha" : ""),RECT_ARGS(mArea));
Chris Craik2af46352012-11-26 18:30:17 -0800372 }
373
Chris Craikff785832013-03-08 13:12:16 -0800374 virtual const char* name() { return isSaveLayerAlpha() ? "SaveLayerAlpha" : "SaveLayer"; }
375
376 int getFlags() { return mFlags; }
Chris Craik2af46352012-11-26 18:30:17 -0800377
Chris Craik3f0854292014-04-15 16:18:08 -0700378 // Called to make SaveLayerOp clip to the provided mask when drawing back/restored
379 void setMask(const SkPath* convexMask) {
380 mConvexMask = convexMask;
381 }
382
Chris Craik2af46352012-11-26 18:30:17 -0800383private:
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500384 bool isSaveLayerAlpha() const {
385 SkXfermode::Mode mode = OpenGLRenderer::getXfermodeDirect(mPaint);
386 int alpha = OpenGLRenderer::getAlphaDirect(mPaint);
387 return alpha < 255 && mode == SkXfermode::kSrcOver_Mode;
Chris Craik2af46352012-11-26 18:30:17 -0800388 }
389
Chris Craik2af46352012-11-26 18:30:17 -0800390 Rect mArea;
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500391 const SkPaint* mPaint;
392 SkPaint mCachedPaint;
Chris Craik2af46352012-11-26 18:30:17 -0800393 int mFlags;
Chris Craik3f0854292014-04-15 16:18:08 -0700394
395 // Convex path, points at data in RenderNode, valid for the duration of the frame only
396 // Only used for masking the SaveLayer which wraps projected RenderNodes
397 const SkPath* mConvexMask;
Chris Craik2af46352012-11-26 18:30:17 -0800398};
399
400class TranslateOp : public StateOp {
401public:
402 TranslateOp(float dx, float dy)
403 : mDx(dx), mDy(dy) {}
404
Andreas Gampe42ddc182014-11-21 09:49:08 -0800405 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800406 renderer.translate(mDx, mDy);
407 }
408
Andreas Gampe42ddc182014-11-21 09:49:08 -0800409 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800410 OP_LOG("Translate by %f %f", mDx, mDy);
411 }
412
413 virtual const char* name() { return "Translate"; }
414
415private:
416 float mDx;
417 float mDy;
418};
419
420class RotateOp : public StateOp {
421public:
422 RotateOp(float degrees)
423 : mDegrees(degrees) {}
424
Andreas Gampe42ddc182014-11-21 09:49:08 -0800425 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800426 renderer.rotate(mDegrees);
427 }
428
Andreas Gampe42ddc182014-11-21 09:49:08 -0800429 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800430 OP_LOG("Rotate by %f degrees", mDegrees);
431 }
432
433 virtual const char* name() { return "Rotate"; }
434
435private:
436 float mDegrees;
437};
438
439class ScaleOp : public StateOp {
440public:
441 ScaleOp(float sx, float sy)
442 : mSx(sx), mSy(sy) {}
443
Andreas Gampe42ddc182014-11-21 09:49:08 -0800444 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800445 renderer.scale(mSx, mSy);
446 }
447
Andreas Gampe42ddc182014-11-21 09:49:08 -0800448 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800449 OP_LOG("Scale by %f %f", mSx, mSy);
450 }
451
452 virtual const char* name() { return "Scale"; }
453
454private:
455 float mSx;
456 float mSy;
457};
458
459class SkewOp : public StateOp {
460public:
461 SkewOp(float sx, float sy)
462 : mSx(sx), mSy(sy) {}
463
Andreas Gampe42ddc182014-11-21 09:49:08 -0800464 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800465 renderer.skew(mSx, mSy);
466 }
467
Andreas Gampe42ddc182014-11-21 09:49:08 -0800468 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800469 OP_LOG("Skew by %f %f", mSx, mSy);
470 }
471
472 virtual const char* name() { return "Skew"; }
473
474private:
475 float mSx;
476 float mSy;
477};
478
479class SetMatrixOp : public StateOp {
480public:
Derek Sollenberger13908822013-12-10 12:28:58 -0500481 SetMatrixOp(const SkMatrix& matrix)
Chris Craik2af46352012-11-26 18:30:17 -0800482 : mMatrix(matrix) {}
483
Andreas Gampe42ddc182014-11-21 09:49:08 -0800484 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800485 renderer.setMatrix(mMatrix);
486 }
487
Andreas Gampe42ddc182014-11-21 09:49:08 -0800488 virtual void output(int level, uint32_t /* logFlags */) const {
Derek Sollenberger13908822013-12-10 12:28:58 -0500489 if (mMatrix.isIdentity()) {
Romain Guy4e7b7722013-07-16 13:47:01 -0700490 OP_LOGS("SetMatrix (reset)");
Derek Sollenberger13908822013-12-10 12:28:58 -0500491 } else {
492 OP_LOG("SetMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(&mMatrix));
Romain Guy4e7b7722013-07-16 13:47:01 -0700493 }
Chris Craik2af46352012-11-26 18:30:17 -0800494 }
495
496 virtual const char* name() { return "SetMatrix"; }
497
498private:
Derek Sollenberger13908822013-12-10 12:28:58 -0500499 const SkMatrix mMatrix;
Chris Craik2af46352012-11-26 18:30:17 -0800500};
501
502class ConcatMatrixOp : public StateOp {
503public:
Derek Sollenberger13908822013-12-10 12:28:58 -0500504 ConcatMatrixOp(const SkMatrix& matrix)
Chris Craik2af46352012-11-26 18:30:17 -0800505 : mMatrix(matrix) {}
506
Andreas Gampe42ddc182014-11-21 09:49:08 -0800507 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800508 renderer.concatMatrix(mMatrix);
509 }
510
Andreas Gampe42ddc182014-11-21 09:49:08 -0800511 virtual void output(int level, uint32_t /* logFlags */) const {
Derek Sollenberger13908822013-12-10 12:28:58 -0500512 OP_LOG("ConcatMatrix " SK_MATRIX_STRING, SK_MATRIX_ARGS(&mMatrix));
Chris Craik2af46352012-11-26 18:30:17 -0800513 }
514
515 virtual const char* name() { return "ConcatMatrix"; }
516
517private:
Derek Sollenberger13908822013-12-10 12:28:58 -0500518 const SkMatrix mMatrix;
Chris Craik2af46352012-11-26 18:30:17 -0800519};
520
Chris Craikff785832013-03-08 13:12:16 -0800521class ClipOp : public StateOp {
522public:
523 ClipOp(SkRegion::Op op) : mOp(op) {}
524
Andreas Gampe42ddc182014-11-21 09:49:08 -0800525 virtual void defer(DeferStateStruct& deferStruct, int saveCount, int /* level */,
526 bool /* useQuickReject */) {
Chris Craikff785832013-03-08 13:12:16 -0800527 // NOTE: must defer op BEFORE applying state, since it may read clip
528 deferStruct.mDeferredList.addClip(deferStruct.mRenderer, this);
529
530 // TODO: Can we avoid applying complex clips at defer time?
531 applyState(deferStruct.mRenderer, saveCount);
532 }
533
534 bool canCauseComplexClip() {
535 return ((mOp != SkRegion::kIntersect_Op) && (mOp != SkRegion::kReplace_Op)) || !isRect();
536 }
537
538protected:
Chris Craikff785832013-03-08 13:12:16 -0800539 virtual bool isRect() { return false; }
540
541 SkRegion::Op mOp;
542};
543
544class ClipRectOp : public ClipOp {
Chris Craik2af46352012-11-26 18:30:17 -0800545public:
546 ClipRectOp(float left, float top, float right, float bottom, SkRegion::Op op)
Chris Craikff785832013-03-08 13:12:16 -0800547 : ClipOp(op), mArea(left, top, right, bottom) {}
Chris Craik2af46352012-11-26 18:30:17 -0800548
Andreas Gampe42ddc182014-11-21 09:49:08 -0800549 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800550 renderer.clipRect(mArea.left, mArea.top, mArea.right, mArea.bottom, mOp);
551 }
552
Andreas Gampe42ddc182014-11-21 09:49:08 -0800553 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800554 OP_LOG("ClipRect " RECT_STRING, RECT_ARGS(mArea));
555 }
556
557 virtual const char* name() { return "ClipRect"; }
558
Chris Craikff785832013-03-08 13:12:16 -0800559protected:
560 virtual bool isRect() { return true; }
Chris Craikb98a0162013-02-21 11:30:22 -0800561
Chris Craik2af46352012-11-26 18:30:17 -0800562private:
563 Rect mArea;
Chris Craik2af46352012-11-26 18:30:17 -0800564};
565
Chris Craikff785832013-03-08 13:12:16 -0800566class ClipPathOp : public ClipOp {
Chris Craik2af46352012-11-26 18:30:17 -0800567public:
Chris Craikd218a922014-01-02 17:13:34 -0800568 ClipPathOp(const SkPath* path, SkRegion::Op op)
Chris Craikff785832013-03-08 13:12:16 -0800569 : ClipOp(op), mPath(path) {}
Chris Craik2af46352012-11-26 18:30:17 -0800570
Andreas Gampe42ddc182014-11-21 09:49:08 -0800571 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800572 renderer.clipPath(mPath, mOp);
573 }
574
Andreas Gampe42ddc182014-11-21 09:49:08 -0800575 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800576 SkRect bounds = mPath->getBounds();
577 OP_LOG("ClipPath bounds " RECT_STRING,
578 bounds.left(), bounds.top(), bounds.right(), bounds.bottom());
579 }
580
581 virtual const char* name() { return "ClipPath"; }
582
583private:
Chris Craikd218a922014-01-02 17:13:34 -0800584 const SkPath* mPath;
Chris Craik2af46352012-11-26 18:30:17 -0800585};
586
Chris Craikff785832013-03-08 13:12:16 -0800587class ClipRegionOp : public ClipOp {
Chris Craik2af46352012-11-26 18:30:17 -0800588public:
Chris Craikd218a922014-01-02 17:13:34 -0800589 ClipRegionOp(const SkRegion* region, SkRegion::Op op)
Chris Craikff785832013-03-08 13:12:16 -0800590 : ClipOp(op), mRegion(region) {}
Chris Craik2af46352012-11-26 18:30:17 -0800591
Andreas Gampe42ddc182014-11-21 09:49:08 -0800592 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800593 renderer.clipRegion(mRegion, mOp);
594 }
595
Andreas Gampe42ddc182014-11-21 09:49:08 -0800596 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800597 SkIRect bounds = mRegion->getBounds();
598 OP_LOG("ClipRegion bounds %d %d %d %d",
599 bounds.left(), bounds.top(), bounds.right(), bounds.bottom());
600 }
601
602 virtual const char* name() { return "ClipRegion"; }
603
604private:
Chris Craikd218a922014-01-02 17:13:34 -0800605 const SkRegion* mRegion;
Chris Craik2af46352012-11-26 18:30:17 -0800606};
607
Chris Craik2af46352012-11-26 18:30:17 -0800608class ResetPaintFilterOp : public StateOp {
609public:
Andreas Gampe42ddc182014-11-21 09:49:08 -0800610 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800611 renderer.resetPaintFilter();
612 }
613
Andreas Gampe42ddc182014-11-21 09:49:08 -0800614 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800615 OP_LOGS("ResetPaintFilter");
616 }
617
618 virtual const char* name() { return "ResetPaintFilter"; }
619};
620
621class SetupPaintFilterOp : public StateOp {
622public:
623 SetupPaintFilterOp(int clearBits, int setBits)
624 : mClearBits(clearBits), mSetBits(setBits) {}
625
Andreas Gampe42ddc182014-11-21 09:49:08 -0800626 virtual void applyState(OpenGLRenderer& renderer, int /* saveCount */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800627 renderer.setupPaintFilter(mClearBits, mSetBits);
628 }
629
Andreas Gampe42ddc182014-11-21 09:49:08 -0800630 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800631 OP_LOG("SetupPaintFilter, clear %#x, set %#x", mClearBits, mSetBits);
632 }
633
634 virtual const char* name() { return "SetupPaintFilter"; }
635
636private:
637 int mClearBits;
638 int mSetBits;
639};
640
Chris Craik2af46352012-11-26 18:30:17 -0800641///////////////////////////////////////////////////////////////////////////////
642// DRAW OPERATIONS - these are operations that can draw to the canvas's device
643///////////////////////////////////////////////////////////////////////////////
644
645class DrawBitmapOp : public DrawBoundedOp {
646public:
Chris Craik79647502014-08-06 13:42:24 -0700647 DrawBitmapOp(const SkBitmap* bitmap, const SkPaint* paint)
648 : DrawBoundedOp(0, 0, bitmap->width(), bitmap->height(), paint)
649 , mBitmap(bitmap)
650 , mAtlas(Caches::getInstance().assetAtlas) {
Romain Guy55b6f952013-06-27 15:27:09 -0700651 mEntry = mAtlas.getEntry(bitmap);
652 if (mEntry) {
653 mEntryGenerationId = mAtlas.getGenerationId();
654 mUvMapper = mEntry->uvMapper;
655 }
Romain Guy3b748a42013-04-17 18:54:38 -0700656 }
Chris Craik2af46352012-11-26 18:30:17 -0800657
Andreas Gampe42ddc182014-11-21 09:49:08 -0800658 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik79647502014-08-06 13:42:24 -0700659 return renderer.drawBitmap(mBitmap, getPaint(renderer));
Chris Craik2af46352012-11-26 18:30:17 -0800660 }
661
Romain Guy55b6f952013-06-27 15:27:09 -0700662 AssetAtlas::Entry* getAtlasEntry() {
663 // The atlas entry is stale, let's get a new one
664 if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) {
665 mEntryGenerationId = mAtlas.getGenerationId();
666 mEntry = mAtlas.getEntry(mBitmap);
667 mUvMapper = mEntry->uvMapper;
668 }
669 return mEntry;
670 }
671
Chris Craik527a3aa2013-03-04 10:19:31 -0800672#define SET_TEXTURE(ptr, posRect, offsetRect, texCoordsRect, xDim, yDim) \
673 TextureVertex::set(ptr++, posRect.xDim - offsetRect.left, posRect.yDim - offsetRect.top, \
674 texCoordsRect.xDim, texCoordsRect.yDim)
675
Romain Guy03c00b52013-06-20 18:30:28 -0700676 /**
677 * This multi-draw operation builds a mesh on the stack by generating a quad
678 * for each bitmap in the batch. This method is also responsible for dirtying
679 * the current layer, if any.
680 */
Andreas Gampe42ddc182014-11-21 09:49:08 -0800681 virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& /* dirty */,
Chris Craikc1c5f082013-09-11 16:23:37 -0700682 const Vector<OpStatePair>& ops, const Rect& bounds) {
683 const DeferredDisplayState& firstState = *(ops[0].state);
684 renderer.restoreDisplayState(firstState, true); // restore all but the clip
685
Chris Craik527a3aa2013-03-04 10:19:31 -0800686 TextureVertex vertices[6 * ops.size()];
687 TextureVertex* vertex = &vertices[0];
688
Romain Guy03c00b52013-06-20 18:30:28 -0700689 const bool hasLayer = renderer.hasLayer();
Chris Craik996fe652013-09-20 17:13:18 -0700690 bool pureTranslate = true;
Romain Guy2db5e992013-05-21 15:29:59 -0700691
Romain Guy3b748a42013-04-17 18:54:38 -0700692 // TODO: manually handle rect clip for bitmaps by adjusting texCoords per op,
693 // and allowing them to be merged in getBatchId()
Chris Craik527a3aa2013-03-04 10:19:31 -0800694 for (unsigned int i = 0; i < ops.size(); i++) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700695 const DeferredDisplayState& state = *(ops[i].state);
696 const Rect& opBounds = state.mBounds;
Romain Guy2db5e992013-05-21 15:29:59 -0700697 // When we reach multiDraw(), the matrix can be either
698 // pureTranslate or simple (translate and/or scale).
699 // If the matrix is not pureTranslate, then we have a scale
Chris Craik996fe652013-09-20 17:13:18 -0700700 pureTranslate &= state.mMatrix.isPureTranslate();
Romain Guy3b748a42013-04-17 18:54:38 -0700701
702 Rect texCoords(0, 0, 1, 1);
Chris Craikc1c5f082013-09-11 16:23:37 -0700703 ((DrawBitmapOp*) ops[i].op)->mUvMapper.map(texCoords);
Romain Guy3b748a42013-04-17 18:54:38 -0700704
Chris Craik527a3aa2013-03-04 10:19:31 -0800705 SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top);
706 SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top);
707 SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom);
708
709 SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, bottom);
710 SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top);
711 SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, bottom);
Romain Guy03c00b52013-06-20 18:30:28 -0700712
713 if (hasLayer) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700714 renderer.dirtyLayer(opBounds.left, opBounds.top, opBounds.right, opBounds.bottom);
Romain Guy03c00b52013-06-20 18:30:28 -0700715 }
Chris Craik527a3aa2013-03-04 10:19:31 -0800716 }
717
Romain Guy55b6f952013-06-27 15:27:09 -0700718 return renderer.drawBitmaps(mBitmap, mEntry, ops.size(), &vertices[0],
Chris Craik996fe652013-09-20 17:13:18 -0700719 pureTranslate, bounds, mPaint);
Chris Craik527a3aa2013-03-04 10:19:31 -0800720 }
721
Andreas Gampe42ddc182014-11-21 09:49:08 -0800722 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800723 OP_LOG("Draw bitmap %p at %f %f", mBitmap, mLocalBounds.left, mLocalBounds.top);
724 }
725
726 virtual const char* name() { return "DrawBitmap"; }
Chris Craik527a3aa2013-03-04 10:19:31 -0800727
Andreas Gampe42ddc182014-11-21 09:49:08 -0800728 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
Chris Craikc1c5f082013-09-11 16:23:37 -0700729 const DeferredDisplayState& state) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700730 deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
Chris Craikd965bc52013-09-16 14:47:13 -0700731 deferInfo.mergeId = getAtlasEntry() ?
732 (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
Romain Guy2db5e992013-05-21 15:29:59 -0700733
Chris Craikd965bc52013-09-16 14:47:13 -0700734 // Don't merge non-simply transformed or neg scale ops, SET_TEXTURE doesn't handle rotation
Chris Craik28ce94a2013-05-31 11:38:03 -0700735 // Don't merge A8 bitmaps - the paint's color isn't compared by mergeId, or in
736 // MergingDrawBatch::canMergeWith()
737 // TODO: support clipped bitmaps by handling them in SET_TEXTURE
Chris Craikd965bc52013-09-16 14:47:13 -0700738 deferInfo.mergeable = state.mMatrix.isSimple() && state.mMatrix.positiveScale() &&
739 !state.mClipSideFlags &&
Chris Craik28ce94a2013-05-31 11:38:03 -0700740 OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode &&
Mike Reed1103b322014-07-08 12:36:44 -0400741 (mBitmap->colorType() != kAlpha_8_SkColorType);
Chris Craikc3566d02013-02-04 16:16:33 -0800742 }
Chris Craik2af46352012-11-26 18:30:17 -0800743
Chris Craik527a3aa2013-03-04 10:19:31 -0800744 const SkBitmap* bitmap() { return mBitmap; }
Chris Craik2af46352012-11-26 18:30:17 -0800745protected:
Chris Craikd218a922014-01-02 17:13:34 -0800746 const SkBitmap* mBitmap;
Romain Guy55b6f952013-06-27 15:27:09 -0700747 const AssetAtlas& mAtlas;
748 uint32_t mEntryGenerationId;
749 AssetAtlas::Entry* mEntry;
Romain Guy3b748a42013-04-17 18:54:38 -0700750 UvMapper mUvMapper;
Chris Craik2af46352012-11-26 18:30:17 -0800751};
752
Chris Craik2af46352012-11-26 18:30:17 -0800753class DrawBitmapRectOp : public DrawBoundedOp {
754public:
Chris Craikd218a922014-01-02 17:13:34 -0800755 DrawBitmapRectOp(const SkBitmap* bitmap,
756 float srcLeft, float srcTop, float srcRight, float srcBottom,
757 float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -0800758 : DrawBoundedOp(dstLeft, dstTop, dstRight, dstBottom, paint),
759 mBitmap(bitmap), mSrc(srcLeft, srcTop, srcRight, srcBottom) {}
760
Andreas Gampe42ddc182014-11-21 09:49:08 -0800761 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -0800762 return renderer.drawBitmap(mBitmap, mSrc.left, mSrc.top, mSrc.right, mSrc.bottom,
763 mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom,
764 getPaint(renderer));
765 }
766
Andreas Gampe42ddc182014-11-21 09:49:08 -0800767 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -0700768 OP_LOG("Draw bitmap %p src=" RECT_STRING ", dst=" RECT_STRING,
Chris Craik2af46352012-11-26 18:30:17 -0800769 mBitmap, RECT_ARGS(mSrc), RECT_ARGS(mLocalBounds));
770 }
771
772 virtual const char* name() { return "DrawBitmapRect"; }
Chris Craik527a3aa2013-03-04 10:19:31 -0800773
Andreas Gampe42ddc182014-11-21 09:49:08 -0800774 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
775 const DeferredDisplayState& /* state */) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700776 deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
Chris Craikc3566d02013-02-04 16:16:33 -0800777 }
Chris Craik2af46352012-11-26 18:30:17 -0800778
779private:
Chris Craikd218a922014-01-02 17:13:34 -0800780 const SkBitmap* mBitmap;
Chris Craik2af46352012-11-26 18:30:17 -0800781 Rect mSrc;
782};
783
784class DrawBitmapDataOp : public DrawBitmapOp {
785public:
Chris Craik79647502014-08-06 13:42:24 -0700786 DrawBitmapDataOp(const SkBitmap* bitmap, const SkPaint* paint)
787 : DrawBitmapOp(bitmap, paint) {}
Chris Craik2af46352012-11-26 18:30:17 -0800788
Andreas Gampe42ddc182014-11-21 09:49:08 -0800789 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik79647502014-08-06 13:42:24 -0700790 return renderer.drawBitmapData(mBitmap, getPaint(renderer));
Chris Craik2af46352012-11-26 18:30:17 -0800791 }
792
Andreas Gampe42ddc182014-11-21 09:49:08 -0800793 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800794 OP_LOG("Draw bitmap %p", mBitmap);
795 }
796
797 virtual const char* name() { return "DrawBitmapData"; }
Chris Craik527a3aa2013-03-04 10:19:31 -0800798
Andreas Gampe42ddc182014-11-21 09:49:08 -0800799 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
800 const DeferredDisplayState& /* state */) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700801 deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
Chris Craikc3566d02013-02-04 16:16:33 -0800802 }
Chris Craik2af46352012-11-26 18:30:17 -0800803};
804
Chris Craik5d116762013-02-19 17:49:31 -0800805class DrawBitmapMeshOp : public DrawBoundedOp {
Chris Craik2af46352012-11-26 18:30:17 -0800806public:
Chris Craikd218a922014-01-02 17:13:34 -0800807 DrawBitmapMeshOp(const SkBitmap* bitmap, int meshWidth, int meshHeight,
808 const float* vertices, const int* colors, const SkPaint* paint)
Chris Craik5d116762013-02-19 17:49:31 -0800809 : DrawBoundedOp(vertices, 2 * (meshWidth + 1) * (meshHeight + 1), paint),
810 mBitmap(bitmap), mMeshWidth(meshWidth), mMeshHeight(meshHeight),
Chris Craik2af46352012-11-26 18:30:17 -0800811 mVertices(vertices), mColors(colors) {}
812
Andreas Gampe42ddc182014-11-21 09:49:08 -0800813 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -0800814 return renderer.drawBitmapMesh(mBitmap, mMeshWidth, mMeshHeight,
815 mVertices, mColors, getPaint(renderer));
816 }
817
Andreas Gampe42ddc182014-11-21 09:49:08 -0800818 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800819 OP_LOG("Draw bitmap %p mesh %d x %d", mBitmap, mMeshWidth, mMeshHeight);
820 }
821
822 virtual const char* name() { return "DrawBitmapMesh"; }
Chris Craik527a3aa2013-03-04 10:19:31 -0800823
Andreas Gampe42ddc182014-11-21 09:49:08 -0800824 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
825 const DeferredDisplayState& /* state */) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700826 deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
Chris Craikc3566d02013-02-04 16:16:33 -0800827 }
Chris Craik2af46352012-11-26 18:30:17 -0800828
829private:
Chris Craikd218a922014-01-02 17:13:34 -0800830 const SkBitmap* mBitmap;
Chris Craik2af46352012-11-26 18:30:17 -0800831 int mMeshWidth;
832 int mMeshHeight;
Chris Craikd218a922014-01-02 17:13:34 -0800833 const float* mVertices;
834 const int* mColors;
Chris Craik2af46352012-11-26 18:30:17 -0800835};
836
837class DrawPatchOp : public DrawBoundedOp {
838public:
Chris Craikd218a922014-01-02 17:13:34 -0800839 DrawPatchOp(const SkBitmap* bitmap, const Res_png_9patch* patch,
840 float left, float top, float right, float bottom, const SkPaint* paint)
Romain Guy03c00b52013-06-20 18:30:28 -0700841 : DrawBoundedOp(left, top, right, bottom, paint),
Romain Guy55b6f952013-06-27 15:27:09 -0700842 mBitmap(bitmap), mPatch(patch), mGenerationId(0), mMesh(NULL),
843 mAtlas(Caches::getInstance().assetAtlas) {
844 mEntry = mAtlas.getEntry(bitmap);
845 if (mEntry) {
846 mEntryGenerationId = mAtlas.getGenerationId();
847 }
Romain Guy3b748a42013-04-17 18:54:38 -0700848 };
Chris Craik2af46352012-11-26 18:30:17 -0800849
Romain Guy55b6f952013-06-27 15:27:09 -0700850 AssetAtlas::Entry* getAtlasEntry() {
851 // The atlas entry is stale, let's get a new one
852 if (mEntry && mEntryGenerationId != mAtlas.getGenerationId()) {
853 mEntryGenerationId = mAtlas.getGenerationId();
854 mEntry = mAtlas.getEntry(mBitmap);
855 }
856 return mEntry;
857 }
858
Romain Guy03c00b52013-06-20 18:30:28 -0700859 const Patch* getMesh(OpenGLRenderer& renderer) {
Romain Guy4c2547f2013-06-11 16:19:24 -0700860 if (!mMesh || renderer.getCaches().patchCache.getGenerationId() != mGenerationId) {
861 PatchCache& cache = renderer.getCaches().patchCache;
Romain Guy55b6f952013-06-27 15:27:09 -0700862 mMesh = cache.get(getAtlasEntry(), mBitmap->width(), mBitmap->height(),
Romain Guy03c00b52013-06-20 18:30:28 -0700863 mLocalBounds.getWidth(), mLocalBounds.getHeight(), mPatch);
Romain Guy4c2547f2013-06-11 16:19:24 -0700864 mGenerationId = cache.getGenerationId();
865 }
Romain Guy03c00b52013-06-20 18:30:28 -0700866 return mMesh;
867 }
868
869 /**
870 * This multi-draw operation builds an indexed mesh on the stack by copying
871 * and transforming the vertices of each 9-patch in the batch. This method
872 * is also responsible for dirtying the current layer, if any.
873 */
Andreas Gampe42ddc182014-11-21 09:49:08 -0800874 virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& /* dirty */,
875 const Vector<OpStatePair>& ops, const Rect& /* bounds */) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700876 const DeferredDisplayState& firstState = *(ops[0].state);
877 renderer.restoreDisplayState(firstState, true); // restore all but the clip
Romain Guy03c00b52013-06-20 18:30:28 -0700878
879 // Batches will usually contain a small number of items so it's
880 // worth performing a first iteration to count the exact number
881 // of vertices we need in the new mesh
882 uint32_t totalVertices = 0;
883 for (unsigned int i = 0; i < ops.size(); i++) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700884 totalVertices += ((DrawPatchOp*) ops[i].op)->getMesh(renderer)->verticesCount;
Romain Guy03c00b52013-06-20 18:30:28 -0700885 }
886
887 const bool hasLayer = renderer.hasLayer();
888
889 uint32_t indexCount = 0;
890
891 TextureVertex vertices[totalVertices];
892 TextureVertex* vertex = &vertices[0];
893
894 // Create a mesh that contains the transformed vertices for all the
895 // 9-patch objects that are part of the batch. Note that onDefer()
896 // enforces ops drawn by this function to have a pure translate or
897 // identity matrix
898 for (unsigned int i = 0; i < ops.size(); i++) {
Chris Craikc1c5f082013-09-11 16:23:37 -0700899 DrawPatchOp* patchOp = (DrawPatchOp*) ops[i].op;
900 const DeferredDisplayState* state = ops[i].state;
Romain Guy03c00b52013-06-20 18:30:28 -0700901 const Patch* opMesh = patchOp->getMesh(renderer);
902 uint32_t vertexCount = opMesh->verticesCount;
903 if (vertexCount == 0) continue;
904
905 // We use the bounds to know where to translate our vertices
906 // Using patchOp->state.mBounds wouldn't work because these
907 // bounds are clipped
Chris Craikc1c5f082013-09-11 16:23:37 -0700908 const float tx = (int) floorf(state->mMatrix.getTranslateX() +
Romain Guy03c00b52013-06-20 18:30:28 -0700909 patchOp->mLocalBounds.left + 0.5f);
Chris Craikc1c5f082013-09-11 16:23:37 -0700910 const float ty = (int) floorf(state->mMatrix.getTranslateY() +
Romain Guy03c00b52013-06-20 18:30:28 -0700911 patchOp->mLocalBounds.top + 0.5f);
912
913 // Copy & transform all the vertices for the current operation
914 TextureVertex* opVertices = opMesh->vertices;
915 for (uint32_t j = 0; j < vertexCount; j++, opVertices++) {
916 TextureVertex::set(vertex++,
Romain Guy3380cfd2013-08-15 16:57:57 -0700917 opVertices->x + tx, opVertices->y + ty,
918 opVertices->u, opVertices->v);
Romain Guy03c00b52013-06-20 18:30:28 -0700919 }
920
921 // Dirty the current layer if possible. When the 9-patch does not
922 // contain empty quads we can take a shortcut and simply set the
923 // dirty rect to the object's bounds.
924 if (hasLayer) {
925 if (!opMesh->hasEmptyQuads) {
926 renderer.dirtyLayer(tx, ty,
927 tx + patchOp->mLocalBounds.getWidth(),
928 ty + patchOp->mLocalBounds.getHeight());
929 } else {
930 const size_t count = opMesh->quads.size();
931 for (size_t i = 0; i < count; i++) {
932 const Rect& quadBounds = opMesh->quads[i];
933 const float x = tx + quadBounds.left;
934 const float y = ty + quadBounds.top;
935 renderer.dirtyLayer(x, y,
936 x + quadBounds.getWidth(), y + quadBounds.getHeight());
937 }
938 }
939 }
940
941 indexCount += opMesh->indexCount;
942 }
943
Romain Guy55b6f952013-06-27 15:27:09 -0700944 return renderer.drawPatches(mBitmap, getAtlasEntry(),
945 &vertices[0], indexCount, getPaint(renderer));
Romain Guy03c00b52013-06-20 18:30:28 -0700946 }
947
Andreas Gampe42ddc182014-11-21 09:49:08 -0800948 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Romain Guy4c2547f2013-06-11 16:19:24 -0700949 // We're not calling the public variant of drawPatch() here
950 // This method won't perform the quickReject() since we've already done it at this point
Romain Guy55b6f952013-06-27 15:27:09 -0700951 return renderer.drawPatch(mBitmap, getMesh(renderer), getAtlasEntry(),
Romain Guy03c00b52013-06-20 18:30:28 -0700952 mLocalBounds.left, mLocalBounds.top, mLocalBounds.right, mLocalBounds.bottom,
953 getPaint(renderer));
Chris Craik2af46352012-11-26 18:30:17 -0800954 }
955
Andreas Gampe42ddc182014-11-21 09:49:08 -0800956 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -0700957 OP_LOG("Draw patch " RECT_STRING, RECT_ARGS(mLocalBounds));
Chris Craik2af46352012-11-26 18:30:17 -0800958 }
959
960 virtual const char* name() { return "DrawPatch"; }
Chris Craik527a3aa2013-03-04 10:19:31 -0800961
Andreas Gampe42ddc182014-11-21 09:49:08 -0800962 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
Chris Craikc1c5f082013-09-11 16:23:37 -0700963 const DeferredDisplayState& state) {
Chris Craik28ce94a2013-05-31 11:38:03 -0700964 deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch;
Romain Guy7f6d6b02013-08-06 13:49:28 -0700965 deferInfo.mergeId = getAtlasEntry() ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
Romain Guy03c00b52013-06-20 18:30:28 -0700966 deferInfo.mergeable = state.mMatrix.isPureTranslate() &&
967 OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode;
Chris Craikc1c5f082013-09-11 16:23:37 -0700968 deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && mBitmap->isOpaque();
Chris Craikc3566d02013-02-04 16:16:33 -0800969 }
Chris Craik2af46352012-11-26 18:30:17 -0800970
971private:
Chris Craikd218a922014-01-02 17:13:34 -0800972 const SkBitmap* mBitmap;
973 const Res_png_9patch* mPatch;
Romain Guy4c2547f2013-06-11 16:19:24 -0700974
Romain Guy4c2547f2013-06-11 16:19:24 -0700975 uint32_t mGenerationId;
976 const Patch* mMesh;
Romain Guy03c00b52013-06-20 18:30:28 -0700977
Romain Guy55b6f952013-06-27 15:27:09 -0700978 const AssetAtlas& mAtlas;
979 uint32_t mEntryGenerationId;
Romain Guy3b748a42013-04-17 18:54:38 -0700980 AssetAtlas::Entry* mEntry;
Chris Craik2af46352012-11-26 18:30:17 -0800981};
982
983class DrawColorOp : public DrawOp {
984public:
985 DrawColorOp(int color, SkXfermode::Mode mode)
Chris Craikf57776b2013-10-25 18:30:17 -0700986 : DrawOp(NULL), mColor(color), mMode(mode) {};
Chris Craik2af46352012-11-26 18:30:17 -0800987
Andreas Gampe42ddc182014-11-21 09:49:08 -0800988 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -0800989 return renderer.drawColor(mColor, mMode);
990 }
991
Andreas Gampe42ddc182014-11-21 09:49:08 -0800992 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -0800993 OP_LOG("Draw color %#x, mode %d", mColor, mMode);
994 }
995
996 virtual const char* name() { return "DrawColor"; }
997
998private:
999 int mColor;
1000 SkXfermode::Mode mMode;
1001};
1002
1003class DrawStrokableOp : public DrawBoundedOp {
1004public:
Chris Craikd218a922014-01-02 17:13:34 -08001005 DrawStrokableOp(float left, float top, float right, float bottom, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001006 : DrawBoundedOp(left, top, right, bottom, paint) {};
Chris Craik947eabf2014-08-19 10:21:12 -07001007 DrawStrokableOp(const Rect& localBounds, const SkPaint* paint)
1008 : DrawBoundedOp(localBounds, paint) {};
Chris Craik2af46352012-11-26 18:30:17 -08001009
John Reckca1b3b82014-06-27 07:21:36 -07001010 virtual bool getLocalBounds(Rect& localBounds) {
Chris Craikc3566d02013-02-04 16:16:33 -08001011 localBounds.set(mLocalBounds);
Chris Craik2af46352012-11-26 18:30:17 -08001012 if (mPaint && mPaint->getStyle() != SkPaint::kFill_Style) {
Chris Craikc3566d02013-02-04 16:16:33 -08001013 localBounds.outset(strokeWidthOutset());
Chris Craik2af46352012-11-26 18:30:17 -08001014 }
1015 return true;
1016 }
Chris Craikc3566d02013-02-04 16:16:33 -08001017
Andreas Gampe42ddc182014-11-21 09:49:08 -08001018 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
1019 const DeferredDisplayState& /* state */) {
Chris Craikc3566d02013-02-04 16:16:33 -08001020 if (mPaint->getPathEffect()) {
Chris Craik28ce94a2013-05-31 11:38:03 -07001021 deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture;
Chris Craik527a3aa2013-03-04 10:19:31 -08001022 } else {
Chris Craik28ce94a2013-05-31 11:38:03 -07001023 deferInfo.batchId = mPaint->isAntiAlias() ?
Chris Craik527a3aa2013-03-04 10:19:31 -08001024 DeferredDisplayList::kOpBatch_AlphaVertices :
1025 DeferredDisplayList::kOpBatch_Vertices;
Chris Craikc3566d02013-02-04 16:16:33 -08001026 }
Chris Craikc3566d02013-02-04 16:16:33 -08001027 }
Chris Craik2af46352012-11-26 18:30:17 -08001028};
1029
1030class DrawRectOp : public DrawStrokableOp {
1031public:
Chris Craikd218a922014-01-02 17:13:34 -08001032 DrawRectOp(float left, float top, float right, float bottom, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001033 : DrawStrokableOp(left, top, right, bottom, paint) {}
1034
Andreas Gampe42ddc182014-11-21 09:49:08 -08001035 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001036 return renderer.drawRect(mLocalBounds.left, mLocalBounds.top,
1037 mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer));
1038 }
1039
Andreas Gampe42ddc182014-11-21 09:49:08 -08001040 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -07001041 OP_LOG("Draw Rect " RECT_STRING, RECT_ARGS(mLocalBounds));
Chris Craik2af46352012-11-26 18:30:17 -08001042 }
1043
Chris Craikc1c5f082013-09-11 16:23:37 -07001044 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
1045 const DeferredDisplayState& state) {
1046 DrawStrokableOp::onDefer(renderer, deferInfo, state);
1047 deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) &&
Chris Craik28ce94a2013-05-31 11:38:03 -07001048 mPaint->getStyle() == SkPaint::kFill_Style;
1049 }
1050
Chris Craik2af46352012-11-26 18:30:17 -08001051 virtual const char* name() { return "DrawRect"; }
1052};
1053
Chris Craik5d116762013-02-19 17:49:31 -08001054class DrawRectsOp : public DrawBoundedOp {
Chris Craik2af46352012-11-26 18:30:17 -08001055public:
Chris Craikd218a922014-01-02 17:13:34 -08001056 DrawRectsOp(const float* rects, int count, const SkPaint* paint)
Chris Craik5d116762013-02-19 17:49:31 -08001057 : DrawBoundedOp(rects, count, paint),
1058 mRects(rects), mCount(count) {}
Chris Craik2af46352012-11-26 18:30:17 -08001059
Andreas Gampe42ddc182014-11-21 09:49:08 -08001060 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001061 return renderer.drawRects(mRects, mCount, getPaint(renderer));
1062 }
1063
Andreas Gampe42ddc182014-11-21 09:49:08 -08001064 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001065 OP_LOG("Draw Rects count %d", mCount);
1066 }
1067
1068 virtual const char* name() { return "DrawRects"; }
1069
Andreas Gampe42ddc182014-11-21 09:49:08 -08001070 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
1071 const DeferredDisplayState& /* state */) {
Chris Craik28ce94a2013-05-31 11:38:03 -07001072 deferInfo.batchId = DeferredDisplayList::kOpBatch_Vertices;
Chris Craikc3566d02013-02-04 16:16:33 -08001073 }
1074
Chris Craik2af46352012-11-26 18:30:17 -08001075private:
1076 const float* mRects;
1077 int mCount;
1078};
1079
1080class DrawRoundRectOp : public DrawStrokableOp {
1081public:
1082 DrawRoundRectOp(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -08001083 float rx, float ry, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001084 : DrawStrokableOp(left, top, right, bottom, paint), mRx(rx), mRy(ry) {}
1085
Andreas Gampe42ddc182014-11-21 09:49:08 -08001086 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001087 return renderer.drawRoundRect(mLocalBounds.left, mLocalBounds.top,
1088 mLocalBounds.right, mLocalBounds.bottom, mRx, mRy, getPaint(renderer));
1089 }
1090
Andreas Gampe42ddc182014-11-21 09:49:08 -08001091 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -07001092 OP_LOG("Draw RoundRect " RECT_STRING ", rx %f, ry %f", RECT_ARGS(mLocalBounds), mRx, mRy);
Chris Craik2af46352012-11-26 18:30:17 -08001093 }
1094
Chris Craik05f3d6e2014-06-02 16:27:04 -07001095 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
1096 const DeferredDisplayState& state) {
1097 DrawStrokableOp::onDefer(renderer, deferInfo, state);
1098 if (!mPaint->getPathEffect()) {
Chris Craik6ac174b2014-06-17 13:47:05 -07001099 renderer.getCaches().tessellationCache.precacheRoundRect(state.mMatrix, *mPaint,
1100 mLocalBounds.getWidth(), mLocalBounds.getHeight(), mRx, mRy);
Chris Craik05f3d6e2014-06-02 16:27:04 -07001101 }
1102 }
1103
Chris Craik2af46352012-11-26 18:30:17 -08001104 virtual const char* name() { return "DrawRoundRect"; }
1105
1106private:
1107 float mRx;
1108 float mRy;
1109};
1110
Jorim Jaggi072707d2014-09-15 17:20:08 +02001111class DrawRoundRectPropsOp : public DrawOp {
1112public:
1113 DrawRoundRectPropsOp(float* left, float* top, float* right, float* bottom,
1114 float *rx, float *ry, const SkPaint* paint)
1115 : DrawOp(paint), mLeft(left), mTop(top), mRight(right), mBottom(bottom),
1116 mRx(rx), mRy(ry) {}
1117
Andreas Gampe42ddc182014-11-21 09:49:08 -08001118 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Jorim Jaggi072707d2014-09-15 17:20:08 +02001119 return renderer.drawRoundRect(*mLeft, *mTop, *mRight, *mBottom,
1120 *mRx, *mRy, getPaint(renderer));
1121 }
1122
Andreas Gampe42ddc182014-11-21 09:49:08 -08001123 virtual void output(int level, uint32_t /* logFlags */) const {
Jorim Jaggi072707d2014-09-15 17:20:08 +02001124 OP_LOG("Draw RoundRect Props " RECT_STRING ", rx %f, ry %f",
1125 *mLeft, *mTop, *mRight, *mBottom, *mRx, *mRy);
1126 }
1127
1128 virtual const char* name() { return "DrawRoundRectProps"; }
1129
1130private:
1131 float* mLeft;
1132 float* mTop;
1133 float* mRight;
1134 float* mBottom;
1135 float* mRx;
1136 float* mRy;
1137};
1138
Chris Craik2af46352012-11-26 18:30:17 -08001139class DrawCircleOp : public DrawStrokableOp {
1140public:
Chris Craikd218a922014-01-02 17:13:34 -08001141 DrawCircleOp(float x, float y, float radius, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001142 : DrawStrokableOp(x - radius, y - radius, x + radius, y + radius, paint),
1143 mX(x), mY(y), mRadius(radius) {}
1144
Andreas Gampe42ddc182014-11-21 09:49:08 -08001145 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001146 return renderer.drawCircle(mX, mY, mRadius, getPaint(renderer));
1147 }
1148
Andreas Gampe42ddc182014-11-21 09:49:08 -08001149 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001150 OP_LOG("Draw Circle x %f, y %f, r %f", mX, mY, mRadius);
1151 }
1152
1153 virtual const char* name() { return "DrawCircle"; }
1154
1155private:
1156 float mX;
1157 float mY;
1158 float mRadius;
1159};
1160
John Reck52244ff2014-05-01 21:27:37 -07001161class DrawCirclePropsOp : public DrawOp {
1162public:
1163 DrawCirclePropsOp(float* x, float* y, float* radius, const SkPaint* paint)
1164 : DrawOp(paint), mX(x), mY(y), mRadius(radius) {}
1165
Andreas Gampe42ddc182014-11-21 09:49:08 -08001166 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
John Reck52244ff2014-05-01 21:27:37 -07001167 return renderer.drawCircle(*mX, *mY, *mRadius, getPaint(renderer));
1168 }
1169
Andreas Gampe42ddc182014-11-21 09:49:08 -08001170 virtual void output(int level, uint32_t /* logFlags */) const {
John Reck52244ff2014-05-01 21:27:37 -07001171 OP_LOG("Draw Circle Props x %p, y %p, r %p", mX, mY, mRadius);
1172 }
1173
1174 virtual const char* name() { return "DrawCircleProps"; }
1175
1176private:
1177 float* mX;
1178 float* mY;
1179 float* mRadius;
1180};
1181
Chris Craik2af46352012-11-26 18:30:17 -08001182class DrawOvalOp : public DrawStrokableOp {
1183public:
Chris Craikd218a922014-01-02 17:13:34 -08001184 DrawOvalOp(float left, float top, float right, float bottom, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001185 : DrawStrokableOp(left, top, right, bottom, paint) {}
1186
Andreas Gampe42ddc182014-11-21 09:49:08 -08001187 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001188 return renderer.drawOval(mLocalBounds.left, mLocalBounds.top,
1189 mLocalBounds.right, mLocalBounds.bottom, getPaint(renderer));
1190 }
1191
Andreas Gampe42ddc182014-11-21 09:49:08 -08001192 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -07001193 OP_LOG("Draw Oval " RECT_STRING, RECT_ARGS(mLocalBounds));
Chris Craik2af46352012-11-26 18:30:17 -08001194 }
1195
1196 virtual const char* name() { return "DrawOval"; }
1197};
1198
1199class DrawArcOp : public DrawStrokableOp {
1200public:
1201 DrawArcOp(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -08001202 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001203 : DrawStrokableOp(left, top, right, bottom, paint),
1204 mStartAngle(startAngle), mSweepAngle(sweepAngle), mUseCenter(useCenter) {}
1205
Andreas Gampe42ddc182014-11-21 09:49:08 -08001206 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001207 return renderer.drawArc(mLocalBounds.left, mLocalBounds.top,
1208 mLocalBounds.right, mLocalBounds.bottom,
1209 mStartAngle, mSweepAngle, mUseCenter, getPaint(renderer));
1210 }
1211
Andreas Gampe42ddc182014-11-21 09:49:08 -08001212 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -07001213 OP_LOG("Draw Arc " RECT_STRING ", start %f, sweep %f, useCenter %d",
Chris Craik2af46352012-11-26 18:30:17 -08001214 RECT_ARGS(mLocalBounds), mStartAngle, mSweepAngle, mUseCenter);
1215 }
1216
1217 virtual const char* name() { return "DrawArc"; }
1218
1219private:
1220 float mStartAngle;
1221 float mSweepAngle;
1222 bool mUseCenter;
1223};
1224
1225class DrawPathOp : public DrawBoundedOp {
1226public:
Chris Craikd218a922014-01-02 17:13:34 -08001227 DrawPathOp(const SkPath* path, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001228 : DrawBoundedOp(paint), mPath(path) {
1229 float left, top, offset;
1230 uint32_t width, height;
Romain Guyca89e2a2013-03-08 17:44:20 -08001231 PathCache::computePathBounds(path, paint, left, top, offset, width, height);
Chris Craik2af46352012-11-26 18:30:17 -08001232 left -= offset;
1233 top -= offset;
1234 mLocalBounds.set(left, top, left + width, top + height);
1235 }
1236
Andreas Gampe42ddc182014-11-21 09:49:08 -08001237 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001238 return renderer.drawPath(mPath, getPaint(renderer));
1239 }
1240
Chris Craikc1c5f082013-09-11 16:23:37 -07001241 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
Andreas Gampe42ddc182014-11-21 09:49:08 -08001242 const DeferredDisplayState& /* state */) {
Chris Craikd218a922014-01-02 17:13:34 -08001243 const SkPaint* paint = getPaint(renderer);
Romain Guyca89e2a2013-03-08 17:44:20 -08001244 renderer.getCaches().pathCache.precache(mPath, paint);
Chris Craik527a3aa2013-03-04 10:19:31 -08001245
Chris Craik28ce94a2013-05-31 11:38:03 -07001246 deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture;
Romain Guyca89e2a2013-03-08 17:44:20 -08001247 }
1248
Andreas Gampe42ddc182014-11-21 09:49:08 -08001249 virtual void output(int level, uint32_t /* logFlags */) const {
John Reckce444ca2014-06-02 15:12:36 -07001250 OP_LOG("Draw Path %p in " RECT_STRING, mPath, RECT_ARGS(mLocalBounds));
Chris Craik2af46352012-11-26 18:30:17 -08001251 }
1252
1253 virtual const char* name() { return "DrawPath"; }
1254
1255private:
Chris Craikd218a922014-01-02 17:13:34 -08001256 const SkPath* mPath;
Chris Craik2af46352012-11-26 18:30:17 -08001257};
1258
Chris Craikc3566d02013-02-04 16:16:33 -08001259class DrawLinesOp : public DrawBoundedOp {
Chris Craik2af46352012-11-26 18:30:17 -08001260public:
Chris Craikd218a922014-01-02 17:13:34 -08001261 DrawLinesOp(const float* points, int count, const SkPaint* paint)
Chris Craik5d116762013-02-19 17:49:31 -08001262 : DrawBoundedOp(points, count, paint),
1263 mPoints(points), mCount(count) {
Chris Craikc3566d02013-02-04 16:16:33 -08001264 mLocalBounds.outset(strokeWidthOutset());
Chris Craik2af46352012-11-26 18:30:17 -08001265 }
1266
Andreas Gampe42ddc182014-11-21 09:49:08 -08001267 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001268 return renderer.drawLines(mPoints, mCount, getPaint(renderer));
1269 }
1270
Andreas Gampe42ddc182014-11-21 09:49:08 -08001271 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001272 OP_LOG("Draw Lines count %d", mCount);
1273 }
1274
1275 virtual const char* name() { return "DrawLines"; }
1276
Andreas Gampe42ddc182014-11-21 09:49:08 -08001277 virtual void onDefer(OpenGLRenderer& /* renderer */, DeferInfo& deferInfo,
1278 const DeferredDisplayState& /* state */) {
Chris Craik28ce94a2013-05-31 11:38:03 -07001279 deferInfo.batchId = mPaint->isAntiAlias() ?
Chris Craikc3566d02013-02-04 16:16:33 -08001280 DeferredDisplayList::kOpBatch_AlphaVertices :
1281 DeferredDisplayList::kOpBatch_Vertices;
1282 }
1283
Chris Craik2af46352012-11-26 18:30:17 -08001284protected:
Chris Craikd218a922014-01-02 17:13:34 -08001285 const float* mPoints;
Chris Craik2af46352012-11-26 18:30:17 -08001286 int mCount;
1287};
1288
1289class DrawPointsOp : public DrawLinesOp {
1290public:
Chris Craikd218a922014-01-02 17:13:34 -08001291 DrawPointsOp(const float* points, int count, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001292 : DrawLinesOp(points, count, paint) {}
1293
Andreas Gampe42ddc182014-11-21 09:49:08 -08001294 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001295 return renderer.drawPoints(mPoints, mCount, getPaint(renderer));
1296 }
1297
Andreas Gampe42ddc182014-11-21 09:49:08 -08001298 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001299 OP_LOG("Draw Points count %d", mCount);
1300 }
1301
1302 virtual const char* name() { return "DrawPoints"; }
1303};
1304
1305class DrawSomeTextOp : public DrawOp {
1306public:
Chris Craikd218a922014-01-02 17:13:34 -08001307 DrawSomeTextOp(const char* text, int bytesCount, int count, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001308 : DrawOp(paint), mText(text), mBytesCount(bytesCount), mCount(count) {};
1309
Andreas Gampe42ddc182014-11-21 09:49:08 -08001310 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001311 OP_LOG("Draw some text, %d bytes", mBytesCount);
1312 }
Chris Craikc3566d02013-02-04 16:16:33 -08001313
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -04001314 virtual bool hasTextShadow() const {
1315 return OpenGLRenderer::hasTextShadow(mPaint);
1316 }
1317
Chris Craikc1c5f082013-09-11 16:23:37 -07001318 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
Andreas Gampe42ddc182014-11-21 09:49:08 -08001319 const DeferredDisplayState& /* state */) {
Chris Craikd218a922014-01-02 17:13:34 -08001320 const SkPaint* paint = getPaint(renderer);
Romain Guy0f667532013-03-01 14:31:04 -08001321 FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint);
Chris Craik59744b72014-07-01 17:56:52 -07001322 fontRenderer.precache(paint, mText, mCount, SkMatrix::I());
Romain Guy0f667532013-03-01 14:31:04 -08001323
Chris Craik98d608d2014-07-17 12:25:11 -07001324 deferInfo.batchId = mPaint->getColor() == SK_ColorBLACK ?
Chris Craikc3566d02013-02-04 16:16:33 -08001325 DeferredDisplayList::kOpBatch_Text :
1326 DeferredDisplayList::kOpBatch_ColorText;
1327 }
Chris Craik527a3aa2013-03-04 10:19:31 -08001328
Chris Craik2af46352012-11-26 18:30:17 -08001329protected:
1330 const char* mText;
1331 int mBytesCount;
1332 int mCount;
1333};
1334
1335class DrawTextOnPathOp : public DrawSomeTextOp {
1336public:
1337 DrawTextOnPathOp(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -08001338 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001339 : DrawSomeTextOp(text, bytesCount, count, paint),
1340 mPath(path), mHOffset(hOffset), mVOffset(vOffset) {
1341 /* TODO: inherit from DrawBounded and init mLocalBounds */
1342 }
1343
Andreas Gampe42ddc182014-11-21 09:49:08 -08001344 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001345 return renderer.drawTextOnPath(mText, mBytesCount, mCount, mPath,
1346 mHOffset, mVOffset, getPaint(renderer));
1347 }
1348
1349 virtual const char* name() { return "DrawTextOnPath"; }
1350
1351private:
Chris Craikd218a922014-01-02 17:13:34 -08001352 const SkPath* mPath;
Chris Craik2af46352012-11-26 18:30:17 -08001353 float mHOffset;
1354 float mVOffset;
1355};
1356
1357class DrawPosTextOp : public DrawSomeTextOp {
1358public:
1359 DrawPosTextOp(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -08001360 const float* positions, const SkPaint* paint)
Chris Craik2af46352012-11-26 18:30:17 -08001361 : DrawSomeTextOp(text, bytesCount, count, paint), mPositions(positions) {
1362 /* TODO: inherit from DrawBounded and init mLocalBounds */
1363 }
1364
Andreas Gampe42ddc182014-11-21 09:49:08 -08001365 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik2af46352012-11-26 18:30:17 -08001366 return renderer.drawPosText(mText, mBytesCount, mCount, mPositions, getPaint(renderer));
1367 }
1368
1369 virtual const char* name() { return "DrawPosText"; }
1370
1371private:
1372 const float* mPositions;
1373};
1374
Chris Craik947eabf2014-08-19 10:21:12 -07001375class DrawTextOp : public DrawStrokableOp {
Chris Craik2af46352012-11-26 18:30:17 -08001376public:
1377 DrawTextOp(const char* text, int bytesCount, int count, float x, float y,
Chris Craikd218a922014-01-02 17:13:34 -08001378 const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds)
Chris Craik947eabf2014-08-19 10:21:12 -07001379 : DrawStrokableOp(bounds, paint), mText(text), mBytesCount(bytesCount), mCount(count),
Chris Craik41541822013-05-03 16:35:54 -07001380 mX(x), mY(y), mPositions(positions), mTotalAdvance(totalAdvance) {
Chris Craik59744b72014-07-01 17:56:52 -07001381 mPrecacheTransform = SkMatrix::InvalidMatrix();
Chris Craik2af46352012-11-26 18:30:17 -08001382 }
1383
Chris Craikc1c5f082013-09-11 16:23:37 -07001384 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
1385 const DeferredDisplayState& state) {
Chris Craikd218a922014-01-02 17:13:34 -08001386 const SkPaint* paint = getPaint(renderer);
Romain Guy0f667532013-03-01 14:31:04 -08001387 FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint);
Chris Craik59744b72014-07-01 17:56:52 -07001388 SkMatrix transform;
1389 renderer.findBestFontTransform(state.mMatrix, &transform);
Romain Guybd3055f2013-03-13 16:14:47 -07001390 if (mPrecacheTransform != transform) {
1391 fontRenderer.precache(paint, mText, mCount, transform);
1392 mPrecacheTransform = transform;
1393 }
Chris Craik98d608d2014-07-17 12:25:11 -07001394 deferInfo.batchId = mPaint->getColor() == SK_ColorBLACK ?
Chris Craik527a3aa2013-03-04 10:19:31 -08001395 DeferredDisplayList::kOpBatch_Text :
1396 DeferredDisplayList::kOpBatch_ColorText;
1397
Kévin PETIT73fc5582014-02-13 11:03:40 +00001398 deferInfo.mergeId = reinterpret_cast<mergeid_t>(mPaint->getColor());
Chris Craik527a3aa2013-03-04 10:19:31 -08001399
1400 // don't merge decorated text - the decorations won't draw in order
Chris Craik98d608d2014-07-17 12:25:11 -07001401 bool hasDecorations = mPaint->getFlags()
1402 & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag);
1403
1404 deferInfo.mergeable = state.mMatrix.isPureTranslate()
1405 && !hasDecorations
1406 && OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode;
Romain Guy0f667532013-03-01 14:31:04 -08001407 }
1408
Andreas Gampe42ddc182014-11-21 09:49:08 -08001409 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Romain Guy9b5a1a22013-08-09 14:06:29 -07001410 Rect bounds;
John Reck3b202512014-06-23 13:13:08 -07001411 getLocalBounds(bounds);
Chris Craik2af46352012-11-26 18:30:17 -08001412 return renderer.drawText(mText, mBytesCount, mCount, mX, mY,
Romain Guy9b5a1a22013-08-09 14:06:29 -07001413 mPositions, getPaint(renderer), mTotalAdvance, bounds);
Chris Craik2af46352012-11-26 18:30:17 -08001414 }
1415
Andreas Gampe42ddc182014-11-21 09:49:08 -08001416 virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& /* dirty */,
1417 const Vector<OpStatePair>& ops, const Rect& /* bounds */) {
Chris Craik527a3aa2013-03-04 10:19:31 -08001418 status_t status = DrawGlInfo::kStatusDone;
Chris Craik527a3aa2013-03-04 10:19:31 -08001419 for (unsigned int i = 0; i < ops.size(); i++) {
Chris Craikc1c5f082013-09-11 16:23:37 -07001420 const DeferredDisplayState& state = *(ops[i].state);
Chris Craik527a3aa2013-03-04 10:19:31 -08001421 DrawOpMode drawOpMode = (i == ops.size() - 1) ? kDrawOpMode_Flush : kDrawOpMode_Defer;
Chris Craikc1c5f082013-09-11 16:23:37 -07001422 renderer.restoreDisplayState(state, true); // restore all but the clip
Chris Craik527a3aa2013-03-04 10:19:31 -08001423
Chris Craikc1c5f082013-09-11 16:23:37 -07001424 DrawTextOp& op = *((DrawTextOp*)ops[i].op);
Romain Guy9b5a1a22013-08-09 14:06:29 -07001425 // quickReject() will not occure in drawText() so we can use mLocalBounds
1426 // directly, we do not need to account for shadow by calling getLocalBounds()
Chris Craik527a3aa2013-03-04 10:19:31 -08001427 status |= renderer.drawText(op.mText, op.mBytesCount, op.mCount, op.mX, op.mY,
Chris Craik41541822013-05-03 16:35:54 -07001428 op.mPositions, op.getPaint(renderer), op.mTotalAdvance, op.mLocalBounds,
1429 drawOpMode);
Chris Craik527a3aa2013-03-04 10:19:31 -08001430 }
1431 return status;
1432 }
1433
Andreas Gampe42ddc182014-11-21 09:49:08 -08001434 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001435 OP_LOG("Draw Text of count %d, bytes %d", mCount, mBytesCount);
1436 }
1437
1438 virtual const char* name() { return "DrawText"; }
1439
1440private:
1441 const char* mText;
1442 int mBytesCount;
1443 int mCount;
1444 float mX;
1445 float mY;
1446 const float* mPositions;
Chris Craik41541822013-05-03 16:35:54 -07001447 float mTotalAdvance;
Chris Craik59744b72014-07-01 17:56:52 -07001448 SkMatrix mPrecacheTransform;
Chris Craik2af46352012-11-26 18:30:17 -08001449};
1450
1451///////////////////////////////////////////////////////////////////////////////
1452// SPECIAL DRAW OPERATIONS
1453///////////////////////////////////////////////////////////////////////////////
1454
1455class DrawFunctorOp : public DrawOp {
1456public:
1457 DrawFunctorOp(Functor* functor)
Chris Craikf57776b2013-10-25 18:30:17 -07001458 : DrawOp(NULL), mFunctor(functor) {}
Chris Craik2af46352012-11-26 18:30:17 -08001459
Chris Craik527a3aa2013-03-04 10:19:31 -08001460 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) {
Chris Craik2af46352012-11-26 18:30:17 -08001461 renderer.startMark("GL functor");
1462 status_t ret = renderer.callDrawGLFunction(mFunctor, dirty);
1463 renderer.endMark();
1464 return ret;
1465 }
1466
Andreas Gampe42ddc182014-11-21 09:49:08 -08001467 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001468 OP_LOG("Draw Functor %p", mFunctor);
1469 }
1470
1471 virtual const char* name() { return "DrawFunctor"; }
1472
1473private:
1474 Functor* mFunctor;
1475};
1476
Chris Craika7090e02014-06-20 16:01:00 -07001477class DrawRenderNodeOp : public DrawBoundedOp {
1478 friend class RenderNode; // grant RenderNode access to info of child
Chris Craik8afd0f22014-08-21 17:41:57 -07001479 friend class DisplayListData; // grant DisplayListData access to info of child
Chris Craik2af46352012-11-26 18:30:17 -08001480public:
Chris Craika7090e02014-06-20 16:01:00 -07001481 DrawRenderNodeOp(RenderNode* renderNode, int flags, const mat4& transformFromParent)
1482 : DrawBoundedOp(0, 0, renderNode->getWidth(), renderNode->getHeight(), 0),
1483 mRenderNode(renderNode), mFlags(flags), mTransformFromParent(transformFromParent) {}
Chris Craikc3566d02013-02-04 16:16:33 -08001484
Andreas Gampe42ddc182014-11-21 09:49:08 -08001485 virtual void defer(DeferStateStruct& deferStruct, int /* saveCount */, int level,
1486 bool /* useQuickReject */) {
Chris Craik8afd0f22014-08-21 17:41:57 -07001487 if (mRenderNode->isRenderable() && !mSkipInOrderDraw) {
Chris Craika7090e02014-06-20 16:01:00 -07001488 mRenderNode->defer(deferStruct, level + 1);
Chris Craikc3566d02013-02-04 16:16:33 -08001489 }
Chris Craikc3566d02013-02-04 16:16:33 -08001490 }
Chris Craik8afd0f22014-08-21 17:41:57 -07001491
Andreas Gampe42ddc182014-11-21 09:49:08 -08001492 virtual void replay(ReplayStateStruct& replayStruct, int /* saveCount */, int level,
1493 bool /* useQuickReject */) {
Chris Craik8afd0f22014-08-21 17:41:57 -07001494 if (mRenderNode->isRenderable() && !mSkipInOrderDraw) {
Chris Craika7090e02014-06-20 16:01:00 -07001495 mRenderNode->replay(replayStruct, level + 1);
Chris Craikff785832013-03-08 13:12:16 -08001496 }
1497 }
Chris Craik2af46352012-11-26 18:30:17 -08001498
Andreas Gampe42ddc182014-11-21 09:49:08 -08001499 virtual status_t applyDraw(OpenGLRenderer& /* renderer */, Rect& /* dirty */) {
Chris Craik80d49022014-06-20 15:03:43 -07001500 LOG_ALWAYS_FATAL("should not be called, because replay() is overridden");
1501 return 0;
Chris Craika08f95c2013-03-15 17:24:33 -07001502 }
Chris Craikff785832013-03-08 13:12:16 -08001503
Chris Craikc5493fb2013-06-19 16:58:58 -07001504 virtual void output(int level, uint32_t logFlags) const {
Chris Craik8afd0f22014-08-21 17:41:57 -07001505 OP_LOG("Draw RenderNode %p %s, flags %#x", mRenderNode, mRenderNode->getName(), mFlags);
Chris Craika7090e02014-06-20 16:01:00 -07001506 if (mRenderNode && (logFlags & kOpLogFlag_Recurse)) {
1507 mRenderNode->output(level + 1);
Chris Craik2af46352012-11-26 18:30:17 -08001508 }
1509 }
1510
Chris Craika7090e02014-06-20 16:01:00 -07001511 virtual const char* name() { return "DrawRenderNode"; }
Chris Craik2af46352012-11-26 18:30:17 -08001512
Chris Craika7090e02014-06-20 16:01:00 -07001513 RenderNode* renderNode() { return mRenderNode; }
John Reck087bc0c2014-04-04 16:20:08 -07001514
Chris Craik2af46352012-11-26 18:30:17 -08001515private:
Chris Craika7090e02014-06-20 16:01:00 -07001516 RenderNode* mRenderNode;
Chris Craikf57776b2013-10-25 18:30:17 -07001517 const int mFlags;
1518
1519 ///////////////////////////
Chris Craika7090e02014-06-20 16:01:00 -07001520 // Properties below are used by RenderNode::computeOrderingImpl() and issueOperations()
Chris Craikf57776b2013-10-25 18:30:17 -07001521 ///////////////////////////
1522 /**
1523 * Records transform vs parent, used for computing total transform without rerunning DL contents
1524 */
1525 const mat4 mTransformFromParent;
1526
1527 /**
Chris Craika7090e02014-06-20 16:01:00 -07001528 * Holds the transformation between the projection surface ViewGroup and this RenderNode
Chris Craikb79a3e32014-03-11 12:20:17 -07001529 * drawing instance. Represents any translations / transformations done within the drawing of
1530 * the compositing ancestor ViewGroup's draw, before the draw of the View represented by this
1531 * DisplayList draw instance.
Chris Craikf57776b2013-10-25 18:30:17 -07001532 *
Chris Craika7090e02014-06-20 16:01:00 -07001533 * Note: doesn't include transformation within the RenderNode, or its properties.
Chris Craikf57776b2013-10-25 18:30:17 -07001534 */
Chris Craikf533e942014-01-14 22:35:37 -08001535 mat4 mTransformFromCompositingAncestor;
Chris Craikf57776b2013-10-25 18:30:17 -07001536 bool mSkipInOrderDraw;
1537};
1538
1539/**
Chris Craik024433f2014-03-26 13:19:14 -07001540 * Not a canvas operation, used only by 3d / z ordering logic in RenderNode::iterate()
Chris Craikf57776b2013-10-25 18:30:17 -07001541 */
1542class DrawShadowOp : public DrawOp {
1543public:
Chris Craik024433f2014-03-26 13:19:14 -07001544 DrawShadowOp(const mat4& transformXY, const mat4& transformZ,
Chris Craik74669862014-08-07 17:27:30 -07001545 float casterAlpha, const SkPath* casterOutline)
1546 : DrawOp(NULL)
1547 , mTransformXY(transformXY)
1548 , mTransformZ(transformZ)
1549 , mCasterAlpha(casterAlpha)
1550 , mCasterOutline(casterOutline) {
Chris Craik61317322014-05-21 13:03:52 -07001551 }
Chris Craikf57776b2013-10-25 18:30:17 -07001552
Andreas Gampe42ddc182014-11-21 09:49:08 -08001553 virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& /* deferInfo */,
Chris Craik05f3d6e2014-06-02 16:27:04 -07001554 const DeferredDisplayState& state) {
1555 renderer.getCaches().tessellationCache.precacheShadows(&state.mMatrix,
Chris Craik74669862014-08-07 17:27:30 -07001556 renderer.getLocalClipBounds(), isCasterOpaque(), mCasterOutline,
Chris Craik05f3d6e2014-06-02 16:27:04 -07001557 &mTransformXY, &mTransformZ, renderer.getLightCenter(), renderer.getLightRadius());
1558 }
1559
Andreas Gampe42ddc182014-11-21 09:49:08 -08001560 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craik05f3d6e2014-06-02 16:27:04 -07001561 TessellationCache::vertexBuffer_pair_t buffers;
Chris Craikc3e75f92014-08-27 15:34:52 -07001562 Matrix4 drawTransform(*(renderer.currentTransform()));
Chris Craik05f3d6e2014-06-02 16:27:04 -07001563 renderer.getCaches().tessellationCache.getShadowBuffers(&drawTransform,
Chris Craik74669862014-08-07 17:27:30 -07001564 renderer.getLocalClipBounds(), isCasterOpaque(), mCasterOutline,
Chris Craik05f3d6e2014-06-02 16:27:04 -07001565 &mTransformXY, &mTransformZ, renderer.getLightCenter(), renderer.getLightRadius(),
1566 buffers);
1567
1568 return renderer.drawShadow(mCasterAlpha, buffers.first, buffers.second);
Chris Craikf57776b2013-10-25 18:30:17 -07001569 }
1570
Andreas Gampe42ddc182014-11-21 09:49:08 -08001571 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik61317322014-05-21 13:03:52 -07001572 OP_LOGS("DrawShadow");
Chris Craikf57776b2013-10-25 18:30:17 -07001573 }
1574
1575 virtual const char* name() { return "DrawShadow"; }
1576
1577private:
Chris Craikaf4d04c2014-07-29 12:50:14 -07001578 bool isCasterOpaque() { return mCasterAlpha >= 1.0f; }
Chris Craik05f3d6e2014-06-02 16:27:04 -07001579
Chris Craikb79a3e32014-03-11 12:20:17 -07001580 const mat4 mTransformXY;
1581 const mat4 mTransformZ;
Chris Craik024433f2014-03-26 13:19:14 -07001582 const float mCasterAlpha;
Chris Craik74669862014-08-07 17:27:30 -07001583 const SkPath* mCasterOutline;
Chris Craik2af46352012-11-26 18:30:17 -08001584};
1585
1586class DrawLayerOp : public DrawOp {
1587public:
Chris Craika08f95c2013-03-15 17:24:33 -07001588 DrawLayerOp(Layer* layer, float x, float y)
Chris Craikf57776b2013-10-25 18:30:17 -07001589 : DrawOp(NULL), mLayer(layer), mX(x), mY(y) {}
Chris Craik2af46352012-11-26 18:30:17 -08001590
Andreas Gampe42ddc182014-11-21 09:49:08 -08001591 virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& /* dirty */) {
Chris Craika08f95c2013-03-15 17:24:33 -07001592 return renderer.drawLayer(mLayer, mX, mY);
Chris Craik2af46352012-11-26 18:30:17 -08001593 }
1594
Andreas Gampe42ddc182014-11-21 09:49:08 -08001595 virtual void output(int level, uint32_t /* logFlags */) const {
Chris Craik2af46352012-11-26 18:30:17 -08001596 OP_LOG("Draw Layer %p at %f %f", mLayer, mX, mY);
1597 }
1598
1599 virtual const char* name() { return "DrawLayer"; }
1600
1601private:
1602 Layer* mLayer;
1603 float mX;
1604 float mY;
1605};
1606
1607}; // namespace uirenderer
1608}; // namespace android
1609
1610#endif // ANDROID_HWUI_DISPLAY_OPERATION_H