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