blob: 75b16713c76111fd1b5df3c9d781c238cb86b1e7 [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",
106 "DrawPath",
107 "DrawLines",
108 "DrawText",
109 "ResetShader",
110 "SetupShader",
111 "ResetColorFilter",
112 "SetupColorFilter",
113 "ResetShadow",
114 "SetupShadow"
115};
116
Romain Guyb051e892010-09-28 19:09:36 -0700117DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -0800118 initFromDisplayListRenderer(recorder);
119}
120
121DisplayList::~DisplayList() {
122 sk_free((void*) mReader.base());
123
124 Caches& caches = Caches::getInstance();
125
126 for (size_t i = 0; i < mBitmapResources.size(); i++) {
127 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
128 }
129 mBitmapResources.clear();
130
131 for (size_t i = 0; i < mShaderResources.size(); i++) {
132 caches.resourceCache.decrementRefcount(mShaderResources.itemAt(i));
133 }
134 mShaderResources.clear();
135
136 for (size_t i = 0; i < mPaints.size(); i++) {
137 delete mPaints.itemAt(i);
138 }
139 mPaints.clear();
140
141 for (size_t i = 0; i < mMatrices.size(); i++) {
142 delete mMatrices.itemAt(i);
143 }
144 mMatrices.clear();
145
146 if (mPathHeap) {
147 for (int i = 0; i < mPathHeap->count(); i++) {
148 caches.pathCache.removeDeferred(&(*mPathHeap)[i]);
149 }
150 mPathHeap->safeUnref();
151 }
152}
153
154void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder) {
Romain Guyb051e892010-09-28 19:09:36 -0700155 const SkWriter32& writer = recorder.writeStream();
156 init();
157
158 if (writer.size() == 0) {
159 return;
160 }
161
162 size_t size = writer.size();
163 void* buffer = sk_malloc_throw(size);
164 writer.flatten(buffer);
165 mReader.setMemory(buffer, size);
166
167 mRCPlayback.reset(&recorder.mRCRecorder);
168 mRCPlayback.setupBuffer(mReader);
169
170 mTFPlayback.reset(&recorder.mTFRecorder);
171 mTFPlayback.setupBuffer(mReader);
172
Chet Haase5c13d892010-10-08 08:37:55 -0700173 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700174
Chet Haase5c13d892010-10-08 08:37:55 -0700175 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
176 for (size_t i = 0; i < bitmapResources.size(); i++) {
177 SkBitmap* resource = bitmapResources.itemAt(i);
178 mBitmapResources.add(resource);
179 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700180 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700181
Chet Haase5c13d892010-10-08 08:37:55 -0700182 const Vector<SkiaShader*> &shaderResources = recorder.getShaderResources();
183 for (size_t i = 0; i < shaderResources.size(); i++) {
184 SkiaShader* resource = shaderResources.itemAt(i);
185 mShaderResources.add(resource);
186 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700187 }
188
Chet Haased98aa2d2010-10-25 15:47:32 -0700189 const Vector<SkPaint*> &paints = recorder.getPaints();
190 for (size_t i = 0; i < paints.size(); i++) {
191 mPaints.add(paints.itemAt(i));
192 }
193
194 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
195 for (size_t i = 0; i < matrices.size(); i++) {
196 mMatrices.add(matrices.itemAt(i));
197 }
198
Romain Guyb051e892010-09-28 19:09:36 -0700199 mPathHeap = recorder.mPathHeap;
Romain Guy9e108412010-11-09 14:35:20 -0800200 if (mPathHeap) {
201 mPathHeap->safeRef();
202 }
Romain Guyb051e892010-09-28 19:09:36 -0700203}
204
Romain Guyb051e892010-09-28 19:09:36 -0700205void DisplayList::init() {
Romain Guyb051e892010-09-28 19:09:36 -0700206 mPathHeap = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700207}
208
Romain Guyffac7fc2011-01-13 17:21:49 -0800209void DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
Romain Guyb051e892010-09-28 19:09:36 -0700210 TextContainer text;
211 mReader.rewind();
212
Romain Guyffac7fc2011-01-13 17:21:49 -0800213#if DEBUG_DISPLAY_LIST
214 uint32_t count = (level + 1) * 2;
215 char indent[count + 1];
216 for (uint32_t i = 0; i < count; i++) {
217 indent[i] = ' ';
218 }
219 indent[count] = '\0';
220 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
221#endif
Romain Guyb051e892010-09-28 19:09:36 -0700222
Romain Guyffac7fc2011-01-13 17:21:49 -0800223 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700224 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700225 int op = mReader.readInt();
Romain Guyffac7fc2011-01-13 17:21:49 -0800226 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
227
Romain Guy5b3b3522010-10-27 18:57:51 -0700228 switch (op) {
Romain Guyb051e892010-09-28 19:09:36 -0700229 case AcquireContext: {
230 renderer.acquireContext();
231 }
232 break;
233 case ReleaseContext: {
234 renderer.releaseContext();
235 }
236 break;
237 case Save: {
238 renderer.save(getInt());
239 }
240 break;
241 case Restore: {
242 renderer.restore();
243 }
244 break;
245 case RestoreToCount: {
246 renderer.restoreToCount(saveCount + getInt());
247 }
248 break;
249 case SaveLayer: {
250 renderer.saveLayer(getFloat(), getFloat(), getFloat(), getFloat(),
251 getPaint(), getInt());
252 }
253 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700254 case SaveLayerAlpha: {
255 renderer.saveLayerAlpha(getFloat(), getFloat(), getFloat(), getFloat(),
256 getInt(), getInt());
257 }
258 break;
Romain Guyb051e892010-09-28 19:09:36 -0700259 case Translate: {
260 renderer.translate(getFloat(), getFloat());
261 }
262 break;
263 case Rotate: {
264 renderer.rotate(getFloat());
265 }
266 break;
267 case Scale: {
268 renderer.scale(getFloat(), getFloat());
269 }
270 break;
271 case SetMatrix: {
272 renderer.setMatrix(getMatrix());
273 }
274 break;
275 case ConcatMatrix: {
276 renderer.concatMatrix(getMatrix());
277 }
278 break;
279 case ClipRect: {
280 renderer.clipRect(getFloat(), getFloat(), getFloat(), getFloat(),
281 (SkRegion::Op) getInt());
282 }
283 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800284 case DrawDisplayList: {
Romain Guyffac7fc2011-01-13 17:21:49 -0800285 renderer.drawDisplayList(getDisplayList(), level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800286 }
287 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800288 case DrawLayer: {
Romain Guyada830f2011-01-13 12:13:20 -0800289 renderer.drawLayer((Layer*) getInt(), getFloat(), getFloat(), getPaint());
Romain Guy6c319ca2011-01-11 14:29:25 -0800290 }
291 break;
Romain Guyb051e892010-09-28 19:09:36 -0700292 case DrawBitmap: {
293 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getPaint());
294 }
295 break;
296 case DrawBitmapMatrix: {
297 renderer.drawBitmap(getBitmap(), getMatrix(), getPaint());
298 }
299 break;
300 case DrawBitmapRect: {
301 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getFloat(), getFloat(),
302 getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
303 }
304 break;
305 case DrawPatch: {
306 int32_t* xDivs = NULL;
307 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700308 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700309 uint32_t xDivsCount = 0;
310 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700311 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700312
313 SkBitmap* bitmap = getBitmap();
314
315 xDivs = getInts(xDivsCount);
316 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700317 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700318
Romain Guy4bb94202010-10-12 15:59:26 -0700319 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
320 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
Romain Guyb051e892010-09-28 19:09:36 -0700321 }
322 break;
323 case DrawColor: {
324 renderer.drawColor(getInt(), (SkXfermode::Mode) getInt());
325 }
326 break;
327 case DrawRect: {
328 renderer.drawRect(getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
329 }
330 break;
331 case DrawPath: {
332 renderer.drawPath(getPath(), getPaint());
333 }
334 break;
335 case DrawLines: {
336 int count = 0;
337 float* points = getFloats(count);
338 renderer.drawLines(points, count, getPaint());
339 }
340 break;
341 case DrawText: {
342 getText(&text);
343 renderer.drawText(text.text(), text.length(), getInt(),
344 getFloat(), getFloat(), getPaint());
345 }
346 break;
347 case ResetShader: {
348 renderer.resetShader();
349 }
350 break;
351 case SetupShader: {
Chet Haase5c13d892010-10-08 08:37:55 -0700352 renderer.setupShader(getShader());
Romain Guyb051e892010-09-28 19:09:36 -0700353 }
354 break;
355 case ResetColorFilter: {
356 renderer.resetColorFilter();
357 }
358 break;
359 case SetupColorFilter: {
Chet Haasead93c2b2010-10-22 16:17:12 -0700360 renderer.setupColorFilter(getColorFilter());
Romain Guyb051e892010-09-28 19:09:36 -0700361 }
362 break;
363 case ResetShadow: {
364 renderer.resetShadow();
365 }
366 break;
367 case SetupShadow: {
368 renderer.setupShadow(getFloat(), getFloat(), getFloat(), getInt());
369 }
370 break;
371 }
372 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800373
374 DISPLAY_LIST_LOGD("%sDone", (char*) indent + 2);
Romain Guyb051e892010-09-28 19:09:36 -0700375}
376
377///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700378// Base structure
379///////////////////////////////////////////////////////////////////////////////
380
381DisplayListRenderer::DisplayListRenderer():
382 mHeap(HEAP_BLOCK_SIZE), mWriter(MIN_WRITER_SIZE) {
Romain Guy4aa90572010-09-26 18:40:37 -0700383 mPathHeap = NULL;
Chet Haase5977baa2011-01-05 18:01:22 -0800384 mDisplayList = NULL;
Romain Guy4aa90572010-09-26 18:40:37 -0700385}
386
387DisplayListRenderer::~DisplayListRenderer() {
388 reset();
389}
390
391void DisplayListRenderer::reset() {
392 if (mPathHeap) {
393 mPathHeap->unref();
394 mPathHeap = NULL;
395 }
396
Romain Guy4aa90572010-09-26 18:40:37 -0700397 mWriter.reset();
398 mHeap.reset();
399
400 mRCRecorder.reset();
401 mTFRecorder.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700402
403 Caches& caches = Caches::getInstance();
404 for (size_t i = 0; i < mBitmapResources.size(); i++) {
405 SkBitmap* resource = mBitmapResources.itemAt(i);
406 caches.resourceCache.decrementRefcount(resource);
407 }
408 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700409
Chet Haase5c13d892010-10-08 08:37:55 -0700410 for (size_t i = 0; i < mShaderResources.size(); i++) {
411 SkiaShader* resource = mShaderResources.itemAt(i);
412 caches.resourceCache.decrementRefcount(resource);
413 }
414 mShaderResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700415
416 mPaints.clear();
417 mPaintMap.clear();
418 mMatrices.clear();
Romain Guy4aa90572010-09-26 18:40:37 -0700419}
420
421///////////////////////////////////////////////////////////////////////////////
422// Operations
423///////////////////////////////////////////////////////////////////////////////
424
Chet Haase5977baa2011-01-05 18:01:22 -0800425DisplayList* DisplayListRenderer::getDisplayList() {
426 if (mDisplayList == NULL) {
427 mDisplayList = new DisplayList(*this);
428 } else {
429 mDisplayList->initFromDisplayListRenderer(*this);
430 }
431 return mDisplayList;
432}
433
Romain Guyb051e892010-09-28 19:09:36 -0700434void DisplayListRenderer::setViewport(int width, int height) {
435 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
436
437 mWidth = width;
438 mHeight = height;
439}
440
Romain Guy6b7bd242010-10-06 19:49:23 -0700441void DisplayListRenderer::prepare(bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700442 mSnapshot = new Snapshot(mFirstSnapshot,
443 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
444 mSaveCount = 1;
445 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
446}
447
Romain Guy4aa90572010-09-26 18:40:37 -0700448void DisplayListRenderer::acquireContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700449 addOp(DisplayList::AcquireContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700450 OpenGLRenderer::acquireContext();
451}
452
453void DisplayListRenderer::releaseContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700454 addOp(DisplayList::ReleaseContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700455 OpenGLRenderer::releaseContext();
456}
457
458int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700459 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700460 addInt(flags);
461 return OpenGLRenderer::save(flags);
462}
463
464void DisplayListRenderer::restore() {
Romain Guyb051e892010-09-28 19:09:36 -0700465 addOp(DisplayList::Restore);
Romain Guy4aa90572010-09-26 18:40:37 -0700466 OpenGLRenderer::restore();
467}
468
469void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guyb051e892010-09-28 19:09:36 -0700470 addOp(DisplayList::RestoreToCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700471 addInt(saveCount);
472 OpenGLRenderer::restoreToCount(saveCount);
473}
474
475int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700476 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700477 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -0700478 addBounds(left, top, right, bottom);
479 addPaint(p);
480 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -0700481 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700482}
483
Romain Guy5b3b3522010-10-27 18:57:51 -0700484int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
485 int alpha, int flags) {
486 addOp(DisplayList::SaveLayerAlpha);
487 addBounds(left, top, right, bottom);
488 addInt(alpha);
489 addInt(flags);
490 return OpenGLRenderer::save(flags);
491}
492
Romain Guy4aa90572010-09-26 18:40:37 -0700493void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -0700494 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -0700495 addPoint(dx, dy);
496 OpenGLRenderer::translate(dx, dy);
497}
498
499void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -0700500 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -0700501 addFloat(degrees);
502 OpenGLRenderer::rotate(degrees);
503}
504
505void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -0700506 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -0700507 addPoint(sx, sy);
508 OpenGLRenderer::scale(sx, sy);
509}
510
511void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700512 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700513 addMatrix(matrix);
514 OpenGLRenderer::setMatrix(matrix);
515}
516
517void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700518 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700519 addMatrix(matrix);
520 OpenGLRenderer::concatMatrix(matrix);
521}
522
523bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
524 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -0700525 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700526 addBounds(left, top, right, bottom);
527 addInt(op);
528 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
529}
530
Romain Guyffac7fc2011-01-13 17:21:49 -0800531void DisplayListRenderer::drawDisplayList(DisplayList* displayList, uint32_t level) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800532 addOp(DisplayList::DrawDisplayList);
533 addDisplayList(displayList);
534}
535
Romain Guyada830f2011-01-13 12:13:20 -0800536void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -0800537 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -0800538 addInt((int) layer);
539 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -0800540 addPaint(paint);
541}
542
Romain Guy4aa90572010-09-26 18:40:37 -0700543void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -0700544 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700545 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -0700546 addBitmap(bitmap);
547 addPoint(left, top);
548 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700549}
550
Chet Haase5c13d892010-10-08 08:37:55 -0700551void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
552 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700553 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700554 addBitmap(bitmap);
555 addMatrix(matrix);
556 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700557}
558
559void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
560 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700561 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700562 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700563 addBitmap(bitmap);
564 addBounds(srcLeft, srcTop, srcRight, srcBottom);
565 addBounds(dstLeft, dstTop, dstRight, dstBottom);
566 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700567}
568
569void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700570 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700571 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700572 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -0700573 addBitmap(bitmap);
574 addInts(xDivs, width);
575 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -0700576 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -0700577 addBounds(left, top, right, bottom);
578 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700579}
580
581void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -0700582 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -0700583 addInt(color);
584 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -0700585}
586
587void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700588 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700589 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700590 addBounds(left, top, right, bottom);
591 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700592}
593
594void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700595 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -0700596 addPath(path);
597 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700598}
599
Chet Haase5c13d892010-10-08 08:37:55 -0700600void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700601 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -0700602 addFloats(points, count);
603 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700604}
605
606void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
607 float x, float y, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700608 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -0700609 addText(text, bytesCount);
610 addInt(count);
611 addPoint(x, y);
612 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700613}
614
615void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -0700616 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -0700617}
618
619void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -0700620 addOp(DisplayList::SetupShader);
621 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700622}
623
624void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -0700625 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -0700626}
627
628void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -0700629 addOp(DisplayList::SetupColorFilter);
630 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -0700631}
632
633void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -0700634 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700635}
636
637void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -0700638 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700639 addFloat(radius);
640 addPoint(dx, dy);
641 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -0700642}
643
Romain Guy4aa90572010-09-26 18:40:37 -0700644}; // namespace uirenderer
645}; // namespace android