blob: 7789358076ee6baafc5d05239a36f3190f0c0805 [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
Chris Craika7090e02014-06-20 16:01:00 -0700172status_t DisplayListRenderer::drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800173 // dirty is an out parameter and should not be recorded,
174 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700175
Chris Craika7090e02014-06-20 16:01:00 -0700176 if (renderNode->stagingProperties().isProjectionReceiver()) {
Chris Craik3f0854292014-04-15 16:18:08 -0700177 // use staging property, since recording on UI thread
178 mDisplayListData->projectionReceiveIndex = mDisplayListData->displayListOps.size();
179 }
Chris Craik2af46352012-11-26 18:30:17 -0800180
Chris Craika7090e02014-06-20 16:01:00 -0700181 DrawRenderNodeOp* op = new (alloc()) DrawRenderNodeOp(renderNode, flags, *currentTransform());
Chris Craikf57776b2013-10-25 18:30:17 -0700182 addDrawOp(op);
John Reck087bc0c2014-04-04 16:20:08 -0700183 mDisplayListData->addChild(op);
Romain Guy65549432012-03-26 16:45:05 -0700184 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800185}
186
Chris Craika08f95c2013-03-15 17:24:33 -0700187status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700188 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700189 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700190 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800191}
192
Chris Craikd218a922014-01-02 17:13:34 -0800193status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
194 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800195 bitmap = refBitmap(bitmap);
196 paint = refPaint(paint);
197
Romain Guy55b6f952013-06-27 15:27:09 -0700198 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700199 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700200}
201
Derek Sollenberger13908822013-12-10 12:28:58 -0500202status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix& matrix,
Chris Craikd218a922014-01-02 17:13:34 -0800203 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800204 bitmap = refBitmap(bitmap);
Chris Craik2af46352012-11-26 18:30:17 -0800205 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800206
Chris Craik2af46352012-11-26 18:30:17 -0800207 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
Chet Haase48659092012-05-31 15:21:51 -0700208 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700209}
210
Chris Craikd218a922014-01-02 17:13:34 -0800211status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700212 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800213 float dstRight, float dstBottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800214 bitmap = refBitmap(bitmap);
215 paint = refPaint(paint);
216
Chris Craik527a3aa2013-03-04 10:19:31 -0800217 if (srcLeft == 0 && srcTop == 0 &&
218 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
219 (srcBottom - srcTop == dstBottom - dstTop) &&
220 (srcRight - srcLeft == dstRight - dstLeft)) {
221 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy55b6f952013-06-27 15:27:09 -0700222 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
Chris Craik527a3aa2013-03-04 10:19:31 -0800223 return DrawGlInfo::kStatusDone;
224 }
225
Chris Craik2af46352012-11-26 18:30:17 -0800226 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
227 srcLeft, srcTop, srcRight, srcBottom,
228 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700229 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700230}
231
Chris Craikd218a922014-01-02 17:13:34 -0800232status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
233 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800234 bitmap = refBitmapData(bitmap);
235 paint = refPaint(paint);
236
237 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700238 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700239}
240
Chris Craikd218a922014-01-02 17:13:34 -0800241status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
242 const float* vertices, const int* colors, const SkPaint* paint) {
Chris Craik0664fef2014-04-11 13:40:05 -0700243 int vertexCount = (meshWidth + 1) * (meshHeight + 1);
Chris Craik2af46352012-11-26 18:30:17 -0800244 bitmap = refBitmap(bitmap);
Chris Craik0664fef2014-04-11 13:40:05 -0700245 vertices = refBuffer<float>(vertices, vertexCount * 2); // 2 floats per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800246 paint = refPaint(paint);
Chris Craik0664fef2014-04-11 13:40:05 -0700247 colors = refBuffer<int>(colors, vertexCount); // 1 color per vertex
Chris Craik2af46352012-11-26 18:30:17 -0800248
249 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
250 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700251 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800252}
253
Chris Craikd218a922014-01-02 17:13:34 -0800254status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
255 float left, float top, float right, float bottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800256 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700257 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700258 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800259
Romain Guy03c00b52013-06-20 18:30:28 -0700260 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
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::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800265 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700266 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700267}
268
Chet Haase48659092012-05-31 15:21:51 -0700269status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800270 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800271 paint = refPaint(paint);
272 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700273 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700274}
275
Chet Haase48659092012-05-31 15:21:51 -0700276status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800277 float rx, float ry, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800278 paint = refPaint(paint);
279 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700280 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800281}
282
Chris Craikd218a922014-01-02 17:13:34 -0800283status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800284 paint = refPaint(paint);
285 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700286 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800287}
288
John Reck52244ff2014-05-01 21:27:37 -0700289status_t DisplayListRenderer::drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
290 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) {
291 mDisplayListData->refProperty(x);
292 mDisplayListData->refProperty(y);
293 mDisplayListData->refProperty(radius);
294 mDisplayListData->refProperty(paint);
295 addDrawOp(new (alloc()) DrawCirclePropsOp(&x->value, &y->value,
296 &radius->value, &paint->value));
297 return DrawGlInfo::kStatusDone;
298}
299
Chet Haase48659092012-05-31 15:21:51 -0700300status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800301 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800302 paint = refPaint(paint);
303 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700304 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800305}
306
Chet Haase48659092012-05-31 15:21:51 -0700307status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800308 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) {
Chris Craik6ac174b2014-06-17 13:47:05 -0700309 if (fabs(sweepAngle) > 360.0f) {
310 return drawOval(left, top, right, bottom, paint);
311 }
312
Chris Craik2af46352012-11-26 18:30:17 -0800313 paint = refPaint(paint);
314 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
315 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700316 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800317}
318
Chris Craikd218a922014-01-02 17:13:34 -0800319status_t DisplayListRenderer::drawPath(const SkPath* path, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800320 path = refPath(path);
321 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800322
Chris Craik2af46352012-11-26 18:30:17 -0800323 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700324 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700325}
326
Chris Craikd218a922014-01-02 17:13:34 -0800327status_t DisplayListRenderer::drawLines(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800328 points = refBuffer<float>(points, count);
329 paint = refPaint(paint);
330
331 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700332 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700333}
334
Chris Craikd218a922014-01-02 17:13:34 -0800335status_t DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800336 points = refBuffer<float>(points, count);
337 paint = refPaint(paint);
338
339 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700340 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700341}
342
Chet Haase48659092012-05-31 15:21:51 -0700343status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800344 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700345 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800346
Chris Craik2af46352012-11-26 18:30:17 -0800347 text = refText(text, bytesCount);
348 path = refPath(path);
349 paint = refPaint(paint);
350
351 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
352 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800353 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700354 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800355}
356
Chet Haase48659092012-05-31 15:21:51 -0700357status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800358 const float* positions, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700359 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800360
Chris Craik2af46352012-11-26 18:30:17 -0800361 text = refText(text, bytesCount);
362 positions = refBuffer<float>(positions, count * 2);
363 paint = refPaint(paint);
364
365 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800366 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700367 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800368}
369
Romain Guyc2525952012-07-27 16:41:22 -0700370status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800371 float x, float y, const float* positions, const SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700372 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800373
Raph Levien996e57c2012-07-23 15:22:52 -0700374 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
375
Chris Craik2af46352012-11-26 18:30:17 -0800376 text = refText(text, bytesCount);
377 positions = refBuffer<float>(positions, count * 2);
378 paint = refPaint(paint);
Raph Levien996e57c2012-07-23 15:22:52 -0700379
Chris Craik41541822013-05-03 16:35:54 -0700380 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
381 x, y, positions, paint, totalAdvance, bounds);
Romain Guy0f667532013-03-01 14:31:04 -0800382 addDrawOp(op);
Raph Levien996e57c2012-07-23 15:22:52 -0700383 return DrawGlInfo::kStatusDone;
384}
385
Chris Craikd218a922014-01-02 17:13:34 -0800386status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800387 if (count <= 0) return DrawGlInfo::kStatusDone;
388
Chris Craik2af46352012-11-26 18:30:17 -0800389 rects = refBuffer<float>(rects, count);
390 paint = refPaint(paint);
391 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800392 return DrawGlInfo::kStatusDone;
393}
394
Romain Guy5ff9df62012-01-23 17:09:05 -0800395void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800396 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800397}
398
399void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800400 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
401}
402
403void DisplayListRenderer::insertRestoreToCount() {
404 if (mRestoreSaveCount >= 0) {
405 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
406 mDisplayListData->displayListOps.add(op);
407 mRestoreSaveCount = -1;
408 }
409}
410
411void DisplayListRenderer::insertTranslate() {
412 if (mHasTranslate) {
413 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
414 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
415 mDisplayListData->displayListOps.add(op);
416 mTranslateX = mTranslateY = 0.0f;
417 }
418 mHasTranslate = false;
419 }
420}
421
422void DisplayListRenderer::addStateOp(StateOp* op) {
423 addOpInternal(op);
424}
425
Romain Guy0f667532013-03-01 14:31:04 -0800426void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800427 Rect localBounds;
John Reck3b202512014-06-23 13:13:08 -0700428 if (op->getLocalBounds(localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800429 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800430 localBounds.right, localBounds.bottom);
431 op->setQuickRejected(rejected);
432 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700433
John Reck44fd8d22014-02-26 11:00:11 -0800434 mDisplayListData->hasDrawOps = true;
Chris Craik2af46352012-11-26 18:30:17 -0800435 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800436}
437
Romain Guy4aa90572010-09-26 18:40:37 -0700438}; // namespace uirenderer
439}; // namespace android