blob: a74a95fc28b82e3ca875bc1188be61c6596cc500 [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
19#include "DisplayListRenderer.h"
20
21namespace android {
22namespace uirenderer {
23
24///////////////////////////////////////////////////////////////////////////////
Romain Guy7975fb62010-10-01 16:36:14 -070025// Defines
26///////////////////////////////////////////////////////////////////////////////
27
28#define PATH_HEAP_SIZE 64
29
30///////////////////////////////////////////////////////////////////////////////
31// Helpers
32///////////////////////////////////////////////////////////////////////////////
33
34PathHeap::PathHeap(): mHeap(PATH_HEAP_SIZE * sizeof(SkPath)) {
35}
36
37PathHeap::PathHeap(SkFlattenableReadBuffer& buffer): mHeap(PATH_HEAP_SIZE * sizeof(SkPath)) {
38 int count = buffer.readS32();
39
40 mPaths.setCount(count);
41 SkPath** ptr = mPaths.begin();
42 SkPath* p = (SkPath*) mHeap.allocThrow(count * sizeof(SkPath));
43
44 for (int i = 0; i < count; i++) {
45 new (p) SkPath;
46 p->unflatten(buffer);
47 *ptr++ = p;
48 p++;
49 }
50}
51
52PathHeap::~PathHeap() {
53 SkPath** iter = mPaths.begin();
54 SkPath** stop = mPaths.end();
55 while (iter < stop) {
56 (*iter)->~SkPath();
57 iter++;
58 }
59}
60
61int PathHeap::append(const SkPath& path) {
62 SkPath* p = (SkPath*) mHeap.allocThrow(sizeof(SkPath));
63 new (p) SkPath(path);
64 *mPaths.append() = p;
65 return mPaths.count();
66}
67
68void PathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
69 int count = mPaths.count();
70
71 buffer.write32(count);
72 SkPath** iter = mPaths.begin();
73 SkPath** stop = mPaths.end();
74 while (iter < stop) {
75 (*iter)->flatten(buffer);
76 iter++;
77 }
78}
79
80///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070081// Display list
82///////////////////////////////////////////////////////////////////////////////
83
Romain Guyffac7fc2011-01-13 17:21:49 -080084const char* DisplayList::OP_NAMES[] = {
85 "AcquireContext",
86 "ReleaseContext",
87 "Save",
88 "Restore",
89 "RestoreToCount",
90 "SaveLayer",
91 "SaveLayerAlpha",
92 "Translate",
93 "Rotate",
94 "Scale",
95 "SetMatrix",
96 "ConcatMatrix",
97 "ClipRect",
98 "DrawDisplayList",
99 "DrawLayer",
100 "DrawBitmap",
101 "DrawBitmapMatrix",
102 "DrawBitmapRect",
103 "DrawPatch",
104 "DrawColor",
105 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -0800106 "DrawRoundRect",
107 "DrawCircle",
Romain Guyffac7fc2011-01-13 17:21:49 -0800108 "DrawPath",
109 "DrawLines",
110 "DrawText",
111 "ResetShader",
112 "SetupShader",
113 "ResetColorFilter",
114 "SetupColorFilter",
115 "ResetShadow",
116 "SetupShadow"
117};
118
Romain Guyb051e892010-09-28 19:09:36 -0700119DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -0800120 initFromDisplayListRenderer(recorder);
121}
122
123DisplayList::~DisplayList() {
124 sk_free((void*) mReader.base());
125
126 Caches& caches = Caches::getInstance();
127
128 for (size_t i = 0; i < mBitmapResources.size(); i++) {
129 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
130 }
131 mBitmapResources.clear();
132
Romain Guy24c00212011-01-14 15:31:00 -0800133 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800134 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800135 }
Romain Guy24c00212011-01-14 15:31:00 -0800136 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800137
138 for (size_t i = 0; i < mPaints.size(); i++) {
139 delete mPaints.itemAt(i);
140 }
141 mPaints.clear();
142
143 for (size_t i = 0; i < mMatrices.size(); i++) {
144 delete mMatrices.itemAt(i);
145 }
146 mMatrices.clear();
147
148 if (mPathHeap) {
149 for (int i = 0; i < mPathHeap->count(); i++) {
150 caches.pathCache.removeDeferred(&(*mPathHeap)[i]);
151 }
152 mPathHeap->safeUnref();
153 }
154}
155
156void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder) {
Romain Guyb051e892010-09-28 19:09:36 -0700157 const SkWriter32& writer = recorder.writeStream();
158 init();
159
160 if (writer.size() == 0) {
161 return;
162 }
163
164 size_t size = writer.size();
165 void* buffer = sk_malloc_throw(size);
166 writer.flatten(buffer);
167 mReader.setMemory(buffer, size);
168
169 mRCPlayback.reset(&recorder.mRCRecorder);
170 mRCPlayback.setupBuffer(mReader);
171
172 mTFPlayback.reset(&recorder.mTFRecorder);
173 mTFPlayback.setupBuffer(mReader);
174
Chet Haase5c13d892010-10-08 08:37:55 -0700175 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700176
Chet Haase5c13d892010-10-08 08:37:55 -0700177 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
178 for (size_t i = 0; i < bitmapResources.size(); i++) {
179 SkBitmap* resource = bitmapResources.itemAt(i);
180 mBitmapResources.add(resource);
181 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700182 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700183
Romain Guy24c00212011-01-14 15:31:00 -0800184 const Vector<SkiaShader*> &shaders = recorder.getShaders();
185 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800186 SkiaShader* shader = shaders.itemAt(i);
187 mShaders.add(shader);
188 caches.resourceCache.incrementRefcount(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700189 }
190
Chet Haased98aa2d2010-10-25 15:47:32 -0700191 const Vector<SkPaint*> &paints = recorder.getPaints();
192 for (size_t i = 0; i < paints.size(); i++) {
193 mPaints.add(paints.itemAt(i));
194 }
195
196 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
197 for (size_t i = 0; i < matrices.size(); i++) {
198 mMatrices.add(matrices.itemAt(i));
199 }
200
Romain Guyb051e892010-09-28 19:09:36 -0700201 mPathHeap = recorder.mPathHeap;
Romain Guy9e108412010-11-09 14:35:20 -0800202 if (mPathHeap) {
203 mPathHeap->safeRef();
204 }
Romain Guyb051e892010-09-28 19:09:36 -0700205}
206
Romain Guyb051e892010-09-28 19:09:36 -0700207void DisplayList::init() {
Romain Guyb051e892010-09-28 19:09:36 -0700208 mPathHeap = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700209}
210
Romain Guyffac7fc2011-01-13 17:21:49 -0800211void DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
Romain Guyb051e892010-09-28 19:09:36 -0700212 TextContainer text;
213 mReader.rewind();
214
Romain Guyffac7fc2011-01-13 17:21:49 -0800215#if DEBUG_DISPLAY_LIST
216 uint32_t count = (level + 1) * 2;
217 char indent[count + 1];
218 for (uint32_t i = 0; i < count; i++) {
219 indent[i] = ' ';
220 }
221 indent[count] = '\0';
222 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
223#endif
Romain Guyb051e892010-09-28 19:09:36 -0700224
Romain Guyffac7fc2011-01-13 17:21:49 -0800225 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700226 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700227 int op = mReader.readInt();
Romain Guyffac7fc2011-01-13 17:21:49 -0800228 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
229
Romain Guy5b3b3522010-10-27 18:57:51 -0700230 switch (op) {
Romain Guyb051e892010-09-28 19:09:36 -0700231 case AcquireContext: {
232 renderer.acquireContext();
233 }
234 break;
235 case ReleaseContext: {
236 renderer.releaseContext();
237 }
238 break;
239 case Save: {
240 renderer.save(getInt());
241 }
242 break;
243 case Restore: {
244 renderer.restore();
245 }
246 break;
247 case RestoreToCount: {
248 renderer.restoreToCount(saveCount + getInt());
249 }
250 break;
251 case SaveLayer: {
252 renderer.saveLayer(getFloat(), getFloat(), getFloat(), getFloat(),
253 getPaint(), getInt());
254 }
255 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700256 case SaveLayerAlpha: {
257 renderer.saveLayerAlpha(getFloat(), getFloat(), getFloat(), getFloat(),
258 getInt(), getInt());
259 }
260 break;
Romain Guyb051e892010-09-28 19:09:36 -0700261 case Translate: {
262 renderer.translate(getFloat(), getFloat());
263 }
264 break;
265 case Rotate: {
266 renderer.rotate(getFloat());
267 }
268 break;
269 case Scale: {
270 renderer.scale(getFloat(), getFloat());
271 }
272 break;
Romain Guy807daf72011-01-18 11:19:19 -0800273 case Skew: {
274 renderer.skew(getFloat(), getFloat());
275 }
276 break;
Romain Guyb051e892010-09-28 19:09:36 -0700277 case SetMatrix: {
278 renderer.setMatrix(getMatrix());
279 }
280 break;
281 case ConcatMatrix: {
282 renderer.concatMatrix(getMatrix());
283 }
284 break;
285 case ClipRect: {
286 renderer.clipRect(getFloat(), getFloat(), getFloat(), getFloat(),
287 (SkRegion::Op) getInt());
288 }
289 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800290 case DrawDisplayList: {
Romain Guyffac7fc2011-01-13 17:21:49 -0800291 renderer.drawDisplayList(getDisplayList(), level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800292 }
293 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800294 case DrawLayer: {
Romain Guyada830f2011-01-13 12:13:20 -0800295 renderer.drawLayer((Layer*) getInt(), getFloat(), getFloat(), getPaint());
Romain Guy6c319ca2011-01-11 14:29:25 -0800296 }
297 break;
Romain Guyb051e892010-09-28 19:09:36 -0700298 case DrawBitmap: {
299 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getPaint());
300 }
301 break;
302 case DrawBitmapMatrix: {
303 renderer.drawBitmap(getBitmap(), getMatrix(), getPaint());
304 }
305 break;
306 case DrawBitmapRect: {
307 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getFloat(), getFloat(),
308 getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
309 }
310 break;
311 case DrawPatch: {
312 int32_t* xDivs = NULL;
313 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700314 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700315 uint32_t xDivsCount = 0;
316 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700317 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700318
319 SkBitmap* bitmap = getBitmap();
320
321 xDivs = getInts(xDivsCount);
322 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700323 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700324
Romain Guy4bb94202010-10-12 15:59:26 -0700325 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
326 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
Romain Guyb051e892010-09-28 19:09:36 -0700327 }
328 break;
329 case DrawColor: {
330 renderer.drawColor(getInt(), (SkXfermode::Mode) getInt());
331 }
332 break;
333 case DrawRect: {
334 renderer.drawRect(getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
335 }
336 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800337 case DrawRoundRect: {
338 renderer.drawRoundRect(getFloat(), getFloat(), getFloat(), getFloat(),
339 getFloat(), getFloat(), getPaint());
340 }
341 break;
342 case DrawCircle: {
343 renderer.drawCircle(getFloat(), getFloat(), getFloat(), getPaint());
344 }
345 break;
Romain Guyb051e892010-09-28 19:09:36 -0700346 case DrawPath: {
347 renderer.drawPath(getPath(), getPaint());
348 }
349 break;
350 case DrawLines: {
351 int count = 0;
352 float* points = getFloats(count);
353 renderer.drawLines(points, count, getPaint());
354 }
355 break;
356 case DrawText: {
357 getText(&text);
358 renderer.drawText(text.text(), text.length(), getInt(),
359 getFloat(), getFloat(), getPaint());
360 }
361 break;
362 case ResetShader: {
363 renderer.resetShader();
364 }
365 break;
366 case SetupShader: {
Chet Haase5c13d892010-10-08 08:37:55 -0700367 renderer.setupShader(getShader());
Romain Guyb051e892010-09-28 19:09:36 -0700368 }
369 break;
370 case ResetColorFilter: {
371 renderer.resetColorFilter();
372 }
373 break;
374 case SetupColorFilter: {
Chet Haasead93c2b2010-10-22 16:17:12 -0700375 renderer.setupColorFilter(getColorFilter());
Romain Guyb051e892010-09-28 19:09:36 -0700376 }
377 break;
378 case ResetShadow: {
379 renderer.resetShadow();
380 }
381 break;
382 case SetupShadow: {
383 renderer.setupShadow(getFloat(), getFloat(), getFloat(), getInt());
384 }
385 break;
386 }
387 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800388
389 DISPLAY_LIST_LOGD("%sDone", (char*) indent + 2);
Romain Guyb051e892010-09-28 19:09:36 -0700390}
391
392///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700393// Base structure
394///////////////////////////////////////////////////////////////////////////////
395
396DisplayListRenderer::DisplayListRenderer():
397 mHeap(HEAP_BLOCK_SIZE), mWriter(MIN_WRITER_SIZE) {
Romain Guy4aa90572010-09-26 18:40:37 -0700398 mPathHeap = NULL;
Chet Haase5977baa2011-01-05 18:01:22 -0800399 mDisplayList = NULL;
Romain Guy4aa90572010-09-26 18:40:37 -0700400}
401
402DisplayListRenderer::~DisplayListRenderer() {
403 reset();
404}
405
406void DisplayListRenderer::reset() {
407 if (mPathHeap) {
408 mPathHeap->unref();
409 mPathHeap = NULL;
410 }
411
Romain Guy4aa90572010-09-26 18:40:37 -0700412 mWriter.reset();
413 mHeap.reset();
414
415 mRCRecorder.reset();
416 mTFRecorder.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700417
418 Caches& caches = Caches::getInstance();
419 for (size_t i = 0; i < mBitmapResources.size(); i++) {
420 SkBitmap* resource = mBitmapResources.itemAt(i);
421 caches.resourceCache.decrementRefcount(resource);
422 }
423 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700424
Romain Guy43ccf462011-01-14 18:51:01 -0800425 for (size_t i = 0; i < mShaders.size(); i++) {
426 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
427 }
Romain Guy24c00212011-01-14 15:31:00 -0800428 mShaders.clear();
429 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800430
431 mPaints.clear();
432 mPaintMap.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700433 mMatrices.clear();
Romain Guy4aa90572010-09-26 18:40:37 -0700434}
435
436///////////////////////////////////////////////////////////////////////////////
437// Operations
438///////////////////////////////////////////////////////////////////////////////
439
Chet Haase5977baa2011-01-05 18:01:22 -0800440DisplayList* DisplayListRenderer::getDisplayList() {
441 if (mDisplayList == NULL) {
442 mDisplayList = new DisplayList(*this);
443 } else {
444 mDisplayList->initFromDisplayListRenderer(*this);
445 }
446 return mDisplayList;
447}
448
Romain Guyb051e892010-09-28 19:09:36 -0700449void DisplayListRenderer::setViewport(int width, int height) {
450 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
451
452 mWidth = width;
453 mHeight = height;
454}
455
Romain Guy6b7bd242010-10-06 19:49:23 -0700456void DisplayListRenderer::prepare(bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700457 mSnapshot = new Snapshot(mFirstSnapshot,
458 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
459 mSaveCount = 1;
460 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
461}
462
Romain Guy4aa90572010-09-26 18:40:37 -0700463void DisplayListRenderer::acquireContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700464 addOp(DisplayList::AcquireContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700465 OpenGLRenderer::acquireContext();
466}
467
468void DisplayListRenderer::releaseContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700469 addOp(DisplayList::ReleaseContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700470 OpenGLRenderer::releaseContext();
471}
472
473int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700474 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700475 addInt(flags);
476 return OpenGLRenderer::save(flags);
477}
478
479void DisplayListRenderer::restore() {
Romain Guyb051e892010-09-28 19:09:36 -0700480 addOp(DisplayList::Restore);
Romain Guy4aa90572010-09-26 18:40:37 -0700481 OpenGLRenderer::restore();
482}
483
484void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guyb051e892010-09-28 19:09:36 -0700485 addOp(DisplayList::RestoreToCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700486 addInt(saveCount);
487 OpenGLRenderer::restoreToCount(saveCount);
488}
489
490int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700491 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700492 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -0700493 addBounds(left, top, right, bottom);
494 addPaint(p);
495 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -0700496 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700497}
498
Romain Guy5b3b3522010-10-27 18:57:51 -0700499int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
500 int alpha, int flags) {
501 addOp(DisplayList::SaveLayerAlpha);
502 addBounds(left, top, right, bottom);
503 addInt(alpha);
504 addInt(flags);
505 return OpenGLRenderer::save(flags);
506}
507
Romain Guy4aa90572010-09-26 18:40:37 -0700508void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -0700509 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -0700510 addPoint(dx, dy);
511 OpenGLRenderer::translate(dx, dy);
512}
513
514void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -0700515 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -0700516 addFloat(degrees);
517 OpenGLRenderer::rotate(degrees);
518}
519
520void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -0700521 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -0700522 addPoint(sx, sy);
523 OpenGLRenderer::scale(sx, sy);
524}
525
Romain Guy807daf72011-01-18 11:19:19 -0800526void DisplayListRenderer::skew(float sx, float sy) {
527 addOp(DisplayList::Skew);
528 addPoint(sx, sy);
529 OpenGLRenderer::skew(sx, sy);
530}
531
Romain Guy4aa90572010-09-26 18:40:37 -0700532void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700533 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700534 addMatrix(matrix);
535 OpenGLRenderer::setMatrix(matrix);
536}
537
538void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700539 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700540 addMatrix(matrix);
541 OpenGLRenderer::concatMatrix(matrix);
542}
543
544bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
545 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -0700546 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700547 addBounds(left, top, right, bottom);
548 addInt(op);
549 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
550}
551
Romain Guyffac7fc2011-01-13 17:21:49 -0800552void DisplayListRenderer::drawDisplayList(DisplayList* displayList, uint32_t level) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800553 addOp(DisplayList::DrawDisplayList);
554 addDisplayList(displayList);
555}
556
Romain Guyada830f2011-01-13 12:13:20 -0800557void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -0800558 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -0800559 addInt((int) layer);
560 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -0800561 addPaint(paint);
562}
563
Romain Guy4aa90572010-09-26 18:40:37 -0700564void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -0700565 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700566 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -0700567 addBitmap(bitmap);
568 addPoint(left, top);
569 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700570}
571
Chet Haase5c13d892010-10-08 08:37:55 -0700572void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
573 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700574 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700575 addBitmap(bitmap);
576 addMatrix(matrix);
577 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700578}
579
580void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
581 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700582 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700583 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700584 addBitmap(bitmap);
585 addBounds(srcLeft, srcTop, srcRight, srcBottom);
586 addBounds(dstLeft, dstTop, dstRight, dstBottom);
587 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700588}
589
590void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700591 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700592 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700593 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -0700594 addBitmap(bitmap);
595 addInts(xDivs, width);
596 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -0700597 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -0700598 addBounds(left, top, right, bottom);
599 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700600}
601
602void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -0700603 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -0700604 addInt(color);
605 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -0700606}
607
608void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700609 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700610 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700611 addBounds(left, top, right, bottom);
612 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700613}
614
Romain Guy01d58e42011-01-19 21:54:02 -0800615void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
616 float rx, float ry, SkPaint* paint) {
617 addOp(DisplayList::DrawRoundRect);
618 addBounds(left, top, right, bottom);
619 addPoint(rx, ry);
620 addPaint(paint);
621}
622
623void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
624 addOp(DisplayList::DrawCircle);
625 addPoint(x, y);
626 addFloat(radius);
627 addPaint(paint);
628}
629
Romain Guy4aa90572010-09-26 18:40:37 -0700630void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700631 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -0700632 addPath(path);
633 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700634}
635
Chet Haase5c13d892010-10-08 08:37:55 -0700636void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700637 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -0700638 addFloats(points, count);
639 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700640}
641
642void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
643 float x, float y, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700644 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -0700645 addText(text, bytesCount);
646 addInt(count);
647 addPoint(x, y);
648 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700649}
650
651void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -0700652 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -0700653}
654
655void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -0700656 addOp(DisplayList::SetupShader);
657 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700658}
659
660void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -0700661 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -0700662}
663
664void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -0700665 addOp(DisplayList::SetupColorFilter);
666 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -0700667}
668
669void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -0700670 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700671}
672
673void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -0700674 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700675 addFloat(radius);
676 addPoint(dx, dy);
677 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -0700678}
679
Romain Guy4aa90572010-09-26 18:40:37 -0700680}; // namespace uirenderer
681}; // namespace android