blob: 2a7f5756a007abf3b347c75ab6521fdab6f20e0e [file] [log] [blame]
Derek Sollenberger1db141f2014-12-16 08:37:20 -05001/*
2 * Copyright (C) 2015 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#include "SkiaCanvasProxy.h"
18
sergeyvaed7f582016-10-14 16:30:21 -070019#include "hwui/Bitmap.h"
20
Derek Sollenberger1db141f2014-12-16 08:37:20 -050021#include <cutils/log.h>
Stan Iliev770e0b52017-01-05 16:53:14 -050022#include <SkLatticeIter.h>
Derek Sollenberger1db141f2014-12-16 08:37:20 -050023#include <SkPatchUtils.h>
Ben Wagnera11ee3c2015-08-04 11:14:15 -040024#include <SkPaint.h>
25#include <SkPath.h>
Tom Hudson17c5adf2015-06-09 15:46:04 -040026#include <SkPixelRef.h>
Ben Wagnera11ee3c2015-08-04 11:14:15 -040027#include <SkRect.h>
28#include <SkRRect.h>
Yuqian Liafc221492016-07-18 13:07:42 -040029#include <SkRSXform.h>
Matt Sarett79fc3b12016-03-24 11:02:44 -040030#include <SkSurface.h>
Derek Sollenberger09bd6c22016-11-03 12:54:06 -040031#include <SkTextBlobRunIterator.h>
Derek Sollenberger1db141f2014-12-16 08:37:20 -050032
Ben Wagner6bbf68d2015-08-19 11:26:06 -040033#include <memory>
34
Derek Sollenberger1db141f2014-12-16 08:37:20 -050035namespace android {
36namespace uirenderer {
37
Tom Hudsonb1476ae2015-03-05 10:30:18 -050038SkiaCanvasProxy::SkiaCanvasProxy(Canvas* canvas, bool filterHwuiCalls)
Derek Sollenberger1db141f2014-12-16 08:37:20 -050039 : INHERITED(canvas->width(), canvas->height())
Tom Hudsonb1476ae2015-03-05 10:30:18 -050040 , mCanvas(canvas)
41 , mFilterHwuiCalls(filterHwuiCalls) {}
Derek Sollenberger1db141f2014-12-16 08:37:20 -050042
43void SkiaCanvasProxy::onDrawPaint(const SkPaint& paint) {
44 mCanvas->drawPaint(paint);
45}
46
47void SkiaCanvasProxy::onDrawPoints(PointMode pointMode, size_t count, const SkPoint pts[],
48 const SkPaint& paint) {
Tom Hudsonb1476ae2015-03-05 10:30:18 -050049 if (!pts || count == 0) {
50 return;
51 }
52
Derek Sollenberger1db141f2014-12-16 08:37:20 -050053 // convert the SkPoints into floats
Ben Wagnere3a40ea2015-08-19 15:49:37 -040054 static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
Derek Sollenberger1db141f2014-12-16 08:37:20 -050055 const size_t floatCount = count << 1;
56 const float* floatArray = &pts[0].fX;
57
58 switch (pointMode) {
59 case kPoints_PointMode: {
60 mCanvas->drawPoints(floatArray, floatCount, paint);
61 break;
62 }
63 case kLines_PointMode: {
64 mCanvas->drawLines(floatArray, floatCount, paint);
65 break;
66 }
67 case kPolygon_PointMode: {
68 SkPaint strokedPaint(paint);
69 strokedPaint.setStyle(SkPaint::kStroke_Style);
70
71 SkPath path;
72 for (size_t i = 0; i < count - 1; i++) {
73 path.moveTo(pts[i]);
74 path.lineTo(pts[i+1]);
75 this->drawPath(path, strokedPaint);
76 path.rewind();
77 }
78 break;
79 }
80 default:
81 LOG_ALWAYS_FATAL("Unknown point type");
82 }
83}
84
85void SkiaCanvasProxy::onDrawOval(const SkRect& rect, const SkPaint& paint) {
86 mCanvas->drawOval(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, paint);
87}
88
89void SkiaCanvasProxy::onDrawRect(const SkRect& rect, const SkPaint& paint) {
90 mCanvas->drawRect(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, paint);
91}
92
93void SkiaCanvasProxy::onDrawRRect(const SkRRect& roundRect, const SkPaint& paint) {
94 if (!roundRect.isComplex()) {
95 const SkRect& rect = roundRect.rect();
96 SkVector radii = roundRect.getSimpleRadii();
97 mCanvas->drawRoundRect(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom,
98 radii.fX, radii.fY, paint);
99 } else {
100 SkPath path;
101 path.addRRect(roundRect);
102 mCanvas->drawPath(path, paint);
103 }
104}
105
106void SkiaCanvasProxy::onDrawPath(const SkPath& path, const SkPaint& paint) {
107 mCanvas->drawPath(path, paint);
108}
109
110void SkiaCanvasProxy::onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
111 const SkPaint* paint) {
sergeyvfc9999502016-10-17 13:07:38 -0700112 sk_sp<Bitmap> hwuiBitmap = Bitmap::createFrom(bitmap.info(), *bitmap.pixelRef());
Tom Hudson17c5adf2015-06-09 15:46:04 -0400113 // HWUI doesn't support extractSubset(), so convert any subsetted bitmap into
114 // a drawBitmapRect(); pass through an un-subsetted bitmap.
sergeyvfc9999502016-10-17 13:07:38 -0700115 if (hwuiBitmap && bitmap.dimensions() != hwuiBitmap->info().dimensions()) {
Tom Hudson17c5adf2015-06-09 15:46:04 -0400116 SkIPoint origin = bitmap.pixelRefOrigin();
sergeyvfc9999502016-10-17 13:07:38 -0700117 mCanvas->drawBitmap(*hwuiBitmap, origin.fX, origin.fY,
Tom Hudson17c5adf2015-06-09 15:46:04 -0400118 origin.fX + bitmap.dimensions().width(),
119 origin.fY + bitmap.dimensions().height(),
120 left, top,
121 left + bitmap.dimensions().width(),
122 top + bitmap.dimensions().height(),
123 paint);
124 } else {
sergeyvaed7f582016-10-14 16:30:21 -0700125 mCanvas->drawBitmap(*hwuiBitmap, left, top, paint);
Tom Hudson17c5adf2015-06-09 15:46:04 -0400126 }
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500127}
128
sergeyvfc9999502016-10-17 13:07:38 -0700129void SkiaCanvasProxy::onDrawBitmapRect(const SkBitmap& skBitmap, const SkRect* srcPtr,
Leon Scroggins IIIf35b9892015-07-31 10:38:40 -0400130 const SkRect& dst, const SkPaint* paint, SrcRectConstraint) {
sergeyvfc9999502016-10-17 13:07:38 -0700131 SkRect src = (srcPtr) ? *srcPtr : SkRect::MakeWH(skBitmap.width(), skBitmap.height());
Tom Hudson17c5adf2015-06-09 15:46:04 -0400132 // TODO: if bitmap is a subset, do we need to add pixelRefOrigin to src?
sergeyvfc9999502016-10-17 13:07:38 -0700133 Bitmap* bitmap = reinterpret_cast<Bitmap*>(skBitmap.pixelRef());
134 mCanvas->drawBitmap(*bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom,
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500135 dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint);
136}
137
138void SkiaCanvasProxy::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
139 const SkRect& dst, const SkPaint*) {
140 //TODO make nine-patch drawing a method on Canvas.h
141 SkDEBUGFAIL("SkiaCanvasProxy::onDrawBitmapNine is not yet supported");
142}
143
Stan Iliev770e0b52017-01-05 16:53:14 -0500144void SkiaCanvasProxy::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
145 const SkPaint* paint) {
146 SkBitmap skiaBitmap;
147 if (image->asLegacyBitmap(&skiaBitmap, SkImage::kRO_LegacyBitmapMode)) {
148 onDrawBitmap(skiaBitmap, left, top, paint);
149 }
150}
151
152void SkiaCanvasProxy::onDrawImageRect(const SkImage* image, const SkRect* srcPtr, const SkRect& dst,
153 const SkPaint* paint, SrcRectConstraint constraint) {
154 SkBitmap skiaBitmap;
155 if (image->asLegacyBitmap(&skiaBitmap, SkImage::kRO_LegacyBitmapMode)) {
156 sk_sp<Bitmap> bitmap = Bitmap::createFrom(skiaBitmap.info(), *skiaBitmap.pixelRef());
157 SkRect src = (srcPtr) ? *srcPtr : SkRect::MakeWH(image->width(), image->height());
158 mCanvas->drawBitmap(*bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom,
159 dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint);
160 }
161}
162
163void SkiaCanvasProxy::onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
164 const SkPaint*) {
165 SkDEBUGFAIL("SkiaCanvasProxy::onDrawImageNine is not yet supported");
166}
167
168void SkiaCanvasProxy::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
169 const SkRect& dst, const SkPaint* paint) {
170 SkLatticeIter iter(lattice, dst);
171 SkRect srcR, dstR;
172 while (iter.next(&srcR, &dstR)) {
173 onDrawImageRect(image, &srcR, dstR, paint, SkCanvas::kStrict_SrcRectConstraint);
174 }
175}
176
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500177void SkiaCanvasProxy::onDrawVertices(VertexMode mode, int vertexCount, const SkPoint vertices[],
Mike Reedc2f31df2016-10-28 17:21:45 -0400178 const SkPoint texs[], const SkColor colors[], SkBlendMode, const uint16_t indices[],
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500179 int indexCount, const SkPaint& paint) {
Mike Reedc2f31df2016-10-28 17:21:45 -0400180 // TODO: should we pass through blendmode
Tom Hudsonb1476ae2015-03-05 10:30:18 -0500181 if (mFilterHwuiCalls) {
182 return;
183 }
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500184 // convert the SkPoints into floats
Ben Wagnere3a40ea2015-08-19 15:49:37 -0400185 static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500186 const int floatCount = vertexCount << 1;
187 const float* vArray = &vertices[0].fX;
188 const float* tArray = (texs) ? &texs[0].fX : NULL;
189 const int* cArray = (colors) ? (int*)colors : NULL;
190 mCanvas->drawVertices(mode, floatCount, vArray, tArray, cArray, indices, indexCount, paint);
191}
192
Matt Sarett79fc3b12016-03-24 11:02:44 -0400193sk_sp<SkSurface> SkiaCanvasProxy::onNewSurface(const SkImageInfo&, const SkSurfaceProps&) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500194 SkDEBUGFAIL("SkiaCanvasProxy::onNewSurface is not supported");
195 return NULL;
196}
197
198void SkiaCanvasProxy::willSave() {
Florin Malitaeecff562015-12-21 10:43:01 -0500199 mCanvas->save(android::SaveFlags::MatrixClip);
200}
201
202static inline SaveFlags::Flags saveFlags(SkCanvas::SaveLayerFlags layerFlags) {
203 SaveFlags::Flags saveFlags = 0;
204
205 if (!(layerFlags & SkCanvas::kDontClipToLayer_Legacy_SaveLayerFlag)) {
206 saveFlags |= SaveFlags::ClipToLayer;
207 }
208
209 if (!(layerFlags & SkCanvas::kIsOpaque_SaveLayerFlag)) {
210 saveFlags |= SaveFlags::HasAlphaLayer;
211 }
212
213 return saveFlags;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500214}
215
Leon Scroggins III5518e7c2016-01-04 09:37:42 -0500216SkCanvas::SaveLayerStrategy SkiaCanvasProxy::getSaveLayerStrategy(const SaveLayerRec& saveLayerRec) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500217 SkRect rect;
Leon Scroggins III5518e7c2016-01-04 09:37:42 -0500218 if (saveLayerRec.fBounds) {
219 rect = *saveLayerRec.fBounds;
220 } else if (!mCanvas->getClipBounds(&rect)) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500221 rect = SkRect::MakeEmpty();
222 }
Leon Scroggins III5518e7c2016-01-04 09:37:42 -0500223 mCanvas->saveLayer(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, saveLayerRec.fPaint,
Florin Malitaeecff562015-12-21 10:43:01 -0500224 saveFlags(saveLayerRec.fSaveLayerFlags));
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500225 return SkCanvas::kNoLayer_SaveLayerStrategy;
226}
227
228void SkiaCanvasProxy::willRestore() {
229 mCanvas->restore();
230}
231
232void SkiaCanvasProxy::didConcat(const SkMatrix& matrix) {
233 mCanvas->concat(matrix);
234}
235
236void SkiaCanvasProxy::didSetMatrix(const SkMatrix& matrix) {
Chris Craik6daa13c2015-08-19 13:32:12 -0700237 mCanvas->setMatrix(matrix);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500238}
239
240void SkiaCanvasProxy::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
241 const SkPaint& paint) {
242 SkPath path;
243 path.addRRect(outer);
244 path.addRRect(inner);
245 path.setFillType(SkPath::kEvenOdd_FillType);
246 this->drawPath(path, paint);
247}
248
249/**
250 * Utility class that converts the incoming text & paint from the given encoding
251 * into glyphIDs.
252 */
253class GlyphIDConverter {
254public:
255 GlyphIDConverter(const void* text, size_t byteLength, const SkPaint& origPaint) {
256 paint = origPaint;
257 if (paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding) {
258 glyphIDs = (uint16_t*)text;
259 count = byteLength >> 1;
260 } else {
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400261 // ensure space for one glyph per ID given UTF8 encoding.
262 storage.reset(new uint16_t[byteLength]);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500263 glyphIDs = storage.get();
264 count = paint.textToGlyphs(text, byteLength, storage.get());
265 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
266 }
267 }
268
269 SkPaint paint;
270 uint16_t* glyphIDs;
271 int count;
272private:
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400273 std::unique_ptr<uint16_t[]> storage;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500274};
275
276void SkiaCanvasProxy::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
277 const SkPaint& origPaint) {
278 // convert to glyphIDs if necessary
279 GlyphIDConverter glyphs(text, byteLength, origPaint);
280
281 // compute the glyph positions
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400282 std::unique_ptr<SkPoint[]> pointStorage(new SkPoint[glyphs.count]);
283 std::unique_ptr<SkScalar[]> glyphWidths(new SkScalar[glyphs.count]);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500284 glyphs.paint.getTextWidths(glyphs.glyphIDs, glyphs.count << 1, glyphWidths.get());
285
286 // compute conservative bounds
287 // NOTE: We could call the faster paint.getFontBounds for a less accurate,
288 // but even more conservative bounds if this is too slow.
289 SkRect bounds;
290 glyphs.paint.measureText(glyphs.glyphIDs, glyphs.count << 1, &bounds);
291
292 // adjust for non-left alignment
293 if (glyphs.paint.getTextAlign() != SkPaint::kLeft_Align) {
294 SkScalar stop = 0;
295 for (int i = 0; i < glyphs.count; i++) {
296 stop += glyphWidths[i];
297 }
298 if (glyphs.paint.getTextAlign() == SkPaint::kCenter_Align) {
299 stop = SkScalarHalf(stop);
300 }
301 if (glyphs.paint.isVerticalText()) {
302 y -= stop;
303 } else {
304 x -= stop;
305 }
306 }
307
308 // setup the first glyph position and adjust bounds if needed
Tom Hudson806a6f02015-02-19 17:11:32 -0500309 int xBaseline = 0;
310 int yBaseline = 0;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500311 if (mCanvas->drawTextAbsolutePos()) {
312 bounds.offset(x,y);
Tom Hudson806a6f02015-02-19 17:11:32 -0500313 xBaseline = x;
314 yBaseline = y;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500315 }
Tom Hudson806a6f02015-02-19 17:11:32 -0500316 pointStorage[0].set(xBaseline, yBaseline);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500317
318 // setup the remaining glyph positions
319 if (glyphs.paint.isVerticalText()) {
320 for (int i = 1; i < glyphs.count; i++) {
Tom Hudson806a6f02015-02-19 17:11:32 -0500321 pointStorage[i].set(xBaseline, glyphWidths[i-1] + pointStorage[i-1].fY);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500322 }
323 } else {
324 for (int i = 1; i < glyphs.count; i++) {
Tom Hudson806a6f02015-02-19 17:11:32 -0500325 pointStorage[i].set(glyphWidths[i-1] + pointStorage[i-1].fX, yBaseline);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500326 }
327 }
328
Ben Wagnere3a40ea2015-08-19 15:49:37 -0400329 static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
sergeyvdccca442016-03-21 15:38:21 -0700330 mCanvas->drawGlyphs(glyphs.glyphIDs, &pointStorage[0].fX, glyphs.count, glyphs.paint,
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500331 x, y, bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, 0);
332}
333
334void SkiaCanvasProxy::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
335 const SkPaint& origPaint) {
336 // convert to glyphIDs if necessary
337 GlyphIDConverter glyphs(text, byteLength, origPaint);
338
339 // convert to relative positions if necessary
340 int x, y;
341 const SkPoint* posArray;
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400342 std::unique_ptr<SkPoint[]> pointStorage;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500343 if (mCanvas->drawTextAbsolutePos()) {
344 x = 0;
345 y = 0;
346 posArray = pos;
347 } else {
348 x = pos[0].fX;
349 y = pos[0].fY;
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400350 pointStorage.reset(new SkPoint[glyphs.count]);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500351 for (int i = 0; i < glyphs.count; i++) {
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400352 pointStorage[i].fX = pos[i].fX - x;
353 pointStorage[i].fY = pos[i].fY - y;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500354 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400355 posArray = pointStorage.get();
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500356 }
357
Derek Sollenberger35934cc2016-03-23 14:59:10 -0400358 // Compute conservative bounds. If the content has already been processed
359 // by Minikin then it had already computed these bounds. Unfortunately,
360 // there is no way to capture those bounds as part of the Skia drawPosText
361 // API so we need to do that computation again here.
Stan Ilievd84d2ee2016-07-25 13:32:25 -0400362 SkRect bounds = SkRect::MakeEmpty();
Derek Sollenberger35934cc2016-03-23 14:59:10 -0400363 for (int i = 0; i < glyphs.count; i++) {
Stan Ilievd84d2ee2016-07-25 13:32:25 -0400364 SkRect glyphBounds = SkRect::MakeEmpty();
Derek Sollenberger35934cc2016-03-23 14:59:10 -0400365 glyphs.paint.measureText(&glyphs.glyphIDs[i], sizeof(uint16_t), &glyphBounds);
366 glyphBounds.offset(pos[i].fX, pos[i].fY);
367 bounds.join(glyphBounds);
368 }
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500369
Ben Wagnere3a40ea2015-08-19 15:49:37 -0400370 static_assert(sizeof(SkPoint) == sizeof(float)*2, "SkPoint is no longer two floats");
sergeyvdccca442016-03-21 15:38:21 -0700371 mCanvas->drawGlyphs(glyphs.glyphIDs, &posArray[0].fX, glyphs.count, glyphs.paint, x, y,
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500372 bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom, 0);
373}
374
375void SkiaCanvasProxy::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
376 SkScalar constY, const SkPaint& paint) {
377 const size_t pointCount = byteLength >> 1;
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400378 std::unique_ptr<SkPoint[]> pts(new SkPoint[pointCount]);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500379 for (size_t i = 0; i < pointCount; i++) {
380 pts[i].set(xpos[i], constY);
381 }
Ben Wagner6bbf68d2015-08-19 11:26:06 -0400382 this->onDrawPosText(text, byteLength, pts.get(), paint);
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500383}
384
385void SkiaCanvasProxy::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
386 const SkMatrix* matrix, const SkPaint& origPaint) {
Yuqian Liafc221492016-07-18 13:07:42 -0400387 SkDEBUGFAIL("SkiaCanvasProxy::onDrawTextOnPath is not supported");
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500388}
389
Yuqian Liafc221492016-07-18 13:07:42 -0400390void SkiaCanvasProxy::onDrawTextRSXform(const void* text, size_t byteLength,
391 const SkRSXform xform[], const SkRect* cullRect, const SkPaint& paint) {
392 GlyphIDConverter glyphs(text, byteLength, paint); // Just get count
393 SkMatrix localM, currM, origM;
394 mCanvas->getMatrix(&currM);
395 origM = currM;
396 for (int i = 0; i < glyphs.count; i++) {
397 localM.setRSXform(*xform++);
398 currM.setConcat(origM, localM);
399 mCanvas->setMatrix(currM);
400 this->onDrawText((char*)text + (byteLength / glyphs.count * i),
401 byteLength / glyphs.count, 0, 0, paint);
402 }
403 mCanvas->setMatrix(origM);
404}
405
406
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500407void SkiaCanvasProxy::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
408 const SkPaint& paint) {
Derek Sollenberger09bd6c22016-11-03 12:54:06 -0400409 SkPaint runPaint = paint;
410
411 SkTextBlobRunIterator it(blob);
412 for (;!it.done(); it.next()) {
413 size_t textLen = it.glyphCount() * sizeof(uint16_t);
414 const SkPoint& offset = it.offset();
415 // applyFontToPaint() always overwrites the exact same attributes,
416 // so it is safe to not re-seed the paint for this reason.
417 it.applyFontToPaint(&runPaint);
418
419 switch (it.positioning()) {
420 case SkTextBlob::kDefault_Positioning:
421 this->drawText(it.glyphs(), textLen, x + offset.x(), y + offset.y(), runPaint);
422 break;
423 case SkTextBlob::kHorizontal_Positioning: {
424 std::unique_ptr<SkPoint[]> pts(new SkPoint[it.glyphCount()]);
425 for (size_t i = 0; i < it.glyphCount(); i++) {
426 pts[i].set(x + offset.x() + it.pos()[i], y + offset.y());
427 }
428 this->drawPosText(it.glyphs(), textLen, pts.get(), runPaint);
429 break;
430 }
431 case SkTextBlob::kFull_Positioning: {
432 std::unique_ptr<SkPoint[]> pts(new SkPoint[it.glyphCount()]);
433 for (size_t i = 0; i < it.glyphCount(); i++) {
434 const size_t xIndex = i*2;
435 const size_t yIndex = xIndex + 1;
436 pts[i].set(x + offset.x() + it.pos()[xIndex], y + offset.y() + it.pos()[yIndex]);
437 }
438 this->drawPosText(it.glyphs(), textLen, pts.get(), runPaint);
439 break;
440 }
441 default:
442 SkFAIL("unhandled positioning mode");
443 }
444 }
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500445}
446
447void SkiaCanvasProxy::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedc2f31df2016-10-28 17:21:45 -0400448 const SkPoint texCoords[4], SkBlendMode bmode, const SkPaint& paint) {
Tom Hudsonb1476ae2015-03-05 10:30:18 -0500449 if (mFilterHwuiCalls) {
450 return;
451 }
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500452 SkPatchUtils::VertexData data;
453
454 SkMatrix matrix;
455 mCanvas->getMatrix(&matrix);
456 SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &matrix);
457
458 // It automatically adjusts lodX and lodY in case it exceeds the number of indices.
459 // If it fails to generate the vertices, then we do not draw.
460 if (SkPatchUtils::getVertexData(&data, cubics, colors, texCoords, lod.width(), lod.height())) {
461 this->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints,
Mike Reedc2f31df2016-10-28 17:21:45 -0400462 data.fTexCoords, data.fColors, bmode, data.fIndices, data.fIndexCount,
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500463 paint);
464 }
465}
466
Mike Reed6e49c9f2016-12-02 15:36:59 -0500467void SkiaCanvasProxy::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500468 mCanvas->clipRect(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, op);
469}
470
Mike Reed6e49c9f2016-12-02 15:36:59 -0500471void SkiaCanvasProxy::onClipRRect(const SkRRect& roundRect, SkClipOp op, ClipEdgeStyle) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500472 SkPath path;
473 path.addRRect(roundRect);
474 mCanvas->clipPath(&path, op);
475}
476
Mike Reed6e49c9f2016-12-02 15:36:59 -0500477void SkiaCanvasProxy::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500478 mCanvas->clipPath(&path, op);
479}
480
Mike Reed6e49c9f2016-12-02 15:36:59 -0500481void SkiaCanvasProxy::onClipRegion(const SkRegion& region, SkClipOp op) {
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500482 mCanvas->clipRegion(&region, op);
483}
484
485}; // namespace uirenderer
486}; // namespace android