blob: b210e64588310d92001b1271a157f4102f069f1a [file] [log] [blame]
Romain Guy4aa90572010-09-26 18:40:37 -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
17#define LOG_TAG "OpenGLRenderer"
18
Romain Guyd5a85fb2012-03-13 11:18:20 -070019#include <SkCamera.h>
Romain Guyc46d07a2013-03-15 19:06:39 -070020#include <SkCanvas.h>
Chet Haase9c1e23b2011-03-24 10:51:31 -070021
Romain Guy65549432012-03-26 16:45:05 -070022#include <private/hwui/DrawGlInfo.h>
23
John Reck113e0822014-03-18 09:22:59 -070024#include "Caches.h"
Chris Craikc3566d02013-02-04 16:16:33 -080025#include "DeferredDisplayList.h"
Chet Haase9c1e23b2011-03-24 10:51:31 -070026#include "DisplayListLogBuffer.h"
Chris Craik2af46352012-11-26 18:30:17 -080027#include "DisplayListOp.h"
Romain Guy4aa90572010-09-26 18:40:37 -070028#include "DisplayListRenderer.h"
John Reck113e0822014-03-18 09:22:59 -070029#include "RenderNode.h"
Romain Guy13631f32012-01-30 17:41:55 -080030
Romain Guy4aa90572010-09-26 18:40:37 -070031namespace android {
32namespace uirenderer {
33
Chris Craikcce47eb2014-07-16 15:12:15 -070034DisplayListRenderer::DisplayListRenderer()
35 : mCaches(Caches::getInstance())
36 , mDisplayListData(0)
37 , mTranslateX(0.0f)
38 , mTranslateY(0.0f)
39 , mHasTranslate(false)
40 , mHighContrastText(false)
41 , mRestoreSaveCount(-1) {
Romain Guy4aa90572010-09-26 18:40:37 -070042}
43
44DisplayListRenderer::~DisplayListRenderer() {
John Reck44fd8d22014-02-26 11:00:11 -080045 LOG_ALWAYS_FATAL_IF(mDisplayListData,
46 "Destroyed a DisplayListRenderer during a record!");
Romain Guy4aa90572010-09-26 18:40:37 -070047}
48
49///////////////////////////////////////////////////////////////////////////////
50// Operations
51///////////////////////////////////////////////////////////////////////////////
52
John Reck44fd8d22014-02-26 11:00:11 -080053DisplayListData* DisplayListRenderer::finishRecording() {
John Reck44fd8d22014-02-26 11:00:11 -080054 mPaintMap.clear();
55 mRegionMap.clear();
56 mPathMap.clear();
57 DisplayListData* data = mDisplayListData;
58 mDisplayListData = 0;
59 return data;
Chet Haase5977baa2011-01-05 18:01:22 -080060}
61
Romain Guy7c25aab2012-10-18 15:05:02 -070062status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -080063 float right, float bottom, bool opaque) {
John Reck44fd8d22014-02-26 11:00:11 -080064
65 LOG_ALWAYS_FATAL_IF(mDisplayListData,
66 "prepareDirty called a second time during a recording!");
67 mDisplayListData = new DisplayListData();
68
Chris Craik14e51302013-12-30 15:32:54 -080069 initializeSaveStack(0, 0, getWidth(), getHeight());
Romain Guy45e4c3d2012-09-11 17:17:07 -070070
Romain Guy45e4c3d2012-09-11 17:17:07 -070071 mDirtyClip = opaque;
Romain Guy27454a42011-01-23 12:01:41 -080072 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -070073
Chet Haase44b2fe32012-06-06 19:03:58 -070074 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -080075}
76
77void DisplayListRenderer::finish() {
78 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -080079 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -070080}
81
Chet Haasedaf98e92011-01-10 14:10:36 -080082void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -080083}
Romain Guy2b1847e2011-01-26 13:43:01 -080084
Chet Haasedaf98e92011-01-10 14:10:36 -080085void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -070086}
87
Romain Guy65549432012-03-26 16:45:05 -070088status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -080089 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -080090 addDrawOp(new (alloc()) DrawFunctorOp(functor));
John Reck09d5cdd2014-07-24 10:36:08 -070091 mDisplayListData->functors.add(functor);
Romain Guy65549432012-03-26 16:45:05 -070092 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -080093}
94
Romain Guy4aa90572010-09-26 18:40:37 -070095int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -080096 addStateOp(new (alloc()) SaveOp(flags));
Chris Craik14e51302013-12-30 15:32:54 -080097 return StatefulBaseRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -070098}
99
100void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700101 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800102 restoreToCount(getSaveCount() - 1);
103 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700104 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800105
106 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800107 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800108 StatefulBaseRenderer::restore();
Romain Guy4aa90572010-09-26 18:40:37 -0700109}
110
111void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800112 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800113 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800114 StatefulBaseRenderer::restoreToCount(saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700115}
116
117int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500118 const SkPaint* paint, int flags) {
119 paint = refPaint(paint);
120 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, flags));
Chris Craik14e51302013-12-30 15:32:54 -0800121 return StatefulBaseRenderer::save(flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700122}
123
Chris Craikb4589422013-12-26 15:13:13 -0800124void DisplayListRenderer::translate(float dx, float dy, float dz) {
125 // ignore dz, not used at defer time
Romain Guy33f6beb2012-02-16 19:24:51 -0800126 mHasTranslate = true;
127 mTranslateX += dx;
128 mTranslateY += dy;
129 insertRestoreToCount();
Chris Craik14e51302013-12-30 15:32:54 -0800130 StatefulBaseRenderer::translate(dx, dy, dz);
Romain Guy4aa90572010-09-26 18:40:37 -0700131}
132
133void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800134 addStateOp(new (alloc()) RotateOp(degrees));
Chris Craik14e51302013-12-30 15:32:54 -0800135 StatefulBaseRenderer::rotate(degrees);
Romain Guy4aa90572010-09-26 18:40:37 -0700136}
137
138void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800139 addStateOp(new (alloc()) ScaleOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800140 StatefulBaseRenderer::scale(sx, sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700141}
142
Romain Guy807daf72011-01-18 11:19:19 -0800143void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800144 addStateOp(new (alloc()) SkewOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800145 StatefulBaseRenderer::skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800146}
147
Derek Sollenberger13908822013-12-10 12:28:58 -0500148void DisplayListRenderer::setMatrix(const SkMatrix& matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800149 addStateOp(new (alloc()) SetMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800150 StatefulBaseRenderer::setMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700151}
152
Derek Sollenberger13908822013-12-10 12:28:58 -0500153void DisplayListRenderer::concatMatrix(const SkMatrix& matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800154 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800155 StatefulBaseRenderer::concatMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700156}
157
158bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
159 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800160 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800161 return StatefulBaseRenderer::clipRect(left, top, right, bottom, op);
Romain Guy4aa90572010-09-26 18:40:37 -0700162}
163
Chris Craikd218a922014-01-02 17:13:34 -0800164bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800165 path = refPath(path);
166 addStateOp(new (alloc()) ClipPathOp(path, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800167 return StatefulBaseRenderer::clipPath(path, op);
Romain Guy735738c2012-12-03 12:34:51 -0800168}
169
Chris Craikd218a922014-01-02 17:13:34 -0800170bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800171 region = refRegion(region);
172 addStateOp(new (alloc()) ClipRegionOp(region, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800173 return StatefulBaseRenderer::clipRegion(region, op);
Romain Guy735738c2012-12-03 12:34:51 -0800174}
175
Chris Craika7090e02014-06-20 16:01:00 -0700176status_t DisplayListRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800177 // dirty is an out parameter and should not be recorded,
178 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700179
Chris Craika7090e02014-06-20 16:01:00 -0700180 if (renderNode->stagingProperties().isProjectionReceiver()) {
Chris Craik3f0854292014-04-15 16:18:08 -0700181 // use staging property, since recording on UI thread
182 mDisplayListData->projectionReceiveIndex = mDisplayListData->displayListOps.size();
183 }
Chris Craik2af46352012-11-26 18:30:17 -0800184
Chris Craika7090e02014-06-20 16:01:00 -0700185 DrawRenderNodeOp* op = new (alloc()) DrawRenderNodeOp(renderNode, flags, *currentTransform());
Chris Craikf57776b2013-10-25 18:30:17 -0700186 addDrawOp(op);
John Reck087bc0c2014-04-04 16:20:08 -0700187 mDisplayListData->addChild(op);
Romain Guy65549432012-03-26 16:45:05 -0700188 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800189}
190
Chris Craika08f95c2013-03-15 17:24:33 -0700191status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700192 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700193 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700194 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800195}
196
Chris Craik79647502014-08-06 13:42:24 -0700197status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800198 bitmap = refBitmap(bitmap);
199 paint = refPaint(paint);
200
Chris Craik79647502014-08-06 13:42:24 -0700201 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, paint));
Chet Haase48659092012-05-31 15:21:51 -0700202 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700203}
204
Chris Craikd218a922014-01-02 17:13:34 -0800205status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700206 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800207 float dstRight, float dstBottom, const SkPaint* paint) {
Chris Craik79647502014-08-06 13:42:24 -0700208 if (srcLeft == 0 && srcTop == 0
209 && srcRight == bitmap->width() && srcBottom == bitmap->height()
210 && (srcBottom - srcTop == dstBottom - dstTop)
211 && (srcRight - srcLeft == dstRight - dstLeft)) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800212 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Chris Craik79647502014-08-06 13:42:24 -0700213 save(SkCanvas::kMatrix_SaveFlag);
214 translate(dstLeft, dstTop);
215 drawBitmap(bitmap, paint);
216 restore();
217 } else {
218 bitmap = refBitmap(bitmap);
219 paint = refPaint(paint);
Chris Craik527a3aa2013-03-04 10:19:31 -0800220
Chris Craik79647502014-08-06 13:42:24 -0700221 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
222 srcLeft, srcTop, srcRight, srcBottom,
223 dstLeft, dstTop, dstRight, dstBottom, paint));
224 }
Chet Haase48659092012-05-31 15:21:51 -0700225 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700226}
227
Chris Craik79647502014-08-06 13:42:24 -0700228status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800229 bitmap = refBitmapData(bitmap);
230 paint = refPaint(paint);
231
Chris Craik79647502014-08-06 13:42:24 -0700232 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, paint));
Chet Haase48659092012-05-31 15:21:51 -0700233 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700234}
235
Chris Craikd218a922014-01-02 17:13:34 -0800236status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
237 const float* vertices, const int* colors, const SkPaint* paint) {
Chris Craik0664fef2014-04-11 13:40:05 -0700238 int vertexCount = (meshWidth + 1) * (meshHeight + 1);
Chris Craik2af46352012-11-26 18:30:17 -0800239 bitmap = refBitmap(bitmap);
Chris Craik0664fef2014-04-11 13:40:05 -0700240 vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800241 paint = refPaint(paint);
Chris Craik0664fef2014-04-11 13:40:05 -0700242 colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800243
244 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
245 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700246 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800247}
248
Chris Craikd218a922014-01-02 17:13:34 -0800249status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
250 float left, float top, float right, float bottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800251 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700252 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700253 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800254
Romain Guy03c00b52013-06-20 18:30:28 -0700255 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700256 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700257}
258
Chet Haase48659092012-05-31 15:21:51 -0700259status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800260 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700261 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700262}
263
Chet Haase48659092012-05-31 15:21:51 -0700264status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800265 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800266 paint = refPaint(paint);
267 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700268 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700269}
270
Chet Haase48659092012-05-31 15:21:51 -0700271status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800272 float rx, float ry, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800273 paint = refPaint(paint);
274 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700275 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800276}
277
Chris Craikd218a922014-01-02 17:13:34 -0800278status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800279 paint = refPaint(paint);
280 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700281 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800282}
283
John Reck52244ff2014-05-01 21:27:37 -0700284status_t DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
285 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
286 mDisplayListData->refProperty(x);
287 mDisplayListData->refProperty(y);
288 mDisplayListData->refProperty(radius);
289 mDisplayListData->refProperty(paint);
290 addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value,
291 &radius->value, &paint->value));
292 return DrawGlInfo::kStatusDone;
293}
294
Chet Haase48659092012-05-31 15:21:51 -0700295status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800296 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800297 paint = refPaint(paint);
298 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700299 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800300}
301
Chet Haase48659092012-05-31 15:21:51 -0700302status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800303 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) {
Chris Craik544e5242014-07-11 10:58:10 -0700304 if (fabs(sweepAngle) >= 360.0f) {
Chris Craik6ac174b2014-06-17 13:47:05 -0700305 return drawOval(left, top, right, bottom, paint);
306 }
307
Chris Craik2af46352012-11-26 18:30:17 -0800308 paint = refPaint(paint);
309 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
310 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700311 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800312}
313
Chris Craikd218a922014-01-02 17:13:34 -0800314status_t DisplayListRenderer::drawPath(const SkPath* path, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800315 path = refPath(path);
316 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800317
Chris Craik2af46352012-11-26 18:30:17 -0800318 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700319 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700320}
321
Chris Craikd218a922014-01-02 17:13:34 -0800322status_t DisplayListRenderer::drawLines(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800323 points = refBuffer<float>(points, count);
324 paint = refPaint(paint);
325
326 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700327 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700328}
329
Chris Craikd218a922014-01-02 17:13:34 -0800330status_t DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800331 points = refBuffer<float>(points, count);
332 paint = refPaint(paint);
333
334 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700335 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700336}
337
Chet Haase48659092012-05-31 15:21:51 -0700338status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800339 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700340 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800341
Chris Craik2af46352012-11-26 18:30:17 -0800342 text = refText(text, bytesCount);
343 path = refPath(path);
344 paint = refPaint(paint);
345
346 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
347 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800348 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700349 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800350}
351
Chet Haase48659092012-05-31 15:21:51 -0700352status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800353 const float* positions, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700354 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800355
Chris Craik2af46352012-11-26 18:30:17 -0800356 text = refText(text, bytesCount);
357 positions = refBuffer<float>(positions, count * 2);
358 paint = refPaint(paint);
359
360 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800361 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700362 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800363}
364
Chris Craikcce47eb2014-07-16 15:12:15 -0700365static void simplifyPaint(int color, SkPaint* paint) {
366 paint->setColor(color);
367 paint->setShader(NULL);
368 paint->setColorFilter(NULL);
369 paint->setLooper(NULL);
370 paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
371 paint->setStrokeJoin(SkPaint::kRound_Join);
372 paint->setLooper(NULL);
373}
374
Romain Guyc2525952012-07-27 16:41:22 -0700375status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800376 float x, float y, const float* positions, const SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700377 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800378
Raph Levien996e57c2012-07-23 15:22:52 -0700379 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
380
Chris Craik2af46352012-11-26 18:30:17 -0800381 text = refText(text, bytesCount);
382 positions = refBuffer<float>(positions, count * 2);
Raph Levien996e57c2012-07-23 15:22:52 -0700383
Chris Craikcce47eb2014-07-16 15:12:15 -0700384 if (CC_UNLIKELY(mHighContrastText)) {
385 // high contrast draw path
386 int color = paint->getColor();
387 int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
388 bool darken = channelSum < (128 * 3);
389
390 // outline
391 SkPaint* outlinePaint = copyPaint(paint);
392 simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, outlinePaint);
393 outlinePaint->setStyle(SkPaint::kStrokeAndFill_Style);
394 addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
395 x, y, positions, outlinePaint, totalAdvance, bounds)); // bounds?
396
397 // inner
398 SkPaint* innerPaint = copyPaint(paint);
399 simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, innerPaint);
400 innerPaint->setStyle(SkPaint::kFill_Style);
401 addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
402 x, y, positions, innerPaint, totalAdvance, bounds));
403 } else {
404 // standard draw path
405 paint = refPaint(paint);
406
407 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
408 x, y, positions, paint, totalAdvance, bounds);
409 addDrawOp(op);
410 }
Raph Levien996e57c2012-07-23 15:22:52 -0700411 return DrawGlInfo::kStatusDone;
412}
413
Chris Craikd218a922014-01-02 17:13:34 -0800414status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800415 if (count <= 0) return DrawGlInfo::kStatusDone;
416
Chris Craik2af46352012-11-26 18:30:17 -0800417 rects = refBuffer<float>(rects, count);
418 paint = refPaint(paint);
419 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800420 return DrawGlInfo::kStatusDone;
421}
422
Romain Guy5ff9df62012-01-23 17:09:05 -0800423void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800424 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800425}
426
427void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800428 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
429}
430
431void DisplayListRenderer::insertRestoreToCount() {
432 if (mRestoreSaveCount >= 0) {
433 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
434 mDisplayListData->displayListOps.add(op);
435 mRestoreSaveCount = -1;
436 }
437}
438
439void DisplayListRenderer::insertTranslate() {
440 if (mHasTranslate) {
441 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
442 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
443 mDisplayListData->displayListOps.add(op);
444 mTranslateX = mTranslateY = 0.0f;
445 }
446 mHasTranslate = false;
447 }
448}
449
450void DisplayListRenderer::addStateOp(StateOp* op) {
451 addOpInternal(op);
452}
453
Romain Guy0f667532013-03-01 14:31:04 -0800454void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800455 Rect localBounds;
John Reck3b202512014-06-23 13:13:08 -0700456 if (op->getLocalBounds(localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800457 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800458 localBounds.right, localBounds.bottom);
459 op->setQuickRejected(rejected);
460 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700461
John Reck44fd8d22014-02-26 11:00:11 -0800462 mDisplayListData->hasDrawOps = true;
Chris Craik2af46352012-11-26 18:30:17 -0800463 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800464}
465
Romain Guy4aa90572010-09-26 18:40:37 -0700466}; // namespace uirenderer
467}; // namespace android