blob: 5abfe79e08d8e2fc0f8d40dd6ea7aee1e4b776a1 [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
Chris Craik0776a602013-02-14 15:36:01 -080024#include "DisplayList.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"
Chet Haase9c1e23b2011-03-24 10:51:31 -070029#include "Caches.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():
John Reck44fd8d22014-02-26 11:00:11 -080035 mCaches(Caches::getInstance()),
Romain Guy54c1a642012-09-27 17:55:46 -070036 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false),
John Reck44fd8d22014-02-26 11:00:11 -080037 mRestoreSaveCount(-1), mDisplayListData(0) {
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() {
50 mShaderMap.clear();
51 mPaintMap.clear();
52 mRegionMap.clear();
53 mPathMap.clear();
54 DisplayListData* data = mDisplayListData;
55 mDisplayListData = 0;
56 return data;
Chet Haase5977baa2011-01-05 18:01:22 -080057}
58
Romain Guyb051e892010-09-28 19:09:36 -070059void DisplayListRenderer::setViewport(int width, int height) {
Chris Craikf57776b2013-10-25 18:30:17 -070060 // TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used
61 mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1);
Romain Guyb051e892010-09-28 19:09:36 -070062
Chris Craik14e51302013-12-30 15:32:54 -080063 initializeViewport(width, height);
Romain Guyb051e892010-09-28 19:09:36 -070064}
65
Romain Guy7c25aab2012-10-18 15:05:02 -070066status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -080067 float right, float bottom, bool opaque) {
John Reck44fd8d22014-02-26 11:00:11 -080068
69 LOG_ALWAYS_FATAL_IF(mDisplayListData,
70 "prepareDirty called a second time during a recording!");
71 mDisplayListData = new DisplayListData();
72
Chris Craik14e51302013-12-30 15:32:54 -080073 initializeSaveStack(0, 0, getWidth(), getHeight());
Romain Guy45e4c3d2012-09-11 17:17:07 -070074
Romain Guy45e4c3d2012-09-11 17:17:07 -070075 mDirtyClip = opaque;
Romain Guy27454a42011-01-23 12:01:41 -080076 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -070077
Chet Haase44b2fe32012-06-06 19:03:58 -070078 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -080079}
80
81void DisplayListRenderer::finish() {
82 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -080083 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -070084}
85
Chet Haasedaf98e92011-01-10 14:10:36 -080086void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -080087}
Romain Guy2b1847e2011-01-26 13:43:01 -080088
Chet Haasedaf98e92011-01-10 14:10:36 -080089void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -070090}
91
Romain Guy65549432012-03-26 16:45:05 -070092status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -080093 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -080094 addDrawOp(new (alloc()) DrawFunctorOp(functor));
John Reck44fd8d22014-02-26 11:00:11 -080095 mDisplayListData->functorCount++;
Romain Guy65549432012-03-26 16:45:05 -070096 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -080097}
98
Romain Guy4aa90572010-09-26 18:40:37 -070099int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -0800100 addStateOp(new (alloc()) SaveOp(flags));
Chris Craik14e51302013-12-30 15:32:54 -0800101 return StatefulBaseRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700102}
103
104void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700105 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800106 restoreToCount(getSaveCount() - 1);
107 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700108 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800109
110 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800111 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800112 StatefulBaseRenderer::restore();
Romain Guy4aa90572010-09-26 18:40:37 -0700113}
114
115void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800116 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800117 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800118 StatefulBaseRenderer::restoreToCount(saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700119}
120
121int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Derek Sollenbergerd44fbe52014-02-05 16:47:00 -0500122 const SkPaint* paint, int flags) {
123 paint = refPaint(paint);
124 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, paint, flags));
Chris Craik14e51302013-12-30 15:32:54 -0800125 return StatefulBaseRenderer::save(flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700126}
127
Chris Craikb4589422013-12-26 15:13:13 -0800128void DisplayListRenderer::translate(float dx, float dy, float dz) {
129 // ignore dz, not used at defer time
Romain Guy33f6beb2012-02-16 19:24:51 -0800130 mHasTranslate = true;
131 mTranslateX += dx;
132 mTranslateY += dy;
133 insertRestoreToCount();
Chris Craik14e51302013-12-30 15:32:54 -0800134 StatefulBaseRenderer::translate(dx, dy, dz);
Romain Guy4aa90572010-09-26 18:40:37 -0700135}
136
137void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800138 addStateOp(new (alloc()) RotateOp(degrees));
Chris Craik14e51302013-12-30 15:32:54 -0800139 StatefulBaseRenderer::rotate(degrees);
Romain Guy4aa90572010-09-26 18:40:37 -0700140}
141
142void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800143 addStateOp(new (alloc()) ScaleOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800144 StatefulBaseRenderer::scale(sx, sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700145}
146
Romain Guy807daf72011-01-18 11:19:19 -0800147void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800148 addStateOp(new (alloc()) SkewOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800149 StatefulBaseRenderer::skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800150}
151
Chris Craikd218a922014-01-02 17:13:34 -0800152void DisplayListRenderer::setMatrix(const SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800153 matrix = refMatrix(matrix);
154 addStateOp(new (alloc()) SetMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800155 StatefulBaseRenderer::setMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700156}
157
Chris Craikd218a922014-01-02 17:13:34 -0800158void DisplayListRenderer::concatMatrix(const SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800159 matrix = refMatrix(matrix);
160 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800161 StatefulBaseRenderer::concatMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700162}
163
164bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
165 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800166 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800167 return StatefulBaseRenderer::clipRect(left, top, right, bottom, op);
Romain Guy4aa90572010-09-26 18:40:37 -0700168}
169
Chris Craikd218a922014-01-02 17:13:34 -0800170bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800171 path = refPath(path);
172 addStateOp(new (alloc()) ClipPathOp(path, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800173 return StatefulBaseRenderer::clipPath(path, op);
Romain Guy735738c2012-12-03 12:34:51 -0800174}
175
Chris Craikd218a922014-01-02 17:13:34 -0800176bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800177 region = refRegion(region);
178 addStateOp(new (alloc()) ClipRegionOp(region, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800179 return StatefulBaseRenderer::clipRegion(region, op);
Romain Guy735738c2012-12-03 12:34:51 -0800180}
181
Romain Guy65549432012-03-26 16:45:05 -0700182status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chris Craikc3566d02013-02-04 16:16:33 -0800183 Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800184 // dirty is an out parameter and should not be recorded,
185 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700186
Chris Craik2af46352012-11-26 18:30:17 -0800187 // TODO: To be safe, the display list should be ref-counted in the
188 // resources cache, but we rely on the caller (UI toolkit) to
189 // do the right thing for now
190
Chris Craikd6b65f62014-01-01 14:45:21 -0800191 DrawDisplayListOp* op = new (alloc()) DrawDisplayListOp(displayList,
192 flags, *currentTransform());
Chris Craikf57776b2013-10-25 18:30:17 -0700193 addDrawOp(op);
194 mDisplayListData->children.push(op);
Chris Craik1df26442014-02-05 16:50:41 -0800195 if (displayList->isProjectionReceiver()) {
196 mDisplayListData->projectionReceiveIndex = mDisplayListData->displayListOps.size() - 1;
197 }
Chris Craikf57776b2013-10-25 18:30:17 -0700198
Romain Guy65549432012-03-26 16:45:05 -0700199 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800200}
201
Chris Craika08f95c2013-03-15 17:24:33 -0700202status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700203 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700204 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700205 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800206}
207
Chris Craikd218a922014-01-02 17:13:34 -0800208status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
209 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800210 bitmap = refBitmap(bitmap);
211 paint = refPaint(paint);
212
Romain Guy55b6f952013-06-27 15:27:09 -0700213 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700214 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700215}
216
Chris Craikd218a922014-01-02 17:13:34 -0800217status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix,
218 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800219 bitmap = refBitmap(bitmap);
220 matrix = refMatrix(matrix);
221 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800222
Chris Craik2af46352012-11-26 18:30:17 -0800223 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
Chet Haase48659092012-05-31 15:21:51 -0700224 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700225}
226
Chris Craikd218a922014-01-02 17:13:34 -0800227status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700228 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800229 float dstRight, float dstBottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800230 bitmap = refBitmap(bitmap);
231 paint = refPaint(paint);
232
Chris Craik527a3aa2013-03-04 10:19:31 -0800233 if (srcLeft == 0 && srcTop == 0 &&
234 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
235 (srcBottom - srcTop == dstBottom - dstTop) &&
236 (srcRight - srcLeft == dstRight - dstLeft)) {
237 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy55b6f952013-06-27 15:27:09 -0700238 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
Chris Craik527a3aa2013-03-04 10:19:31 -0800239 return DrawGlInfo::kStatusDone;
240 }
241
Chris Craik2af46352012-11-26 18:30:17 -0800242 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
243 srcLeft, srcTop, srcRight, srcBottom,
244 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700245 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700246}
247
Chris Craikd218a922014-01-02 17:13:34 -0800248status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
249 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800250 bitmap = refBitmapData(bitmap);
251 paint = refPaint(paint);
252
253 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700254 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700255}
256
Chris Craikd218a922014-01-02 17:13:34 -0800257status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
258 const float* vertices, const int* colors, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800259 int count = (meshWidth + 1) * (meshHeight + 1) * 2;
260 bitmap = refBitmap(bitmap);
261 vertices = refBuffer<float>(vertices, count);
262 paint = refPaint(paint);
263 colors = refBuffer<int>(colors, count);
264
265 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
266 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700267 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800268}
269
Chris Craikd218a922014-01-02 17:13:34 -0800270status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
271 float left, float top, float right, float bottom, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800272 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700273 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700274 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800275
Romain Guy03c00b52013-06-20 18:30:28 -0700276 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, 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::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800281 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700282 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700283}
284
Chet Haase48659092012-05-31 15:21:51 -0700285status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800286 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800287 paint = refPaint(paint);
288 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700289 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700290}
291
Chet Haase48659092012-05-31 15:21:51 -0700292status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800293 float rx, float ry, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800294 paint = refPaint(paint);
295 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700296 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800297}
298
Chris Craikd218a922014-01-02 17:13:34 -0800299status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800300 paint = refPaint(paint);
301 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700302 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800303}
304
Chet Haase48659092012-05-31 15:21:51 -0700305status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800306 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800307 paint = refPaint(paint);
308 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700309 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800310}
311
Chet Haase48659092012-05-31 15:21:51 -0700312status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Chris Craikd218a922014-01-02 17:13:34 -0800313 float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800314 paint = refPaint(paint);
315 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
316 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700317 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800318}
319
Chris Craikd218a922014-01-02 17:13:34 -0800320status_t DisplayListRenderer::drawPath(const SkPath* path, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800321 path = refPath(path);
322 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800323
Chris Craik2af46352012-11-26 18:30:17 -0800324 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700325 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700326}
327
Chris Craikd218a922014-01-02 17:13:34 -0800328status_t DisplayListRenderer::drawLines(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800329 points = refBuffer<float>(points, count);
330 paint = refPaint(paint);
331
332 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700333 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700334}
335
Chris Craikd218a922014-01-02 17:13:34 -0800336status_t DisplayListRenderer::drawPoints(const float* points, int count, const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800337 points = refBuffer<float>(points, count);
338 paint = refPaint(paint);
339
340 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700341 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700342}
343
Chet Haase48659092012-05-31 15:21:51 -0700344status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800345 const SkPath* path, float hOffset, float vOffset, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700346 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800347
Chris Craik2af46352012-11-26 18:30:17 -0800348 text = refText(text, bytesCount);
349 path = refPath(path);
350 paint = refPaint(paint);
351
352 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
353 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800354 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700355 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800356}
357
Chet Haase48659092012-05-31 15:21:51 -0700358status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800359 const float* positions, const SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700360 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800361
Chris Craik2af46352012-11-26 18:30:17 -0800362 text = refText(text, bytesCount);
363 positions = refBuffer<float>(positions, count * 2);
364 paint = refPaint(paint);
365
366 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800367 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700368 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800369}
370
Romain Guyc2525952012-07-27 16:41:22 -0700371status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craikd218a922014-01-02 17:13:34 -0800372 float x, float y, const float* positions, const SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700373 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800374
Raph Levien996e57c2012-07-23 15:22:52 -0700375 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
376
Chris Craik2af46352012-11-26 18:30:17 -0800377 text = refText(text, bytesCount);
378 positions = refBuffer<float>(positions, count * 2);
379 paint = refPaint(paint);
Raph Levien996e57c2012-07-23 15:22:52 -0700380
Chris Craik41541822013-05-03 16:35:54 -0700381 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
382 x, y, positions, paint, totalAdvance, bounds);
Romain Guy0f667532013-03-01 14:31:04 -0800383 addDrawOp(op);
Raph Levien996e57c2012-07-23 15:22:52 -0700384 return DrawGlInfo::kStatusDone;
385}
386
Chris Craikd218a922014-01-02 17:13:34 -0800387status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800388 if (count <= 0) return DrawGlInfo::kStatusDone;
389
Chris Craik2af46352012-11-26 18:30:17 -0800390 rects = refBuffer<float>(rects, count);
391 paint = refPaint(paint);
392 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800393 return DrawGlInfo::kStatusDone;
394}
395
Romain Guy4aa90572010-09-26 18:40:37 -0700396void DisplayListRenderer::resetShader() {
Chris Craik2af46352012-11-26 18:30:17 -0800397 addStateOp(new (alloc()) ResetShaderOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700398}
399
400void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chris Craik2af46352012-11-26 18:30:17 -0800401 shader = refShader(shader);
402 addStateOp(new (alloc()) SetupShaderOp(shader));
Romain Guy4aa90572010-09-26 18:40:37 -0700403}
404
Romain Guy4aa90572010-09-26 18:40:37 -0700405void DisplayListRenderer::resetShadow() {
Chris Craik2af46352012-11-26 18:30:17 -0800406 addStateOp(new (alloc()) ResetShadowOp());
Romain Guy9b5a1a22013-08-09 14:06:29 -0700407 OpenGLRenderer::resetShadow();
Romain Guy4aa90572010-09-26 18:40:37 -0700408}
409
410void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Chris Craik2af46352012-11-26 18:30:17 -0800411 addStateOp(new (alloc()) SetupShadowOp(radius, dx, dy, color));
Romain Guy9b5a1a22013-08-09 14:06:29 -0700412 OpenGLRenderer::setupShadow(radius, dx, dy, color);
Romain Guy4aa90572010-09-26 18:40:37 -0700413}
414
Romain Guy5ff9df62012-01-23 17:09:05 -0800415void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800416 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800417}
418
419void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800420 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
421}
422
423void DisplayListRenderer::insertRestoreToCount() {
424 if (mRestoreSaveCount >= 0) {
425 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
426 mDisplayListData->displayListOps.add(op);
427 mRestoreSaveCount = -1;
428 }
429}
430
431void DisplayListRenderer::insertTranslate() {
432 if (mHasTranslate) {
433 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
434 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
435 mDisplayListData->displayListOps.add(op);
436 mTranslateX = mTranslateY = 0.0f;
437 }
438 mHasTranslate = false;
439 }
440}
441
442void DisplayListRenderer::addStateOp(StateOp* op) {
443 addOpInternal(op);
444}
445
Romain Guy0f667532013-03-01 14:31:04 -0800446void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800447 Rect localBounds;
Chris Craikc1c5f082013-09-11 16:23:37 -0700448 if (op->getLocalBounds(mDrawModifiers, localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800449 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800450 localBounds.right, localBounds.bottom);
451 op->setQuickRejected(rejected);
452 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700453
John Reck44fd8d22014-02-26 11:00:11 -0800454 mDisplayListData->hasDrawOps = true;
Chris Craik2af46352012-11-26 18:30:17 -0800455 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800456}
457
Romain Guy4aa90572010-09-26 18:40:37 -0700458}; // namespace uirenderer
459}; // namespace android