OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2006,2007,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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return InterpolationLow; | 323 return InterpolationLow; |
324 | 324 |
325 // Everything else gets resampled. | 325 // Everything else gets resampled. |
326 // High quality interpolation only enabled for scaling and translation. | 326 // High quality interpolation only enabled for scaling and translation. |
327 if (!(matrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Ma
sk))) | 327 if (!(matrix.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Ma
sk))) |
328 return InterpolationHigh; | 328 return InterpolationHigh; |
329 | 329 |
330 return InterpolationLow; | 330 return InterpolationLow; |
331 } | 331 } |
332 | 332 |
333 | |
334 bool shouldDrawAntiAliased(const GraphicsContext* context, const SkRect& destRec
t) | |
335 { | |
336 if (!context->shouldAntialias()) | |
337 return false; | |
338 const SkMatrix totalMatrix = context->getTotalMatrix(); | |
339 // Don't disable anti-aliasing if we're rotated or skewed. | |
340 if (!totalMatrix.rectStaysRect()) | |
341 return true; | |
342 // Disable anti-aliasing for scales or n*90 degree rotations. | |
343 // Allow to opt out of the optimization though for "hairline" geometry | |
344 // images - using the shouldAntialiasHairlineImages() GraphicsContext flag. | |
345 if (!context->shouldAntialiasHairlineImages()) | |
346 return false; | |
347 // Check if the dimensions of the destination are "small" (less than one | |
348 // device pixel). To prevent sudden drop-outs. Since we know that | |
349 // kRectStaysRect_Mask is set, the matrix either has scale and no skew or | |
350 // vice versa. We can query the kAffine_Mask flag to determine which case | |
351 // it is. | |
352 // FIXME: This queries the CTM while drawing, which is generally | |
353 // discouraged. Always drawing with AA can negatively impact performance | |
354 // though - that's why it's not always on. | |
355 SkScalar widthExpansion, heightExpansion; | |
356 if (totalMatrix.getType() & SkMatrix::kAffine_Mask) | |
357 widthExpansion = totalMatrix[SkMatrix::kMSkewY], heightExpansion = total
Matrix[SkMatrix::kMSkewX]; | |
358 else | |
359 widthExpansion = totalMatrix[SkMatrix::kMScaleX], heightExpansion = tota
lMatrix[SkMatrix::kMScaleY]; | |
360 return destRect.width() * fabs(widthExpansion) < 1 || destRect.height() * fa
bs(heightExpansion) < 1; | |
361 } | |
362 | |
363 int clampedAlphaForBlending(float alpha) | 333 int clampedAlphaForBlending(float alpha) |
364 { | 334 { |
365 if (alpha < 0) | 335 if (alpha < 0) |
366 return 0; | 336 return 0; |
367 int roundedAlpha = roundf(alpha * 256); | 337 int roundedAlpha = roundf(alpha * 256); |
368 if (roundedAlpha > 256) | 338 if (roundedAlpha > 256) |
369 roundedAlpha = 256; | 339 roundedAlpha = 256; |
370 return roundedAlpha; | 340 return roundedAlpha; |
371 } | 341 } |
372 | 342 |
373 SkColor scaleAlpha(SkColor color, float alpha) | 343 SkColor scaleAlpha(SkColor color, float alpha) |
374 { | 344 { |
375 return scaleAlpha(color, clampedAlphaForBlending(alpha)); | 345 return scaleAlpha(color, clampedAlphaForBlending(alpha)); |
376 } | 346 } |
377 | 347 |
378 SkColor scaleAlpha(SkColor color, int alpha) | 348 SkColor scaleAlpha(SkColor color, int alpha) |
379 { | 349 { |
380 int a = (SkColorGetA(color) * alpha) >> 8; | 350 int a = (SkColorGetA(color) * alpha) >> 8; |
381 return (color & 0x00FFFFFF) | (a << 24); | 351 return (color & 0x00FFFFFF) | (a << 24); |
382 } | 352 } |
383 | 353 |
384 } // namespace blink | 354 } // namespace blink |
OLD | NEW |