blob: fc4d40bec43ff7c744aaa53f6fb3274c23799808 [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
Romain Guy58ecc202012-09-07 11:58:36 -070034DisplayListRenderer::DisplayListRenderer():
Chris Craikeea6ef92014-03-05 16:37:35 -080035 mCaches(Caches::getInstance()), mDisplayListData(0),
Romain Guy54c1a642012-09-27 17:55:46 -070036 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false),
Chris Craikeea6ef92014-03-05 16:37:35 -080037 mRestoreSaveCount(-1) {
Romain Guy4aa90572010-09-26 18:40:37 -070038}
39
40DisplayListRenderer::~DisplayListRenderer() {
John Reck44fd8d22014-02-26 11:00:11 -080041 LOG_ALWAYS_FATAL_IF(mDisplayListData,
42 "Destroyed a DisplayListRenderer during a record!");
Romain Guy4aa90572010-09-26 18:40:37 -070043}
44
45///////////////////////////////////////////////////////////////////////////////
46// Operations
47///////////////////////////////////////////////////////////////////////////////
48
John Reck44fd8d22014-02-26 11:00:11 -080049DisplayListData* DisplayListRenderer::finishRecording() {
John Reck44fd8d22014-02-26 11:00:11 -080050 mPaintMap.clear();
51 mRegionMap.clear();
52 mPathMap.clear();
53 DisplayListData* data = mDisplayListData;
54 mDisplayListData = 0;
55 return data;
Chet Haase5977baa2011-01-05 18:01:22 -080056}
57
Romain Guy7c25aab2012-10-18 15:05:02 -070058status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -080059 float right, float bottom, bool opaque) {
John Reck44fd8d22014-02-26 11:00:11 -080060
61 LOG_ALWAYS_FATAL_IF(mDisplayListData,
62 "prepareDirty called a second time during a recording!");
63 mDisplayListData = new DisplayListData();
64
Chris Craik14e51302013-12-30 15:32:54 -080065 initializeSaveStack(0, 0, getWidth(), getHeight());
Romain Guy45e4c3d2012-09-11 17:17:07 -070066
Romain Guy45e4c3d2012-09-11 17:17:07 -070067 mDirtyClip = opaque;
Romain Guy27454a42011-01-23 12:01:41 -080068 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -070069
Chet Haase44b2fe32012-06-06 19:03:58 -070070 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -080071}
72
73void DisplayListRenderer::finish() {
74 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -080075 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -070076}
77
Chet Haasedaf98e92011-01-10 14:10:36 -080078void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -080079}
Romain Guy2b1847e2011-01-26 13:43:01 -080080
Chet Haasedaf98e92011-01-10 14:10:36 -080081void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -070082}
83
Romain Guy65549432012-03-26 16:45:05 -070084status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -080085 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -080086 addDrawOp(new (alloc()) DrawFunctorOp(functor));
John Reck44fd8d22014-02-26 11:00:11 -080087 mDisplayListData->functorCount++;
Romain Guy65549432012-03-26 16:45:05 -070088 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -080089}
90
Romain Guy4aa90572010-09-26 18:40:37 -070091int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -080092 addStateOp(new (alloc()) SaveOp(flags));
Chris Craik14e51302013-12-30 15:32:54 -080093 return StatefulBaseRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -070094}
95
96void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -070097 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -080098 restoreToCount(getSaveCount() - 1);
99 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700100 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800101
102 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800103 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800104 StatefulBaseRenderer::restore();
Romain Guy4aa90572010-09-26 18:40:37 -0700105}
106
107void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800108 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800109 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800110 StatefulBaseRenderer::restoreToCount(saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700111}
112
113int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500114 const SkPaint* paint, int flags) {
115 paint = refPaint(paint);
116 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, flags));
Chris Craik14e51302013-12-30 15:32:54 -0800117 return StatefulBaseRenderer::save(flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700118}
119
Chris Craikb4589422013-12-26 15:13:13 -0800120void DisplayListRenderer::translate(float dx, float dy, float dz) {
121 // ignore dz, not used at defer time
Romain Guy33f6beb2012-02-16 19:24:51 -0800122 mHasTranslate = true;
123 mTranslateX += dx;
124 mTranslateY += dy;
125 insertRestoreToCount();
Chris Craik14e51302013-12-30 15:32:54 -0800126 StatefulBaseRenderer::translate(dx, dy, dz);
Romain Guy4aa90572010-09-26 18:40:37 -0700127}
128
129void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800130 addStateOp(new (alloc()) RotateOp(degrees));
Chris Craik14e51302013-12-30 15:32:54 -0800131 StatefulBaseRenderer::rotate(degrees);
Romain Guy4aa90572010-09-26 18:40:37 -0700132}
133
134void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800135 addStateOp(new (alloc()) ScaleOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800136 StatefulBaseRenderer::scale(sx, sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700137}
138
Romain Guy807daf72011-01-18 11:19:19 -0800139void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800140 addStateOp(new (alloc()) SkewOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800141 StatefulBaseRenderer::skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800142}
143
Derek Sollenberger13908822013-12-10 12:28:58 -0500144void DisplayListRenderer::setMatrix(const SkMatrix& matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800145 addStateOp(new (alloc()) SetMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800146 StatefulBaseRenderer::setMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700147}
148
Derek Sollenberger13908822013-12-10 12:28:58 -0500149void DisplayListRenderer::concatMatrix(const SkMatrix& matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800150 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800151 StatefulBaseRenderer::concatMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700152}
153
154bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
155 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800156 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800157 return StatefulBaseRenderer::clipRect(left, top, right, bottom, op);
Romain Guy4aa90572010-09-26 18:40:37 -0700158}
159
Chris Craikd218a922014-01-02 17:13:34 -0800160bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800161 path = refPath(path);
162 addStateOp(new (alloc()) ClipPathOp(path, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800163 return StatefulBaseRenderer::clipPath(path, op);
Romain Guy735738c2012-12-03 12:34:51 -0800164}
165
Chris Craikd218a922014-01-02 17:13:34 -0800166bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800167 region = refRegion(region);
168 addStateOp(new (alloc()) ClipRegionOp(region, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800169 return StatefulBaseRenderer::clipRegion(region, op);
Romain Guy735738c2012-12-03 12:34:51 -0800170}
171
John Recke18264b2014-03-12 13:56:30 -0700172status_t DisplayListRenderer::drawDisplayList(RenderNode* displayList,
Chris Craikc3566d02013-02-04 16:16:33 -0800173 Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800174 // dirty is an out parameter and should not be recorded,
175 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700176
Chris Craik3f0854292014-04-15 16:18:08 -0700177 if (displayList->stagingProperties().isProjectionReceiver()) {
178 // use staging property, since recording on UI thread
179 mDisplayListData->projectionReceiveIndex = mDisplayListData->displayListOps.size();
180 }
Chris Craik2af46352012-11-26 18:30:17 -0800181
Chris Craikd6b65f62014-01-01 14:45:21 -0800182 DrawDisplayListOp* op = new (alloc()) DrawDisplayListOp(displayList,
183 flags, *currentTransform());
Chris Craikf57776b2013-10-25 18:30:17 -0700184 addDrawOp(op);
John Reck087bc0c2014-04-04 16:20:08 -0700185 mDisplayListData->addChild(op);
Romain Guy65549432012-03-26 16:45:05 -0700186 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800187}
188
Chris Craika08f95c2013-03-15 17:24:33 -0700189status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700190 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700191 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700192 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800193}
194
Chris Craikd218a922014-01-02 17:13:34 -0800195status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
196 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800197 bitmap = refBitmap(bitmap);
198 paint = refPaint(paint);
199
Romain Guy55b6f952013-06-27 15:27:09 -0700200 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700201 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700202}
203
Derek Sollenberger13908822013-12-10 12:28:58 -0500204status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
Chris Craikd218a922014-01-02 17:13:34 -0800205 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800206 bitmap = refBitmap(bitmap);
Chris Craik2af46352012-11-26 18:30:17 -0800207 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800208
Chris Craik2af46352012-11-26 18:30:17 -0800209 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
Chet Haase48659092012-05-31 15:21:51 -0700210 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700211}
212
Chris Craikd218a922014-01-02 17:13:34 -0800213status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700214 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800215 float dstRight, float dstBottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800216 bitmap = refBitmap(bitmap);
217 paint = refPaint(paint);
218
Chris Craik527a3aa2013-03-04 10:19:31 -0800219 if (srcLeft == 0 && srcTop == 0 &&
220 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
221 (srcBottom - srcTop == dstBottom - dstTop) &&
222 (srcRight - srcLeft == dstRight - dstLeft)) {
223 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy55b6f952013-06-27 15:27:09 -0700224 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
Chris Craik527a3aa2013-03-04 10:19:31 -0800225 return DrawGlInfo::kStatusDone;
226 }
227
Chris Craik2af46352012-11-26 18:30:17 -0800228 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
229 srcLeft, srcTop, srcRight, srcBottom,
230 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700231 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700232}
233
Chris Craikd218a922014-01-02 17:13:34 -0800234status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
235 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800236 bitmap = refBitmapData(bitmap);
237 paint = refPaint(paint);
238
239 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700240 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700241}
242
Chris Craikd218a922014-01-02 17:13:34 -0800243status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
244 const float* vertices, const int* colors, const SkPaint* paint) {
Chris Craik0664fef2014-04-11 13:40:05 -0700245 int vertexCount = (meshWidth + 1) * (meshHeight + 1);
Chris Craik2af46352012-11-26 18:30:17 -0800246 bitmap = refBitmap(bitmap);
Chris Craik0664fef2014-04-11 13:40:05 -0700247 vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800248 paint = refPaint(paint);
Chris Craik0664fef2014-04-11 13:40:05 -0700249 colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800250
251 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
252 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700253 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800254}
255
Chris Craikd218a922014-01-02 17:13:34 -0800256status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
257 float left, float top, float right, float bottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800258 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700259 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700260 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800261
Romain Guy03c00b52013-06-20 18:30:28 -0700262 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700263 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700264}
265
Chet Haase48659092012-05-31 15:21:51 -0700266status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800267 addDrawOp(new (alloc()) DrawColorOp(color, mode));
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::drawRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800272 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800273 paint = refPaint(paint);
274 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700275 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700276}
277
Chet Haase48659092012-05-31 15:21:51 -0700278status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800279 float rx, float ry, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800280 paint = refPaint(paint);
281 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700282 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800283}
284
Chris Craikd218a922014-01-02 17:13:34 -0800285status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800286 paint = refPaint(paint);
287 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700288 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800289}
290
John Reck52244ff2014-05-01 21:27:37 -0700291status_t DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
292 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
293 mDisplayListData->refProperty(x);
294 mDisplayListData->refProperty(y);
295 mDisplayListData->refProperty(radius);
296 mDisplayListData->refProperty(paint);
297 addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value,
298 &radius->value, &paint->value));
299 return DrawGlInfo::kStatusDone;
300}
301
Chet Haase48659092012-05-31 15:21:51 -0700302status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800303 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800304 paint = refPaint(paint);
305 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700306 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800307}
308
Chet Haase48659092012-05-31 15:21:51 -0700309status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800310 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) {
Chris Craik6ac174b2014-06-17 13:47:05 -0700311 if (fabs(sweepAngle) > 360.0f) {
312 return drawOval(left, top, right, bottom, paint);
313 }
314
Chris Craik2af46352012-11-26 18:30:17 -0800315 paint = refPaint(paint);
316 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
317 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700318 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800319}
320
Chris Craikd218a922014-01-02 17:13:34 -0800321status_t DisplayListRenderer::drawPath(const SkPath* path, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800322 path = refPath(path);
323 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800324
Chris Craik2af46352012-11-26 18:30:17 -0800325 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700326 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700327}
328
Chris Craikd218a922014-01-02 17:13:34 -0800329status_t DisplayListRenderer::drawLines(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800330 points = refBuffer<float>(points, count);
331 paint = refPaint(paint);
332
333 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700334 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700335}
336
Chris Craikd218a922014-01-02 17:13:34 -0800337status_t DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800338 points = refBuffer<float>(points, count);
339 paint = refPaint(paint);
340
341 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700342 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700343}
344
Chet Haase48659092012-05-31 15:21:51 -0700345status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800346 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700347 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800348
Chris Craik2af46352012-11-26 18:30:17 -0800349 text = refText(text, bytesCount);
350 path = refPath(path);
351 paint = refPaint(paint);
352
353 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
354 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800355 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700356 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800357}
358
Chet Haase48659092012-05-31 15:21:51 -0700359status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800360 const float* positions, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700361 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800362
Chris Craik2af46352012-11-26 18:30:17 -0800363 text = refText(text, bytesCount);
364 positions = refBuffer<float>(positions, count * 2);
365 paint = refPaint(paint);
366
367 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800368 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700369 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800370}
371
Romain Guyc2525952012-07-27 16:41:22 -0700372status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800373 float x, float y, const float* positions, const SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700374 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800375
Raph Levien996e57c2012-07-23 15:22:52 -0700376 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
377
Chris Craik2af46352012-11-26 18:30:17 -0800378 text = refText(text, bytesCount);
379 positions = refBuffer<float>(positions, count * 2);
380 paint = refPaint(paint);
Raph Levien996e57c2012-07-23 15:22:52 -0700381
Chris Craik41541822013-05-03 16:35:54 -0700382 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
383 x, y, positions, paint, totalAdvance, bounds);
Romain Guy0f667532013-03-01 14:31:04 -0800384 addDrawOp(op);
Raph Levien996e57c2012-07-23 15:22:52 -0700385 return DrawGlInfo::kStatusDone;
386}
387
Chris Craikd218a922014-01-02 17:13:34 -0800388status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800389 if (count <= 0) return DrawGlInfo::kStatusDone;
390
Chris Craik2af46352012-11-26 18:30:17 -0800391 rects = refBuffer<float>(rects, count);
392 paint = refPaint(paint);
393 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800394 return DrawGlInfo::kStatusDone;
395}
396
Romain Guy5ff9df62012-01-23 17:09:05 -0800397void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800398 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800399}
400
401void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800402 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
403}
404
405void DisplayListRenderer::insertRestoreToCount() {
406 if (mRestoreSaveCount >= 0) {
407 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
408 mDisplayListData->displayListOps.add(op);
409 mRestoreSaveCount = -1;
410 }
411}
412
413void DisplayListRenderer::insertTranslate() {
414 if (mHasTranslate) {
415 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
416 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
417 mDisplayListData->displayListOps.add(op);
418 mTranslateX = mTranslateY = 0.0f;
419 }
420 mHasTranslate = false;
421 }
422}
423
424void DisplayListRenderer::addStateOp(StateOp* op) {
425 addOpInternal(op);
426}
427
Romain Guy0f667532013-03-01 14:31:04 -0800428void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800429 Rect localBounds;
Chris Craikc1c5f082013-09-11 16:23:37 -0700430 if (op->getLocalBounds(mDrawModifiers, localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800431 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800432 localBounds.right, localBounds.bottom);
433 op->setQuickRejected(rejected);
434 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700435
John Reck44fd8d22014-02-26 11:00:11 -0800436 mDisplayListData->hasDrawOps = true;
Chris Craik2af46352012-11-26 18:30:17 -0800437 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800438}
439
Romain Guy4aa90572010-09-26 18:40:37 -0700440}; // namespace uirenderer
441}; // namespace android