blob: 2d0185aaa9e236845f8719cbd2d64f51b056ba59 [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
Greg Daniel8cd3edf2017-01-09 14:15:41 -050019#include "GlLayer.h"
Chris Craikb565df12015-10-05 13:00:52 -070020#include "Matrix.h"
Chris Craik98787e62015-11-13 10:55:30 -080021#include "Rect.h"
Chris Craik0b7e8242015-10-28 16:50:44 -070022#include "RenderNode.h"
Chris Craik6e068c012016-01-15 16:15:30 -080023#include "TessellationCache.h"
John Reck1bcacfd2017-11-03 10:12:19 -070024#include "Vector.h"
25#include "font/FontUtil.h"
Chris Craik98787e62015-11-13 10:55:30 -080026#include "utils/LinearAllocator.h"
Chris Craik5e00c7c2016-07-06 16:10:09 -070027#include "utils/PaintUtils.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;
sergeyv3e9999b2017-01-19 15:37:02 -080040class DeferredLayerUpdater;
41
Chris Craikb565df12015-10-05 13:00:52 -070042struct Vertex;
43
Doris Liu766431a2016-02-04 22:17:11 +000044namespace VectorDrawable {
45class Tree;
46}
47
Chris Craikb565df12015-10-05 13:00:52 -070048/**
Chris Craik7cbf63d2016-01-06 13:46:52 -080049 * Authoritative op list, used for generating the op ID enum, ID based LUTS, and
50 * the functions to which they dispatch. Parameter macros are executed for each op,
51 * in order, based on the op's type.
Chris Craikb565df12015-10-05 13:00:52 -070052 *
Chris Craikb87eadd2016-01-06 09:16:05 -080053 * There are 4 types of op, which defines dispatch/LUT capability:
Chris Craik7cbf63d2016-01-06 13:46:52 -080054 *
Chris Craikb87eadd2016-01-06 09:16:05 -080055 * | DisplayList | Render | Merge |
56 * -------------|-------------|-------------|-------------|
57 * PRE RENDER | Yes | | |
58 * RENDER ONLY | | Yes | |
59 * UNMERGEABLE | Yes | Yes | |
60 * MERGEABLE | Yes | Yes | Yes |
61 *
62 * PRE RENDER - These ops are recorded into DisplayLists, but can't be directly rendered. This
63 * may be because they need to be transformed into other op types (e.g. CirclePropsOp),
64 * be traversed to access multiple renderable ops within (e.g. RenderNodeOp), or because they
65 * modify renderbuffer lifecycle, instead of directly rendering content (the various LayerOps).
66 *
67 * RENDER ONLY - These ops cannot be recorded into DisplayLists, and are instead implicitly
68 * constructed from other commands/RenderNode properties. They cannot be merged.
69 *
70 * UNMERGEABLE - These ops can be recorded into DisplayLists and rendered directly, but do not
71 * support merged rendering.
72 *
73 * MERGEABLE - These ops can be recorded into DisplayLists and rendered individually, or merged
74 * under certain circumstances.
Chris Craikb565df12015-10-05 13:00:52 -070075 */
John Reck1bcacfd2017-11-03 10:12:19 -070076#define MAP_OPS_BASED_ON_TYPE(PRE_RENDER_OP_FN, RENDER_ONLY_OP_FN, UNMERGEABLE_OP_FN, \
77 MERGEABLE_OP_FN) \
78 PRE_RENDER_OP_FN(RenderNodeOp) \
79 PRE_RENDER_OP_FN(CirclePropsOp) \
80 PRE_RENDER_OP_FN(RoundRectPropsOp) \
81 PRE_RENDER_OP_FN(BeginLayerOp) \
82 PRE_RENDER_OP_FN(EndLayerOp) \
83 PRE_RENDER_OP_FN(BeginUnclippedLayerOp) \
84 PRE_RENDER_OP_FN(EndUnclippedLayerOp) \
85 PRE_RENDER_OP_FN(VectorDrawableOp) \
86 \
87 RENDER_ONLY_OP_FN(ShadowOp) \
88 RENDER_ONLY_OP_FN(LayerOp) \
89 RENDER_ONLY_OP_FN(CopyToLayerOp) \
90 RENDER_ONLY_OP_FN(CopyFromLayerOp) \
91 \
92 UNMERGEABLE_OP_FN(ArcOp) \
93 UNMERGEABLE_OP_FN(BitmapMeshOp) \
94 UNMERGEABLE_OP_FN(BitmapRectOp) \
95 UNMERGEABLE_OP_FN(ColorOp) \
96 UNMERGEABLE_OP_FN(FunctorOp) \
97 UNMERGEABLE_OP_FN(LinesOp) \
98 UNMERGEABLE_OP_FN(OvalOp) \
99 UNMERGEABLE_OP_FN(PathOp) \
100 UNMERGEABLE_OP_FN(PointsOp) \
101 UNMERGEABLE_OP_FN(RectOp) \
102 UNMERGEABLE_OP_FN(RoundRectOp) \
103 UNMERGEABLE_OP_FN(SimpleRectsOp) \
104 UNMERGEABLE_OP_FN(TextOnPathOp) \
105 UNMERGEABLE_OP_FN(TextureLayerOp) \
106 \
107 MERGEABLE_OP_FN(BitmapOp) \
108 MERGEABLE_OP_FN(PatchOp) \
109 MERGEABLE_OP_FN(TextOp)
Chris Craik15c3f192015-12-03 12:16:56 -0800110
111/**
Chris Craik7cbf63d2016-01-06 13:46:52 -0800112 * LUT generators, which will insert nullptr for unsupported ops
Chris Craik15c3f192015-12-03 12:16:56 -0800113 */
Chris Craik7cbf63d2016-01-06 13:46:52 -0800114#define NULLPTR_OP_FN(Type) nullptr,
Chris Craik15c3f192015-12-03 12:16:56 -0800115
Chris Craik7cbf63d2016-01-06 13:46:52 -0800116#define BUILD_DEFERRABLE_OP_LUT(OP_FN) \
John Reck1bcacfd2017-11-03 10:12:19 -0700117 { MAP_OPS_BASED_ON_TYPE(OP_FN, NULLPTR_OP_FN, OP_FN, OP_FN) }
Chris Craik7cbf63d2016-01-06 13:46:52 -0800118
119#define BUILD_MERGEABLE_OP_LUT(OP_FN) \
John Reck1bcacfd2017-11-03 10:12:19 -0700120 { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, NULLPTR_OP_FN, NULLPTR_OP_FN, OP_FN) }
Chris Craik7cbf63d2016-01-06 13:46:52 -0800121
122#define BUILD_RENDERABLE_OP_LUT(OP_FN) \
John Reck1bcacfd2017-11-03 10:12:19 -0700123 { MAP_OPS_BASED_ON_TYPE(NULLPTR_OP_FN, OP_FN, OP_FN, OP_FN) }
Chris Craik7cbf63d2016-01-06 13:46:52 -0800124
Chris Craik91eff222016-02-22 13:39:33 -0800125#define BUILD_FULL_OP_LUT(OP_FN) \
John Reck1bcacfd2017-11-03 10:12:19 -0700126 { MAP_OPS_BASED_ON_TYPE(OP_FN, OP_FN, OP_FN, OP_FN) }
Chris Craik91eff222016-02-22 13:39:33 -0800127
Chris Craik7cbf63d2016-01-06 13:46:52 -0800128/**
129 * Op mapping functions, which skip unsupported ops.
130 *
131 * Note: Do not use for LUTS, since these do not preserve ID order.
132 */
Chris Craik15c3f192015-12-03 12:16:56 -0800133#define NULL_OP_FN(Type)
134
John Reck1bcacfd2017-11-03 10:12:19 -0700135#define MAP_DEFERRABLE_OPS(OP_FN) MAP_OPS_BASED_ON_TYPE(OP_FN, NULL_OP_FN, OP_FN, OP_FN)
Chris Craikb87eadd2016-01-06 09:16:05 -0800136
John Reck1bcacfd2017-11-03 10:12:19 -0700137#define MAP_MERGEABLE_OPS(OP_FN) MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, NULL_OP_FN, NULL_OP_FN, OP_FN)
Chris Craik7cbf63d2016-01-06 13:46:52 -0800138
John Reck1bcacfd2017-11-03 10:12:19 -0700139#define MAP_RENDERABLE_OPS(OP_FN) MAP_OPS_BASED_ON_TYPE(NULL_OP_FN, OP_FN, OP_FN, OP_FN)
Chris Craik7cbf63d2016-01-06 13:46:52 -0800140
Chris Craikb565df12015-10-05 13:00:52 -0700141// Generate OpId enum
142#define IDENTITY_FN(Type) Type,
143namespace RecordedOpId {
John Reck1bcacfd2017-11-03 10:12:19 -0700144enum {
145 MAP_OPS_BASED_ON_TYPE(IDENTITY_FN, IDENTITY_FN, IDENTITY_FN, IDENTITY_FN) Count,
146};
Chris Craikb565df12015-10-05 13:00:52 -0700147}
John Reck1bcacfd2017-11-03 10:12:19 -0700148static_assert(RecordedOpId::RenderNodeOp == 0, "First index must be zero for LUTs to work");
Chris Craikb565df12015-10-05 13:00:52 -0700149
John Reck1bcacfd2017-11-03 10:12:19 -0700150#define BASE_PARAMS \
151 const Rect &unmappedBounds, const Matrix4 &localMatrix, const ClipBase *localClip, \
152 const SkPaint *paint
153#define BASE_PARAMS_PAINTLESS \
154 const Rect &unmappedBounds, const Matrix4 &localMatrix, const ClipBase *localClip
Chris Craike4db79d2015-12-22 16:32:23 -0800155#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, paint)
John Reck1bcacfd2017-11-03 10:12:19 -0700156#define SUPER_PAINTLESS(Type) \
157 RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClip, nullptr)
Chris Craikb565df12015-10-05 13:00:52 -0700158
159struct RecordedOp {
160 /* ID from RecordedOpId - generally used for jumping into function tables */
161 const int opId;
162
Chris Craik386aa032015-12-07 17:08:25 -0800163 /* bounds in *local* space, without accounting for DisplayList transformation, or stroke */
Chris Craikb565df12015-10-05 13:00:52 -0700164 const Rect unmappedBounds;
165
166 /* transform in recording space (vs DisplayList origin) */
167 const Matrix4 localMatrix;
168
Chris Craike4db79d2015-12-22 16:32:23 -0800169 /* clip in recording space - nullptr if not clipped */
170 const ClipBase* localClip;
Chris Craikb565df12015-10-05 13:00:52 -0700171
172 /* optional paint, stored in base object to simplify merging logic */
173 const SkPaint* paint;
John Reck1bcacfd2017-11-03 10:12:19 -0700174
Chris Craikb565df12015-10-05 13:00:52 -0700175protected:
176 RecordedOp(unsigned int opId, BASE_PARAMS)
177 : opId(opId)
178 , unmappedBounds(unmappedBounds)
179 , localMatrix(localMatrix)
Chris Craike4db79d2015-12-22 16:32:23 -0800180 , localClip(localClip)
Chris Craikb565df12015-10-05 13:00:52 -0700181 , paint(paint) {}
182};
183
184struct RenderNodeOp : RecordedOp {
185 RenderNodeOp(BASE_PARAMS_PAINTLESS, RenderNode* renderNode)
John Reck1bcacfd2017-11-03 10:12:19 -0700186 : SUPER_PAINTLESS(RenderNodeOp), renderNode(renderNode) {}
187 RenderNode* renderNode; // not const, since drawing modifies it
Chris Craik8d1f2122015-11-24 16:40:09 -0800188
189 /**
190 * Holds the transformation between the projection surface ViewGroup and this RenderNode
191 * drawing instance. Represents any translations / transformations done within the drawing of
192 * the compositing ancestor ViewGroup's draw, before the draw of the View represented by this
193 * DisplayList draw instance.
194 *
195 * Note: doesn't include transformation within the RenderNode, or its properties.
196 */
197 Matrix4 transformFromCompositingAncestor;
Chris Craik161f54b2015-11-05 11:08:52 -0800198 bool skipInOrderDraw = false;
Chris Craikb565df12015-10-05 13:00:52 -0700199};
200
Chris Craika1717272015-11-19 13:02:43 -0800201////////////////////////////////////////////////////////////////////////////////////////////////////
202// Standard Ops
203////////////////////////////////////////////////////////////////////////////////////////////////////
204
Chris Craik386aa032015-12-07 17:08:25 -0800205struct ArcOp : RecordedOp {
206 ArcOp(BASE_PARAMS, float startAngle, float sweepAngle, bool useCenter)
John Reck1bcacfd2017-11-03 10:12:19 -0700207 : SUPER(ArcOp), startAngle(startAngle), sweepAngle(sweepAngle), useCenter(useCenter) {}
Chris Craik386aa032015-12-07 17:08:25 -0800208 const float startAngle;
209 const float sweepAngle;
210 const bool useCenter;
211};
212
Chris Craikb565df12015-10-05 13:00:52 -0700213struct BitmapOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700214 BitmapOp(BASE_PARAMS, Bitmap* bitmap) : SUPER(BitmapOp), bitmap(bitmap) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700215 Bitmap* bitmap;
Chris Craikb565df12015-10-05 13:00:52 -0700216};
217
Chris Craikf09ff5a2015-12-08 17:21:58 -0800218struct BitmapMeshOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700219 BitmapMeshOp(BASE_PARAMS, Bitmap* bitmap, int meshWidth, int meshHeight, const float* vertices,
220 const int* colors)
Chris Craikf09ff5a2015-12-08 17:21:58 -0800221 : SUPER(BitmapMeshOp)
222 , bitmap(bitmap)
223 , meshWidth(meshWidth)
224 , meshHeight(meshHeight)
225 , vertices(vertices)
226 , colors(colors) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700227 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800228 const int meshWidth;
229 const int meshHeight;
230 const float* vertices;
231 const int* colors;
232};
233
234struct BitmapRectOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700235 BitmapRectOp(BASE_PARAMS, Bitmap* bitmap, const Rect& src)
John Reck1bcacfd2017-11-03 10:12:19 -0700236 : SUPER(BitmapRectOp), bitmap(bitmap), src(src) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700237 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800238 const Rect src;
239};
240
Chris Craik268a9c02015-12-09 18:05:12 -0800241struct CirclePropsOp : RecordedOp {
Chris Craike4db79d2015-12-22 16:32:23 -0800242 CirclePropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
John Reck1bcacfd2017-11-03 10:12:19 -0700243 float* x, float* y, float* radius)
Chris Craike4db79d2015-12-22 16:32:23 -0800244 : RecordedOp(RecordedOpId::CirclePropsOp, Rect(), localMatrix, localClip, paint)
Chris Craik268a9c02015-12-09 18:05:12 -0800245 , x(x)
246 , y(y)
247 , radius(radius) {}
248 const float* x;
249 const float* y;
250 const float* radius;
251};
252
Chris Craika2048482016-03-25 14:17:49 -0700253struct ColorOp : RecordedOp {
254 // Note: unbounded op that will fillclip, so no bounds/matrix needed
Mike Reed260ab722016-10-07 15:59:20 -0400255 ColorOp(const ClipBase* localClip, int color, SkBlendMode mode)
Chris Craika2048482016-03-25 14:17:49 -0700256 : RecordedOp(RecordedOpId::ColorOp, Rect(), Matrix4::identity(), localClip, nullptr)
257 , color(color)
258 , mode(mode) {}
259 const int color;
Mike Reed260ab722016-10-07 15:59:20 -0400260 const SkBlendMode mode;
Chris Craika2048482016-03-25 14:17:49 -0700261};
262
Chris Craike29ce6f2015-12-10 16:25:13 -0800263struct FunctorOp : RecordedOp {
Chris Craik4c3980b2016-03-15 14:20:18 -0700264 // Note: undefined record-time bounds, since this op fills the clip
265 // TODO: explicitly define bounds
266 FunctorOp(const Matrix4& localMatrix, const ClipBase* localClip, Functor* functor)
267 : RecordedOp(RecordedOpId::FunctorOp, Rect(), localMatrix, localClip, nullptr)
Chris Craike29ce6f2015-12-10 16:25:13 -0800268 , functor(functor) {}
269 Functor* functor;
270};
271
Chris Craika1717272015-11-19 13:02:43 -0800272struct LinesOp : RecordedOp {
273 LinesOp(BASE_PARAMS, const float* points, const int floatCount)
John Reck1bcacfd2017-11-03 10:12:19 -0700274 : SUPER(LinesOp), points(points), floatCount(floatCount) {}
Chris Craika1717272015-11-19 13:02:43 -0800275 const float* points;
276 const int floatCount;
277};
278
Chris Craik386aa032015-12-07 17:08:25 -0800279struct OvalOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700280 OvalOp(BASE_PARAMS) : SUPER(OvalOp) {}
Chris Craik386aa032015-12-07 17:08:25 -0800281};
282
Chris Craikf09ff5a2015-12-08 17:21:58 -0800283struct PatchOp : RecordedOp {
sergeyvec4a4b12016-10-20 18:39:04 -0700284 PatchOp(BASE_PARAMS, Bitmap* bitmap, const Res_png_9patch* patch)
John Reck1bcacfd2017-11-03 10:12:19 -0700285 : SUPER(PatchOp), bitmap(bitmap), patch(patch) {}
sergeyvec4a4b12016-10-20 18:39:04 -0700286 Bitmap* bitmap;
Chris Craikf09ff5a2015-12-08 17:21:58 -0800287 const Res_png_9patch* patch;
288};
289
Chris Craik386aa032015-12-07 17:08:25 -0800290struct PathOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700291 PathOp(BASE_PARAMS, const SkPath* path) : SUPER(PathOp), path(path) {}
Chris Craik386aa032015-12-07 17:08:25 -0800292 const SkPath* path;
293};
294
295struct PointsOp : RecordedOp {
296 PointsOp(BASE_PARAMS, const float* points, const int floatCount)
John Reck1bcacfd2017-11-03 10:12:19 -0700297 : SUPER(PointsOp), points(points), floatCount(floatCount) {}
Chris Craik386aa032015-12-07 17:08:25 -0800298 const float* points;
299 const int floatCount;
300};
301
Chris Craikb565df12015-10-05 13:00:52 -0700302struct RectOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700303 RectOp(BASE_PARAMS) : SUPER(RectOp) {}
Chris Craikb565df12015-10-05 13:00:52 -0700304};
305
Chris Craik386aa032015-12-07 17:08:25 -0800306struct RoundRectOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700307 RoundRectOp(BASE_PARAMS, float rx, float ry) : SUPER(RoundRectOp), rx(rx), ry(ry) {}
Chris Craik386aa032015-12-07 17:08:25 -0800308 const float rx;
309 const float ry;
310};
311
Chris Craik268a9c02015-12-09 18:05:12 -0800312struct RoundRectPropsOp : RecordedOp {
Chris Craike4db79d2015-12-22 16:32:23 -0800313 RoundRectPropsOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
John Reck1bcacfd2017-11-03 10:12:19 -0700314 float* left, float* top, float* right, float* bottom, float* rx, float* ry)
Chris Craike4db79d2015-12-22 16:32:23 -0800315 : RecordedOp(RecordedOpId::RoundRectPropsOp, Rect(), localMatrix, localClip, paint)
Chris Craik268a9c02015-12-09 18:05:12 -0800316 , left(left)
317 , top(top)
318 , right(right)
319 , bottom(bottom)
320 , rx(rx)
321 , ry(ry) {}
322 const float* left;
323 const float* top;
324 const float* right;
325 const float* bottom;
326 const float* rx;
327 const float* ry;
328};
329
Doris Liu766431a2016-02-04 22:17:11 +0000330struct VectorDrawableOp : RecordedOp {
331 VectorDrawableOp(VectorDrawable::Tree* tree, BASE_PARAMS_PAINTLESS)
John Reck1bcacfd2017-11-03 10:12:19 -0700332 : SUPER_PAINTLESS(VectorDrawableOp), vectorDrawable(tree) {}
Doris Liu766431a2016-02-04 22:17:11 +0000333 VectorDrawable::Tree* vectorDrawable;
334};
335
Chris Craikd3daa312015-11-06 10:59:56 -0800336/**
337 * Real-time, dynamic-lit shadow.
338 *
339 * Uses invalid/empty bounds and matrix since ShadowOp bounds aren't known at defer time,
340 * and are resolved dynamically, and transform isn't needed.
341 *
Chris Craik98787e62015-11-13 10:55:30 -0800342 * State construction handles these properties specially, ignoring matrix/bounds.
Chris Craikd3daa312015-11-06 10:59:56 -0800343 */
344struct ShadowOp : RecordedOp {
Chris Craik6e068c012016-01-15 16:15:30 -0800345 ShadowOp(sp<TessellationCache::ShadowTask>& shadowTask, float casterAlpha)
Chris Craike4db79d2015-12-22 16:32:23 -0800346 : RecordedOp(RecordedOpId::ShadowOp, Rect(), Matrix4::identity(), nullptr, nullptr)
Chris Craik6e068c012016-01-15 16:15:30 -0800347 , shadowTask(shadowTask)
John Reck1bcacfd2017-11-03 10:12:19 -0700348 , casterAlpha(casterAlpha){};
Chris Craik6e068c012016-01-15 16:15:30 -0800349 sp<TessellationCache::ShadowTask> shadowTask;
Chris Craikd3daa312015-11-06 10:59:56 -0800350 const float casterAlpha;
Chris Craikd3daa312015-11-06 10:59:56 -0800351};
352
John Reck1bcacfd2017-11-03 10:12:19 -0700353struct SimpleRectsOp : RecordedOp { // Filled, no AA (TODO: better name?)
Chris Craikb565df12015-10-05 13:00:52 -0700354 SimpleRectsOp(BASE_PARAMS, Vertex* vertices, size_t vertexCount)
John Reck1bcacfd2017-11-03 10:12:19 -0700355 : SUPER(SimpleRectsOp), vertices(vertices), vertexCount(vertexCount) {}
Chris Craikb565df12015-10-05 13:00:52 -0700356 Vertex* vertices;
357 const size_t vertexCount;
358};
359
Chris Craika1717272015-11-19 13:02:43 -0800360struct TextOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700361 TextOp(BASE_PARAMS, const glyph_t* glyphs, const float* positions, int glyphCount, float x,
362 float y)
Chris Craika1717272015-11-19 13:02:43 -0800363 : SUPER(TextOp)
364 , glyphs(glyphs)
365 , positions(positions)
366 , glyphCount(glyphCount)
367 , x(x)
368 , y(y) {}
369 const glyph_t* glyphs;
370 const float* positions;
371 const int glyphCount;
372 const float x;
373 const float y;
374};
375
Chris Craikd7448e62015-12-15 10:34:36 -0800376struct TextOnPathOp : RecordedOp {
Chris Craik4c3980b2016-03-15 14:20:18 -0700377 // TODO: explicitly define bounds
378 TextOnPathOp(const Matrix4& localMatrix, const ClipBase* localClip, const SkPaint* paint,
John Reck1bcacfd2017-11-03 10:12:19 -0700379 const glyph_t* glyphs, int glyphCount, const SkPath* path, float hOffset,
380 float vOffset)
Chris Craik4c3980b2016-03-15 14:20:18 -0700381 : RecordedOp(RecordedOpId::TextOnPathOp, Rect(), localMatrix, localClip, paint)
Chris Craikd7448e62015-12-15 10:34:36 -0800382 , glyphs(glyphs)
383 , glyphCount(glyphCount)
384 , path(path)
385 , hOffset(hOffset)
386 , vOffset(vOffset) {}
387 const glyph_t* glyphs;
388 const int glyphCount;
389
390 const SkPath* path;
391 const float hOffset;
392 const float vOffset;
393};
394
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800395struct TextureLayerOp : RecordedOp {
sergeyv3e9999b2017-01-19 15:37:02 -0800396 TextureLayerOp(BASE_PARAMS_PAINTLESS, DeferredLayerUpdater* layer)
John Reck1bcacfd2017-11-03 10:12:19 -0700397 : SUPER_PAINTLESS(TextureLayerOp), layerHandle(layer) {}
Chris Craikaafb01d2016-03-25 18:34:11 -0700398
399 // Copy an existing TextureLayerOp, replacing the underlying matrix
400 TextureLayerOp(const TextureLayerOp& op, const Matrix4& replacementMatrix)
401 : RecordedOp(RecordedOpId::TextureLayerOp, op.unmappedBounds, replacementMatrix,
John Reck1bcacfd2017-11-03 10:12:19 -0700402 op.localClip, op.paint)
403 , layerHandle(op.layerHandle) {}
sergeyv3e9999b2017-01-19 15:37:02 -0800404 DeferredLayerUpdater* layerHandle;
Chris Craikd2dfd8f2015-12-16 14:27:20 -0800405};
406
Chris Craika1717272015-11-19 13:02:43 -0800407////////////////////////////////////////////////////////////////////////////////////////////////////
408// Layers
409////////////////////////////////////////////////////////////////////////////////////////////////////
410
Chris Craik6fe991e52015-10-20 09:39:42 -0700411/**
412 * Stateful operation! denotes the creation of an off-screen layer,
413 * and that commands following will render into it.
414 */
415struct BeginLayerOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700416 BeginLayerOp(BASE_PARAMS) : SUPER(BeginLayerOp) {}
Chris Craik6fe991e52015-10-20 09:39:42 -0700417};
418
419/**
420 * Stateful operation! Denotes end of off-screen layer, and that
421 * commands since last BeginLayerOp should be drawn into parent FBO.
422 *
423 * State in this op is empty, it just serves to signal that a layer has been finished.
424 */
425struct EndLayerOp : RecordedOp {
426 EndLayerOp()
Chris Craike4db79d2015-12-22 16:32:23 -0800427 : RecordedOp(RecordedOpId::EndLayerOp, Rect(), Matrix4::identity(), nullptr, nullptr) {}
Chris Craik6fe991e52015-10-20 09:39:42 -0700428};
429
Chris Craikb87eadd2016-01-06 09:16:05 -0800430struct BeginUnclippedLayerOp : RecordedOp {
John Reck1bcacfd2017-11-03 10:12:19 -0700431 BeginUnclippedLayerOp(BASE_PARAMS) : SUPER(BeginUnclippedLayerOp) {}
Chris Craikb87eadd2016-01-06 09:16:05 -0800432};
433
434struct EndUnclippedLayerOp : RecordedOp {
435 EndUnclippedLayerOp()
John Reck1bcacfd2017-11-03 10:12:19 -0700436 : RecordedOp(RecordedOpId::EndUnclippedLayerOp, Rect(), Matrix4::identity(), nullptr,
437 nullptr) {}
Chris Craikb87eadd2016-01-06 09:16:05 -0800438};
439
440struct CopyToLayerOp : RecordedOp {
441 CopyToLayerOp(const RecordedOp& op, OffscreenBuffer** layerHandle)
John Reck1bcacfd2017-11-03 10:12:19 -0700442 : RecordedOp(RecordedOpId::CopyToLayerOp, op.unmappedBounds, op.localMatrix,
443 nullptr, // clip intentionally ignored
444 op.paint)
Chris Craikb87eadd2016-01-06 09:16:05 -0800445 , layerHandle(layerHandle) {}
446
447 // Records a handle to the Layer object, since the Layer itself won't be
448 // constructed until after this operation is constructed.
449 OffscreenBuffer** layerHandle;
450};
451
Chris Craikb87eadd2016-01-06 09:16:05 -0800452// draw the parameter layer underneath
453struct CopyFromLayerOp : RecordedOp {
454 CopyFromLayerOp(const RecordedOp& op, OffscreenBuffer** layerHandle)
John Reck1bcacfd2017-11-03 10:12:19 -0700455 : RecordedOp(RecordedOpId::CopyFromLayerOp, op.unmappedBounds, op.localMatrix,
456 nullptr, // clip intentionally ignored
457 op.paint)
Chris Craikb87eadd2016-01-06 09:16:05 -0800458 , layerHandle(layerHandle) {}
459
460 // Records a handle to the Layer object, since the Layer itself won't be
461 // constructed until after this operation is constructed.
462 OffscreenBuffer** layerHandle;
463};
464
Chris Craik0b7e8242015-10-28 16:50:44 -0700465/**
466 * Draws an OffscreenBuffer.
467 *
468 * Alpha, mode, and colorfilter are embedded, since LayerOps are always dynamically generated,
469 * when creating/tracking a SkPaint* during defer isn't worth the bother.
470 */
Chris Craik6fe991e52015-10-20 09:39:42 -0700471struct LayerOp : RecordedOp {
Chris Craik74af6e22016-04-05 13:18:56 -0700472 // Records a one-use (saveLayer) layer for drawing.
Chris Craik5854b342015-10-26 15:49:56 -0700473 LayerOp(BASE_PARAMS, OffscreenBuffer** layerHandle)
Chris Craik0b7e8242015-10-28 16:50:44 -0700474 : SUPER_PAINTLESS(LayerOp)
475 , layerHandle(layerHandle)
Chris Craike5b50192016-01-04 15:09:19 -0800476 , alpha(paint ? paint->getAlpha() / 255.0f : 1.0f)
Mike Reed260ab722016-10-07 15:59:20 -0400477 , mode(PaintUtils::getBlendModeDirect(paint))
Chris Craik74af6e22016-04-05 13:18:56 -0700478 , colorFilter(paint ? paint->getColorFilter() : nullptr) {}
Chris Craik0b7e8242015-10-28 16:50:44 -0700479
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -0700480 explicit LayerOp(RenderNode& node)
John Reck1bcacfd2017-11-03 10:12:19 -0700481 : RecordedOp(RecordedOpId::LayerOp, Rect(node.getWidth(), node.getHeight()),
482 Matrix4::identity(), nullptr, nullptr)
Chris Craikb87eadd2016-01-06 09:16:05 -0800483 , layerHandle(node.getLayerHandle())
484 , alpha(node.properties().layerProperties().alpha() / 255.0f)
485 , mode(node.properties().layerProperties().xferMode())
Chris Craik74af6e22016-04-05 13:18:56 -0700486 , colorFilter(node.properties().layerProperties().colorFilter()) {}
Chris Craik0b7e8242015-10-28 16:50:44 -0700487
Chris Craik818c9fb2015-10-23 14:33:42 -0700488 // Records a handle to the Layer object, since the Layer itself won't be
489 // constructed until after this operation is constructed.
Chris Craik5854b342015-10-26 15:49:56 -0700490 OffscreenBuffer** layerHandle;
Chris Craik0b7e8242015-10-28 16:50:44 -0700491 const float alpha;
Mike Reed260ab722016-10-07 15:59:20 -0400492 const SkBlendMode mode;
Chris Craik0b7e8242015-10-28 16:50:44 -0700493
494 // pointer to object owned by either LayerProperties, or a recorded Paint object in a
495 // BeginLayerOp. Lives longer than LayerOp in either case, so no skia ref counting is used.
496 SkColorFilter* colorFilter;
Chris Craik6fe991e52015-10-20 09:39:42 -0700497};
498
John Reck1bcacfd2017-11-03 10:12:19 -0700499}; // namespace uirenderer
500}; // namespace android