OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
11 #include "SkDrawFilter.h" | 11 #include "SkDrawFilter.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
13 #include "SkMetaData.h" | 13 #include "SkMetaData.h" |
14 #include "SkNinePatchIter.h" | 14 #include "SkNinePatchIter.h" |
15 #include "SkPatchUtils.h" | 15 #include "SkPatchUtils.h" |
16 #include "SkPathMeasure.h" | 16 #include "SkPathMeasure.h" |
17 #include "SkRasterClip.h" | 17 #include "SkRasterClip.h" |
18 #include "SkRSXform.h" | 18 #include "SkRSXform.h" |
19 #include "SkShader.h" | 19 #include "SkShader.h" |
20 #include "SkTextBlob.h" | 20 #include "SkTextBlob.h" |
21 #include "SkTextToPathIter.h" | 21 #include "SkTextToPathIter.h" |
22 | 22 |
23 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) | 23 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) |
24 : fSurfaceProps(surfaceProps) | 24 : fSurfaceProps(surfaceProps) |
25 #ifdef SK_DEBUG | 25 #ifdef SK_DEBUG |
26 , fAttachedToCanvas(false) | 26 , fAttachedToCanvas(false) |
27 #endif | 27 #endif |
28 { | 28 { |
29 fOrigin.setZero(); | 29 fOrigin.setZero(); |
30 fMetaData = NULL; | 30 fMetaData = nullptr; |
31 } | 31 } |
32 | 32 |
33 SkBaseDevice::~SkBaseDevice() { delete fMetaData; } | 33 SkBaseDevice::~SkBaseDevice() { delete fMetaData; } |
34 | 34 |
35 SkMetaData& SkBaseDevice::getMetaData() { | 35 SkMetaData& SkBaseDevice::getMetaData() { |
36 // metadata users are rare, so we lazily allocate it. If that changes we | 36 // metadata users are rare, so we lazily allocate it. If that changes we |
37 // can decide to just make it a field in the device (rather than a ptr) | 37 // can decide to just make it a field in the device (rather than a ptr) |
38 if (NULL == fMetaData) { | 38 if (nullptr == fMetaData) { |
39 fMetaData = new SkMetaData; | 39 fMetaData = new SkMetaData; |
40 } | 40 } |
41 return *fMetaData; | 41 return *fMetaData; |
42 } | 42 } |
43 | 43 |
44 SkImageInfo SkBaseDevice::imageInfo() const { | 44 SkImageInfo SkBaseDevice::imageInfo() const { |
45 return SkImageInfo::MakeUnknown(); | 45 return SkImageInfo::MakeUnknown(); |
46 } | 46 } |
47 | 47 |
48 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { | 48 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) { |
(...skipping 22 matching lines...) Expand all Loading... |
71 return geo; | 71 return geo; |
72 } | 72 } |
73 | 73 |
74 void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, | 74 void SkBaseDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer, |
75 const SkRRect& inner, const SkPaint& paint) { | 75 const SkRRect& inner, const SkPaint& paint) { |
76 SkPath path; | 76 SkPath path; |
77 path.addRRect(outer); | 77 path.addRRect(outer); |
78 path.addRRect(inner); | 78 path.addRRect(inner); |
79 path.setFillType(SkPath::kEvenOdd_FillType); | 79 path.setFillType(SkPath::kEvenOdd_FillType); |
80 | 80 |
81 const SkMatrix* preMatrix = NULL; | 81 const SkMatrix* preMatrix = nullptr; |
82 const bool pathIsMutable = true; | 82 const bool pathIsMutable = true; |
83 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); | 83 this->drawPath(draw, path, paint, preMatrix, pathIsMutable); |
84 } | 84 } |
85 | 85 |
86 void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPoint cubics[12], const
SkColor colors[4], | 86 void SkBaseDevice::drawPatch(const SkDraw& draw, const SkPoint cubics[12], const
SkColor colors[4], |
87 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { | 87 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { |
88 SkPatchUtils::VertexData data; | 88 SkPatchUtils::VertexData data; |
89 | 89 |
90 SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, draw.fMatrix); | 90 SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, draw.fMatrix); |
91 | 91 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 pnt.setShader(shader); | 205 pnt.setShader(shader); |
206 | 206 |
207 if (colors && colors[i] != SK_ColorWHITE) { | 207 if (colors && colors[i] != SK_ColorWHITE) { |
208 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color
s[i], mode)); | 208 SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(color
s[i], mode)); |
209 pnt.setColorFilter(cf); | 209 pnt.setColorFilter(cf); |
210 } | 210 } |
211 | 211 |
212 path.rewind(); | 212 path.rewind(); |
213 path.addPoly(quad, 4, true); | 213 path.addPoly(quad, 4, true); |
214 path.setConvexity(SkPath::kConvex_Convexity); | 214 path.setConvexity(SkPath::kConvex_Convexity); |
215 this->drawPath(draw, path, pnt, NULL, true); | 215 this->drawPath(draw, path, pnt, nullptr, true); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 219 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
220 | 220 |
221 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { | 221 bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowByt
es, int x, int y) { |
222 #ifdef SK_DEBUG | 222 #ifdef SK_DEBUG |
223 SkASSERT(info.width() > 0 && info.height() > 0); | 223 SkASSERT(info.width() > 0 && info.height() > 0); |
224 SkASSERT(dstP); | 224 SkASSERT(dstP); |
225 SkASSERT(rowBytes >= info.minRowBytes()); | 225 SkASSERT(rowBytes >= info.minRowBytes()); |
(...skipping 30 matching lines...) Expand all Loading... |
256 } | 256 } |
257 | 257 |
258 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const S
kMatrix*, | 258 bool SkBaseDevice::EXPERIMENTAL_drawPicture(SkCanvas*, const SkPicture*, const S
kMatrix*, |
259 const SkPaint*) { | 259 const SkPaint*) { |
260 // The base class doesn't perform any accelerated picture rendering | 260 // The base class doesn't perform any accelerated picture rendering |
261 return false; | 261 return false; |
262 } | 262 } |
263 | 263 |
264 bool SkBaseDevice::accessPixels(SkPixmap* pmap) { | 264 bool SkBaseDevice::accessPixels(SkPixmap* pmap) { |
265 SkPixmap tempStorage; | 265 SkPixmap tempStorage; |
266 if (NULL == pmap) { | 266 if (nullptr == pmap) { |
267 pmap = &tempStorage; | 267 pmap = &tempStorage; |
268 } | 268 } |
269 return this->onAccessPixels(pmap); | 269 return this->onAccessPixels(pmap); |
270 } | 270 } |
271 | 271 |
272 bool SkBaseDevice::peekPixels(SkPixmap* pmap) { | 272 bool SkBaseDevice::peekPixels(SkPixmap* pmap) { |
273 SkPixmap tempStorage; | 273 SkPixmap tempStorage; |
274 if (NULL == pmap) { | 274 if (nullptr == pmap) { |
275 pmap = &tempStorage; | 275 pmap = &tempStorage; |
276 } | 276 } |
277 return this->onPeekPixels(pmap); | 277 return this->onPeekPixels(pmap); |
278 } | 278 } |
279 | 279 |
280 ////////////////////////////////////////////////////////////////////////////////
////////// | 280 ////////////////////////////////////////////////////////////////////////////////
////////// |
281 | 281 |
282 static void morphpoints(SkPoint dst[], const SkPoint src[], int count, | 282 static void morphpoints(SkPoint dst[], const SkPoint src[], int count, |
283 SkPathMeasure& meas, const SkMatrix& matrix) { | 283 SkPathMeasure& meas, const SkMatrix& matrix) { |
284 SkMatrix::MapXYProc proc = matrix.getMapXYProc(); | 284 SkMatrix::MapXYProc proc = matrix.getMapXYProc(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 default: | 350 default: |
351 SkDEBUGFAIL("unknown verb"); | 351 SkDEBUGFAIL("unknown verb"); |
352 break; | 352 break; |
353 } | 353 } |
354 } | 354 } |
355 } | 355 } |
356 | 356 |
357 void SkBaseDevice::drawTextOnPath(const SkDraw& draw, const void* text, size_t b
yteLength, | 357 void SkBaseDevice::drawTextOnPath(const SkDraw& draw, const void* text, size_t b
yteLength, |
358 const SkPath& follow, const SkMatrix* matrix, | 358 const SkPath& follow, const SkMatrix* matrix, |
359 const SkPaint& paint) { | 359 const SkPaint& paint) { |
360 SkASSERT(byteLength == 0 || text != NULL); | 360 SkASSERT(byteLength == 0 || text != nullptr); |
361 | 361 |
362 // nothing to draw | 362 // nothing to draw |
363 if (text == NULL || byteLength == 0 || draw.fRC->isEmpty()) { | 363 if (text == nullptr || byteLength == 0 || draw.fRC->isEmpty()) { |
364 return; | 364 return; |
365 } | 365 } |
366 | 366 |
367 SkTextToPathIter iter((const char*)text, byteLength, paint, true); | 367 SkTextToPathIter iter((const char*)text, byteLength, paint, true); |
368 SkPathMeasure meas(follow, false); | 368 SkPathMeasure meas(follow, false); |
369 SkScalar hOffset = 0; | 369 SkScalar hOffset = 0; |
370 | 370 |
371 // need to measure first | 371 // need to measure first |
372 if (paint.getTextAlign() != SkPaint::kLeft_Align) { | 372 if (paint.getTextAlign() != SkPaint::kLeft_Align) { |
373 SkScalar pathLen = meas.getLength(); | 373 SkScalar pathLen = meas.getLength(); |
(...skipping 14 matching lines...) Expand all Loading... |
388 if (iterPath) { | 388 if (iterPath) { |
389 SkPath tmp; | 389 SkPath tmp; |
390 SkMatrix m(scaledMatrix); | 390 SkMatrix m(scaledMatrix); |
391 | 391 |
392 tmp.setIsVolatile(true); | 392 tmp.setIsVolatile(true); |
393 m.postTranslate(xpos + hOffset, 0); | 393 m.postTranslate(xpos + hOffset, 0); |
394 if (matrix) { | 394 if (matrix) { |
395 m.postConcat(*matrix); | 395 m.postConcat(*matrix); |
396 } | 396 } |
397 morphpath(&tmp, *iterPath, meas, m); | 397 morphpath(&tmp, *iterPath, meas, m); |
398 this->drawPath(draw, tmp, iter.getPaint(), NULL, true); | 398 this->drawPath(draw, tmp, iter.getPaint(), nullptr, true); |
399 } | 399 } |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 ////////////////////////////////////////////////////////////////////////////////
////////// | 403 ////////////////////////////////////////////////////////////////////////////////
////////// |
404 | 404 |
405 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { | 405 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { |
406 uint32_t flags = paint.getFlags(); | 406 uint32_t flags = paint.getFlags(); |
407 | 407 |
408 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | 408 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
409 return flags; | 409 return flags; |
410 } | 410 } |
411 | 411 |
412 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() | 412 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() |
413 || this->onShouldDisableLCD(paint)) { | 413 || this->onShouldDisableLCD(paint)) { |
414 | 414 |
415 flags &= ~SkPaint::kLCDRenderText_Flag; | 415 flags &= ~SkPaint::kLCDRenderText_Flag; |
416 flags |= SkPaint::kGenA8FromLCD_Flag; | 416 flags |= SkPaint::kGenA8FromLCD_Flag; |
417 } | 417 } |
418 | 418 |
419 return flags; | 419 return flags; |
420 } | 420 } |
421 | 421 |
OLD | NEW |