blob: 051ccfeca7a261668367dbfa529e82d0715b03f0 [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 }
Chris Craikf57776b2013-10-25 18:30:17 -0700114 // TODO: should just avoid setting the DisplayList's DisplayListData
Romain Guy04c9d8c2011-08-25 14:01:48 -0700115 displayList->setRenderable(mHasDrawOps);
Jeff Brown162a0212011-07-21 17:02:54 -0700116 return displayList;
Chet Haase5977baa2011-01-05 18:01:22 -0800117}
118
Romain Guyb051e892010-09-28 19:09:36 -0700119void DisplayListRenderer::setViewport(int width, int height) {
Chris Craikf57776b2013-10-25 18:30:17 -0700120 // TODO: DisplayListRenderer shouldn't have a projection matrix, as it should never be used
121 mViewProjMatrix.loadOrtho(0, width, height, 0, -1, 1);
Romain Guyb051e892010-09-28 19:09:36 -0700122
Chris Craik14e51302013-12-30 15:32:54 -0800123 initializeViewport(width, height);
Romain Guyb051e892010-09-28 19:09:36 -0700124}
125
Romain Guy7c25aab2012-10-18 15:05:02 -0700126status_t DisplayListRenderer::prepareDirty(float left, float top,
Romain Guy7d7b5492011-01-24 16:33:45 -0800127 float right, float bottom, bool opaque) {
Chris Craik14e51302013-12-30 15:32:54 -0800128 initializeSaveStack(0, 0, getWidth(), getHeight());
Romain Guy45e4c3d2012-09-11 17:17:07 -0700129
Romain Guy45e4c3d2012-09-11 17:17:07 -0700130 mDirtyClip = opaque;
Romain Guy27454a42011-01-23 12:01:41 -0800131 mRestoreSaveCount = -1;
Romain Guy45e4c3d2012-09-11 17:17:07 -0700132
Chet Haase44b2fe32012-06-06 19:03:58 -0700133 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Romain Guy27454a42011-01-23 12:01:41 -0800134}
135
136void DisplayListRenderer::finish() {
137 insertRestoreToCount();
Chris Craik2af46352012-11-26 18:30:17 -0800138 insertTranslate();
Romain Guyb051e892010-09-28 19:09:36 -0700139}
140
Chet Haasedaf98e92011-01-10 14:10:36 -0800141void DisplayListRenderer::interrupt() {
Chet Haasedaf98e92011-01-10 14:10:36 -0800142}
Romain Guy2b1847e2011-01-26 13:43:01 -0800143
Chet Haasedaf98e92011-01-10 14:10:36 -0800144void DisplayListRenderer::resume() {
Romain Guy4aa90572010-09-26 18:40:37 -0700145}
146
Romain Guy65549432012-03-26 16:45:05 -0700147status_t DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) {
Romain Guycabfcc12011-03-07 18:06:46 -0800148 // Ignore dirty during recording, it matters only when we replay
Chris Craik2af46352012-11-26 18:30:17 -0800149 addDrawOp(new (alloc()) DrawFunctorOp(functor));
Romain Guy54c1a642012-09-27 17:55:46 -0700150 mFunctorCount++;
Romain Guy65549432012-03-26 16:45:05 -0700151 return DrawGlInfo::kStatusDone; // No invalidate needed at record-time
Chet Haasedaf98e92011-01-10 14:10:36 -0800152}
153
Romain Guy4aa90572010-09-26 18:40:37 -0700154int DisplayListRenderer::save(int flags) {
Chris Craik2af46352012-11-26 18:30:17 -0800155 addStateOp(new (alloc()) SaveOp(flags));
Chris Craik14e51302013-12-30 15:32:54 -0800156 return StatefulBaseRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700157}
158
159void DisplayListRenderer::restore() {
Romain Guy04c9d8c2011-08-25 14:01:48 -0700160 if (mRestoreSaveCount < 0) {
Romain Guy33f6beb2012-02-16 19:24:51 -0800161 restoreToCount(getSaveCount() - 1);
162 return;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700163 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800164
165 mRestoreSaveCount--;
Chris Craik2af46352012-11-26 18:30:17 -0800166 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800167 StatefulBaseRenderer::restore();
Romain Guy4aa90572010-09-26 18:40:37 -0700168}
169
170void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800171 mRestoreSaveCount = saveCount;
Chris Craik2af46352012-11-26 18:30:17 -0800172 insertTranslate();
Chris Craik14e51302013-12-30 15:32:54 -0800173 StatefulBaseRenderer::restoreToCount(saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700174}
175
176int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chris Craikff785832013-03-08 13:12:16 -0800177 int alpha, SkXfermode::Mode mode, int flags) {
178 addStateOp(new (alloc()) SaveLayerOp(left, top, right, bottom, alpha, mode, flags));
Chris Craik14e51302013-12-30 15:32:54 -0800179 return StatefulBaseRenderer::save(flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700180}
181
Chris Craikb4589422013-12-26 15:13:13 -0800182void DisplayListRenderer::translate(float dx, float dy, float dz) {
183 // ignore dz, not used at defer time
Romain Guy33f6beb2012-02-16 19:24:51 -0800184 mHasTranslate = true;
185 mTranslateX += dx;
186 mTranslateY += dy;
187 insertRestoreToCount();
Chris Craik14e51302013-12-30 15:32:54 -0800188 StatefulBaseRenderer::translate(dx, dy, dz);
Romain Guy4aa90572010-09-26 18:40:37 -0700189}
190
191void DisplayListRenderer::rotate(float degrees) {
Chris Craik2af46352012-11-26 18:30:17 -0800192 addStateOp(new (alloc()) RotateOp(degrees));
Chris Craik14e51302013-12-30 15:32:54 -0800193 StatefulBaseRenderer::rotate(degrees);
Romain Guy4aa90572010-09-26 18:40:37 -0700194}
195
196void DisplayListRenderer::scale(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800197 addStateOp(new (alloc()) ScaleOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800198 StatefulBaseRenderer::scale(sx, sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700199}
200
Romain Guy807daf72011-01-18 11:19:19 -0800201void DisplayListRenderer::skew(float sx, float sy) {
Chris Craik2af46352012-11-26 18:30:17 -0800202 addStateOp(new (alloc()) SkewOp(sx, sy));
Chris Craik14e51302013-12-30 15:32:54 -0800203 StatefulBaseRenderer::skew(sx, sy);
Romain Guy807daf72011-01-18 11:19:19 -0800204}
205
Chris Craikd218a922014-01-02 17:13:34 -0800206void DisplayListRenderer::setMatrix(const SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800207 matrix = refMatrix(matrix);
208 addStateOp(new (alloc()) SetMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800209 StatefulBaseRenderer::setMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700210}
211
Chris Craikd218a922014-01-02 17:13:34 -0800212void DisplayListRenderer::concatMatrix(const SkMatrix* matrix) {
Chris Craik2af46352012-11-26 18:30:17 -0800213 matrix = refMatrix(matrix);
214 addStateOp(new (alloc()) ConcatMatrixOp(matrix));
Chris Craik14e51302013-12-30 15:32:54 -0800215 StatefulBaseRenderer::concatMatrix(matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700216}
217
218bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
219 SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800220 addStateOp(new (alloc()) ClipRectOp(left, top, right, bottom, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800221 return StatefulBaseRenderer::clipRect(left, top, right, bottom, op);
Romain Guy4aa90572010-09-26 18:40:37 -0700222}
223
Chris Craikd218a922014-01-02 17:13:34 -0800224bool DisplayListRenderer::clipPath(const SkPath* path, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800225 path = refPath(path);
226 addStateOp(new (alloc()) ClipPathOp(path, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800227 return StatefulBaseRenderer::clipPath(path, op);
Romain Guy735738c2012-12-03 12:34:51 -0800228}
229
Chris Craikd218a922014-01-02 17:13:34 -0800230bool DisplayListRenderer::clipRegion(const SkRegion* region, SkRegion::Op op) {
Chris Craik2af46352012-11-26 18:30:17 -0800231 region = refRegion(region);
232 addStateOp(new (alloc()) ClipRegionOp(region, op));
Chris Craikd6b65f62014-01-01 14:45:21 -0800233 return StatefulBaseRenderer::clipRegion(region, op);
Romain Guy735738c2012-12-03 12:34:51 -0800234}
235
Romain Guy65549432012-03-26 16:45:05 -0700236status_t DisplayListRenderer::drawDisplayList(DisplayList* displayList,
Chris Craikc3566d02013-02-04 16:16:33 -0800237 Rect& dirty, int32_t flags) {
Romain Guycabfcc12011-03-07 18:06:46 -0800238 // dirty is an out parameter and should not be recorded,
239 // it matters only when replaying the display list
Chet Haaseb85967b2012-03-26 14:37:51 -0700240
Chris Craik2af46352012-11-26 18:30:17 -0800241 // TODO: To be safe, the display list should be ref-counted in the
242 // resources cache, but we rely on the caller (UI toolkit) to
243 // do the right thing for now
244
Chris Craikd6b65f62014-01-01 14:45:21 -0800245 DrawDisplayListOp* op = new (alloc()) DrawDisplayListOp(displayList,
246 flags, *currentTransform());
Chris Craikf57776b2013-10-25 18:30:17 -0700247 addDrawOp(op);
248 mDisplayListData->children.push(op);
249
Romain Guy65549432012-03-26 16:45:05 -0700250 return DrawGlInfo::kStatusDone;
Romain Guy0fe478e2010-11-08 12:08:41 -0800251}
252
Chris Craika08f95c2013-03-15 17:24:33 -0700253status_t DisplayListRenderer::drawLayer(Layer* layer, float x, float y) {
Romain Guyce4a7df2013-03-28 11:32:33 -0700254 layer = refLayer(layer);
Chris Craika08f95c2013-03-15 17:24:33 -0700255 addDrawOp(new (alloc()) DrawLayerOp(layer, x, y));
Chet Haase48659092012-05-31 15:21:51 -0700256 return DrawGlInfo::kStatusDone;
Romain Guy6c319ca2011-01-11 14:29:25 -0800257}
258
Chris Craikd218a922014-01-02 17:13:34 -0800259status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float left, float top,
260 const SkPaint* paint) {
Chris Craik2af46352012-11-26 18:30:17 -0800261 bitmap = refBitmap(bitmap);
262 paint = refPaint(paint);
263
Romain Guy55b6f952013-06-27 15:27:09 -0700264 addDrawOp(new (alloc()) DrawBitmapOp(bitmap, left, top, paint));
Chet Haase48659092012-05-31 15:21:51 -0700265 return DrawGlInfo::kStatusDone;
Romain Guy4aa90572010-09-26 18:40:37 -0700266}
267
Chris Craikd218a922014-01-02 17:13:34 -0800268status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix,
269 const 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
Chris Craikd218a922014-01-02 17:13:34 -0800278status_t DisplayListRenderer::drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700279 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd218a922014-01-02 17:13:34 -0800280 float dstRight, float dstBottom, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800299status_t DisplayListRenderer::drawBitmapData(const SkBitmap* bitmap, float left, float top,
300 const 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
Chris Craikd218a922014-01-02 17:13:34 -0800308status_t DisplayListRenderer::drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
309 const float* vertices, const int* colors, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800321status_t DisplayListRenderer::drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
322 float left, float top, float right, float bottom, const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800337 const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800344 float rx, float ry, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800350status_t DisplayListRenderer::drawCircle(float x, float y, float radius, const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800357 const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800364 float startAngle, float sweepAngle, bool useCenter, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800371status_t DisplayListRenderer::drawPath(const SkPath* path, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800379status_t DisplayListRenderer::drawLines(const float* points, int count, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800387status_t DisplayListRenderer::drawPoints(const float* points, int count, const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800396 const SkPath* path, float hOffset, float vOffset, const 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,
Chris Craikd218a922014-01-02 17:13:34 -0800410 const float* positions, const 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 Craikd218a922014-01-02 17:13:34 -0800423 float x, float y, const float* positions, const 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
Chris Craikd218a922014-01-02 17:13:34 -0800438status_t DisplayListRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
Romain Guy672433d2013-01-04 19:05:13 -0800439 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 Guy9b5a1a22013-08-09 14:06:29 -0700467 OpenGLRenderer::resetShadow();
Romain Guy4aa90572010-09-26 18:40:37 -0700468}
469
470void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Chris Craik2af46352012-11-26 18:30:17 -0800471 addStateOp(new (alloc()) SetupShadowOp(radius, dx, dy, color));
Romain Guy9b5a1a22013-08-09 14:06:29 -0700472 OpenGLRenderer::setupShadow(radius, dx, dy, color);
Romain Guy4aa90572010-09-26 18:40:37 -0700473}
474
Romain Guy5ff9df62012-01-23 17:09:05 -0800475void DisplayListRenderer::resetPaintFilter() {
Chris Craik2af46352012-11-26 18:30:17 -0800476 addStateOp(new (alloc()) ResetPaintFilterOp());
Romain Guy5ff9df62012-01-23 17:09:05 -0800477}
478
479void DisplayListRenderer::setupPaintFilter(int clearBits, int setBits) {
Chris Craik2af46352012-11-26 18:30:17 -0800480 addStateOp(new (alloc()) SetupPaintFilterOp(clearBits, setBits));
481}
482
483void DisplayListRenderer::insertRestoreToCount() {
484 if (mRestoreSaveCount >= 0) {
485 DisplayListOp* op = new (alloc()) RestoreToCountOp(mRestoreSaveCount);
486 mDisplayListData->displayListOps.add(op);
487 mRestoreSaveCount = -1;
488 }
489}
490
491void DisplayListRenderer::insertTranslate() {
492 if (mHasTranslate) {
493 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
494 DisplayListOp* op = new (alloc()) TranslateOp(mTranslateX, mTranslateY);
495 mDisplayListData->displayListOps.add(op);
496 mTranslateX = mTranslateY = 0.0f;
497 }
498 mHasTranslate = false;
499 }
500}
501
502void DisplayListRenderer::addStateOp(StateOp* op) {
503 addOpInternal(op);
504}
505
Romain Guy0f667532013-03-01 14:31:04 -0800506void DisplayListRenderer::addDrawOp(DrawOp* op) {
Chris Craik2af46352012-11-26 18:30:17 -0800507 Rect localBounds;
Chris Craikc1c5f082013-09-11 16:23:37 -0700508 if (op->getLocalBounds(mDrawModifiers, localBounds)) {
Chris Craikf0a59072013-11-19 18:00:46 -0800509 bool rejected = quickRejectConservative(localBounds.left, localBounds.top,
Chris Craik2af46352012-11-26 18:30:17 -0800510 localBounds.right, localBounds.bottom);
511 op->setQuickRejected(rejected);
512 }
Chris Craikc1c5f082013-09-11 16:23:37 -0700513
Chris Craik2af46352012-11-26 18:30:17 -0800514 mHasDrawOps = true;
515 addOpInternal(op);
Romain Guy5ff9df62012-01-23 17:09:05 -0800516}
517
Romain Guy4aa90572010-09-26 18:40:37 -0700518}; // namespace uirenderer
519}; // namespace android