blob: ba4c2a0adcc901e590114951a34198a7070afaa1 [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():
Chris Craik2af46352012-11-26 18:30:17 -080035 mCaches(Caches::getInstance()), mDisplayListData(new DisplayListData),
Romain Guy54c1a642012-09-27 17:55:46 -070036 mTranslateX(0.0f), mTranslateY(0.0f), mHasTranslate(false),
37 mHasDrawOps(false), mFunctorCount(0) {
Romain Guy4aa90572010-09-26 18:40:37 -070038}
39
40DisplayListRenderer::~DisplayListRenderer() {
41 reset();
42}
43
44void DisplayListRenderer::reset() {
Chris Craik2af46352012-11-26 18:30:17 -080045 mDisplayListData = new DisplayListData();
Romain Guy58ecc202012-09-07 11:58:36 -070046 mCaches.resourceCache.lock();
47
Chet Haase5c13d892010-10-08 08:37:55 -070048 for (size_t i = 0; i < mBitmapResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070049 mCaches.resourceCache.decrementRefcountLocked(mBitmapResources.itemAt(i));
Chet Haase5c13d892010-10-08 08:37:55 -070050 }
Chet Haased98aa2d2010-10-25 15:47:32 -070051
Romain Guy49c5fc02012-05-15 11:10:01 -070052 for (size_t i = 0; i < mOwnedBitmapResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070053 mCaches.resourceCache.decrementRefcountLocked(mOwnedBitmapResources.itemAt(i));
Romain Guy49c5fc02012-05-15 11:10:01 -070054 }
Romain Guy49c5fc02012-05-15 11:10:01 -070055
Romain Guyd586ad92011-06-22 16:14:36 -070056 for (size_t i = 0; i < mFilterResources.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070057 mCaches.resourceCache.decrementRefcountLocked(mFilterResources.itemAt(i));
Romain Guyd586ad92011-06-22 16:14:36 -070058 }
Romain Guyd586ad92011-06-22 16:14:36 -070059
Romain Guye3b0a012013-06-26 15:45:41 -070060 for (size_t i = 0; i < mPatchResources.size(); i++) {
61 mCaches.resourceCache.decrementRefcountLocked(mPatchResources.itemAt(i));
62 }
63
Romain Guy43ccf462011-01-14 18:51:01 -080064 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070065 mCaches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -080066 }
Romain Guy43ccf462011-01-14 18:51:01 -080067
Chet Haased34dd712012-05-02 18:50:34 -070068 for (size_t i = 0; i < mSourcePaths.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070069 mCaches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
Chet Haased34dd712012-05-02 18:50:34 -070070 }
Romain Guy58ecc202012-09-07 11:58:36 -070071
Chet Haase603f6de2012-09-14 15:31:25 -070072 for (size_t i = 0; i < mLayers.size(); i++) {
73 mCaches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
74 }
75
Romain Guy58ecc202012-09-07 11:58:36 -070076 mCaches.resourceCache.unlock();
77
78 mBitmapResources.clear();
79 mOwnedBitmapResources.clear();
80 mFilterResources.clear();
Romain Guye3b0a012013-06-26 15:45:41 -070081 mPatchResources.clear();
Chet Haased34dd712012-05-02 18:50:34 -070082 mSourcePaths.clear();
83
Romain Guy58ecc202012-09-07 11:58:36 -070084 mShaders.clear();
85 mShaderMap.clear();
86
Romain Guy43ccf462011-01-14 18:51:01 -080087 mPaints.clear();
88 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -070089
Romain Guy735738c2012-12-03 12:34:51 -080090 mRegions.clear();
91 mRegionMap.clear();
92
Romain Guy2fc941e2011-02-03 15:06:05 -080093 mPaths.clear();
94 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -070095
Chet Haased98aa2d2010-10-25 15:47:32 -070096 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -070097
Chet Haase603f6de2012-09-14 15:31:25 -070098 mLayers.clear();
99
Romain Guy04c9d8c2011-08-25 14:01:48 -0700100 mHasDrawOps = false;
Romain Guy54c1a642012-09-27 17:55:46 -0700101 mFunctorCount = 0;
Romain Guy4aa90572010-09-26 18:40:37 -0700102}
103
104///////////////////////////////////////////////////////////////////////////////
105// Operations
106///////////////////////////////////////////////////////////////////////////////
107
Jeff Brown162a0212011-07-21 17:02:54 -0700108DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
109 if (!displayList) {
110 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -0800111 } else {
Jeff Brown162a0212011-07-21 17:02:54 -0700112 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800113 }
Romain Guy04c9d8c2011-08-25 14:01:48 -0700114 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -0700115 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -0800116}
117
Romain Guy49c5fc02012-05-15 11:10:01 -0700118bool DisplayListRenderer::isDeferred() {
119 return true;
120}
121
Romain Guyb051e892010-09-28 19:09:36 -0700122void DisplayListRenderer::setViewport(int width, int height) {
123 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
124
125 mWidth = width;
126 mHeight = height;
127}
128
Romain Guy7c25aab2012-10-18 15:05:02 -0700129status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -0800130 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700131 mSnapshot = new Snapshot(mFirstSnapshot,
132 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
133 mSaveCount = 1;
Romain Guy45e4c3d2012-09-11 17:17:07 -0700134
Romain Guyb051e892010-09-28 19:09:36 -0700135 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy45e4c3d2012-09-11 17:17:07 -0700136 mDirtyClip = opaque;
137
Romain Guy27454a42011-01-23 12:01:41 -0800138 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -0700139
Chet Haase44b2fe32012-06-06 19:03:58 -0700140 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -0800141}
142
143void DisplayListRenderer::finish() {
144 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -0800145 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -0700146}
147
Chet Haasedaf98e92011-01-10 14:10:36 -0800148void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800149}
Romain Guy2b1847e2011-01-26 13:43:01 -0800150
Chet Haasedaf98e92011-01-10 14:10:36 -0800151void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700152}
153
Romain Guy65549432012-03-26 16:45:05 -0700154status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -0800155 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -0800156 addDrawOp(new (alloc()) DrawFunctorOp(functor));
Romain Guy54c1a642012-09-27 17:55:46 -0700157 mFunctorCount++;
Romain Guy65549432012-03-26 16:45:05 -0700158 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -0800159}
160
Romain Guy4aa90572010-09-26 18:40:37 -0700161int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -0800162 addStateOp(new (alloc()) SaveOp(flags));
Romain Guy4aa90572010-09-26 18:40:37 -0700163 return OpenGLRenderer::save(flags);
164}
165
166void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700167 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800168 restoreToCount(getSaveCount() - 1);
169 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700170 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800171
172 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800173 insertTranslate();
Romain Guy4aa90572010-09-26 18:40:37 -0700174 OpenGLRenderer::restore();
175}
176
177void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800178 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800179 insertTranslate();
Romain Guy4aa90572010-09-26 18:40:37 -0700180 OpenGLRenderer::restoreToCount(saveCount);
181}
182
183int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chris Craikff785832013-03-08 13:12:16 -0800184 int alpha, SkXfermode::Mode mode, int flags) {
185 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, alpha, mode, flags));
Romain Guy5b3b3522010-10-27 18:57:51 -0700186 return OpenGLRenderer::save(flags);
187}
188
Romain Guy4aa90572010-09-26 18:40:37 -0700189void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800190 mHasTranslate = true;
191 mTranslateX += dx;
192 mTranslateY += dy;
193 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -0700194 OpenGLRenderer::translate(dx, dy);
195}
196
197void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800198 addStateOp(new (alloc()) RotateOp(degrees));
Romain Guy4aa90572010-09-26 18:40:37 -0700199 OpenGLRenderer::rotate(degrees);
200}
201
202void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800203 addStateOp(new (alloc()) ScaleOp(sx, sy));
Romain Guy4aa90572010-09-26 18:40:37 -0700204 OpenGLRenderer::scale(sx, sy);
205}
206
Romain Guy807daf72011-01-18 11:19:19 -0800207void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800208 addStateOp(new (alloc()) SkewOp(sx, sy));
Romain Guy807daf72011-01-18 11:19:19 -0800209 OpenGLRenderer::skew(sx, sy);
210}
211
Romain Guy4aa90572010-09-26 18:40:37 -0700212void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800213 matrix = refMatrix(matrix);
214 addStateOp(new (alloc()) SetMatrixOp(matrix));
Romain Guy4aa90572010-09-26 18:40:37 -0700215 OpenGLRenderer::setMatrix(matrix);
216}
217
218void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800219 matrix = refMatrix(matrix);
220 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Romain Guy4aa90572010-09-26 18:40:37 -0700221 OpenGLRenderer::concatMatrix(matrix);
222}
223
224bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
225 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800226 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Romain Guy4aa90572010-09-26 18:40:37 -0700227 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
228}
229
Romain Guy735738c2012-12-03 12:34:51 -0800230bool DisplayListRenderer::clipPath(SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800231 path = refPath(path);
232 addStateOp(new (alloc()) ClipPathOp(path, op));
Romain Guy735738c2012-12-03 12:34:51 -0800233 return OpenGLRenderer::clipPath(path, op);
234}
235
236bool DisplayListRenderer::clipRegion(SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800237 region = refRegion(region);
238 addStateOp(new (alloc()) ClipRegionOp(region, op));
Romain Guy735738c2012-12-03 12:34:51 -0800239 return OpenGLRenderer::clipRegion(region, op);
240}
241
Romain Guy65549432012-03-26 16:45:05 -0700242status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chris Craikc3566d02013-02-04 16:16:33 -0800243 Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800244 // dirty is an out parameter and should not be recorded,
245 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700246
Chris Craik2af46352012-11-26 18:30:17 -0800247 // TODO: To be safe, the display list should be ref-counted in the
248 // resources cache, but we rely on the caller (UI toolkit) to
249 // do the right thing for now
250
251 addDrawOp(new (alloc()) DrawDisplayListOp(displayList, flags));
Romain Guy65549432012-03-26 16:45:05 -0700252 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800253}
254
Chris Craika08f95c2013-03-15 17:24:33 -0700255status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700256 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700257 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700258 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800259}
260
Chet Haase48659092012-05-31 15:21:51 -0700261status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800262 bitmap = refBitmap(bitmap);
263 paint = refPaint(paint);
264
Romain Guy55b6f952013-06-27 15:27:09 -0700265 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
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::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800270 bitmap = refBitmap(bitmap);
271 matrix = refMatrix(matrix);
272 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800273
Chris Craik2af46352012-11-26 18:30:17 -0800274 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, 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::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700279 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700280 float dstRight, float dstBottom, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800281 bitmap = refBitmap(bitmap);
282 paint = refPaint(paint);
283
Chris Craik527a3aa2013-03-04 10:19:31 -0800284 if (srcLeft == 0 && srcTop == 0 &&
285 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
286 (srcBottom - srcTop == dstBottom - dstTop) &&
287 (srcRight - srcLeft == dstRight - dstLeft)) {
288 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy55b6f952013-06-27 15:27:09 -0700289 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint));
Chris Craik527a3aa2013-03-04 10:19:31 -0800290 return DrawGlInfo::kStatusDone;
291 }
292
Chris Craik2af46352012-11-26 18:30:17 -0800293 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
294 srcLeft, srcTop, srcRight, srcBottom,
295 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700296 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700297}
298
Chet Haase48659092012-05-31 15:21:51 -0700299status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
300 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800301 bitmap = refBitmapData(bitmap);
302 paint = refPaint(paint);
303
304 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700305 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700306}
307
Chet Haase48659092012-05-31 15:21:51 -0700308status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -0800309 float* vertices, int* colors, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800310 int count = (meshWidth + 1) * (meshHeight + 1) * 2;
311 bitmap = refBitmap(bitmap);
312 vertices = refBuffer<float>(vertices, count);
313 paint = refPaint(paint);
314 colors = refBuffer<int>(colors, count);
315
316 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
317 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700318 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800319}
320
Romain Guy3b748a42013-04-17 18:54:38 -0700321status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
322 float left, float top, float right, float bottom, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800323 bitmap = refBitmap(bitmap);
Romain Guye3b0a012013-06-26 15:45:41 -0700324 patch = refPatch(patch);
Romain Guy16ea8d32013-06-21 11:35:52 -0700325 paint = refPaint(paint);
Chris Craik2af46352012-11-26 18:30:17 -0800326
Romain Guy03c00b52013-06-20 18:30:28 -0700327 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700328 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700329}
330
Chet Haase48659092012-05-31 15:21:51 -0700331status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800332 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700333 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700334}
335
Chet Haase48659092012-05-31 15:21:51 -0700336status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700337 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800338 paint = refPaint(paint);
339 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700340 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700341}
342
Chet Haase48659092012-05-31 15:21:51 -0700343status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -0800344 float rx, float ry, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800345 paint = refPaint(paint);
346 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700347 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800348}
349
Chet Haase48659092012-05-31 15:21:51 -0700350status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800351 paint = refPaint(paint);
352 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700353 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800354}
355
Chet Haase48659092012-05-31 15:21:51 -0700356status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800357 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800358 paint = refPaint(paint);
359 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700360 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800361}
362
Chet Haase48659092012-05-31 15:21:51 -0700363status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -0800364 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800365 paint = refPaint(paint);
366 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
367 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700368 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800369}
370
Chet Haase48659092012-05-31 15:21:51 -0700371status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800372 path = refPath(path);
373 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800374
Chris Craik2af46352012-11-26 18:30:17 -0800375 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700376 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700377}
378
Chet Haase48659092012-05-31 15:21:51 -0700379status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800380 points = refBuffer<float>(points, count);
381 paint = refPaint(paint);
382
383 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700384 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700385}
386
Chet Haase48659092012-05-31 15:21:51 -0700387status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800388 points = refBuffer<float>(points, count);
389 paint = refPaint(paint);
390
391 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700392 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700393}
394
Chet Haase48659092012-05-31 15:21:51 -0700395status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -0800396 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700397 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800398
Chris Craik2af46352012-11-26 18:30:17 -0800399 text = refText(text, bytesCount);
400 path = refPath(path);
401 paint = refPaint(paint);
402
403 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
404 hOffset, vOffset, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800405 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700406 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800407}
408
Chet Haase48659092012-05-31 15:21:51 -0700409status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -0800410 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700411 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800412
Chris Craik2af46352012-11-26 18:30:17 -0800413 text = refText(text, bytesCount);
414 positions = refBuffer<float>(positions, count * 2);
415 paint = refPaint(paint);
416
417 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f667532013-03-01 14:31:04 -0800418 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700419 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800420}
421
Romain Guyc2525952012-07-27 16:41:22 -0700422status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craik527a3aa2013-03-04 10:19:31 -0800423 float x, float y, const float* positions, SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700424 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800425
Raph Levien996e57c2012-07-23 15:22:52 -0700426 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
427
Chris Craik2af46352012-11-26 18:30:17 -0800428 text = refText(text, bytesCount);
429 positions = refBuffer<float>(positions, count * 2);
430 paint = refPaint(paint);
Raph Levien996e57c2012-07-23 15:22:52 -0700431
Chris Craik41541822013-05-03 16:35:54 -0700432 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
433 x, y, positions, paint, totalAdvance, bounds);
Romain Guy0f667532013-03-01 14:31:04 -0800434 addDrawOp(op);
Raph Levien996e57c2012-07-23 15:22:52 -0700435 return DrawGlInfo::kStatusDone;
436}
437
Romain Guy672433d2013-01-04 19:05:13 -0800438status_t DisplayListRenderer::drawRects(const float* rects, int count, SkPaint* paint) {
439 if (count <= 0) return DrawGlInfo::kStatusDone;
440
Chris Craik2af46352012-11-26 18:30:17 -0800441 rects = refBuffer<float>(rects, count);
442 paint = refPaint(paint);
443 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800444 return DrawGlInfo::kStatusDone;
445}
446
Romain Guy4aa90572010-09-26 18:40:37 -0700447void DisplayListRenderer::resetShader() {
Chris Craik2af46352012-11-26 18:30:17 -0800448 addStateOp(new (alloc()) ResetShaderOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700449}
450
451void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chris Craik2af46352012-11-26 18:30:17 -0800452 shader = refShader(shader);
453 addStateOp(new (alloc()) SetupShaderOp(shader));
Romain Guy4aa90572010-09-26 18:40:37 -0700454}
455
456void DisplayListRenderer::resetColorFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800457 addStateOp(new (alloc()) ResetColorFilterOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700458}
459
460void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chris Craik2af46352012-11-26 18:30:17 -0800461 filter = refColorFilter(filter);
462 addStateOp(new (alloc()) SetupColorFilterOp(filter));
Romain Guy4aa90572010-09-26 18:40:37 -0700463}
464
465void DisplayListRenderer::resetShadow() {
Chris Craik2af46352012-11-26 18:30:17 -0800466 addStateOp(new (alloc()) ResetShadowOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700467}
468
469void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Chris Craik2af46352012-11-26 18:30:17 -0800470 addStateOp(new (alloc()) SetupShadowOp(radius, dx, dy, color));
Romain Guy4aa90572010-09-26 18:40:37 -0700471}
472
Romain Guy5ff9df62012-01-23 17:09:05 -0800473void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800474 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800475}
476
477void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800478 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
479}
480
481void DisplayListRenderer::insertRestoreToCount() {
482 if (mRestoreSaveCount >= 0) {
483 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
484 mDisplayListData->displayListOps.add(op);
485 mRestoreSaveCount = -1;
486 }
487}
488
489void DisplayListRenderer::insertTranslate() {
490 if (mHasTranslate) {
491 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
492 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
493 mDisplayListData->displayListOps.add(op);
494 mTranslateX = mTranslateY = 0.0f;
495 }
496 mHasTranslate = false;
497 }
498}
499
500void DisplayListRenderer::addStateOp(StateOp* op) {
501 addOpInternal(op);
502}
503
Romain Guy0f667532013-03-01 14:31:04 -0800504void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800505 Rect localBounds;
506 if (op->getLocalBounds(localBounds)) {
Romain Guy0f667532013-03-01 14:31:04 -0800507 bool rejected = quickRejectNoScissor(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800508 localBounds.right, localBounds.bottom);
509 op->setQuickRejected(rejected);
510 }
511 mHasDrawOps = true;
512 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800513}
514
Romain Guy4aa90572010-09-26 18:40:37 -0700515}; // namespace uirenderer
516}; // namespace android