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 if (!context->shouldAntialias()) |
| 338 return false; |
| 339 const SkMatrix totalMatrix = context->getTotalMatrix(); |
| 340 // Don't disable anti-aliasing if we're rotated or skewed. |
| 341 if (!totalMatrix.rectStaysRect()) |
| 342 return true; |
| 343 // Disable anti-aliasing for scales or n*90 degree rotations. |
| 344 // Allow to opt out of the optimization though for "hairline" geometry |
| 345 // images - using the shouldAntialiasHairlineImages() GraphicsContext flag. |
| 346 if (!context->shouldAntialiasHairlineImages()) |
| 347 return false; |
| 348 // Check if the dimensions of the destination are "small" (less than one |
| 349 // device pixel). To prevent sudden drop-outs. Since we know that |
| 350 // kRectStaysRect_Mask is set, the matrix either has scale and no skew or |
| 351 // vice versa. We can query the kAffine_Mask flag to determine which case |
| 352 // it is. |
| 353 // FIXME: This queries the CTM while drawing, which is generally |
| 354 // discouraged. Always drawing with AA can negatively impact performance |
| 355 // though - that's why it's not always on. |
| 356 SkScalar widthExpansion, heightExpansion; |
| 357 if (totalMatrix.getType() & SkMatrix::kAffine_Mask) |
| 358 widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = total
Matrix[SkMatrix::kMSkewX]; |
| 359 else |
| 360 widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = tota
lMatrix[SkMatrix::kMScaleY]; |
| 361 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa
bs(heightExpansion) < 1; |
338 } | 362 } |
339 | 363 |
340 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons
t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const | 364 void NativeImageSkia::draw(GraphicsContext* context, const SkRect& srcRect, cons
t SkRect& destRect, PassRefPtr<SkXfermode> compOp) const |
341 { | 365 { |
342 TRACE_EVENT0("skia", "NativeImageSkia::draw"); | 366 TRACE_EVENT0("skia", "NativeImageSkia::draw"); |
343 SkPaint paint; | 367 SkPaint paint; |
344 paint.setXfermode(compOp.get()); | 368 paint.setXfermode(compOp.get()); |
345 paint.setColorFilter(context->colorFilter()); | 369 paint.setColorFilter(context->colorFilter()); |
346 paint.setAlpha(context->getNormalizedAlpha()); | 370 paint.setAlpha(context->getNormalizedAlpha()); |
347 paint.setLooper(context->drawLooper()); | 371 paint.setLooper(context->drawLooper()); |
348 // only antialias if we're rotated or skewed | 372 paint.setAntiAlias(shouldDrawAntiAliased(context, destRect)); |
349 paint.setAntiAlias(hasNon90rotation(context)); | |
350 | 373 |
351 ResamplingMode resampling; | 374 ResamplingMode resampling; |
352 if (context->isAccelerated()) { | 375 if (context->isAccelerated()) { |
353 resampling = LinearResampling; | 376 resampling = LinearResampling; |
354 } else if (context->printing()) { | 377 } else if (context->printing()) { |
355 resampling = NoResampling; | 378 resampling = NoResampling; |
356 } else { | 379 } else { |
357 // Take into account scale applied to the canvas when computing sampling
mode (e.g. CSS scale or page scale). | 380 // Take into account scale applied to the canvas when computing sampling
mode (e.g. CSS scale or page scale). |
358 SkRect destRectTarget = destRect; | 381 SkRect destRectTarget = destRect; |
359 SkMatrix totalMatrix = context->getTotalMatrix(); | 382 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) | 610 SkIRect NativeImageSkia::ImageResourceInfo::rectInSubset(const SkIRect& otherSca
ledImageSubset) |
588 { | 611 { |
589 if (!scaledImageSubset.contains(otherScaledImageSubset)) | 612 if (!scaledImageSubset.contains(otherScaledImageSubset)) |
590 return SkIRect::MakeEmpty(); | 613 return SkIRect::MakeEmpty(); |
591 SkIRect subsetRect = otherScaledImageSubset; | 614 SkIRect subsetRect = otherScaledImageSubset; |
592 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); | 615 subsetRect.offset(-scaledImageSubset.x(), -scaledImageSubset.y()); |
593 return subsetRect; | 616 return subsetRect; |
594 } | 617 } |
595 | 618 |
596 } // namespace WebCore | 619 } // namespace WebCore |
OLD | NEW |