blob: c7dc29bbcebdaabd6f8acf79f1368b9b7d579cb6 [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 Reck44fd8d22014-02-26 11:00:11 -080091 mDisplayListData->functorCount++;
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 Craikd218a922014-01-02 17:13:34 -0800197status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
198 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800199 bitmap = refBitmap(bitmap);
200 paint = refPaint(paint);
201
Romain Guy55b6f952013-06-27 15:27:09 -0700202 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700203 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700204}
205
Derek Sollenberger13908822013-12-10 12:28:58 -0500206status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
Chris Craikd218a922014-01-02 17:13:34 -0800207 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800208 bitmap = refBitmap(bitmap);
Chris Craik2af46352012-11-26 18:30:17 -0800209 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800210
Chris Craik2af46352012-11-26 18:30:17 -0800211 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
Chet Haase48659092012-05-31 15:21:51 -0700212 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700213}
214
Chris Craikd218a922014-01-02 17:13:34 -0800215status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700216 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800217 float dstRight, float dstBottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800218 bitmap = refBitmap(bitmap);
219 paint = refPaint(paint);
220
Chris Craik527a3aa2013-03-04 10:19:31 -0800221 if (srcLeft == 0 && srcTop == 0 &&
222 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
223 (srcBottom - srcTop == dstBottom - dstTop) &&
224 (srcRight - srcLeft == dstRight - dstLeft)) {
225 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy55b6f952013-06-27 15:27:09 -0700226 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
Chris Craik527a3aa2013-03-04 10:19:31 -0800227 return DrawGlInfo::kStatusDone;
228 }
229
Chris Craik2af46352012-11-26 18:30:17 -0800230 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
231 srcLeft, srcTop, srcRight, srcBottom,
232 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700233 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700234}
235
Chris Craikd218a922014-01-02 17:13:34 -0800236status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
237 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800238 bitmap = refBitmapData(bitmap);
239 paint = refPaint(paint);
240
241 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700242 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700243}
244
Chris Craikd218a922014-01-02 17:13:34 -0800245status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
246 const float* vertices, const int* colors, const SkPaint* paint) {
Chris Craik0664fef2014-04-11 13:40:05 -0700247 int vertexCount = (meshWidth + 1) * (meshHeight + 1);
Chris Craik2af46352012-11-26 18:30:17 -0800248 bitmap = refBitmap(bitmap);
Chris Craik0664fef2014-04-11 13:40:05 -0700249 vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800250 paint = refPaint(paint);
Chris Craik0664fef2014-04-11 13:40:05 -0700251 colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800252
253 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
254 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700255 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800256}
257
Chris Craikd218a922014-01-02 17:13:34 -0800258status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
259 float left, float top, float right, float bottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800260 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700261 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700262 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800263
Romain Guy03c00b52013-06-20 18:30:28 -0700264 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700265 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700266}
267
Chet Haase48659092012-05-31 15:21:51 -0700268status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800269 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700270 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700271}
272
Chet Haase48659092012-05-31 15:21:51 -0700273status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800274 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800275 paint = refPaint(paint);
276 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700277 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700278}
279
Chet Haase48659092012-05-31 15:21:51 -0700280status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800281 float rx, float ry, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800282 paint = refPaint(paint);
283 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700284 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800285}
286
Chris Craikd218a922014-01-02 17:13:34 -0800287status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800288 paint = refPaint(paint);
289 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700290 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800291}
292
John Reck52244ff2014-05-01 21:27:37 -0700293status_t DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
294 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
295 mDisplayListData->refProperty(x);
296 mDisplayListData->refProperty(y);
297 mDisplayListData->refProperty(radius);
298 mDisplayListData->refProperty(paint);
299 addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value,
300 &radius->value, &paint->value));
301 return DrawGlInfo::kStatusDone;
302}
303
Chet Haase48659092012-05-31 15:21:51 -0700304status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800305 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800306 paint = refPaint(paint);
307 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700308 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800309}
310
Chet Haase48659092012-05-31 15:21:51 -0700311status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800312 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) {
Chris Craik544e5242014-07-11 10:58:10 -0700313 if (fabs(sweepAngle) >= 360.0f) {
Chris Craik6ac174b2014-06-17 13:47:05 -0700314 return drawOval(left, top, right, bottom, paint);
315 }
316
Chris Craik2af46352012-11-26 18:30:17 -0800317 paint = refPaint(paint);
318 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
319 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700320 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800321}
322
Chris Craikd218a922014-01-02 17:13:34 -0800323status_t DisplayListRenderer::drawPath(const SkPath* path, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800324 path = refPath(path);
325 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800326
Chris Craik2af46352012-11-26 18:30:17 -0800327 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700328 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700329}
330
Chris Craikd218a922014-01-02 17:13:34 -0800331status_t DisplayListRenderer::drawLines(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800332 points = refBuffer<float>(points, count);
333 paint = refPaint(paint);
334
335 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700336 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700337}
338
Chris Craikd218a922014-01-02 17:13:34 -0800339status_t DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800340 points = refBuffer<float>(points, count);
341 paint = refPaint(paint);
342
343 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700344 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700345}
346
Chet Haase48659092012-05-31 15:21:51 -0700347status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800348 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700349 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800350
Chris Craik2af46352012-11-26 18:30:17 -0800351 text = refText(text, bytesCount);
352 path = refPath(path);
353 paint = refPaint(paint);
354
355 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
356 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800357 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700358 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800359}
360
Chet Haase48659092012-05-31 15:21:51 -0700361status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800362 const float* positions, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700363 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800364
Chris Craik2af46352012-11-26 18:30:17 -0800365 text = refText(text, bytesCount);
366 positions = refBuffer<float>(positions, count * 2);
367 paint = refPaint(paint);
368
369 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800370 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700371 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800372}
373
Chris Craikcce47eb2014-07-16 15:12:15 -0700374static void simplifyPaint(int color, SkPaint* paint) {
375 paint->setColor(color);
376 paint->setShader(NULL);
377 paint->setColorFilter(NULL);
378 paint->setLooper(NULL);
379 paint->setStrokeWidth(4 + 0.04 * paint->getTextSize());
380 paint->setStrokeJoin(SkPaint::kRound_Join);
381 paint->setLooper(NULL);
382}
383
Romain Guyc2525952012-07-27 16:41:22 -0700384status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800385 float x, float y, const float* positions, const SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700386 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800387
Raph Levien996e57c2012-07-23 15:22:52 -0700388 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
389
Chris Craik2af46352012-11-26 18:30:17 -0800390 text = refText(text, bytesCount);
391 positions = refBuffer<float>(positions, count * 2);
Raph Levien996e57c2012-07-23 15:22:52 -0700392
Chris Craikcce47eb2014-07-16 15:12:15 -0700393 if (CC_UNLIKELY(mHighContrastText)) {
394 // high contrast draw path
395 int color = paint->getColor();
396 int channelSum = SkColorGetR(color) + SkColorGetG(color) + SkColorGetB(color);
397 bool darken = channelSum < (128 * 3);
398
399 // outline
400 SkPaint* outlinePaint = copyPaint(paint);
401 simplifyPaint(darken ? SK_ColorWHITE : SK_ColorBLACK, outlinePaint);
402 outlinePaint->setStyle(SkPaint::kStrokeAndFill_Style);
403 addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
404 x, y, positions, outlinePaint, totalAdvance, bounds)); // bounds?
405
406 // inner
407 SkPaint* innerPaint = copyPaint(paint);
408 simplifyPaint(darken ? SK_ColorBLACK : SK_ColorWHITE, innerPaint);
409 innerPaint->setStyle(SkPaint::kFill_Style);
410 addDrawOp(new (alloc()) DrawTextOp(text, bytesCount, count,
411 x, y, positions, innerPaint, totalAdvance, bounds));
412 } else {
413 // standard draw path
414 paint = refPaint(paint);
415
416 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
417 x, y, positions, paint, totalAdvance, bounds);
418 addDrawOp(op);
419 }
Raph Levien996e57c2012-07-23 15:22:52 -0700420 return DrawGlInfo::kStatusDone;
421}
422
Chris Craikd218a922014-01-02 17:13:34 -0800423status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800424 if (count <= 0) return DrawGlInfo::kStatusDone;
425
Chris Craik2af46352012-11-26 18:30:17 -0800426 rects = refBuffer<float>(rects, count);
427 paint = refPaint(paint);
428 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800429 return DrawGlInfo::kStatusDone;
430}
431
Romain Guy5ff9df62012-01-23 17:09:05 -0800432void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800433 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800434}
435
436void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800437 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
438}
439
440void DisplayListRenderer::insertRestoreToCount() {
441 if (mRestoreSaveCount >= 0) {
442 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
443 mDisplayListData->displayListOps.add(op);
444 mRestoreSaveCount = -1;
445 }
446}
447
448void DisplayListRenderer::insertTranslate() {
449 if (mHasTranslate) {
450 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
451 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
452 mDisplayListData->displayListOps.add(op);
453 mTranslateX = mTranslateY = 0.0f;
454 }
455 mHasTranslate = false;
456 }
457}
458
459void DisplayListRenderer::addStateOp(StateOp* op) {
460 addOpInternal(op);
461}
462
Romain Guy0f667532013-03-01 14:31:04 -0800463void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800464 Rect localBounds;
John Reck3b202512014-06-23 13:13:08 -0700465 if (op->getLocalBounds(localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800466 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800467 localBounds.right, localBounds.bottom);
468 op->setQuickRejected(rejected);
469 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700470
John Reck44fd8d22014-02-26 11:00:11 -0800471 mDisplayListData->hasDrawOps = true;
Chris Craik2af46352012-11-26 18:30:17 -0800472 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800473}
474
Romain Guy4aa90572010-09-26 18:40:37 -0700475}; // namespace uirenderer
476}; // namespace android