blob: dea2be68c8db64b5189bc1510275e09df683045c [file] [log] [blame]
Chris Craikb565df12015-10-05 13:00:52 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
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
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Chris Craikb565df12015-10-05 13:00:52 -070018
Chris Craika1717272015-11-19 13:02:43 -080019#include "font/FontUtil.h"
Greg Daniel8cd3edf2017-01-09 14:15:41 -050020#include "GlLayer.h"
Chris Craikb565df12015-10-05 13:00:52 -070021#include "Matrix.h"
Chris Craik98787e62015-11-13 10:55:30 -080022#include "Rect.h"
Chris Craik0b7e8242015-10-28 16:50:44 -070023#include "RenderNode.h"
Chris Craik6e068c012016-01-15 16:15:30 -080024#include "TessellationCache.h"
Chris Craik98787e62015-11-13 10:55:30 -080025#include "utils/LinearAllocator.h"
Chris Craik5e00c7c2016-07-06 16:10:09 -070026#include "utils/PaintUtils.h"
Chris Craik98787e62015-11-13 10:55:30 -080027#include "Vector.h"
Chris Craikb565df12015-10-05 13:00:52 -070028
Chris Craikf09ff5a2015-12-08 17:21:58 -080029#include <androidfw/ResourceTypes.h>
Chris Craikb565df12015-10-05 13:00:52 -070030
31class SkBitmap;
32class SkPaint;
33
34namespace android {
35namespace uirenderer {
36
Chris Craike4db79d2015-12-22 16:32:23 -080037struct ClipBase;
Chris Craik5854b342015-10-26 15:49:56 -070038class OffscreenBuffer;
Chris Craikb565df12015-10-05 13:00:52 -070039class RenderNode;
40struct Vertex;
41
Doris Liu766431a2016-02-04 22:17:11 +000042namespace VectorDrawable {
43class Tree;
44}
45
Chris Craikb565df12015-10-05 13:00:52 -070046/**
Chris Craik7cbf63d2016-01-06 13:46:52 -080047 * Authoritative op list, used for generating the op ID enum, ID based LUTS, and
48 * the functions to which they dispatch. Parameter macros are executed for each op,
49 * in order, based on the op's type.
Chris Craikb565df12015-10-05 13:00:52 -070050 *
Chris Craikb87eadd2016-01-06 09:16:05 -080051 * There are 4 types of op, which defines dispatch/LUT capability:
Chris Craik7cbf63d2016-01-06 13:46:52 -080052 *
Chris Craikb87eadd2016-01-06 09:16:05 -080053 * | DisplayList | Render | Merge |
54 * -------------|-------------|-------------|-------------|
55 * PRE RENDER | Yes | | |
56 * RENDER ONLY | | Yes | |
57 * UNMERGEABLE | Yes | Yes | |
58 * MERGEABLE | Yes | Yes | Yes |
59 *
60 * PRE RENDER - These ops are recorded into DisplayLists, but can't be directly rendered. This
61 * may be because they need to be transformed into other op types (e.g. CirclePropsOp),
62 * be traversed to access multiple renderable ops within (e.g. RenderNodeOp), or because they
63 * modify renderbuffer lifecycle, instead of directly rendering content (the various LayerOps).
64 *
65 * RENDER ONLY - These ops cannot be recorded into DisplayLists, and are instead implicitly
66 * constructed from other commands/RenderNode properties. They cannot be merged.
67 *
68 * UNMERGEABLE - These ops can be recorded into DisplayLists and rendered directly, but do not
69 * support merged rendering.
70 *
71 * MERGEABLE - These ops can be recorded into DisplayLists and rendered individually, or merged
72 * under certain circumstances.
Chris Craikb565df12015-10-05 13:00:52 -070073 */
Chris Craik7cbf63d2016-01-06 13:46:52 -080074#define MAP_OPS_BASED_ON_TYPE(PRE_RENDER_OP_FN, RENDER_ONLY_OP_FN, UNMERGEABLE_OP_FN, MERGEABLE_OP_FN) \
75 PRE_RENDER_OP_FN(RenderNodeOp) \
76 PRE_RENDER_OP_FN(CirclePropsOp) \
77 PRE_RENDER_OP_FN(RoundRectPropsOp) \
78 PRE_RENDER_OP_FN(BeginLayerOp) \
79 PRE_RENDER_OP_FN(EndLayerOp) \
Chris Craikb87eadd2016-01-06 09:16:05 -080080 PRE_RENDER_OP_FN(BeginUnclippedLayerOp) \
81 PRE_RENDER_OP_FN(EndUnclippedLayerOp) \
Doris Liu766431a2016-02-04 22:17:11 +000082 PRE_RENDER_OP_FN(VectorDrawableOp) \
Chris Craik7cbf63d2016-01-06 13:46:52 -080083 \
84 RENDER_ONLY_OP_FN(ShadowOp) \
85 RENDER_ONLY_OP_FN(LayerOp) \
Chris Craikb87eadd2016-01-06 09:16:05 -080086 RENDER_ONLY_OP_FN(CopyToLayerOp) \
87 RENDER_ONLY_OP_FN(CopyFromLayerOp) \
Chris Craik7cbf63d2016-01-06 13:46:52 -080088 \
89 UNMERGEABLE_OP_FN(ArcOp) \
90 UNMERGEABLE_OP_FN(BitmapMeshOp) \
91 UNMERGEABLE_OP_FN(BitmapRectOp) \
Chris Craika2048482016-03-25 14:17:49 -070092 UNMERGEABLE_OP_FN(ColorOp) \
Chris Craik7cbf63d2016-01-06 13:46:52 -080093 UNMERGEABLE_OP_FN(FunctorOp) \
94 UNMERGEABLE_OP_FN(LinesOp) \
95 UNMERGEABLE_OP_FN(OvalOp) \
96 UNMERGEABLE_OP_FN(PathOp) \
97 UNMERGEABLE_OP_FN(PointsOp) \
98 UNMERGEABLE_OP_FN(RectOp) \
99 UNMERGEABLE_OP_FN(RoundRectOp) \
100 UNMERGEABLE_OP_FN(SimpleRectsOp) \
101 UNMERGEABLE_OP_FN(TextOnPathOp) \
102 UNMERGEABLE_OP_FN(TextureLayerOp) \
103 \
104 MERGEABLE_OP_FN(BitmapOp) \
105 MERGEABLE_OP_FN(PatchOp) \
106 MERGEABLE_OP_FN(TextOp)
Chris Craik15c3f192015-12-03 12:16:56 -0800107
108/**
Chris Craik7cbf63d2016-01-06 13:46:52 -0800109 * LUT generators, which will insert nullptr for unsupported ops
Chris Craik15c3f192015-12-03 12:16:56 -0800110 */
Chris Craik7cbf63d2016-01-06 13:46:52 -0800111#define NULLPTR_OP_FN(Type) nullptr,
Chris Craik15c3f192015-12-03 12:16:56 -0800112
Chris Craik7cbf63d2016-01-06 13:46:52 -0800113#define BUILD_DEFERRABLE_OP_LUT(OP_FN) \
114 { MAP_OPS_BASED_ON_TYPE(OP_FN, NULLPTR_OP_FN, OP_FN, OP_FN) }
115
116#define BUILD_MERGEABLE_OP_LUT(OP_FN) \
117 { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, NULLPTR_OP_FN, NULLPTR_OP_FN, OP_FN) }
118
119#define BUILD_RENDERABLE_OP_LUT(OP_FN) \
120 { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, OP_FN, OP_FN, OP_FN) }
121
Chris Craik91eff222016-02-22 13:39:33 -0800122#define BUILD_FULL_OP_LUT(OP_FN) \
123 { MAP_OPS_BASED_ON_TYPE(OP_FN, OP_FN, OP_FN, OP_FN) }
124
Chris Craik7cbf63d2016-01-06 13:46:52 -0800125/**
126 * Op mapping functions, which skip unsupported ops.
127 *
128 * Note: Do not use for LUTS, since these do not preserve ID order.
129 */
Chris Craik15c3f192015-12-03 12:16:56 -0800130#define NULL_OP_FN(Type)
131
Chris Craikb87eadd2016-01-06 09:16:05 -0800132#define MAP_DEFERRABLE_OPS(OP_FN) \
133 MAP_OPS_BASED_ON_TYPE(OP_FN, NULL_OP_FN, OP_FN, OP_FN)
134
Chris Craik7cbf63d2016-01-06 13:46:52 -0800135#define MAP_MERGEABLE_OPS(OP_FN) \
136 MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, NULL_OP_FN, NULL_OP_FN, OP_FN)
137
138#define MAP_RENDERABLE_OPS(OP_FN) \
139 MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, OP_FN, OP_FN, OP_FN)
140
Chris Craikb565df12015-10-05 13:00:52 -0700141// Generate OpId enum
142#define IDENTITY_FN(Type) Type,
143namespace RecordedOpId {
144 enum {
Chris Craik7cbf63d2016-01-06 13:46:52 -0800145 MAP_OPS_BASED_ON_TYPE(IDENTITY_FN, IDENTITY_FN, IDENTITY_FN, IDENTITY_FN)
Chris Craikb565df12015-10-05 13:00:52 -0700146 Count,
147 };
148}
Chris Craik7cbf63d2016-01-06 13:46:52 -0800149static_assert(RecordedOpId::RenderNodeOp == 0,
Chris Craikb565df12015-10-05 13:00:52 -0700150 "First index must be zero for LUTs to work");
151
Chris Craike4db79d2015-12-22 16:32:23 -0800152#define BASE_PARAMS const Rect& unmappedBounds, const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint
153#define BASE_PARAMS_PAINTLESS const Rect& unmappedBounds, const Matrix4& localMatrix, const ClipBase* localClip
154#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, paint)
155#define SUPER_PAINTLESS(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, nullptr)
Chris Craikb565df12015-10-05 13:00:52 -0700156
157struct RecordedOp {
158 /* ID from RecordedOpId - generally used for jumping into function tables */
159 const int opId;
160
Chris Craik386aa032015-12-07 17:08:25 -0800161 /* bounds in *local* space, without accounting for DisplayList transformation, or stroke */
Chris Craikb565df12015-10-05 13:00:52 -0700162 const Rect unmappedBounds;
163
164 /* transform in recording space (vs DisplayList origin) */
165 const Matrix4 localMatrix;
166
Chris Craike4db79d2015-12-22 16:32:23 -0800167 /* clip in recording space - nullptr if not clipped */
168 const ClipBase* localClip;
Chris Craikb565df12015-10-05 13:00:52 -0700169
170 /* optional paint, stored in base object to simplify merging logic */
171 const SkPaint* paint;
172protected:
173 RecordedOp(unsigned int opId, BASE_PARAMS)
174 : opId(opId)
175 , unmappedBounds(unmappedBounds)
176 , localMatrix(localMatrix)
Chris Craike4db79d2015-12-22 16:32:23 -0800177 , localClip(localClip)
Chris Craikb565df12015-10-05 13:00:52 -0700178 , paint(paint) {}
179};
180
181struct RenderNodeOp : RecordedOp {
182 RenderNodeOp(BASE_PARAMS_PAINTLESS, RenderNode* renderNode)
183 : SUPER_PAINTLESS(RenderNodeOp)
184 , renderNode(renderNode) {}
Chris Craik8d1f2122015-11-24 16:40:09 -0800185 RenderNode * renderNode; // not const, since drawing modifies it
186
187 /**
188 * Holds the transformation between the projection surface ViewGroup and this RenderNode
189 * drawing instance. Represents any translations / transformations done within the drawing of
190 * the compositing ancestor ViewGroup's draw, before the draw of the View represented by this
191 * DisplayList draw instance.
192 *
193 * Note: doesn't include transformation within the RenderNode, or its properties.
194 */
195 Matrix4 transformFromCompositingAncestor;
Chris Craik161f54b2015-11-05 11:08:52 -0800196 bool skipInOrderDraw = false;
Chris Craikb565df12015-10-05 13:00:52 -0700197};
198
Chris Craika1717272015-11-19 13:02:43 -0800199////////////////////////////////////////////////////////////////////////////////////////////////////
200// Standard Ops
201////////////////////////////////////////////////////////////////////////////////////////////////////
202
Chris Craik386aa032015-12-07 17:08:25 -0800203struct ArcOp : RecordedOp {
204 ArcOp(BASE_PARAMS, float startAngle, float sweepAngle, bool useCenter)
205 : SUPER(ArcOp)
206 , startAngle(startAngle)
207 , sweepAngle(sweepAngle)
208 , useCenter(useCenter) {}
209 const float startAngle;
210 const float sweepAngle;
211 const bool useCenter;
212};
213
Chris Craikb565df12015-10-05 13:00:52 -0700214struct BitmapOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700215 BitmapOp(BASE_PARAMS, Bitmap* bitmap)
Chris Craikb565df12015-10-05 13:00:52 -0700216 : SUPER(BitmapOp)
217 , bitmap(bitmap) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700218 Bitmap* bitmap;
Chris Craikb565df12015-10-05 13:00:52 -0700219};
220
Chris Craikf09ff5a2015-12-08 17:21:58 -0800221struct BitmapMeshOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700222 BitmapMeshOp(BASE_PARAMS, Bitmap* bitmap, int meshWidth, int meshHeight,
Chris Craikf09ff5a2015-12-08 17:21:58 -0800223 const float* vertices, const int* colors)
224 : SUPER(BitmapMeshOp)
225 , bitmap(bitmap)
226 , meshWidth(meshWidth)
227 , meshHeight(meshHeight)
228 , vertices(vertices)
229 , colors(colors) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700230 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800231 const int meshWidth;
232 const int meshHeight;
233 const float* vertices;
234 const int* colors;
235};
236
237struct BitmapRectOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700238 BitmapRectOp(BASE_PARAMS, Bitmap* bitmap, const Rect& src)
Chris Craikf09ff5a2015-12-08 17:21:58 -0800239 : SUPER(BitmapRectOp)
240 , bitmap(bitmap)
241 , src(src) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700242 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800243 const Rect src;
244};
245
Chris Craik268a9c02015-12-09 18:05:12 -0800246struct CirclePropsOp : RecordedOp {
Chris Craike4db79d2015-12-22 16:32:23 -0800247 CirclePropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
Chris Craik268a9c02015-12-09 18:05:12 -0800248 float* x, float* y, float* radius)
Chris Craike4db79d2015-12-22 16:32:23 -0800249 : RecordedOp(RecordedOpId::CirclePropsOp, Rect(), localMatrix, localClip, paint)
Chris Craik268a9c02015-12-09 18:05:12 -0800250 , x(x)
251 , y(y)
252 , radius(radius) {}
253 const float* x;
254 const float* y;
255 const float* radius;
256};
257
Chris Craika2048482016-03-25 14:17:49 -0700258struct ColorOp : RecordedOp {
259 // Note: unbounded op that will fillclip, so no bounds/matrix needed
Mike Reed260ab722016-10-07 15:59:20 -0400260 ColorOp(const ClipBase* localClip, int color, SkBlendMode mode)
Chris Craika2048482016-03-25 14:17:49 -0700261 : RecordedOp(RecordedOpId::ColorOp, Rect(), Matrix4::identity(), localClip, nullptr)
262 , color(color)
263 , mode(mode) {}
264 const int color;
Mike Reed260ab722016-10-07 15:59:20 -0400265 const SkBlendMode mode;
Chris Craika2048482016-03-25 14:17:49 -0700266};
267
Chris Craike29ce6f2015-12-10 16:25:13 -0800268struct FunctorOp : RecordedOp {
Chris Craik4c3980b2016-03-15 14:20:18 -0700269 // Note: undefined record-time bounds, since this op fills the clip
270 // TODO: explicitly define bounds
271 FunctorOp(const Matrix4& localMatrix, const ClipBase* localClip, Functor* functor)
272 : RecordedOp(RecordedOpId::FunctorOp, Rect(), localMatrix, localClip, nullptr)
Chris Craike29ce6f2015-12-10 16:25:13 -0800273 , functor(functor) {}
274 Functor* functor;
275};
276
Chris Craika1717272015-11-19 13:02:43 -0800277struct LinesOp : RecordedOp {
278 LinesOp(BASE_PARAMS, const float* points, const int floatCount)
279 : SUPER(LinesOp)
280 , points(points)
281 , floatCount(floatCount) {}
282 const float* points;
283 const int floatCount;
284};
285
Chris Craik386aa032015-12-07 17:08:25 -0800286struct OvalOp : RecordedOp {
287 OvalOp(BASE_PARAMS)
288 : SUPER(OvalOp) {}
289};
290
Chris Craikf09ff5a2015-12-08 17:21:58 -0800291struct PatchOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700292 PatchOp(BASE_PARAMS, Bitmap* bitmap, const Res_png_9patch* patch)
Chris Craikf09ff5a2015-12-08 17:21:58 -0800293 : SUPER(PatchOp)
294 , bitmap(bitmap)
295 , patch(patch) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700296 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800297 const Res_png_9patch* patch;
298};
299
Chris Craik386aa032015-12-07 17:08:25 -0800300struct PathOp : RecordedOp {
301 PathOp(BASE_PARAMS, const SkPath* path)
302 : SUPER(PathOp)
303 , path(path) {}
304 const SkPath* path;
305};
306
307struct PointsOp : RecordedOp {
308 PointsOp(BASE_PARAMS, const float* points, const int floatCount)
309 : SUPER(PointsOp)
310 , points(points)
311 , floatCount(floatCount) {}
312 const float* points;
313 const int floatCount;
314};
315
Chris Craikb565df12015-10-05 13:00:52 -0700316struct RectOp : RecordedOp {
317 RectOp(BASE_PARAMS)
318 : SUPER(RectOp) {}
319};
320
Chris Craik386aa032015-12-07 17:08:25 -0800321struct RoundRectOp : RecordedOp {
322 RoundRectOp(BASE_PARAMS, float rx, float ry)
323 : SUPER(RoundRectOp)
324 , rx(rx)
325 , ry(ry) {}
326 const float rx;
327 const float ry;
328};
329
Chris Craik268a9c02015-12-09 18:05:12 -0800330struct RoundRectPropsOp : RecordedOp {
Chris Craike4db79d2015-12-22 16:32:23 -0800331 RoundRectPropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
Chris Craik268a9c02015-12-09 18:05:12 -0800332 float* left, float* top, float* right, float* bottom, float *rx, float *ry)
Chris Craike4db79d2015-12-22 16:32:23 -0800333 : RecordedOp(RecordedOpId::RoundRectPropsOp, Rect(), localMatrix, localClip, paint)
Chris Craik268a9c02015-12-09 18:05:12 -0800334 , left(left)
335 , top(top)
336 , right(right)
337 , bottom(bottom)
338 , rx(rx)
339 , ry(ry) {}
340 const float* left;
341 const float* top;
342 const float* right;
343 const float* bottom;
344 const float* rx;
345 const float* ry;
346};
347
Doris Liu766431a2016-02-04 22:17:11 +0000348struct VectorDrawableOp : RecordedOp {
349 VectorDrawableOp(VectorDrawable::Tree* tree, BASE_PARAMS_PAINTLESS)
350 : SUPER_PAINTLESS(VectorDrawableOp)
351 , vectorDrawable(tree) {}
352 VectorDrawable::Tree* vectorDrawable;
353};
354
Chris Craikd3daa312015-11-06 10:59:56 -0800355/**
356 * Real-time, dynamic-lit shadow.
357 *
358 * Uses invalid/empty bounds and matrix since ShadowOp bounds aren't known at defer time,
359 * and are resolved dynamically, and transform isn't needed.
360 *
Chris Craik98787e62015-11-13 10:55:30 -0800361 * State construction handles these properties specially, ignoring matrix/bounds.
Chris Craikd3daa312015-11-06 10:59:56 -0800362 */
363struct ShadowOp : RecordedOp {
Chris Craik6e068c012016-01-15 16:15:30 -0800364 ShadowOp(sp<TessellationCache::ShadowTask>& shadowTask, float casterAlpha)
Chris Craike4db79d2015-12-22 16:32:23 -0800365 : RecordedOp(RecordedOpId::ShadowOp, Rect(), Matrix4::identity(), nullptr, nullptr)
Chris Craik6e068c012016-01-15 16:15:30 -0800366 , shadowTask(shadowTask)
367 , casterAlpha(casterAlpha) {
Chris Craikd3daa312015-11-06 10:59:56 -0800368 };
Chris Craik6e068c012016-01-15 16:15:30 -0800369 sp<TessellationCache::ShadowTask> shadowTask;
Chris Craikd3daa312015-11-06 10:59:56 -0800370 const float casterAlpha;
Chris Craikd3daa312015-11-06 10:59:56 -0800371};
372
Chris Craikb565df12015-10-05 13:00:52 -0700373struct SimpleRectsOp : RecordedOp { // Filled, no AA (TODO: better name?)
374 SimpleRectsOp(BASE_PARAMS, Vertex* vertices, size_t vertexCount)
375 : SUPER(SimpleRectsOp)
376 , vertices(vertices)
377 , vertexCount(vertexCount) {}
378 Vertex* vertices;
379 const size_t vertexCount;
380};
381
Chris Craika1717272015-11-19 13:02:43 -0800382struct TextOp : RecordedOp {
383 TextOp(BASE_PARAMS, const glyph_t* glyphs, const float* positions, int glyphCount,
384 float x, float y)
385 : SUPER(TextOp)
386 , glyphs(glyphs)
387 , positions(positions)
388 , glyphCount(glyphCount)
389 , x(x)
390 , y(y) {}
391 const glyph_t* glyphs;
392 const float* positions;
393 const int glyphCount;
394 const float x;
395 const float y;
396};
397
Chris Craikd7448e62015-12-15 10:34:36 -0800398struct TextOnPathOp : RecordedOp {
Chris Craik4c3980b2016-03-15 14:20:18 -0700399 // TODO: explicitly define bounds
400 TextOnPathOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
401 const glyph_t* glyphs, int glyphCount, const SkPath* path, float hOffset, float vOffset)
402 : RecordedOp(RecordedOpId::TextOnPathOp, Rect(), localMatrix, localClip, paint)
Chris Craikd7448e62015-12-15 10:34:36 -0800403 , glyphs(glyphs)
404 , glyphCount(glyphCount)
405 , path(path)
406 , hOffset(hOffset)
407 , vOffset(vOffset) {}
408 const glyph_t* glyphs;
409 const int glyphCount;
410
411 const SkPath* path;
412 const float hOffset;
413 const float vOffset;
414};
415
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800416struct TextureLayerOp : RecordedOp {
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500417 TextureLayerOp(BASE_PARAMS_PAINTLESS, GlLayer* layer)
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800418 : SUPER_PAINTLESS(TextureLayerOp)
419 , layer(layer) {}
Chris Craikaafb01d2016-03-25 18:34:11 -0700420
421 // Copy an existing TextureLayerOp, replacing the underlying matrix
422 TextureLayerOp(const TextureLayerOp& op, const Matrix4& replacementMatrix)
423 : RecordedOp(RecordedOpId::TextureLayerOp, op.unmappedBounds, replacementMatrix,
424 op.localClip, op.paint)
425 , layer(op.layer) {
426
427 }
Greg Daniel8cd3edf2017-01-09 14:15:41 -0500428 GlLayer* layer;
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800429};
430
Chris Craika1717272015-11-19 13:02:43 -0800431////////////////////////////////////////////////////////////////////////////////////////////////////
432// Layers
433////////////////////////////////////////////////////////////////////////////////////////////////////
434
Chris Craik6fe991e52015-10-20 09:39:42 -0700435/**
436 * Stateful operation! denotes the creation of an off-screen layer,
437 * and that commands following will render into it.
438 */
439struct BeginLayerOp : RecordedOp {
440 BeginLayerOp(BASE_PARAMS)
441 : SUPER(BeginLayerOp) {}
442};
443
444/**
445 * Stateful operation! Denotes end of off-screen layer, and that
446 * commands since last BeginLayerOp should be drawn into parent FBO.
447 *
448 * State in this op is empty, it just serves to signal that a layer has been finished.
449 */
450struct EndLayerOp : RecordedOp {
451 EndLayerOp()
Chris Craike4db79d2015-12-22 16:32:23 -0800452 : RecordedOp(RecordedOpId::EndLayerOp, Rect(), Matrix4::identity(), nullptr, nullptr) {}
Chris Craik6fe991e52015-10-20 09:39:42 -0700453};
454
Chris Craikb87eadd2016-01-06 09:16:05 -0800455struct BeginUnclippedLayerOp : RecordedOp {
456 BeginUnclippedLayerOp(BASE_PARAMS)
457 : SUPER(BeginUnclippedLayerOp) {}
458};
459
460struct EndUnclippedLayerOp : RecordedOp {
461 EndUnclippedLayerOp()
462 : RecordedOp(RecordedOpId::EndUnclippedLayerOp, Rect(), Matrix4::identity(), nullptr, nullptr) {}
463};
464
465struct CopyToLayerOp : RecordedOp {
466 CopyToLayerOp(const RecordedOp& op, OffscreenBuffer** layerHandle)
467 : RecordedOp(RecordedOpId::CopyToLayerOp,
468 op.unmappedBounds,
469 op.localMatrix,
470 nullptr, // clip intentionally ignored
471 op.paint)
472 , layerHandle(layerHandle) {}
473
474 // Records a handle to the Layer object, since the Layer itself won't be
475 // constructed until after this operation is constructed.
476 OffscreenBuffer** layerHandle;
477};
478
479
480// draw the parameter layer underneath
481struct CopyFromLayerOp : RecordedOp {
482 CopyFromLayerOp(const RecordedOp& op, OffscreenBuffer** layerHandle)
483 : RecordedOp(RecordedOpId::CopyFromLayerOp,
484 op.unmappedBounds,
485 op.localMatrix,
486 nullptr, // clip intentionally ignored
487 op.paint)
488 , layerHandle(layerHandle) {}
489
490 // Records a handle to the Layer object, since the Layer itself won't be
491 // constructed until after this operation is constructed.
492 OffscreenBuffer** layerHandle;
493};
494
Chris Craik0b7e8242015-10-28 16:50:44 -0700495/**
496 * Draws an OffscreenBuffer.
497 *
498 * Alpha, mode, and colorfilter are embedded, since LayerOps are always dynamically generated,
499 * when creating/tracking a SkPaint* during defer isn't worth the bother.
500 */
Chris Craik6fe991e52015-10-20 09:39:42 -0700501struct LayerOp : RecordedOp {
Chris Craik74af6e22016-04-05 13:18:56 -0700502 // Records a one-use (saveLayer) layer for drawing.
Chris Craik5854b342015-10-26 15:49:56 -0700503 LayerOp(BASE_PARAMS, OffscreenBuffer** layerHandle)
Chris Craik0b7e8242015-10-28 16:50:44 -0700504 : SUPER_PAINTLESS(LayerOp)
505 , layerHandle(layerHandle)
Chris Craike5b50192016-01-04 15:09:19 -0800506 , alpha(paint ? paint->getAlpha() / 255.0f : 1.0f)
Mike Reed260ab722016-10-07 15:59:20 -0400507 , mode(PaintUtils::getBlendModeDirect(paint))
Chris Craik74af6e22016-04-05 13:18:56 -0700508 , colorFilter(paint ? paint->getColorFilter() : nullptr) {}
Chris Craik0b7e8242015-10-28 16:50:44 -0700509
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -0700510 explicit LayerOp(RenderNode& node)
Chris Craikb87eadd2016-01-06 09:16:05 -0800511 : RecordedOp(RecordedOpId::LayerOp, Rect(node.getWidth(), node.getHeight()), Matrix4::identity(), nullptr, nullptr)
512 , layerHandle(node.getLayerHandle())
513 , alpha(node.properties().layerProperties().alpha() / 255.0f)
514 , mode(node.properties().layerProperties().xferMode())
Chris Craik74af6e22016-04-05 13:18:56 -0700515 , colorFilter(node.properties().layerProperties().colorFilter()) {}
Chris Craik0b7e8242015-10-28 16:50:44 -0700516
Chris Craik818c9fb2015-10-23 14:33:42 -0700517 // Records a handle to the Layer object, since the Layer itself won't be
518 // constructed until after this operation is constructed.
Chris Craik5854b342015-10-26 15:49:56 -0700519 OffscreenBuffer** layerHandle;
Chris Craik0b7e8242015-10-28 16:50:44 -0700520 const float alpha;
Mike Reed260ab722016-10-07 15:59:20 -0400521 const SkBlendMode mode;
Chris Craik0b7e8242015-10-28 16:50:44 -0700522
523 // pointer to object owned by either LayerProperties, or a recorded Paint object in a
524 // BeginLayerOp. Lives longer than LayerOp in either case, so no skia ref counting is used.
525 SkColorFilter* colorFilter;
Chris Craik6fe991e52015-10-20 09:39:42 -0700526};
527
Chris Craikb565df12015-10-05 13:00:52 -0700528}; // namespace uirenderer
529}; // namespace android