blob: 6d85a16b39193ee9a1b1e41d84bc56a32cb106af [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 Guy43ccf462011-01-14 18:51:01 -080060 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070061 mCaches.resourceCache.decrementRefcountLocked(mShaders.itemAt(i));
Romain Guy43ccf462011-01-14 18:51:01 -080062 }
Romain Guy43ccf462011-01-14 18:51:01 -080063
Chet Haased34dd712012-05-02 18:50:34 -070064 for (size_t i = 0; i < mSourcePaths.size(); i++) {
Romain Guy58ecc202012-09-07 11:58:36 -070065 mCaches.resourceCache.decrementRefcountLocked(mSourcePaths.itemAt(i));
Chet Haased34dd712012-05-02 18:50:34 -070066 }
Romain Guy58ecc202012-09-07 11:58:36 -070067
Chet Haase603f6de2012-09-14 15:31:25 -070068 for (size_t i = 0; i < mLayers.size(); i++) {
69 mCaches.resourceCache.decrementRefcountLocked(mLayers.itemAt(i));
70 }
71
Romain Guy58ecc202012-09-07 11:58:36 -070072 mCaches.resourceCache.unlock();
73
74 mBitmapResources.clear();
75 mOwnedBitmapResources.clear();
76 mFilterResources.clear();
Chet Haased34dd712012-05-02 18:50:34 -070077 mSourcePaths.clear();
78
Romain Guy58ecc202012-09-07 11:58:36 -070079 mShaders.clear();
80 mShaderMap.clear();
81
Romain Guy43ccf462011-01-14 18:51:01 -080082 mPaints.clear();
83 mPaintMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -070084
Romain Guy735738c2012-12-03 12:34:51 -080085 mRegions.clear();
86 mRegionMap.clear();
87
Romain Guy2fc941e2011-02-03 15:06:05 -080088 mPaths.clear();
89 mPathMap.clear();
Romain Guyd586ad92011-06-22 16:14:36 -070090
Chet Haased98aa2d2010-10-25 15:47:32 -070091 mMatrices.clear();
Romain Guy04c9d8c2011-08-25 14:01:48 -070092
Chet Haase603f6de2012-09-14 15:31:25 -070093 mLayers.clear();
94
Romain Guy04c9d8c2011-08-25 14:01:48 -070095 mHasDrawOps = false;
Romain Guy54c1a642012-09-27 17:55:46 -070096 mFunctorCount = 0;
Romain Guy4aa90572010-09-26 18:40:37 -070097}
98
99///////////////////////////////////////////////////////////////////////////////
100// Operations
101///////////////////////////////////////////////////////////////////////////////
102
Jeff Brown162a0212011-07-21 17:02:54 -0700103DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
104 if (!displayList) {
105 displayList = new DisplayList(*this);
Chet Haase5977baa2011-01-05 18:01:22 -0800106 } else {
Jeff Brown162a0212011-07-21 17:02:54 -0700107 displayList->initFromDisplayListRenderer(*this, true);
Chet Haase5977baa2011-01-05 18:01:22 -0800108 }
Romain Guy04c9d8c2011-08-25 14:01:48 -0700109 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -0700110 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -0800111}
112
Romain Guy49c5fc02012-05-15 11:10:01 -0700113bool DisplayListRenderer::isDeferred() {
114 return true;
115}
116
Romain Guyb051e892010-09-28 19:09:36 -0700117void DisplayListRenderer::setViewport(int width, int height) {
118 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
119
120 mWidth = width;
121 mHeight = height;
122}
123
Romain Guy7c25aab2012-10-18 15:05:02 -0700124status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -0800125 float right, float bottom, bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700126 mSnapshot = new Snapshot(mFirstSnapshot,
127 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
128 mSaveCount = 1;
Romain Guy45e4c3d2012-09-11 17:17:07 -0700129
Romain Guyb051e892010-09-28 19:09:36 -0700130 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy45e4c3d2012-09-11 17:17:07 -0700131 mDirtyClip = opaque;
132
Romain Guy27454a42011-01-23 12:01:41 -0800133 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -0700134
Chet Haase44b2fe32012-06-06 19:03:58 -0700135 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -0800136}
137
138void DisplayListRenderer::finish() {
139 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -0800140 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -0700141}
142
Chet Haasedaf98e92011-01-10 14:10:36 -0800143void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800144}
Romain Guy2b1847e2011-01-26 13:43:01 -0800145
Chet Haasedaf98e92011-01-10 14:10:36 -0800146void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700147}
148
Romain Guy65549432012-03-26 16:45:05 -0700149status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -0800150 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -0800151 addDrawOp(new (alloc()) DrawFunctorOp(functor));
Romain Guy54c1a642012-09-27 17:55:46 -0700152 mFunctorCount++;
Romain Guy65549432012-03-26 16:45:05 -0700153 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -0800154}
155
Romain Guy4aa90572010-09-26 18:40:37 -0700156int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -0800157 addStateOp(new (alloc()) SaveOp(flags));
Romain Guy4aa90572010-09-26 18:40:37 -0700158 return OpenGLRenderer::save(flags);
159}
160
161void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700162 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800163 restoreToCount(getSaveCount() - 1);
164 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700165 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800166
167 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800168 insertTranslate();
Romain Guy4aa90572010-09-26 18:40:37 -0700169 OpenGLRenderer::restore();
170}
171
172void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800173 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800174 insertTranslate();
Romain Guy4aa90572010-09-26 18:40:37 -0700175 OpenGLRenderer::restoreToCount(saveCount);
176}
177
178int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chris Craikff785832013-03-08 13:12:16 -0800179 int alpha, SkXfermode::Mode mode, int flags) {
180 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, alpha, mode, flags));
Romain Guy5b3b3522010-10-27 18:57:51 -0700181 return OpenGLRenderer::save(flags);
182}
183
Romain Guy4aa90572010-09-26 18:40:37 -0700184void DisplayListRenderer::translate(float dx, float dy) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800185 mHasTranslate = true;
186 mTranslateX += dx;
187 mTranslateY += dy;
188 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -0700189 OpenGLRenderer::translate(dx, dy);
190}
191
192void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800193 addStateOp(new (alloc()) RotateOp(degrees));
Romain Guy4aa90572010-09-26 18:40:37 -0700194 OpenGLRenderer::rotate(degrees);
195}
196
197void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800198 addStateOp(new (alloc()) ScaleOp(sx, sy));
Romain Guy4aa90572010-09-26 18:40:37 -0700199 OpenGLRenderer::scale(sx, sy);
200}
201
Romain Guy807daf72011-01-18 11:19:19 -0800202void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800203 addStateOp(new (alloc()) SkewOp(sx, sy));
Romain Guy807daf72011-01-18 11:19:19 -0800204 OpenGLRenderer::skew(sx, sy);
205}
206
Romain Guy4aa90572010-09-26 18:40:37 -0700207void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800208 matrix = refMatrix(matrix);
209 addStateOp(new (alloc()) SetMatrixOp(matrix));
Romain Guy4aa90572010-09-26 18:40:37 -0700210 OpenGLRenderer::setMatrix(matrix);
211}
212
213void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800214 matrix = refMatrix(matrix);
215 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Romain Guy4aa90572010-09-26 18:40:37 -0700216 OpenGLRenderer::concatMatrix(matrix);
217}
218
219bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
220 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800221 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Romain Guy4aa90572010-09-26 18:40:37 -0700222 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
223}
224
Romain Guy735738c2012-12-03 12:34:51 -0800225bool DisplayListRenderer::clipPath(SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800226 path = refPath(path);
227 addStateOp(new (alloc()) ClipPathOp(path, op));
Romain Guy735738c2012-12-03 12:34:51 -0800228 return OpenGLRenderer::clipPath(path, op);
229}
230
231bool DisplayListRenderer::clipRegion(SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800232 region = refRegion(region);
233 addStateOp(new (alloc()) ClipRegionOp(region, op));
Romain Guy735738c2012-12-03 12:34:51 -0800234 return OpenGLRenderer::clipRegion(region, op);
235}
236
Romain Guy65549432012-03-26 16:45:05 -0700237status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chris Craikc3566d02013-02-04 16:16:33 -0800238 Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800239 // dirty is an out parameter and should not be recorded,
240 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700241
Chris Craik2af46352012-11-26 18:30:17 -0800242 // TODO: To be safe, the display list should be ref-counted in the
243 // resources cache, but we rely on the caller (UI toolkit) to
244 // do the right thing for now
245
246 addDrawOp(new (alloc()) DrawDisplayListOp(displayList, flags));
Romain Guy65549432012-03-26 16:45:05 -0700247 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800248}
249
Chris Craika08f95c2013-03-15 17:24:33 -0700250status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700251 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700252 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700253 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800254}
255
Chet Haase48659092012-05-31 15:21:51 -0700256status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800257 bitmap = refBitmap(bitmap);
258 paint = refPaint(paint);
259
Romain Guy3b748a42013-04-17 18:54:38 -0700260 const AssetAtlas::Entry* entry = mCaches.assetAtlas.getEntry(bitmap);
261 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint, entry));
Chet Haase48659092012-05-31 15:21:51 -0700262 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700263}
264
Chet Haase48659092012-05-31 15:21:51 -0700265status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800266 bitmap = refBitmap(bitmap);
267 matrix = refMatrix(matrix);
268 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800269
Chris Craik2af46352012-11-26 18:30:17 -0800270 addDrawOp(new (alloc()) DrawBitmapMatrixOp(bitmap, matrix, paint));
Chet Haase48659092012-05-31 15:21:51 -0700271 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700272}
273
Chet Haase48659092012-05-31 15:21:51 -0700274status_t DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700275 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700276 float dstRight, float dstBottom, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800277 bitmap = refBitmap(bitmap);
278 paint = refPaint(paint);
279
Chris Craik527a3aa2013-03-04 10:19:31 -0800280 if (srcLeft == 0 && srcTop == 0 &&
281 srcRight == bitmap->width() && srcBottom == bitmap->height() &&
282 (srcBottom - srcTop == dstBottom - dstTop) &&
283 (srcRight - srcLeft == dstRight - dstLeft)) {
284 // transform simple rect to rect drawing case into position bitmap ops, since they merge
Romain Guy3b748a42013-04-17 18:54:38 -0700285 const AssetAtlas::Entry* entry = mCaches.assetAtlas.getEntry(bitmap);
286 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, dstLeft, dstTop, paint, entry));
Chris Craik527a3aa2013-03-04 10:19:31 -0800287 return DrawGlInfo::kStatusDone;
288 }
289
Chris Craik2af46352012-11-26 18:30:17 -0800290 addDrawOp(new (alloc()) DrawBitmapRectOp(bitmap,
291 srcLeft, srcTop, srcRight, srcBottom,
292 dstLeft, dstTop, dstRight, dstBottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700293 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700294}
295
Chet Haase48659092012-05-31 15:21:51 -0700296status_t DisplayListRenderer::drawBitmapData(SkBitmap* bitmap, float left, float top,
297 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800298 bitmap = refBitmapData(bitmap);
299 paint = refPaint(paint);
300
301 addDrawOp(new (alloc()) DrawBitmapDataOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700302 return DrawGlInfo::kStatusDone;
Romain Guye651cc62012-05-14 19:44:40 -0700303}
304
Chet Haase48659092012-05-31 15:21:51 -0700305status_t DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -0800306 float* vertices, int* colors, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800307 int count = (meshWidth + 1) * (meshHeight + 1) * 2;
308 bitmap = refBitmap(bitmap);
309 vertices = refBuffer<float>(vertices, count);
310 paint = refPaint(paint);
311 colors = refBuffer<int>(colors, count);
312
313 addDrawOp(new (alloc()) DrawBitmapMeshOp(bitmap, meshWidth, meshHeight,
314 vertices, colors, paint));
Chet Haase48659092012-05-31 15:21:51 -0700315 return DrawGlInfo::kStatusDone;
Romain Guy5a7b4662011-01-20 19:09:30 -0800316}
317
Romain Guy3b748a42013-04-17 18:54:38 -0700318status_t DisplayListRenderer::drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
319 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guybe6f9dc2012-07-16 12:41:17 -0700320 int alpha;
321 SkXfermode::Mode mode;
322 OpenGLRenderer::getAlphaAndModeDirect(paint, &alpha, &mode);
323
Chris Craik2af46352012-11-26 18:30:17 -0800324 bitmap = refBitmap(bitmap);
Chris Craik2af46352012-11-26 18:30:17 -0800325
Romain Guy3b748a42013-04-17 18:54:38 -0700326 addDrawOp(new (alloc()) DrawPatchOp(bitmap, patch, left, top, right, bottom, alpha, mode));
Chet Haase48659092012-05-31 15:21:51 -0700327 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700328}
329
Chet Haase48659092012-05-31 15:21:51 -0700330status_t DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Chris Craik2af46352012-11-26 18:30:17 -0800331 addDrawOp(new (alloc()) DrawColorOp(color, mode));
Chet Haase48659092012-05-31 15:21:51 -0700332 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700333}
334
Chet Haase48659092012-05-31 15:21:51 -0700335status_t DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700336 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800337 paint = refPaint(paint);
338 addDrawOp(new (alloc()) DrawRectOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700339 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700340}
341
Chet Haase48659092012-05-31 15:21:51 -0700342status_t DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
Chet Haasea1cff502012-02-21 13:43:44 -0800343 float rx, float ry, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800344 paint = refPaint(paint);
345 addDrawOp(new (alloc()) DrawRoundRectOp(left, top, right, bottom, rx, ry, paint));
Chet Haase48659092012-05-31 15:21:51 -0700346 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800347}
348
Chet Haase48659092012-05-31 15:21:51 -0700349status_t DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800350 paint = refPaint(paint);
351 addDrawOp(new (alloc()) DrawCircleOp(x, y, radius, paint));
Chet Haase48659092012-05-31 15:21:51 -0700352 return DrawGlInfo::kStatusDone;
Romain Guy01d58e42011-01-19 21:54:02 -0800353}
354
Chet Haase48659092012-05-31 15:21:51 -0700355status_t DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800356 SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800357 paint = refPaint(paint);
358 addDrawOp(new (alloc()) DrawOvalOp(left, top, right, bottom, paint));
Chet Haase48659092012-05-31 15:21:51 -0700359 return DrawGlInfo::kStatusDone;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800360}
361
Chet Haase48659092012-05-31 15:21:51 -0700362status_t DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -0800363 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800364 paint = refPaint(paint);
365 addDrawOp(new (alloc()) DrawArcOp(left, top, right, bottom,
366 startAngle, sweepAngle, useCenter, paint));
Chet Haase48659092012-05-31 15:21:51 -0700367 return DrawGlInfo::kStatusDone;
Romain Guy8b2f5262011-01-23 16:15:02 -0800368}
369
Chet Haase48659092012-05-31 15:21:51 -0700370status_t DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800371 path = refPath(path);
372 paint = refPaint(paint);
Romain Guy33f6beb2012-02-16 19:24:51 -0800373
Chris Craik2af46352012-11-26 18:30:17 -0800374 addDrawOp(new (alloc()) DrawPathOp(path, paint));
Chet Haase48659092012-05-31 15:21:51 -0700375 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700376}
377
Chet Haase48659092012-05-31 15:21:51 -0700378status_t DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800379 points = refBuffer<float>(points, count);
380 paint = refPaint(paint);
381
382 addDrawOp(new (alloc()) DrawLinesOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700383 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700384}
385
Chet Haase48659092012-05-31 15:21:51 -0700386status_t DisplayListRenderer::drawPoints(float* points, int count, SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800387 points = refBuffer<float>(points, count);
388 paint = refPaint(paint);
389
390 addDrawOp(new (alloc()) DrawPointsOp(points, count, paint));
Chet Haase48659092012-05-31 15:21:51 -0700391 return DrawGlInfo::kStatusDone;
Romain Guyed6fcb02011-03-21 13:11:28 -0700392}
393
Chet Haase48659092012-05-31 15:21:51 -0700394status_t DisplayListRenderer::drawTextOnPath(const char* text, int bytesCount, int count,
Romain Guy325740f2012-02-24 16:48:34 -0800395 SkPath* path, float hOffset, float vOffset, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700396 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800397
Chris Craik2af46352012-11-26 18:30:17 -0800398 text = refText(text, bytesCount);
399 path = refPath(path);
400 paint = refPaint(paint);
401
402 DrawOp* op = new (alloc()) DrawTextOnPathOp(text, bytesCount, count, path,
403 hOffset, vOffset, paint);
Romain Guy0f6675332013-03-01 14:31:04 -0800404 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700405 return DrawGlInfo::kStatusDone;
Romain Guy325740f2012-02-24 16:48:34 -0800406}
407
Chet Haase48659092012-05-31 15:21:51 -0700408status_t DisplayListRenderer::drawPosText(const char* text, int bytesCount, int count,
Romain Guyeb9a5362012-01-17 17:39:26 -0800409 const float* positions, SkPaint* paint) {
Chet Haase48659092012-05-31 15:21:51 -0700410 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
Chris Craik2af46352012-11-26 18:30:17 -0800411
Chris Craik2af46352012-11-26 18:30:17 -0800412 text = refText(text, bytesCount);
413 positions = refBuffer<float>(positions, count * 2);
414 paint = refPaint(paint);
415
416 DrawOp* op = new (alloc()) DrawPosTextOp(text, bytesCount, count, positions, paint);
Romain Guy0f6675332013-03-01 14:31:04 -0800417 addDrawOp(op);
Chet Haase48659092012-05-31 15:21:51 -0700418 return DrawGlInfo::kStatusDone;
Romain Guyeb9a5362012-01-17 17:39:26 -0800419}
420
Romain Guyc2525952012-07-27 16:41:22 -0700421status_t DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
Chris Craik527a3aa2013-03-04 10:19:31 -0800422 float x, float y, const float* positions, SkPaint* paint,
Chris Craik41541822013-05-03 16:35:54 -0700423 float totalAdvance, const Rect& bounds, DrawOpMode drawOpMode) {
Chris Craik527a3aa2013-03-04 10:19:31 -0800424
Raph Levien996e57c2012-07-23 15:22:52 -0700425 if (!text || count <= 0) return DrawGlInfo::kStatusDone;
426
Chris Craik2af46352012-11-26 18:30:17 -0800427 text = refText(text, bytesCount);
428 positions = refBuffer<float>(positions, count * 2);
429 paint = refPaint(paint);
Raph Levien996e57c2012-07-23 15:22:52 -0700430
Chris Craik41541822013-05-03 16:35:54 -0700431 DrawOp* op = new (alloc()) DrawTextOp(text, bytesCount, count,
432 x, y, positions, paint, totalAdvance, bounds);
Romain Guy0f6675332013-03-01 14:31:04 -0800433 addDrawOp(op);
Raph Levien996e57c2012-07-23 15:22:52 -0700434 return DrawGlInfo::kStatusDone;
435}
436
Romain Guy672433d2013-01-04 19:05:13 -0800437status_t DisplayListRenderer::drawRects(const float* rects, int count, SkPaint* paint) {
438 if (count <= 0) return DrawGlInfo::kStatusDone;
439
Chris Craik2af46352012-11-26 18:30:17 -0800440 rects = refBuffer<float>(rects, count);
441 paint = refPaint(paint);
442 addDrawOp(new (alloc()) DrawRectsOp(rects, count, paint));
Romain Guy672433d2013-01-04 19:05:13 -0800443 return DrawGlInfo::kStatusDone;
444}
445
Romain Guy4aa90572010-09-26 18:40:37 -0700446void DisplayListRenderer::resetShader() {
Chris Craik2af46352012-11-26 18:30:17 -0800447 addStateOp(new (alloc()) ResetShaderOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700448}
449
450void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chris Craik2af46352012-11-26 18:30:17 -0800451 shader = refShader(shader);
452 addStateOp(new (alloc()) SetupShaderOp(shader));
Romain Guy4aa90572010-09-26 18:40:37 -0700453}
454
455void DisplayListRenderer::resetColorFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800456 addStateOp(new (alloc()) ResetColorFilterOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700457}
458
459void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chris Craik2af46352012-11-26 18:30:17 -0800460 filter = refColorFilter(filter);
461 addStateOp(new (alloc()) SetupColorFilterOp(filter));
Romain Guy4aa90572010-09-26 18:40:37 -0700462}
463
464void DisplayListRenderer::resetShadow() {
Chris Craik2af46352012-11-26 18:30:17 -0800465 addStateOp(new (alloc()) ResetShadowOp());
Romain Guy4aa90572010-09-26 18:40:37 -0700466}
467
468void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Chris Craik2af46352012-11-26 18:30:17 -0800469 addStateOp(new (alloc()) SetupShadowOp(radius, dx, dy, color));
Romain Guy4aa90572010-09-26 18:40:37 -0700470}
471
Romain Guy5ff9df62012-01-23 17:09:05 -0800472void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800473 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800474}
475
476void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800477 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
478}
479
480void DisplayListRenderer::insertRestoreToCount() {
481 if (mRestoreSaveCount >= 0) {
482 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
483 mDisplayListData->displayListOps.add(op);
484 mRestoreSaveCount = -1;
485 }
486}
487
488void DisplayListRenderer::insertTranslate() {
489 if (mHasTranslate) {
490 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
491 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
492 mDisplayListData->displayListOps.add(op);
493 mTranslateX = mTranslateY = 0.0f;
494 }
495 mHasTranslate = false;
496 }
497}
498
499void DisplayListRenderer::addStateOp(StateOp* op) {
500 addOpInternal(op);
501}
502
Romain Guy0f6675332013-03-01 14:31:04 -0800503void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800504 Rect localBounds;
505 if (op->getLocalBounds(localBounds)) {
Romain Guy0f6675332013-03-01 14:31:04 -0800506 bool rejected = quickRejectNoScissor(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800507 localBounds.right, localBounds.bottom);
508 op->setQuickRejected(rejected);
509 }
510 mHasDrawOps = true;
511 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800512}
513
Romain Guy4aa90572010-09-26 18:40:37 -0700514}; // namespace uirenderer
515}; // namespace android