blob: 16067719a83da99527a7059bf1927e53a69896a0 [file] [log] [blame]
junov@google.com4370aed2012-01-18 16:21:08 +00001
2/*
junov@chromium.org10f7f972012-07-31 21:01:51 +00003 * Copyright 2012 Google Inc.
junov@google.com4370aed2012-01-18 16:21:08 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "SkDeferredCanvas.h"
10
11#include "SkPaint.h"
12#include "SkShader.h"
13#include "SkColorFilter.h"
14#include "SkDrawFilter.h"
15
reed@google.com563a3b42012-06-26 19:24:50 +000016SK_DEFINE_INST_COUNT(SkDeferredCanvas::DeviceContext)
17
junov@chromium.orgbfeddae2012-07-23 13:35:14 +000018enum {
19 // Deferred canvas will auto-flush when recording reaches this limit
20 kDefaultMaxRecordingStorageBytes = 64*1024*1024,
21};
22
junov@google.com4370aed2012-01-18 16:21:08 +000023namespace {
junov@chromium.org10f7f972012-07-31 21:01:51 +000024bool shouldDrawImmediately(const SkBitmap* bitmap, const SkPaint* paint) {
25 if (bitmap && bitmap->getTexture() && !bitmap->isImmutable()) {
26 return true;
27 }
28 if (paint) {
29 SkShader* shader = paint->getShader();
30 // Here we detect the case where the shader is an SkBitmapProcShader
31 // with a gpu texture attached. Checking this without RTTI
32 // requires making the assumption that only gradient shaders
33 // and SkBitmapProcShader implement asABitmap(). The following
34 // code may need to be revised if that assumption is ever broken.
35 if (shader && !shader->asAGradient(NULL)) {
36 SkBitmap bm;
37 if (shader->asABitmap(&bm, NULL, NULL) &&
38 NULL != bm.getTexture()) {
39 return true;
40 }
41 }
42 }
43 return false;
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +000044}
45}
46
47class AutoImmediateDrawIfNeeded {
48public:
junov@chromium.org10f7f972012-07-31 21:01:51 +000049 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkBitmap* bitmap,
50 const SkPaint* paint) {
51 this->init(canvas, bitmap, paint);
52 }
53
54 AutoImmediateDrawIfNeeded(SkDeferredCanvas& canvas, const SkPaint* paint) {
55 this->init(canvas, NULL, paint);
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +000056 }
57
58 ~AutoImmediateDrawIfNeeded() {
59 if (fCanvas) {
60 fCanvas->setDeferredDrawing(true);
61 }
62 }
63private:
junov@chromium.org10f7f972012-07-31 21:01:51 +000064 void init(SkDeferredCanvas& canvas, const SkBitmap* bitmap, const SkPaint* paint)
65 {
66 if (canvas.isDeferredDrawing() && shouldDrawImmediately(bitmap, paint)) {
67 canvas.setDeferredDrawing(false);
68 fCanvas = &canvas;
69 } else {
70 fCanvas = NULL;
71 }
72 }
73
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +000074 SkDeferredCanvas* fCanvas;
75};
76
77namespace {
junov@google.com4370aed2012-01-18 16:21:08 +000078
junov@chromium.orgc16ca922012-02-24 22:06:27 +000079bool isPaintOpaque(const SkPaint* paint,
80 const SkBitmap* bmpReplacesShader = NULL) {
junov@google.com4370aed2012-01-18 16:21:08 +000081 // TODO: SkXfermode should have a virtual isOpaque method, which would
82 // make it possible to test modes that do not have a Coeff representation.
junov@chromium.org87f982c2012-02-23 21:34:34 +000083
84 if (!paint) {
85 return bmpReplacesShader ? bmpReplacesShader->isOpaque() : true;
86 }
87
junov@google.com4370aed2012-01-18 16:21:08 +000088 SkXfermode::Coeff srcCoeff, dstCoeff;
junov@chromium.org87f982c2012-02-23 21:34:34 +000089 if (SkXfermode::AsCoeff(paint->getXfermode(), &srcCoeff, &dstCoeff)){
junov@google.com4370aed2012-01-18 16:21:08 +000090 switch (dstCoeff) {
91 case SkXfermode::kZero_Coeff:
92 return true;
93 case SkXfermode::kISA_Coeff:
junov@chromium.org87f982c2012-02-23 21:34:34 +000094 if (paint->getAlpha() != 255) {
junov@google.com4370aed2012-01-18 16:21:08 +000095 break;
96 }
97 if (bmpReplacesShader) {
98 if (!bmpReplacesShader->isOpaque()) {
99 break;
100 }
junov@chromium.org87f982c2012-02-23 21:34:34 +0000101 } else if (paint->getShader() && !paint->getShader()->isOpaque()) {
junov@google.com4370aed2012-01-18 16:21:08 +0000102 break;
103 }
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000104 if (paint->getColorFilter() &&
105 ((paint->getColorFilter()->getFlags() &
junov@google.com4370aed2012-01-18 16:21:08 +0000106 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
107 break;
108 }
109 return true;
110 case SkXfermode::kSA_Coeff:
junov@chromium.org87f982c2012-02-23 21:34:34 +0000111 if (paint->getAlpha() != 0) {
junov@google.com4370aed2012-01-18 16:21:08 +0000112 break;
113 }
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000114 if (paint->getColorFilter() &&
115 ((paint->getColorFilter()->getFlags() &
junov@google.com4370aed2012-01-18 16:21:08 +0000116 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
117 break;
118 }
119 return true;
120 case SkXfermode::kSC_Coeff:
junov@chromium.org87f982c2012-02-23 21:34:34 +0000121 if (paint->getColor() != 0) { // all components must be 0
junov@google.com4370aed2012-01-18 16:21:08 +0000122 break;
123 }
junov@chromium.org87f982c2012-02-23 21:34:34 +0000124 if (bmpReplacesShader || paint->getShader()) {
junov@google.com4370aed2012-01-18 16:21:08 +0000125 break;
126 }
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000127 if (paint->getColorFilter() && (
128 (paint->getColorFilter()->getFlags() &
junov@google.com4370aed2012-01-18 16:21:08 +0000129 SkColorFilter::kAlphaUnchanged_Flag) == 0)) {
130 break;
131 }
132 return true;
133 default:
134 break;
135 }
136 }
137 return false;
138}
139
140} // unnamed namespace
141
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000142SkDeferredCanvas::SkDeferredCanvas() {
junov@google.com4370aed2012-01-18 16:21:08 +0000143 init();
144}
145
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000146SkDeferredCanvas::SkDeferredCanvas(SkDevice* device) {
junov@google.com4370aed2012-01-18 16:21:08 +0000147 init();
148 setDevice(device);
149}
150
151SkDeferredCanvas::SkDeferredCanvas(SkDevice* device,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000152 DeviceContext* deviceContext) {
junov@google.com4370aed2012-01-18 16:21:08 +0000153 init();
154 setDevice(device);
155 setDeviceContext(deviceContext);
156}
157
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000158void SkDeferredCanvas::init() {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000159 fDeferredDrawing = true; // On by default
junov@google.com4370aed2012-01-18 16:21:08 +0000160}
161
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000162void SkDeferredCanvas::setMaxRecordingStorage(size_t maxStorage) {
163 validate();
164 this->getDeferredDevice()->setMaxRecordingStorage(maxStorage);
165}
166
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000167size_t SkDeferredCanvas::storageAllocatedForRecording() const {
168 return this->getDeferredDevice()->storageAllocatedForRecording();
169}
170
171size_t SkDeferredCanvas::freeMemoryIfPossible(size_t bytesToFree) {
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000172 return this->getDeferredDevice()->freeMemoryIfPossible(bytesToFree);
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000173}
174
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000175void SkDeferredCanvas::validate() const {
junov@google.com4370aed2012-01-18 16:21:08 +0000176 SkASSERT(getDevice());
junov@google.com4370aed2012-01-18 16:21:08 +0000177}
178
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000179SkCanvas* SkDeferredCanvas::drawingCanvas() const {
180 validate();
181 return fDeferredDrawing ? getDeferredDevice()->recordingCanvas() :
182 getDeferredDevice()->immediateCanvas();
183}
184
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000185SkDeferredCanvas::DeferredDevice* SkDeferredCanvas::getDeferredDevice() const {
junov@google.com4370aed2012-01-18 16:21:08 +0000186 return static_cast<SkDeferredCanvas::DeferredDevice*>(getDevice());
187}
188
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000189void SkDeferredCanvas::setDeferredDrawing(bool val) {
junov@google.com4370aed2012-01-18 16:21:08 +0000190 validate(); // Must set device before calling this method
junov@google.com4370aed2012-01-18 16:21:08 +0000191 if (val != fDeferredDrawing) {
192 if (fDeferredDrawing) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000193 // Going live.
junov@google.com4370aed2012-01-18 16:21:08 +0000194 getDeferredDevice()->flushPending();
195 }
196 fDeferredDrawing = val;
197 }
198}
199
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +0000200bool SkDeferredCanvas::isDeferredDrawing() {
201 return fDeferredDrawing;
202}
203
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000204SkDeferredCanvas::~SkDeferredCanvas() {
junov@google.com4370aed2012-01-18 16:21:08 +0000205}
206
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000207SkDevice* SkDeferredCanvas::setDevice(SkDevice* device) {
junov@google.com4370aed2012-01-18 16:21:08 +0000208 INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (device)))->unref();
209 return device;
210}
211
212SkDeferredCanvas::DeviceContext* SkDeferredCanvas::setDeviceContext(
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000213 DeviceContext* deviceContext) {
214
junov@google.com4370aed2012-01-18 16:21:08 +0000215 DeferredDevice* deferredDevice = getDeferredDevice();
216 SkASSERT(deferredDevice);
217 if (deferredDevice) {
218 deferredDevice->setDeviceContext(deviceContext);
219 }
220 return deviceContext;
221}
222
223bool SkDeferredCanvas::isFullFrame(const SkRect* rect,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000224 const SkPaint* paint) const {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000225 SkCanvas* canvas = drawingCanvas();
junov@google.com4370aed2012-01-18 16:21:08 +0000226 SkISize canvasSize = getDeviceSize();
227 if (rect) {
228 if (!canvas->getTotalMatrix().rectStaysRect()) {
229 return false; // conservative
230 }
231
232 SkRect transformedRect;
233 canvas->getTotalMatrix().mapRect(&transformedRect, *rect);
234
235 if (paint) {
236 SkPaint::Style paintStyle = paint->getStyle();
237 if (!(paintStyle == SkPaint::kFill_Style ||
238 paintStyle == SkPaint::kStrokeAndFill_Style)) {
239 return false;
240 }
241 if (paint->getMaskFilter() || paint->getLooper()
242 || paint->getPathEffect() || paint->getImageFilter()) {
243 return false; // conservative
244 }
245 }
246
247 // The following test holds with AA enabled, and is conservative
248 // by a 0.5 pixel margin with AA disabled
junov@chromium.orgb1e218e2012-02-13 22:27:58 +0000249 if (transformedRect.fLeft > SkIntToScalar(0) ||
250 transformedRect.fTop > SkIntToScalar(0) ||
251 transformedRect.fRight < SkIntToScalar(canvasSize.fWidth) ||
252 transformedRect.fBottom < SkIntToScalar(canvasSize.fHeight)) {
junov@google.com4370aed2012-01-18 16:21:08 +0000253 return false;
254 }
255 }
256
257 switch (canvas->getClipType()) {
258 case SkCanvas::kRect_ClipType :
259 {
260 SkIRect bounds;
261 canvas->getClipDeviceBounds(&bounds);
262 if (bounds.fLeft > 0 || bounds.fTop > 0 ||
263 bounds.fRight < canvasSize.fWidth ||
264 bounds.fBottom < canvasSize.fHeight)
265 return false;
266 }
267 break;
268 case SkCanvas::kComplex_ClipType :
269 return false; // conservative
270 case SkCanvas::kEmpty_ClipType:
271 default:
272 break;
273 };
274
275 return true;
276}
277
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000278int SkDeferredCanvas::save(SaveFlags flags) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000279 drawingCanvas()->save(flags);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000280 return this->INHERITED::save(flags);
junov@google.com4370aed2012-01-18 16:21:08 +0000281}
282
283int SkDeferredCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000284 SaveFlags flags) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000285 drawingCanvas()->saveLayer(bounds, paint, flags);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000286 int count = this->INHERITED::save(flags);
287 this->clipRectBounds(bounds, flags, NULL);
288 return count;
junov@google.com4370aed2012-01-18 16:21:08 +0000289}
290
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000291void SkDeferredCanvas::restore() {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000292 drawingCanvas()->restore();
junov@chromium.orga907ac32012-02-24 21:54:07 +0000293 this->INHERITED::restore();
junov@google.com4370aed2012-01-18 16:21:08 +0000294}
295
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000296bool SkDeferredCanvas::isDrawingToLayer() const {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000297 return drawingCanvas()->isDrawingToLayer();
junov@google.com4370aed2012-01-18 16:21:08 +0000298}
299
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000300bool SkDeferredCanvas::translate(SkScalar dx, SkScalar dy) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000301 drawingCanvas()->translate(dx, dy);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000302 return this->INHERITED::translate(dx, dy);
junov@google.com4370aed2012-01-18 16:21:08 +0000303}
304
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000305bool SkDeferredCanvas::scale(SkScalar sx, SkScalar sy) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000306 drawingCanvas()->scale(sx, sy);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000307 return this->INHERITED::scale(sx, sy);
junov@google.com4370aed2012-01-18 16:21:08 +0000308}
309
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000310bool SkDeferredCanvas::rotate(SkScalar degrees) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000311 drawingCanvas()->rotate(degrees);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000312 return this->INHERITED::rotate(degrees);
junov@google.com4370aed2012-01-18 16:21:08 +0000313}
314
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000315bool SkDeferredCanvas::skew(SkScalar sx, SkScalar sy) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000316 drawingCanvas()->skew(sx, sy);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000317 return this->INHERITED::skew(sx, sy);
junov@google.com4370aed2012-01-18 16:21:08 +0000318}
319
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000320bool SkDeferredCanvas::concat(const SkMatrix& matrix) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000321 drawingCanvas()->concat(matrix);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000322 return this->INHERITED::concat(matrix);
junov@google.com4370aed2012-01-18 16:21:08 +0000323}
324
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000325void SkDeferredCanvas::setMatrix(const SkMatrix& matrix) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000326 drawingCanvas()->setMatrix(matrix);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000327 this->INHERITED::setMatrix(matrix);
junov@google.com4370aed2012-01-18 16:21:08 +0000328}
329
330bool SkDeferredCanvas::clipRect(const SkRect& rect,
331 SkRegion::Op op,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000332 bool doAntiAlias) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000333 drawingCanvas()->clipRect(rect, op, doAntiAlias);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000334 return this->INHERITED::clipRect(rect, op, doAntiAlias);
junov@google.com4370aed2012-01-18 16:21:08 +0000335}
336
337bool SkDeferredCanvas::clipPath(const SkPath& path,
338 SkRegion::Op op,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000339 bool doAntiAlias) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000340 drawingCanvas()->clipPath(path, op, doAntiAlias);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000341 return this->INHERITED::clipPath(path, op, doAntiAlias);
junov@google.com4370aed2012-01-18 16:21:08 +0000342}
343
344bool SkDeferredCanvas::clipRegion(const SkRegion& deviceRgn,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000345 SkRegion::Op op) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000346 drawingCanvas()->clipRegion(deviceRgn, op);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000347 return this->INHERITED::clipRegion(deviceRgn, op);
junov@google.com4370aed2012-01-18 16:21:08 +0000348}
349
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000350void SkDeferredCanvas::clear(SkColor color) {
junov@google.com4370aed2012-01-18 16:21:08 +0000351 // purge pending commands
352 if (fDeferredDrawing) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000353 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000354 }
355
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000356 drawingCanvas()->clear(color);
junov@google.com4370aed2012-01-18 16:21:08 +0000357}
358
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000359void SkDeferredCanvas::drawPaint(const SkPaint& paint) {
360 if (fDeferredDrawing && isFullFrame(NULL, &paint) &&
361 isPaintOpaque(&paint)) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000362 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000363 }
junov@chromium.org10f7f972012-07-31 21:01:51 +0000364 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000365 drawingCanvas()->drawPaint(paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000366}
367
368void SkDeferredCanvas::drawPoints(PointMode mode, size_t count,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000369 const SkPoint pts[], const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000370 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000371 drawingCanvas()->drawPoints(mode, count, pts, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000372}
373
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000374void SkDeferredCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
375 if (fDeferredDrawing && isFullFrame(&rect, &paint) &&
376 isPaintOpaque(&paint)) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000377 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000378 }
379
junov@chromium.org10f7f972012-07-31 21:01:51 +0000380 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000381 drawingCanvas()->drawRect(rect, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000382}
383
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000384void SkDeferredCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000385 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000386 drawingCanvas()->drawPath(path, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000387}
388
389void SkDeferredCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar left,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000390 SkScalar top, const SkPaint* paint) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000391 SkRect bitmapRect = SkRect::MakeXYWH(left, top,
392 SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height()));
junov@google.com4370aed2012-01-18 16:21:08 +0000393 if (fDeferredDrawing &&
394 isFullFrame(&bitmapRect, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000395 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000396 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000397 }
398
junov@chromium.org10f7f972012-07-31 21:01:51 +0000399 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000400 drawingCanvas()->drawBitmap(bitmap, left, top, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000401}
402
403void SkDeferredCanvas::drawBitmapRect(const SkBitmap& bitmap,
404 const SkIRect* src,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000405 const SkRect& dst,
406 const SkPaint* paint) {
junov@google.com4370aed2012-01-18 16:21:08 +0000407 if (fDeferredDrawing &&
408 isFullFrame(&dst, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000409 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000410 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000411 }
412
junov@chromium.org10f7f972012-07-31 21:01:51 +0000413 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000414 drawingCanvas()->drawBitmapRect(bitmap, src,
junov@google.com4370aed2012-01-18 16:21:08 +0000415 dst, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000416}
417
418
419void SkDeferredCanvas::drawBitmapMatrix(const SkBitmap& bitmap,
420 const SkMatrix& m,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000421 const SkPaint* paint) {
junov@google.com4370aed2012-01-18 16:21:08 +0000422 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
423 // covers canvas entirely and transformed bitmap covers canvas entirely
junov@chromium.org10f7f972012-07-31 21:01:51 +0000424 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000425 drawingCanvas()->drawBitmapMatrix(bitmap, m, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000426}
427
428void SkDeferredCanvas::drawBitmapNine(const SkBitmap& bitmap,
429 const SkIRect& center, const SkRect& dst,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000430 const SkPaint* paint) {
junov@google.com4370aed2012-01-18 16:21:08 +0000431 // TODO: reset recording canvas if paint+bitmap is opaque and clip rect
432 // covers canvas entirely and dst covers canvas entirely
junov@chromium.org10f7f972012-07-31 21:01:51 +0000433 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000434 drawingCanvas()->drawBitmapNine(bitmap, center,
junov@google.com4370aed2012-01-18 16:21:08 +0000435 dst, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000436}
437
438void SkDeferredCanvas::drawSprite(const SkBitmap& bitmap, int left, int top,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000439 const SkPaint* paint) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000440 SkRect bitmapRect = SkRect::MakeXYWH(
441 SkIntToScalar(left),
442 SkIntToScalar(top),
443 SkIntToScalar(bitmap.width()),
444 SkIntToScalar(bitmap.height()));
junov@google.com4370aed2012-01-18 16:21:08 +0000445 if (fDeferredDrawing &&
446 isFullFrame(&bitmapRect, paint) &&
junov@chromium.org87f982c2012-02-23 21:34:34 +0000447 isPaintOpaque(paint, &bitmap)) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000448 getDeferredDevice()->contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000449 }
450
junov@chromium.org10f7f972012-07-31 21:01:51 +0000451 AutoImmediateDrawIfNeeded autoDraw(*this, &bitmap, paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000452 drawingCanvas()->drawSprite(bitmap, left, top,
junov@google.com4370aed2012-01-18 16:21:08 +0000453 paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000454}
455
456void SkDeferredCanvas::drawText(const void* text, size_t byteLength,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000457 SkScalar x, SkScalar y, const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000458 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000459 drawingCanvas()->drawText(text, byteLength, x, y, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000460}
461
462void SkDeferredCanvas::drawPosText(const void* text, size_t byteLength,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000463 const SkPoint pos[], const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000464 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000465 drawingCanvas()->drawPosText(text, byteLength, pos, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000466}
467
468void SkDeferredCanvas::drawPosTextH(const void* text, size_t byteLength,
469 const SkScalar xpos[], SkScalar constY,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000470 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000471 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000472 drawingCanvas()->drawPosTextH(text, byteLength, xpos, constY, paint);
junov@google.com4370aed2012-01-18 16:21:08 +0000473}
474
475void SkDeferredCanvas::drawTextOnPath(const void* text, size_t byteLength,
476 const SkPath& path,
477 const SkMatrix* matrix,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000478 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000479 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000480 drawingCanvas()->drawTextOnPath(text, byteLength,
junov@google.com4370aed2012-01-18 16:21:08 +0000481 path, matrix,
482 paint);
483}
484
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000485void SkDeferredCanvas::drawPicture(SkPicture& picture) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000486 drawingCanvas()->drawPicture(picture);
junov@google.com4370aed2012-01-18 16:21:08 +0000487}
488
489void SkDeferredCanvas::drawVertices(VertexMode vmode, int vertexCount,
490 const SkPoint vertices[],
491 const SkPoint texs[],
492 const SkColor colors[], SkXfermode* xmode,
493 const uint16_t indices[], int indexCount,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000494 const SkPaint& paint) {
junov@chromium.org10f7f972012-07-31 21:01:51 +0000495 AutoImmediateDrawIfNeeded autoDraw(*this, &paint);
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000496 drawingCanvas()->drawVertices(vmode, vertexCount,
junov@google.com4370aed2012-01-18 16:21:08 +0000497 vertices, texs,
498 colors, xmode,
499 indices, indexCount,
500 paint);
501}
502
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000503SkBounder* SkDeferredCanvas::setBounder(SkBounder* bounder) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000504 drawingCanvas()->setBounder(bounder);
junov@chromium.orga907ac32012-02-24 21:54:07 +0000505 return INHERITED::setBounder(bounder);
junov@google.com4370aed2012-01-18 16:21:08 +0000506}
507
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000508SkDrawFilter* SkDeferredCanvas::setDrawFilter(SkDrawFilter* filter) {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000509 drawingCanvas()->setDrawFilter(filter);
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000510 return INHERITED::setDrawFilter(filter);
junov@google.com4370aed2012-01-18 16:21:08 +0000511}
512
513SkCanvas* SkDeferredCanvas::canvasForDrawIter() {
junov@chromium.org5e5a0952012-02-28 15:27:59 +0000514 return drawingCanvas();
junov@google.com4370aed2012-01-18 16:21:08 +0000515}
516
junov@chromium.org77eec242012-07-18 17:54:45 +0000517// SkDeferredCanvas::DeferredPipeController
518//-------------------------------------------
519
520SkDeferredCanvas::DeferredPipeController::DeferredPipeController() :
521 fAllocator(kMinBlockSize) {
522 fBlock = NULL;
523 fBytesWritten = 0;
524}
525
526SkDeferredCanvas::DeferredPipeController::~DeferredPipeController() {
527 fAllocator.reset();
528}
529
530void SkDeferredCanvas::DeferredPipeController::setPlaybackCanvas(SkCanvas* canvas) {
531 fReader.setCanvas(canvas);
532}
533
534void* SkDeferredCanvas::DeferredPipeController::requestBlock(size_t minRequest, size_t *actual) {
535 if (fBlock) {
536 // Save the previous block for later
537 PipeBlock previousBloc(fBlock, fBytesWritten);
538 fBlockList.push(previousBloc);
539 }
540 int32_t blockSize = SkMax32(minRequest, kMinBlockSize);
541 fBlock = fAllocator.allocThrow(blockSize);
542 fBytesWritten = 0;
543 *actual = blockSize;
544 return fBlock;
545}
546
547void SkDeferredCanvas::DeferredPipeController::notifyWritten(size_t bytes) {
548 fBytesWritten += bytes;
549}
550
551void SkDeferredCanvas::DeferredPipeController::playback() {
552
553 for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) {
554 fReader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock].fSize);
555 }
556 fBlockList.reset();
557
558 if (fBlock) {
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000559 fReader.playback(fBlock, fBytesWritten);
junov@chromium.org77eec242012-07-18 17:54:45 +0000560 fBlock = NULL;
561 }
562
563 // Release all allocated blocks
564 fAllocator.reset();
565}
566
567void SkDeferredCanvas::DeferredPipeController::reset() {
568 fBlockList.reset();
569 fBlock = NULL;
570 fAllocator.reset();
571}
572
junov@google.com4370aed2012-01-18 16:21:08 +0000573// SkDeferredCanvas::DeferredDevice
574//------------------------------------
575
576SkDeferredCanvas::DeferredDevice::DeferredDevice(
577 SkDevice* immediateDevice, DeviceContext* deviceContext) :
578 SkDevice(SkBitmap::kNo_Config, immediateDevice->width(),
579 immediateDevice->height(), immediateDevice->isOpaque())
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000580 , fFreshFrame(true) {
581
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000582 fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
junov@google.com4370aed2012-01-18 16:21:08 +0000583 fDeviceContext = deviceContext;
584 SkSafeRef(fDeviceContext);
585 fImmediateDevice = immediateDevice; // ref counted via fImmediateCanvas
586 fImmediateCanvas = SkNEW_ARGS(SkCanvas, (fImmediateDevice));
junov@chromium.org77eec242012-07-18 17:54:45 +0000587 fPipeController.setPlaybackCanvas(fImmediateCanvas);
junov@chromium.org77eec242012-07-18 17:54:45 +0000588 beginRecording();
junov@google.com4370aed2012-01-18 16:21:08 +0000589}
590
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000591SkDeferredCanvas::DeferredDevice::~DeferredDevice() {
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +0000592 flushPending();
junov@google.com4370aed2012-01-18 16:21:08 +0000593 SkSafeUnref(fImmediateCanvas);
594 SkSafeUnref(fDeviceContext);
595}
junov@chromium.org77eec242012-07-18 17:54:45 +0000596
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000597void SkDeferredCanvas::DeferredDevice::setMaxRecordingStorage(size_t maxStorage) {
598 fMaxRecordingStorageBytes = maxStorage;
599 recordingCanvas(); // Accessing the recording canvas applies the new limit.
600}
junov@chromium.org77eec242012-07-18 17:54:45 +0000601
602void SkDeferredCanvas::DeferredDevice::endRecording() {
junov@chromium.org77eec242012-07-18 17:54:45 +0000603 fPipeWriter.endRecording();
604 fPipeController.reset();
junov@chromium.org77eec242012-07-18 17:54:45 +0000605 fRecordingCanvas = NULL;
606}
607
608void SkDeferredCanvas::DeferredDevice::beginRecording() {
junov@chromium.org77eec242012-07-18 17:54:45 +0000609 fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0);
junov@chromium.org77eec242012-07-18 17:54:45 +0000610}
junov@google.com4370aed2012-01-18 16:21:08 +0000611
612void SkDeferredCanvas::DeferredDevice::setDeviceContext(
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000613 DeviceContext* deviceContext) {
junov@google.com4370aed2012-01-18 16:21:08 +0000614 SkRefCnt_SafeAssign(fDeviceContext, deviceContext);
615}
616
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000617void SkDeferredCanvas::DeferredDevice::contentsCleared() {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000618 if (!fRecordingCanvas->isDrawingToLayer()) {
619 fFreshFrame = true;
junov@google.com4370aed2012-01-18 16:21:08 +0000620
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000621 // TODO: find a way to transfer the state stack and layers
622 // to the new recording canvas. For now, purging only works
623 // with an empty stack.
624 if (fRecordingCanvas->getSaveCount() == 0) {
junov@google.com4370aed2012-01-18 16:21:08 +0000625
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000626 // Save state that is trashed by the purge
627 SkDrawFilter* drawFilter = fRecordingCanvas->getDrawFilter();
628 SkSafeRef(drawFilter); // So that it survives the purge
629 SkMatrix matrix = fRecordingCanvas->getTotalMatrix();
630 SkRegion clipRegion = fRecordingCanvas->getTotalClip();
junov@google.com4370aed2012-01-18 16:21:08 +0000631
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000632 // beginRecording creates a new recording canvas and discards the
633 // old one, hence purging deferred draw ops.
junov@chromium.org77eec242012-07-18 17:54:45 +0000634 this->endRecording();
635 this->beginRecording();
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000636
637 // Restore pre-purge state
638 if (!clipRegion.isEmpty()) {
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000639 fRecordingCanvas->clipRegion(clipRegion,
640 SkRegion::kReplace_Op);
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000641 }
642 if (!matrix.isIdentity()) {
643 fRecordingCanvas->setMatrix(matrix);
644 }
645 if (drawFilter) {
646 fRecordingCanvas->setDrawFilter(drawFilter)->unref();
647 }
648 }
junov@google.com4370aed2012-01-18 16:21:08 +0000649 }
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000650}
651
652bool SkDeferredCanvas::DeferredDevice::isFreshFrame() {
653 bool ret = fFreshFrame;
654 fFreshFrame = false;
655 return ret;
junov@google.com4370aed2012-01-18 16:21:08 +0000656}
657
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000658void SkDeferredCanvas::DeferredDevice::flushPending() {
junov@chromium.org77eec242012-07-18 17:54:45 +0000659 if (!fPipeController.hasRecorded()) {
660 return;
661 }
junov@google.com4370aed2012-01-18 16:21:08 +0000662 if (fDeviceContext) {
663 fDeviceContext->prepareForDraw();
664 }
junov@chromium.org77eec242012-07-18 17:54:45 +0000665
junov@chromium.org77eec242012-07-18 17:54:45 +0000666 fPipeWriter.flushRecording(true);
667 fPipeController.playback();
junov@google.com4370aed2012-01-18 16:21:08 +0000668}
669
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000670void SkDeferredCanvas::DeferredDevice::flush() {
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000671 this->flushPending();
junov@chromium.orgbf6c1e42012-01-30 14:53:22 +0000672 fImmediateCanvas->flush();
junov@google.com4370aed2012-01-18 16:21:08 +0000673}
674
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000675size_t SkDeferredCanvas::DeferredDevice::freeMemoryIfPossible(size_t bytesToFree) {
676 return fPipeWriter.freeMemoryIfPossible(bytesToFree);
677}
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000678
679size_t SkDeferredCanvas::DeferredDevice::storageAllocatedForRecording() const {
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000680 return (fPipeController.storageAllocatedForRecording()
681 + fPipeWriter.storageAllocatedForRecording());
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000682}
683
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000684SkCanvas* SkDeferredCanvas::DeferredDevice::recordingCanvas() {
junov@chromium.org2e14ba82012-08-07 14:26:57 +0000685 size_t storageAllocated = this->storageAllocatedForRecording();
686 if (storageAllocated > fMaxRecordingStorageBytes) {
687 // First, attempt to reduce cache without flushing
688 size_t tryFree = storageAllocated - fMaxRecordingStorageBytes;
689 if (this->freeMemoryIfPossible(tryFree) < tryFree) {
690 // Flush is necessary to free more space.
691 this->flushPending();
692 // Free as much as possible to avoid oscillating around fMaxRecordingStorageBytes
693 // which could cause a high flushing frequency.
694 this->freeMemoryIfPossible(~0);
695 }
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000696 }
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000697 return fRecordingCanvas;
698}
699
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000700uint32_t SkDeferredCanvas::DeferredDevice::getDeviceCapabilities() {
junov@google.com4370aed2012-01-18 16:21:08 +0000701 return fImmediateDevice->getDeviceCapabilities();
702}
703
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000704int SkDeferredCanvas::DeferredDevice::width() const {
junov@google.com4370aed2012-01-18 16:21:08 +0000705 return fImmediateDevice->width();
706}
707
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000708int SkDeferredCanvas::DeferredDevice::height() const {
junov@google.com4370aed2012-01-18 16:21:08 +0000709 return fImmediateDevice->height();
710}
711
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000712SkGpuRenderTarget* SkDeferredCanvas::DeferredDevice::accessRenderTarget() {
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000713 this->flushPending();
junov@google.com4370aed2012-01-18 16:21:08 +0000714 return fImmediateDevice->accessRenderTarget();
715}
716
717void SkDeferredCanvas::DeferredDevice::writePixels(const SkBitmap& bitmap,
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000718 int x, int y, SkCanvas::Config8888 config8888) {
719
junov@google.com4370aed2012-01-18 16:21:08 +0000720 if (x <= 0 && y <= 0 && (x + bitmap.width()) >= width() &&
721 (y + bitmap.height()) >= height()) {
junov@chromium.org8f9ecbd2012-02-13 21:53:45 +0000722 contentsCleared();
junov@google.com4370aed2012-01-18 16:21:08 +0000723 }
724
725 if (SkBitmap::kARGB_8888_Config == bitmap.config() &&
726 SkCanvas::kNative_Premul_Config8888 != config8888 &&
727 kPMColorAlias != config8888) {
728 //Special case config: no deferral
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000729 this->flushPending();
junov@google.com4370aed2012-01-18 16:21:08 +0000730 fImmediateDevice->writePixels(bitmap, x, y, config8888);
junov@chromium.org09640d62012-07-25 20:09:37 +0000731 return;
junov@google.com4370aed2012-01-18 16:21:08 +0000732 }
733
734 SkPaint paint;
735 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
junov@chromium.org10f7f972012-07-31 21:01:51 +0000736 if (shouldDrawImmediately(&bitmap, NULL)) {
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +0000737 this->flushPending();
738 fImmediateCanvas->drawSprite(bitmap, x, y, &paint);
739 } else {
junov@chromium.orgb10a6bd2012-07-25 17:27:13 +0000740 recordingCanvas()->drawSprite(bitmap, x, y, &paint);
741 }
junov@google.com4370aed2012-01-18 16:21:08 +0000742}
743
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000744const SkBitmap& SkDeferredCanvas::DeferredDevice::onAccessBitmap(SkBitmap*) {
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000745 this->flushPending();
junov@chromium.org1f9767c2012-02-07 16:27:57 +0000746 return fImmediateDevice->accessBitmap(false);
junov@google.com4370aed2012-01-18 16:21:08 +0000747}
748
749SkDevice* SkDeferredCanvas::DeferredDevice::onCreateCompatibleDevice(
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000750 SkBitmap::Config config, int width, int height, bool isOpaque,
751 Usage usage) {
752
junov@google.com4370aed2012-01-18 16:21:08 +0000753 // Save layer usage not supported, and not required by SkDeferredCanvas.
754 SkASSERT(usage != kSaveLayer_Usage);
755 // Create a compatible non-deferred device.
scroggo@google.comd7dbd422012-07-03 15:16:30 +0000756 SkAutoTUnref<SkDevice> compatibleDevice
757 (fImmediateDevice->createCompatibleDevice(config, width, height,
758 isOpaque));
junov@google.com4370aed2012-01-18 16:21:08 +0000759 return SkNEW_ARGS(DeferredDevice, (compatibleDevice, fDeviceContext));
760}
761
762bool SkDeferredCanvas::DeferredDevice::onReadPixels(
junov@chromium.orgc16ca922012-02-24 22:06:27 +0000763 const SkBitmap& bitmap, int x, int y, SkCanvas::Config8888 config8888) {
junov@chromium.orgbfeddae2012-07-23 13:35:14 +0000764 this->flushPending();
junov@google.com4370aed2012-01-18 16:21:08 +0000765 return fImmediateCanvas->readPixels(const_cast<SkBitmap*>(&bitmap),
766 x, y, config8888);
767}