blob: 45662a77cfdde86afe61fde07343ac83ecfcac71 [file] [log] [blame]
Romain Guye4d01122010-06-16 18:44:05 -07001/*
2 * Copyright (C) 2010 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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
18#define ANDROID_HWUI_OPENGL_RENDERER_H
Romain Guy9d5316e2010-06-24 19:30:36 -070019
Chris Craik03ae2722015-02-25 11:01:09 -080020#include "CanvasState.h"
21#include "Debug.h"
22#include "Extensions.h"
23#include "Matrix.h"
24#include "Program.h"
25#include "Rect.h"
26#include "Snapshot.h"
27#include "UvMapper.h"
28#include "Vertex.h"
29#include "Caches.h"
30#include "utils/PaintUtils.h"
31
Romain Guy9d5316e2010-06-24 19:30:36 -070032#include <GLES2/gl2.h>
33#include <GLES2/gl2ext.h>
Romain Guy85bf02f2010-06-22 13:11:24 -070034
Romain Guyce0537b2010-06-29 21:05:21 -070035#include <SkBitmap.h>
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050036#include <SkCanvas.h>
37#include <SkColorFilter.h>
Romain Guyf6a11b82010-06-23 17:47:49 -070038#include <SkMatrix.h>
Romain Guyce0537b2010-06-29 21:05:21 -070039#include <SkPaint.h>
Romain Guy079ba2c2010-07-16 14:12:24 -070040#include <SkRegion.h>
Romain Guy85bf02f2010-06-22 13:11:24 -070041#include <SkXfermode.h>
Romain Guye4d01122010-06-16 18:44:05 -070042
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -040043#include <utils/Blur.h>
Chet Haasedaf98e92011-01-10 14:10:36 -080044#include <utils/Functor.h>
Romain Guybb9524b2010-06-22 18:56:38 -070045#include <utils/RefBase.h>
Romain Guyba6be8a2012-04-23 18:22:09 -070046#include <utils/SortedVector.h>
Romain Guybb9524b2010-06-22 18:56:38 -070047
Romain Guy79537452011-10-12 13:48:51 -070048#include <cutils/compiler.h>
49
Romain Guy3b748a42013-04-17 18:54:38 -070050#include <androidfw/ResourceTypes.h>
51
John Reck272a6852015-07-29 16:48:58 -070052#include <vector>
53
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040054class SkShader;
55
Romain Guye4d01122010-06-16 18:44:05 -070056namespace android {
Romain Guy9d5316e2010-06-24 19:30:36 -070057namespace uirenderer {
Romain Guye4d01122010-06-16 18:44:05 -070058
Chris Craik03ae2722015-02-25 11:01:09 -080059enum class DrawOpMode {
60 kImmediate,
61 kDefer,
62 kFlush
63};
64
Chris Craikb4589422013-12-26 15:13:13 -080065class DeferredDisplayState;
Chris Craik117bdbc2015-02-05 10:12:38 -080066struct Glop;
John Reck3b202512014-06-23 13:13:08 -070067class RenderState;
John Recke18264b2014-03-12 13:56:30 -070068class RenderNode;
Chris Craik82840732015-04-03 09:37:49 -070069class TextDrawFunctor;
Chris Craikb4589422013-12-26 15:13:13 -080070class VertexBuffer;
Chris Craikb4589422013-12-26 15:13:13 -080071
Chris Craikff785832013-03-08 13:12:16 -080072enum StateDeferFlags {
73 kStateDeferFlag_Draw = 0x1,
74 kStateDeferFlag_Clip = 0x2
75};
76
Chris Craik28ce94a2013-05-31 11:38:03 -070077enum ClipSideFlags {
Chris Craika02c4ed2013-06-14 13:43:58 -070078 kClipSide_None = 0x0,
Chris Craik28ce94a2013-05-31 11:38:03 -070079 kClipSide_Left = 0x1,
80 kClipSide_Top = 0x2,
81 kClipSide_Right = 0x4,
82 kClipSide_Bottom = 0x8,
Chris Craikd72b73c2013-06-17 13:52:06 -070083 kClipSide_Full = 0xF,
84 kClipSide_ConservativeFull = 0x1F
Chris Craik28ce94a2013-05-31 11:38:03 -070085};
86
Chris Craikbf759452014-08-11 16:00:44 -070087enum VertexBufferDisplayFlags {
88 kVertexBuffer_Offset = 0x1,
Chris Craik91a8c7c2014-08-12 14:31:35 -070089 kVertexBuffer_ShadowInterp = 0x2,
Chris Craikbf759452014-08-11 16:00:44 -070090};
91
Chris Craik4063a0e2013-11-15 16:06:56 -080092/**
93 * Defines additional transformation that should be applied by the model view matrix, beyond that of
94 * the currentTransform()
95 */
96enum ModelViewMode {
97 /**
98 * Used when the model view should simply translate geometry passed to the shader. The resulting
99 * matrix will be a simple translation.
100 */
101 kModelViewMode_Translate = 0,
102
103 /**
104 * Used when the model view should translate and scale geometry. The resulting matrix will be a
105 * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect.
106 */
107 kModelViewMode_TranslateAndScale = 1,
108};
109
Romain Guyf6a11b82010-06-23 17:47:49 -0700110///////////////////////////////////////////////////////////////////////////////
Romain Guyf6a11b82010-06-23 17:47:49 -0700111// Renderer
112///////////////////////////////////////////////////////////////////////////////
Romain Guy5cbbce52010-06-27 22:59:20 -0700113/**
Chris Craik14e51302013-12-30 15:32:54 -0800114 * OpenGL Renderer implementation.
Romain Guy5cbbce52010-06-27 22:59:20 -0700115 */
Chris Craik03ae2722015-02-25 11:01:09 -0800116class OpenGLRenderer : public CanvasStateClient {
Romain Guye4d01122010-06-16 18:44:05 -0700117public:
John Reck3b202512014-06-23 13:13:08 -0700118 OpenGLRenderer(RenderState& renderState);
Romain Guye2d345e2010-09-24 18:39:22 -0700119 virtual ~OpenGLRenderer();
Romain Guye4d01122010-06-16 18:44:05 -0700120
Chris Craik03ae2722015-02-25 11:01:09 -0800121 /**
122 * Sets the dimension of the underlying drawing surface. This method must
123 * be called at least once every time the drawing surface changes size.
124 *
125 * @param width The width in pixels of the underlysing surface
126 * @param height The height in pixels of the underlysing surface
127 */
128 void setViewport(int width, int height) { mState.setViewport(width, height); }
129
John Reck3b202512014-06-23 13:13:08 -0700130 void initProperties();
Alan Viverette50210d92015-05-14 18:05:36 -0700131 void initLight(float lightRadius, uint8_t ambientShadowAlpha,
132 uint8_t spotShadowAlpha);
133 void setLightCenter(const Vector3& lightCenter);
Romain Guy87e2f7572012-09-24 11:37:12 -0700134
Chris Craik03ae2722015-02-25 11:01:09 -0800135 /*
136 * Prepares the renderer to draw a frame. This method must be invoked
137 * at the beginning of each frame. Only the specified rectangle of the
138 * frame is assumed to be dirty. A clip will automatically be set to
139 * the specified rectangle.
140 *
141 * @param opaque If true, the target surface is considered opaque
142 * and will not be cleared. If false, the target surface
143 * will be cleared
144 */
Chris Craike84a2082014-12-22 14:28:49 -0800145 virtual void prepareDirty(float left, float top, float right, float bottom,
Chris Craik03ae2722015-02-25 11:01:09 -0800146 bool opaque);
147
148 /**
149 * Prepares the renderer to draw a frame. This method must be invoked
150 * at the beginning of each frame. When this method is invoked, the
151 * entire drawing surface is assumed to be redrawn.
152 *
153 * @param opaque If true, the target surface is considered opaque
154 * and will not be cleared. If false, the target surface
155 * will be cleared
156 */
157 void prepare(bool opaque) {
Tom Hudson984162f2014-10-10 13:38:16 -0400158 prepareDirty(0.0f, 0.0f, mState.getWidth(), mState.getHeight(), opaque);
159 }
Romain Guyc89b14b2012-08-08 14:53:48 -0700160
Chris Craik03ae2722015-02-25 11:01:09 -0800161 /**
162 * Indicates the end of a frame. This method must be invoked whenever
163 * the caller is done rendering a frame.
164 * Returns true if any drawing was done during the frame (the output
165 * has changed / is "dirty" and should be displayed to the user).
166 */
167 virtual bool finish();
168
169 void callDrawGLFunction(Functor* functor, Rect& dirty);
Romain Guy08ae3172010-06-21 19:35:50 -0700170
John Reck3b202512014-06-23 13:13:08 -0700171 void pushLayerUpdate(Layer* layer);
172 void cancelLayerUpdate(Layer* layer);
John Reck3b202512014-06-23 13:13:08 -0700173 void flushLayerUpdates();
John Reck443a7142014-09-04 17:40:05 -0700174 void markLayersAsBuildLayers();
Romain Guy11cb6422012-09-21 00:39:43 -0700175
John Reck3b202512014-06-23 13:13:08 -0700176 virtual int saveLayer(float left, float top, float right, float bottom,
Chris Craik03ae2722015-02-25 11:01:09 -0800177 const SkPaint* paint, int flags) {
Chris Craike84a2082014-12-22 14:28:49 -0800178 return saveLayer(left, top, right, bottom, paint, flags, nullptr);
Chris Craik3f0854292014-04-15 16:18:08 -0700179 }
180
181 // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if
182 // created, which will in turn clip to that mask when drawn back/restored.
183 int saveLayer(float left, float top, float right, float bottom,
184 const SkPaint* paint, int flags, const SkPath* convexMask);
Romain Guybd6b79b2010-06-26 00:13:53 -0700185
Chris Craikd90144d2013-03-19 15:03:48 -0700186 int saveLayerDeferred(float left, float top, float right, float bottom,
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500187 const SkPaint* paint, int flags);
Chris Craikd90144d2013-03-19 15:03:48 -0700188
Chris Craik03ae2722015-02-25 11:01:09 -0800189 void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
190 void drawLayer(Layer* layer, float x, float y);
191 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
Tom Hudson107843d2014-09-08 11:26:26 -0400192 void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
Chris Craikd218a922014-01-02 17:13:34 -0800193 TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
Chris Craik03ae2722015-02-25 11:01:09 -0800194 void drawBitmap(const SkBitmap* bitmap, Rect src, Rect dst,
195 const SkPaint* paint);
196 void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
197 const float* vertices, const int* colors, const SkPaint* paint);
Tom Hudson107843d2014-09-08 11:26:26 -0400198 void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
Chris Craikd218a922014-01-02 17:13:34 -0800199 TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
Tom Hudson107843d2014-09-08 11:26:26 -0400200 void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
Chris Craikd218a922014-01-02 17:13:34 -0800201 float left, float top, float right, float bottom, const SkPaint* paint);
Chris Craik03ae2722015-02-25 11:01:09 -0800202 void drawColor(int color, SkXfermode::Mode mode);
203 void drawRect(float left, float top, float right, float bottom,
204 const SkPaint* paint);
205 void drawRoundRect(float left, float top, float right, float bottom,
206 float rx, float ry, const SkPaint* paint);
207 void drawCircle(float x, float y, float radius, const SkPaint* paint);
208 void drawOval(float left, float top, float right, float bottom,
209 const SkPaint* paint);
210 void drawArc(float left, float top, float right, float bottom,
211 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
212 void drawPath(const SkPath* path, const SkPaint* paint);
213 void drawLines(const float* points, int count, const SkPaint* paint);
214 void drawPoints(const float* points, int count, const SkPaint* paint);
215 void drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
216 float hOffset, float vOffset, const SkPaint* paint);
217 void drawPosText(const char* text, int bytesCount, int count,
218 const float* positions, const SkPaint* paint);
219 void drawText(const char* text, int bytesCount, int count, float x, float y,
Chris Craikd218a922014-01-02 17:13:34 -0800220 const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
Chris Craik03ae2722015-02-25 11:01:09 -0800221 DrawOpMode drawOpMode = DrawOpMode::kImmediate);
222 void drawRects(const float* rects, int count, const SkPaint* paint);
Romain Guy08ae3172010-06-21 19:35:50 -0700223
Tom Hudson107843d2014-09-08 11:26:26 -0400224 void drawShadow(float casterAlpha,
Chris Craike84a2082014-12-22 14:28:49 -0800225 const VertexBuffer* ambientShadowVertexBuffer,
226 const VertexBuffer* spotShadowVertexBuffer);
Chris Craikf57776b2013-10-25 18:30:17 -0700227
Chris Craik03ae2722015-02-25 11:01:09 -0800228 void setDrawFilter(SkDrawFilter* filter);
Romain Guy5ff9df62012-01-23 17:09:05 -0800229
Chris Craik5e49b302013-07-30 19:05:20 -0700230 /**
231 * Store the current display state (most importantly, the current clip and transform), and
232 * additionally map the state's bounds from local to window coordinates.
233 *
234 * Returns true if quick-rejected
235 */
Chris Craikff785832013-03-08 13:12:16 -0800236 bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
Chris Craik527a3aa2013-03-04 10:19:31 -0800237 void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
Chris Craik28ce94a2013-05-31 11:38:03 -0700238 void setupMergedMultiDraw(const Rect* clipRect);
Chris Craikc3566d02013-02-04 16:16:33 -0800239
John Reck3b202512014-06-23 13:13:08 -0700240 bool isCurrentTransformSimple() {
Chris Craikd6b65f62014-01-01 14:45:21 -0800241 return currentTransform()->isSimple();
Romain Guy672433d2013-01-04 19:05:13 -0800242 }
243
Romain Guy0f6675332013-03-01 14:31:04 -0800244 Caches& getCaches() {
245 return mCaches;
246 }
247
Chris Craik65fe5ee2015-01-26 18:06:29 -0800248 RenderState& renderState() {
249 return mRenderState;
250 }
251
Tom Hudson984162f2014-10-10 13:38:16 -0400252 int getViewportWidth() { return mState.getViewportWidth(); }
253 int getViewportHeight() { return mState.getViewportHeight(); }
Chris Craik0e87f002013-06-19 16:54:59 -0700254
Romain Guy17112ad2012-08-07 11:24:39 -0700255 /**
Chris Craika08f95c2013-03-15 17:24:33 -0700256 * Scales the alpha on the current snapshot. This alpha value will be modulated
Romain Guy17112ad2012-08-07 11:24:39 -0700257 * with other alpha values when drawing primitives.
258 */
Tom Hudson984162f2014-10-10 13:38:16 -0400259 void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); }
Romain Guy17112ad2012-08-07 11:24:39 -0700260
261 /**
Romain Guy0f6675332013-03-01 14:31:04 -0800262 * Inserts a named event marker in the stream of GL commands.
263 */
264 void eventMark(const char* name) const;
265
266 /**
Chris Craik62d307c2014-07-29 10:35:13 -0700267 * Inserts a formatted event marker in the stream of GL commands.
268 */
269 void eventMarkDEBUG(const char *fmt, ...) const;
270
271 /**
Romain Guy17112ad2012-08-07 11:24:39 -0700272 * Inserts a named group marker in the stream of GL commands. This marker
273 * can be used by tools to group commands into logical groups. A call to
274 * this method must always be followed later on by a call to endMark().
275 */
Romain Guy13631f32012-01-30 17:41:55 -0800276 void startMark(const char* name) const;
Romain Guy17112ad2012-08-07 11:24:39 -0700277
278 /**
279 * Closes the last group marker opened by startMark().
280 */
Romain Guy13631f32012-01-30 17:41:55 -0800281 void endMark() const;
282
Chet Haased15ebf22012-09-05 11:40:29 -0700283 /**
284 * Gets the alpha and xfermode out of a paint object. If the paint is null
285 * alpha will be 255 and the xfermode will be SRC_OVER. This method does
Chris Craik16ecda52013-03-29 10:59:59 -0700286 * not multiply the paint's alpha by the current snapshot's alpha, and does
287 * not replace the alpha with the overrideLayerAlpha
Chet Haased15ebf22012-09-05 11:40:29 -0700288 *
289 * @param paint The paint to extract values from
290 * @param alpha Where to store the resulting alpha
291 * @param mode Where to store the resulting xfermode
292 */
Chris Craike84a2082014-12-22 14:28:49 -0800293 static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha,
294 SkXfermode::Mode* mode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800295 *mode = getXfermodeDirect(paint);
296 *alpha = getAlphaDirect(paint);
297 }
Chet Haased15ebf22012-09-05 11:40:29 -0700298
Chris Craikd218a922014-01-02 17:13:34 -0800299 static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800300 if (!paint) return SkXfermode::kSrcOver_Mode;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500301 return PaintUtils::getXfermode(paint->getXfermode());
Chris Craik527a3aa2013-03-04 10:19:31 -0800302 }
303
Chris Craikc1c5f082013-09-11 16:23:37 -0700304 static inline int getAlphaDirect(const SkPaint* paint) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800305 if (!paint) return 255;
306 return paint->getAlpha();
Chet Haased15ebf22012-09-05 11:40:29 -0700307 }
308
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -0400309 struct TextShadow {
310 SkScalar radius;
311 float dx;
312 float dy;
313 SkColor color;
314 };
315
316 static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) {
317 SkDrawLooper::BlurShadowRec blur;
318 if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) {
319 if (textShadow) {
320 textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma);
321 textShadow->dx = blur.fOffset.fX;
322 textShadow->dy = blur.fOffset.fY;
323 textShadow->color = blur.fColor;
324 }
325 return true;
326 }
327 return false;
328 }
329
330 static inline bool hasTextShadow(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800331 return getTextShadow(paint, nullptr);
Derek Sollenbergerc29a0a42014-03-31 13:52:39 -0400332 }
333
Romain Guy624234f2013-03-05 16:43:31 -0800334 /**
Chris Craik59744b72014-07-01 17:56:52 -0700335 * Build the best transform to use to rasterize text given a full
336 * transform matrix, and whether filteration is needed.
337 *
338 * Returns whether filtration is needed
Romain Guy624234f2013-03-05 16:43:31 -0800339 */
Chris Craik59744b72014-07-01 17:56:52 -0700340 bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const;
Romain Guy624234f2013-03-05 16:43:31 -0800341
Chris Craik527a3aa2013-03-04 10:19:31 -0800342#if DEBUG_MERGE_BEHAVIOR
343 void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
344 mCaches.setScissorEnabled(false);
345
346 // should only be called outside of other draw ops, so stencil can only be in test state
347 bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
348 mCaches.stencil.disable();
349
350 drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
351
352 if (stencilWasEnabled) mCaches.stencil.enableTest();
Tom Hudson107843d2014-09-08 11:26:26 -0400353 mDirty = true;
Chris Craik527a3aa2013-03-04 10:19:31 -0800354 }
355#endif
356
Tom Hudson984162f2014-10-10 13:38:16 -0400357 const Vector3& getLightCenter() const { return mState.currentLightCenter(); }
Chris Craik05f3d6e2014-06-02 16:27:04 -0700358 float getLightRadius() const { return mLightRadius; }
Chris Craik69e5adf2014-08-14 13:34:01 -0700359 uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; }
360 uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; }
Chris Craik05f3d6e2014-06-02 16:27:04 -0700361
Tom Hudson984162f2014-10-10 13:38:16 -0400362 ///////////////////////////////////////////////////////////////////
363 /// State manipulation
364
Chris Craik03ae2722015-02-25 11:01:09 -0800365 int getSaveCount() const;
366 int save(int flags);
367 void restore();
368 void restoreToCount(int saveCount);
Tom Hudson984162f2014-10-10 13:38:16 -0400369
Chris Craik6daa13c2015-08-19 13:32:12 -0700370 void setGlobalMatrix(const Matrix4& matrix) {
371 mState.setMatrix(matrix);
372 }
373 void setLocalMatrix(const Matrix4& matrix);
Tom Hudsonac7b6d32015-06-30 11:26:13 -0400374 void setLocalMatrix(const SkMatrix& matrix);
Chris Craik03ae2722015-02-25 11:01:09 -0800375 void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); }
Tom Hudson984162f2014-10-10 13:38:16 -0400376
Chris Craik03ae2722015-02-25 11:01:09 -0800377 void translate(float dx, float dy, float dz = 0.0f);
378 void rotate(float degrees);
379 void scale(float sx, float sy);
380 void skew(float sx, float sy);
Tom Hudson984162f2014-10-10 13:38:16 -0400381
382 void setMatrix(const Matrix4& matrix); // internal only convenience method
383 void concatMatrix(const Matrix4& matrix); // internal only convenience method
384
Chris Craik03ae2722015-02-25 11:01:09 -0800385 const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); }
Tom Hudson984162f2014-10-10 13:38:16 -0400386 const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
Chris Craik03ae2722015-02-25 11:01:09 -0800387 bool quickRejectConservative(float left, float top,
388 float right, float bottom) const {
Tom Hudson984162f2014-10-10 13:38:16 -0400389 return mState.quickRejectConservative(left, top, right, bottom);
390 }
391
Chris Craik03ae2722015-02-25 11:01:09 -0800392 bool clipRect(float left, float top,
393 float right, float bottom, SkRegion::Op op);
394 bool clipPath(const SkPath* path, SkRegion::Op op);
395 bool clipRegion(const SkRegion* region, SkRegion::Op op);
Tom Hudson984162f2014-10-10 13:38:16 -0400396
397 /**
398 * Does not support different clipping Ops (that is, every call to setClippingOutline is
399 * effectively using SkRegion::kReplaceOp)
400 *
401 * The clipping outline is independent from the regular clip.
402 */
403 void setClippingOutline(LinearAllocator& allocator, const Outline* outline);
404 void setClippingRoundRect(LinearAllocator& allocator,
405 const Rect& rect, float radius, bool highPriority = true);
Chris Craikfca52b752015-04-28 11:45:59 -0700406 void setProjectionPathMask(LinearAllocator& allocator, const SkPath* path);
Tom Hudson984162f2014-10-10 13:38:16 -0400407
408 inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); }
409 inline const mat4* currentTransform() const { return mState.currentTransform(); }
410
411 ///////////////////////////////////////////////////////////////////
412 /// CanvasStateClient interface
413
Chris Craike84a2082014-12-22 14:28:49 -0800414 virtual void onViewportInitialized() override;
415 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override;
Chris Craik6b109c72015-02-27 10:55:28 -0800416 virtual GLuint getTargetFbo() const override { return 0; }
Tom Hudson984162f2014-10-10 13:38:16 -0400417
Chris Craik4ac36f82014-12-09 16:54:03 -0800418 SkPath* allocPathForFrame() {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800419 std::unique_ptr<SkPath> path(new SkPath());
420 SkPath* returnPath = path.get();
421 mTempPaths.push_back(std::move(path));
422 return returnPath;
Chris Craik4ac36f82014-12-09 16:54:03 -0800423 }
424
Tom Hudsonac7b6d32015-06-30 11:26:13 -0400425 void setBaseTransform(const Matrix4& matrix) { mBaseTransform = matrix; }
426
Romain Guye2d345e2010-09-24 18:39:22 -0700427protected:
428 /**
Romain Guy96885eb2013-03-26 15:05:58 -0700429 * Perform the setup specific to a frame. This method does not
430 * issue any OpenGL commands.
431 */
432 void setupFrameState(float left, float top, float right, float bottom, bool opaque);
433
434 /**
435 * Indicates the start of rendering. This method will setup the
436 * initial OpenGL state (viewport, clearing the buffer, etc.)
437 */
Tom Hudson107843d2014-09-08 11:26:26 -0400438 void startFrame();
Romain Guy96885eb2013-03-26 15:05:58 -0700439
440 /**
Romain Guy7c25aab2012-10-18 15:05:02 -0700441 * Clears the underlying surface if needed.
442 */
Tom Hudson107843d2014-09-08 11:26:26 -0400443 virtual void clear(float left, float top, float right, float bottom, bool opaque);
Romain Guy7c25aab2012-10-18 15:05:02 -0700444
445 /**
Romain Guy35643dd2012-09-18 15:40:58 -0700446 * Call this method after updating a layer during a drawing pass.
447 */
448 void resumeAfterLayer();
449
450 /**
Romain Guy8ce00302013-01-15 18:51:42 -0800451 * This method is called whenever a stencil buffer is required. Subclasses
452 * should override this method and call attachStencilBufferToLayer() on the
453 * appropriate layer(s).
454 */
455 virtual void ensureStencilBuffer();
456
457 /**
458 * Obtains a stencil render buffer (allocating it if necessary) and
459 * attaches it to the specified layer.
460 */
461 void attachStencilBufferToLayer(Layer* layer);
462
Rob Tsuk487a92c2015-01-06 13:22:54 -0800463 /**
464 * Draw a rectangle list. Currently only used for the the stencil buffer so that the stencil
465 * will have a value of 'n' in every unclipped pixel, where 'n' is the number of rectangles
466 * in the list.
467 */
468 void drawRectangleList(const RectangleList& rectangleList);
469
Chris Craikf0a59072013-11-19 18:00:46 -0800470 bool quickRejectSetupScissor(float left, float top, float right, float bottom,
Chris Craike84a2082014-12-22 14:28:49 -0800471 const SkPaint* paint = nullptr);
472 bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = nullptr) {
Chris Craikf0a59072013-11-19 18:00:46 -0800473 return quickRejectSetupScissor(bounds.left, bounds.top,
474 bounds.right, bounds.bottom, paint);
475 }
476
Romain Guy8ce00302013-01-15 18:51:42 -0800477 /**
Romain Guye2d345e2010-09-24 18:39:22 -0700478 * Compose the layer defined in the current snapshot with the layer
479 * defined by the previous snapshot.
480 *
481 * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
482 *
483 * @param curent The current snapshot containing the layer to compose
484 * @param previous The previous snapshot to compose the current layer with
485 */
Chris Craik14e51302013-12-30 15:32:54 -0800486 virtual void composeLayer(const Snapshot& current, const Snapshot& previous);
Romain Guy694b5192010-07-21 21:33:20 -0700487
Romain Guyada830f2011-01-13 12:13:20 -0800488 /**
Romain Guyf219da52011-01-16 12:54:25 -0800489 * Marks the specified region as dirty at the specified bounds.
Romain Guyada830f2011-01-13 12:13:20 -0800490 */
Romain Guyf219da52011-01-16 12:54:25 -0800491 void dirtyLayerUnchecked(Rect& bounds, Region* region);
Romain Guyada830f2011-01-13 12:13:20 -0800492
Romain Guy42f3a4b2011-01-19 13:42:26 -0800493 /**
494 * Returns the region of the current layer.
495 */
Romain Guy624234f2013-03-05 16:43:31 -0800496 virtual Region* getRegion() const {
Tom Hudson984162f2014-10-10 13:38:16 -0400497 return mState.currentRegion();
Romain Guyf219da52011-01-16 12:54:25 -0800498 }
499
Romain Guy42f3a4b2011-01-19 13:42:26 -0800500 /**
501 * Indicates whether rendering is currently targeted at a layer.
502 */
Romain Guy624234f2013-03-05 16:43:31 -0800503 virtual bool hasLayer() const {
Tom Hudson984162f2014-10-10 13:38:16 -0400504 return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion();
Romain Guyf219da52011-01-16 12:54:25 -0800505 }
Romain Guy1bd1bad2011-01-14 20:07:20 -0800506
Romain Guy77a81162011-06-14 16:45:55 -0700507 /**
508 * Renders the specified layer as a textured quad.
509 *
510 * @param layer The layer to render
511 * @param rect The bounds of the layer
512 */
513 void drawTextureLayer(Layer* layer, const Rect& rect);
514
Romain Guybe6f9dc2012-07-16 12:41:17 -0700515 /**
516 * Gets the alpha and xfermode out of a paint object. If the paint is null
Chris Craik8df5ffa2015-04-28 17:47:20 -0700517 * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for snapshot alpha.
Romain Guybe6f9dc2012-07-16 12:41:17 -0700518 *
519 * @param paint The paint to extract values from
520 * @param alpha Where to store the resulting alpha
521 * @param mode Where to store the resulting xfermode
522 */
Chris Craikd218a922014-01-02 17:13:34 -0800523 inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const;
Chris Craik16ecda52013-03-29 10:59:59 -0700524
525 /**
Chris Craik8df5ffa2015-04-28 17:47:20 -0700526 * Gets the alpha from a layer, accounting for snapshot alpha
Chris Craik16ecda52013-03-29 10:59:59 -0700527 *
528 * @param layer The layer from which the alpha is extracted
529 */
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500530 inline float getLayerAlpha(const Layer* layer) const;
Romain Guybe6f9dc2012-07-16 12:41:17 -0700531
532 /**
Romain Guy11cb6422012-09-21 00:39:43 -0700533 * Set to true to suppress error checks at the end of a frame.
534 */
Romain Guy624234f2013-03-05 16:43:31 -0800535 virtual bool suppressErrorChecks() const {
Romain Guy11cb6422012-09-21 00:39:43 -0700536 return false;
537 }
538
Tom Hudson984162f2014-10-10 13:38:16 -0400539 CanvasState mState;
Chris Craik65fe5ee2015-01-26 18:06:29 -0800540 Caches& mCaches;
Chris Craik65fe5ee2015-01-26 18:06:29 -0800541 RenderState& mRenderState;
Tom Hudson984162f2014-10-10 13:38:16 -0400542
Romain Guy85bf02f2010-06-22 13:11:24 -0700543private:
Chris Craik3375f8a2015-06-23 17:33:06 -0700544 enum class GlopRenderType {
545 Standard,
546 Multi,
547 LayerClear
548 };
549
550 void renderGlop(const Glop& glop, GlopRenderType type = GlopRenderType::Standard);
Chris Craik117bdbc2015-02-05 10:12:38 -0800551
Romain Guy5cbbce52010-06-27 22:59:20 -0700552 /**
Romain Guydcfc8362013-01-03 13:08:57 -0800553 * Discards the content of the framebuffer if supported by the driver.
554 * This method should be called at the beginning of a frame to optimize
555 * rendering on some tiler architectures.
556 */
557 void discardFramebuffer(float left, float top, float right, float bottom);
558
559 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700560 * Sets the clipping rectangle using glScissor. The clip is defined by
561 * the current snapshot's clipRect member.
562 */
Romain Guybb9524b2010-06-22 18:56:38 -0700563 void setScissorFromClip();
564
Romain Guy5cbbce52010-06-27 22:59:20 -0700565 /**
Romain Guy8ce00302013-01-15 18:51:42 -0800566 * Sets the clipping region using the stencil buffer. The clip region
567 * is defined by the current snapshot's clipRegion member.
568 */
569 void setStencilFromClip();
570
571 /**
Chris Craik408eb122013-03-26 18:55:15 -0700572 * Given the local bounds of the layer, calculates ...
Chris Craikd90144d2013-03-19 15:03:48 -0700573 */
574 void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
575
576 /**
Chris Craik408eb122013-03-26 18:55:15 -0700577 * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
578 */
579 void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
580 bool fboLayer, int alpha);
581
582 /**
Romain Guyd55a8612010-06-28 17:42:46 -0700583 * Creates a new layer stored in the specified snapshot.
584 *
585 * @param snapshot The snapshot associated with the new layer
586 * @param left The left coordinate of the layer
587 * @param top The top coordinate of the layer
588 * @param right The right coordinate of the layer
589 * @param bottom The bottom coordinate of the layer
590 * @param alpha The translucency of the layer
591 * @param mode The blending mode of the layer
592 * @param flags The layer save flags
Chris Craik3f0854292014-04-15 16:18:08 -0700593 * @param mask A mask to use when drawing the layer back, may be empty
Romain Guyd55a8612010-06-28 17:42:46 -0700594 *
595 * @return True if the layer was successfully created, false otherwise
596 */
Chet Haased48885a2012-08-28 17:43:28 -0700597 bool createLayer(float left, float top, float right, float bottom,
Chris Craik3f0854292014-04-15 16:18:08 -0700598 const SkPaint* paint, int flags, const SkPath* convexMask);
Romain Guyd55a8612010-06-28 17:42:46 -0700599
600 /**
Romain Guy5b3b3522010-10-27 18:57:51 -0700601 * Creates a new layer stored in the specified snapshot as an FBO.
602 *
603 * @param layer The layer to store as an FBO
604 * @param snapshot The snapshot associated with the new layer
605 * @param bounds The bounds of the layer
Romain Guy5b3b3522010-10-27 18:57:51 -0700606 */
Chris Craike63f7c622013-10-17 10:30:55 -0700607 bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip);
Romain Guy5b3b3522010-10-27 18:57:51 -0700608
609 /**
610 * Compose the specified layer as a region.
611 *
612 * @param layer The layer to compose
613 * @param rect The layer's bounds
614 */
615 void composeLayerRegion(Layer* layer, const Rect& rect);
616
617 /**
Chris Craik53e51e42015-06-01 10:35:35 -0700618 * Restores the content in layer to the screen, swapping the blend mode,
619 * specifically used in the restore() of a saveLayerAlpha().
Romain Guy5b3b3522010-10-27 18:57:51 -0700620 *
Chris Craik53e51e42015-06-01 10:35:35 -0700621 * This allows e.g. a layer that would have been drawn on top of existing content (with SrcOver)
622 * to be drawn underneath.
623 *
624 * This will always ignore the canvas transform.
Romain Guy5b3b3522010-10-27 18:57:51 -0700625 */
Chris Craik53e51e42015-06-01 10:35:35 -0700626 void composeLayerRectSwapped(Layer* layer, const Rect& rect);
627
628 /**
629 * Draws the content in layer to the screen.
630 */
631 void composeLayerRect(Layer* layer, const Rect& rect);
Romain Guy5b3b3522010-10-27 18:57:51 -0700632
Romain Guy54be1cd2011-06-13 19:04:27 -0700633 /**
634 * Clears all the regions corresponding to the current list of layers.
635 * This method MUST be invoked before any drawing operation.
636 */
637 void clearLayerRegions();
638
639 /**
Romain Guyf219da52011-01-16 12:54:25 -0800640 * Mark the layer as dirty at the specified coordinates. The coordinates
641 * are transformed with the supplied matrix.
642 */
643 void dirtyLayer(const float left, const float top,
Chris Craik083e7332015-02-27 17:04:20 -0800644 const float right, const float bottom, const Matrix4& transform);
Romain Guyf219da52011-01-16 12:54:25 -0800645
646 /**
647 * Mark the layer as dirty at the specified coordinates.
648 */
649 void dirtyLayer(const float left, const float top,
650 const float right, const float bottom);
651
652 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700653 * Draws a colored rectangle with the specified color. The specified coordinates
Romain Guy735738c2012-12-03 12:34:51 -0800654 * are transformed by the current snapshot's transform matrix unless specified
655 * otherwise.
Romain Guy5cbbce52010-06-27 22:59:20 -0700656 *
657 * @param left The left coordinate of the rectangle
658 * @param top The top coordinate of the rectangle
659 * @param right The right coordinate of the rectangle
660 * @param bottom The bottom coordinate of the rectangle
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500661 * @param paint The paint containing the color, blending mode, etc.
Romain Guy3d58c032010-07-14 16:34:53 -0700662 * @param ignoreTransform True if the current transform should be ignored
Romain Guy5cbbce52010-06-27 22:59:20 -0700663 */
Romain Guy026c5e162010-06-28 17:12:22 -0700664 void drawColorRect(float left, float top, float right, float bottom,
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500665 const SkPaint* paint, bool ignoreTransform = false);
Romain Guy5cbbce52010-06-27 22:59:20 -0700666
Romain Guy54be1cd2011-06-13 19:04:27 -0700667 /**
Romain Guy735738c2012-12-03 12:34:51 -0800668 * Draws a series of colored rectangles with the specified color. The specified
669 * coordinates are transformed by the current snapshot's transform matrix unless
670 * specified otherwise.
671 *
672 * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
673 * per rectangle
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500674 * @param paint The paint containing the color, blending mode, etc.
Romain Guy735738c2012-12-03 12:34:51 -0800675 * @param ignoreTransform True if the current transform should be ignored
Romain Guy8ce00302013-01-15 18:51:42 -0800676 * @param dirty True if calling this method should dirty the current layer
Romain Guy3bbacf22013-02-06 16:51:04 -0800677 * @param clip True if the rects should be clipped, false otherwise
Romain Guy735738c2012-12-03 12:34:51 -0800678 */
Tom Hudson107843d2014-09-08 11:26:26 -0400679 void drawColorRects(const float* rects, int count, const SkPaint* paint,
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500680 bool ignoreTransform = false, bool dirty = true, bool clip = true);
Romain Guy735738c2012-12-03 12:34:51 -0800681
682 /**
Romain Guy54be1cd2011-06-13 19:04:27 -0700683 * Draws the shape represented by the specified path texture.
684 * This method invokes drawPathTexture() but takes into account
685 * the extra left/top offset and the texture offset to correctly
686 * position the final shape.
687 *
688 * @param left The left coordinate of the shape to render
689 * @param top The top coordinate of the shape to render
690 * @param texture The texture reprsenting the shape
691 * @param paint The paint to draw the shape with
692 */
Chris Craik30036092015-02-12 10:41:39 -0800693 void drawShape(float left, float top, PathTexture* texture, const SkPaint* paint);
Romain Guy54be1cd2011-06-13 19:04:27 -0700694
695 /**
Chris Craik65cd6122012-12-10 17:56:27 -0800696 * Renders a strip of polygons with the specified paint, used for tessellated geometry.
697 *
698 * @param vertexBuffer The VertexBuffer to be drawn
699 * @param paint The paint to render with
Chris Craikbf759452014-08-11 16:00:44 -0700700 * @param flags flags with which to draw
Chris Craik65cd6122012-12-10 17:56:27 -0800701 */
Tom Hudson107843d2014-09-08 11:26:26 -0400702 void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
Chris Craikbf759452014-08-11 16:00:44 -0700703 const SkPaint* paint, int flags = 0);
Chris Craik65cd6122012-12-10 17:56:27 -0800704
705 /**
Chris Craik05f3d6e2014-06-02 16:27:04 -0700706 * Convenience for translating method
707 */
Tom Hudson107843d2014-09-08 11:26:26 -0400708 void drawVertexBuffer(const VertexBuffer& vertexBuffer,
Chris Craikbf759452014-08-11 16:00:44 -0700709 const SkPaint* paint, int flags = 0) {
Tom Hudson107843d2014-09-08 11:26:26 -0400710 drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
Chris Craik05f3d6e2014-06-02 16:27:04 -0700711 }
712
713 /**
Chris Craik710f46d2012-09-17 17:25:49 -0700714 * Renders the convex hull defined by the specified path as a strip of polygons.
Romain Guy54be1cd2011-06-13 19:04:27 -0700715 *
Chris Craik710f46d2012-09-17 17:25:49 -0700716 * @param path The hull of the path to draw
Chris Craikcb4d6002012-09-25 12:00:29 -0700717 * @param paint The paint to render with
Romain Guy54be1cd2011-06-13 19:04:27 -0700718 */
Tom Hudson107843d2014-09-08 11:26:26 -0400719 void drawConvexPath(const SkPath& path, const SkPaint* paint);
Chet Haase858aa932011-05-12 09:06:00 -0700720
Romain Guy5cbbce52010-06-27 22:59:20 -0700721 /**
Romain Guy0a417492010-08-16 20:26:20 -0700722 * Draws text underline and strike-through if needed.
723 *
724 * @param text The text to decor
725 * @param bytesCount The number of bytes in the text
Chris Craik41541822013-05-03 16:35:54 -0700726 * @param totalAdvance The total advance in pixels, defines underline/strikethrough length
Romain Guy0a417492010-08-16 20:26:20 -0700727 * @param x The x coordinate where the text will be drawn
728 * @param y The y coordinate where the text will be drawn
729 * @param paint The paint to draw the text with
730 */
Chris Craikd218a922014-01-02 17:13:34 -0800731 void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint);
Romain Guy1e45aae2010-08-13 19:39:53 -0700732
Raph Levien416a8472012-07-19 22:48:17 -0700733 /**
734 * Draws shadow layer on text (with optional positions).
735 *
736 * @param paint The paint to draw the shadow with
737 * @param text The text to draw
738 * @param bytesCount The number of bytes in the text
739 * @param count The number of glyphs in the text
740 * @param positions The x, y positions of individual glyphs (or NULL)
741 * @param fontRenderer The font renderer object
742 * @param alpha The alpha value for drawing the shadow
Raph Levien416a8472012-07-19 22:48:17 -0700743 * @param x The x coordinate where the shadow will be drawn
744 * @param y The y coordinate where the shadow will be drawn
745 */
Chris Craikd218a922014-01-02 17:13:34 -0800746 void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count,
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500747 const float* positions, FontRenderer& fontRenderer, int alpha,
Raph Levien416a8472012-07-19 22:48:17 -0700748 float x, float y);
749
Romain Guy54be1cd2011-06-13 19:04:27 -0700750 /**
751 * Draws a path texture. Path textures are alpha8 bitmaps that need special
752 * compositing to apply colors/filters/etc.
753 *
754 * @param texture The texture to render
755 * @param x The x coordinate where the texture will be drawn
756 * @param y The y coordinate where the texture will be drawn
757 * @param paint The paint to draw the texture with
758 */
Chris Craik30036092015-02-12 10:41:39 -0800759 void drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800760
Romain Guy1e45aae2010-08-13 19:39:53 -0700761 /**
Romain Guyac670c02010-07-27 17:39:27 -0700762 * Resets the texture coordinates stored in mMeshVertices. Setting the values
Romain Guy026c5e162010-06-28 17:12:22 -0700763 * back to default is achieved by calling:
764 *
Romain Guy8ba548f2010-06-30 19:21:21 -0700765 * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
Romain Guy026c5e162010-06-28 17:12:22 -0700766 *
767 * @param u1 The left coordinate of the texture
768 * @param v1 The bottom coordinate of the texture
769 * @param u2 The right coordinate of the texture
770 * @param v2 The top coordinate of the texture
771 */
772 void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
773
Romain Guy8ba548f2010-06-30 19:21:21 -0700774 /**
Romain Guy768bffc2013-02-27 13:50:45 -0800775 * Returns true if the specified paint will draw invisible text.
776 */
777 bool canSkipText(const SkPaint* paint) const;
778
Romain Guy11cb6422012-09-21 00:39:43 -0700779 bool updateLayer(Layer* layer, bool inFrame);
780 void updateLayers();
Romain Guy96885eb2013-03-26 15:05:58 -0700781 void flushLayers();
Romain Guy11cb6422012-09-21 00:39:43 -0700782
Chris Craike63f7c622013-10-17 10:30:55 -0700783#if DEBUG_LAYERS_AS_REGIONS
Romain Guy17112ad2012-08-07 11:24:39 -0700784 /**
785 * Renders the specified region as a series of rectangles. This method
786 * is used for debugging only.
787 */
Chris Craike63f7c622013-10-17 10:30:55 -0700788 void drawRegionRectsDebug(const Region& region);
789#endif
Romain Guy3a3133d2011-02-01 22:59:58 -0800790
Romain Guy8ce00302013-01-15 18:51:42 -0800791 /**
792 * Renders the specified region as a series of rectangles. The region
793 * must be in screen-space coordinates.
794 */
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -0500795 void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false);
Romain Guy8ce00302013-01-15 18:51:42 -0800796
797 /**
798 * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
799 * is turned on.
800 */
801 void debugClip();
802
Romain Guy7c450aa2012-09-21 19:15:00 -0700803 void debugOverdraw(bool enable, bool clear);
804 void renderOverdraw();
Romain Guy78dd96d2013-05-03 14:24:16 -0700805 void countOverdraw();
Romain Guy7c450aa2012-09-21 19:15:00 -0700806
Romain Guy746b7402010-10-26 16:27:31 -0700807 /**
808 * Should be invoked every time the glScissor is modified.
809 */
Tom Hudson984162f2014-10-10 13:38:16 -0400810 inline void dirtyClip() { mState.setDirtyClip(true); }
Romain Guy746b7402010-10-26 16:27:31 -0700811
Romain Guy3b748a42013-04-17 18:54:38 -0700812 inline const UvMapper& getMapper(const Texture* texture) {
813 return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
814 }
815
816 /**
817 * Returns a texture object for the specified bitmap. The texture can
818 * come from the texture cache or an atlas. If this method returns
819 * NULL, the texture could not be found and/or allocated.
820 */
Chris Craikd218a922014-01-02 17:13:34 -0800821 Texture* getTexture(const SkBitmap* bitmap);
Romain Guy3b748a42013-04-17 18:54:38 -0700822
Tom Hudson107843d2014-09-08 11:26:26 -0400823 bool reportAndClearDirty() { bool ret = mDirty; mDirty = false; return ret; }
Tom Hudson984162f2014-10-10 13:38:16 -0400824 inline Snapshot* writableSnapshot() { return mState.writableSnapshot(); }
825 inline const Snapshot* currentSnapshot() const { return mState.currentSnapshot(); }
Tom Hudson107843d2014-09-08 11:26:26 -0400826
Romain Guy2b7028e2012-09-19 17:25:38 -0700827 // State used to define the clipping region
Chris Craik5f803622013-03-21 14:39:04 -0700828 Rect mTilingClip;
Romain Guy96885eb2013-03-26 15:05:58 -0700829 // Is the target render surface opaque
830 bool mOpaque;
831 // Is a frame currently being rendered
832 bool mFrameStarted;
Romain Guy9d5316e2010-06-24 19:30:36 -0700833
Romain Guy3b748a42013-04-17 18:54:38 -0700834 // Default UV mapper
835 const UvMapper mUvMapper;
836
Romain Guy8f3b8e32012-03-27 16:33:45 -0700837 // List of rectangles to clear after saveLayer() is invoked
Chris Craik51d6a3d2014-12-22 17:16:56 -0800838 std::vector<Rect> mLayers;
Romain Guy11cb6422012-09-21 00:39:43 -0700839 // List of layers to update at the beginning of a frame
John Reck272a6852015-07-29 16:48:58 -0700840 std::vector< sp<Layer> > mLayerUpdates;
Romain Guy54be1cd2011-06-13 19:04:27 -0700841
Romain Guy87e2f7572012-09-24 11:37:12 -0700842 // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
843 // Properties.h
844 bool mScissorOptimizationDisabled;
845
Chris Craikdeeda3d2014-05-05 19:09:33 -0700846 bool mSkipOutlineClip;
847
Tom Hudson107843d2014-09-08 11:26:26 -0400848 // True if anything has been drawn since the last call to
849 // reportAndClearDirty()
850 bool mDirty;
851
Chris Craik058fc642014-07-23 18:19:28 -0700852 // Lighting + shadows
853 Vector3 mLightCenter;
854 float mLightRadius;
855 uint8_t mAmbientShadowAlpha;
856 uint8_t mSpotShadowAlpha;
857
Chris Craik4ac36f82014-12-09 16:54:03 -0800858 // Paths kept alive for the duration of the frame
Chris Craik51d6a3d2014-12-22 17:16:56 -0800859 std::vector<std::unique_ptr<SkPath>> mTempPaths;
Chris Craik4ac36f82014-12-09 16:54:03 -0800860
Tom Hudsonac7b6d32015-06-30 11:26:13 -0400861 /**
862 * Initial transform for a rendering pass; transform from global device
863 * coordinates to the current RenderNode's drawing content coordinates,
864 * with the RenderNode's RenderProperty transforms already applied.
865 * Calling setMatrix(mBaseTransform) will result in drawing at the origin
866 * of the DisplayList's recorded surface prior to any Canvas
867 * transformation.
868 */
869 Matrix4 mBaseTransform;
870
Romain Guy96885eb2013-03-26 15:05:58 -0700871 friend class Layer;
Chris Craik82840732015-04-03 09:37:49 -0700872 friend class TextDrawFunctor;
Romain Guy03c00b52013-06-20 18:30:28 -0700873 friend class DrawBitmapOp;
874 friend class DrawPatchOp;
Romain Guyb051e892010-09-28 19:09:36 -0700875
Romain Guybb9524b2010-06-22 18:56:38 -0700876}; // class OpenGLRenderer
Romain Guye4d01122010-06-16 18:44:05 -0700877
Romain Guy9d5316e2010-06-24 19:30:36 -0700878}; // namespace uirenderer
Romain Guye4d01122010-06-16 18:44:05 -0700879}; // namespace android
880
Romain Guy5b3b3522010-10-27 18:57:51 -0700881#endif // ANDROID_HWUI_OPENGL_RENDERER_H