OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 | 325 |
326 m_resizedImage = resizedImage; | 326 m_resizedImage = resizedImage; |
327 } | 327 } |
328 | 328 |
329 SkBitmap resizedSubset; | 329 SkBitmap resizedSubset; |
330 SkIRect resizedSubsetRect = m_cachedImageInfo.rectInSubset(scaledImageSubset ); | 330 SkIRect resizedSubsetRect = m_cachedImageInfo.rectInSubset(scaledImageSubset ); |
331 m_resizedImage.extractSubset(&resizedSubset, resizedSubsetRect); | 331 m_resizedImage.extractSubset(&resizedSubset, resizedSubsetRect); |
332 return resizedSubset; | 332 return resizedSubset; |
333 } | 333 } |
334 | 334 |
335 static bool hasNon90rotation(GraphicsContext* context) | 335 static bool shouldDrawAntiAliased(GraphicsContext* context, const SkRect& destRe ct) |
336 { | 336 { |
337 return !context->getTotalMatrix().rectStaysRect(); | 337 const SkMatrix totalMatrix = context->getTotalMatrix(); |
338 // Enable anti-aliasing if we're rotated or skewed. | |
339 if (!totalMatrix.rectStaysRect()) | |
340 return true; | |
341 // Check if the dimensions of the destination are "small" (less than one | |
342 // destination pixel). To prevent sudden drop-outs. Since we know that | |
343 // kRectStaysRect_Mask is set, we can use the kAffine_Mask flag to select | |
344 // the relevant components of the matrix to compute the transformed vector. | |
Justin Novosad
2014/03/25 14:35:07
Reformulate for clarity. Suggestion : Since we kno
| |
345 SkScalar widthExpansion, heightExpansion; | |
346 if (totalMatrix.getType() & SkMatrix::kAffine_Mask) | |
347 widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = total Matrix[SkMatrix::kMSkewX]; | |
348 else | |
349 widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = tota lMatrix[SkMatrix::kMScaleY]; | |
350 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa bs(heightExpansion) < 1; | |
338 } | 351 } |
339 | 352 |
340 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const | 353 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const |
341 { | 354 { |
342 TRACE_EVENT0("skia", "NativeImageSkia::draw"); | 355 TRACE_EVENT0("skia", "NativeImageSkia::draw"); |
343 SkPaint paint; | 356 SkPaint paint; |
344 paint.setXfermode(compOp.get()); | 357 paint.setXfermode(compOp.get()); |
345 paint.setColorFilter(context->colorFilter()); | 358 paint.setColorFilter(context->colorFilter()); |
346 paint.setAlpha(context->getNormalizedAlpha()); | 359 paint.setAlpha(context->getNormalizedAlpha()); |
347 paint.setLooper(context->drawLooper()); | 360 paint.setLooper(context->drawLooper()); |
348 // only antialias if we're rotated or skewed | 361 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); |
349 paint.setAntiAlias(hasNon90rotation(context)); | |
350 | 362 |
351 ResamplingMode resampling; | 363 ResamplingMode resampling; |
352 if (context->isAccelerated()) { | 364 if (context->isAccelerated()) { |
353 resampling = LinearResampling; | 365 resampling = LinearResampling; |
354 } else if (context->printing()) { | 366 } else if (context->printing()) { |
355 resampling = NoResampling; | 367 resampling = NoResampling; |
356 } else { | 368 } else { |
357 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). | 369 // Take into account scale applied to the canvas when computing sampling mode (e.g. CSS scale or page scale). |
358 SkRect destRectTarget = destRect; | 370 SkRect destRectTarget = destRect; |
359 SkMatrix totalMatrix = context->getTotalMatrix(); | 371 SkMatrix totalMatrix = context->getTotalMatrix(); |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
587 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) | 599 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca ledImageSubset) |
588 { | 600 { |
589 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 601 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
590 return SkIRect::MakeEmpty(); | 602 return SkIRect::MakeEmpty(); |
591 SkIRect subsetRect = otherScaledImageSubset; | 603 SkIRect subsetRect = otherScaledImageSubset; |
592 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 604 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
593 return subsetRect; | 605 return subsetRect; |
594 } | 606 } |
595 | 607 |
596 } // namespace WebCore | 608 } // namespace WebCore |
OLD | NEW |