Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 218 } |
| 219 | 219 |
| 220 startAnimation(); | 220 startAnimation(); |
| 221 } | 221 } |
| 222 | 222 |
| 223 namespace { | 223 namespace { |
| 224 | 224 |
| 225 sk_sp<SkShader> createPatternShader(const SkImage* image, | 225 sk_sp<SkShader> createPatternShader(const SkImage* image, |
| 226 const SkMatrix& shaderMatrix, | 226 const SkMatrix& shaderMatrix, |
| 227 const SkPaint& paint, | 227 const SkPaint& paint, |
| 228 const FloatSize& spacing) { | 228 const FloatSize& spacing, |
| 229 SkShader::TileMode tmx, | |
| 230 SkShader::TileMode tmy) { | |
| 229 if (spacing.isZero()) | 231 if (spacing.isZero()) |
| 230 return image->makeShader(SkShader::kRepeat_TileMode, | 232 return image->makeShader(tmx, tmy, &shaderMatrix); |
| 231 SkShader::kRepeat_TileMode, &shaderMatrix); | |
| 232 | 233 |
| 233 // Arbitrary tiling is currently only supported for SkPictureShader, so we use | 234 // Arbitrary tiling is currently only supported for SkPictureShader, so we use |
| 234 // that instead of a plain bitmap shader to implement spacing. | 235 // that instead of a plain bitmap shader to implement spacing. |
| 235 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), | 236 const SkRect tileRect = SkRect::MakeWH(image->width() + spacing.width(), |
| 236 image->height() + spacing.height()); | 237 image->height() + spacing.height()); |
| 237 | 238 |
| 238 SkPictureRecorder recorder; | 239 SkPictureRecorder recorder; |
| 239 SkCanvas* canvas = recorder.beginRecording(tileRect); | 240 SkCanvas* canvas = recorder.beginRecording(tileRect); |
| 240 canvas->drawImage(image, 0, 0, &paint); | 241 canvas->drawImage(image, 0, 0, &paint); |
| 241 | 242 |
| 242 return SkShader::MakePictureShader( | 243 return SkShader::MakePictureShader(recorder.finishRecordingAsPicture(), tmx, |
| 243 recorder.finishRecordingAsPicture(), SkShader::kRepeat_TileMode, | 244 tmy, &shaderMatrix, nullptr); |
| 244 SkShader::kRepeat_TileMode, &shaderMatrix, nullptr); | 245 } |
| 246 | |
| 247 SkShader::TileMode computeTileMode(float destOffset, | |
|
fs
2016/12/19 16:49:22
Maybe structure this as an interval containment ch
f(malita)
2016/12/19 17:34:56
Done.
| |
| 248 float destSize, | |
| 249 float tileOffset, | |
| 250 float tileSize) { | |
| 251 return destOffset >= tileOffset && | |
| 252 destOffset + destSize <= tileOffset + tileSize | |
| 253 ? SkShader::kClamp_TileMode | |
| 254 : SkShader::kRepeat_TileMode; | |
| 245 } | 255 } |
| 246 | 256 |
| 247 } // anonymous namespace | 257 } // anonymous namespace |
| 248 | 258 |
| 249 void Image::drawPattern(GraphicsContext& context, | 259 void Image::drawPattern(GraphicsContext& context, |
| 250 const FloatRect& floatSrcRect, | 260 const FloatRect& floatSrcRect, |
| 251 const FloatSize& scale, | 261 const FloatSize& scale, |
| 252 const FloatPoint& phase, | 262 const FloatPoint& phase, |
| 253 SkBlendMode compositeOp, | 263 SkBlendMode compositeOp, |
| 254 const FloatRect& destRect, | 264 const FloatRect& destRect, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 279 // set to the pattern's transform, which just includes scale. | 289 // set to the pattern's transform, which just includes scale. |
| 280 localMatrix.preScale(scale.width(), scale.height()); | 290 localMatrix.preScale(scale.width(), scale.height()); |
| 281 | 291 |
| 282 // Fetch this now as subsetting may swap the image. | 292 // Fetch this now as subsetting may swap the image. |
| 283 auto imageID = image->uniqueID(); | 293 auto imageID = image->uniqueID(); |
| 284 | 294 |
| 285 image = image->makeSubset(enclosingIntRect(normSrcRect)); | 295 image = image->makeSubset(enclosingIntRect(normSrcRect)); |
| 286 if (!image) | 296 if (!image) |
| 287 return; | 297 return; |
| 288 | 298 |
| 299 const FloatSize tileSize( | |
| 300 image->width() * scale.width() + repeatSpacing.width(), | |
| 301 image->height() * scale.height() + repeatSpacing.height()); | |
| 302 const auto tmx = computeTileMode(destRect.x(), destRect.width(), adjustedX, | |
| 303 tileSize.width()); | |
| 304 const auto tmy = computeTileMode(destRect.y(), destRect.height(), adjustedY, | |
| 305 tileSize.height()); | |
| 306 | |
| 289 { | 307 { |
| 290 SkPaint paint = context.fillPaint(); | 308 SkPaint paint = context.fillPaint(); |
| 291 paint.setColor(SK_ColorBLACK); | 309 paint.setColor(SK_ColorBLACK); |
| 292 paint.setBlendMode(compositeOp); | 310 paint.setBlendMode(compositeOp); |
| 293 paint.setFilterQuality( | 311 paint.setFilterQuality( |
| 294 context.computeFilterQuality(this, destRect, normSrcRect)); | 312 context.computeFilterQuality(this, destRect, normSrcRect)); |
| 295 paint.setAntiAlias(context.shouldAntialias()); | 313 paint.setAntiAlias(context.shouldAntialias()); |
| 296 paint.setShader(createPatternShader( | 314 paint.setShader( |
| 297 image.get(), localMatrix, paint, | 315 createPatternShader(image.get(), localMatrix, paint, |
| 298 FloatSize(repeatSpacing.width() / scale.width(), | 316 FloatSize(repeatSpacing.width() / scale.width(), |
| 299 repeatSpacing.height() / scale.height()))); | 317 repeatSpacing.height() / scale.height()), |
| 318 tmx, tmy)); | |
| 300 context.drawRect(destRect, paint); | 319 context.drawRect(destRect, paint); |
| 301 } | 320 } |
| 302 | 321 |
| 303 if (currentFrameIsLazyDecoded()) | 322 if (currentFrameIsLazyDecoded()) |
| 304 PlatformInstrumentation::didDrawLazyPixelRef(imageID); | 323 PlatformInstrumentation::didDrawLazyPixelRef(imageID); |
| 305 } | 324 } |
| 306 | 325 |
| 307 PassRefPtr<Image> Image::imageForDefaultFrame() { | 326 PassRefPtr<Image> Image::imageForDefaultFrame() { |
| 308 RefPtr<Image> image(this); | 327 RefPtr<Image> image(this); |
| 309 | 328 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 FloatRect subset = dest; | 383 FloatRect subset = dest; |
| 365 subset.setX((dest.x() - tile.x()) / scale.width()); | 384 subset.setX((dest.x() - tile.x()) / scale.width()); |
| 366 subset.setY((dest.y() - tile.y()) / scale.height()); | 385 subset.setY((dest.y() - tile.y()) / scale.height()); |
| 367 subset.setWidth(dest.width() / scale.width()); | 386 subset.setWidth(dest.width() / scale.width()); |
| 368 subset.setHeight(dest.height() / scale.height()); | 387 subset.setHeight(dest.height() / scale.height()); |
| 369 | 388 |
| 370 return subset; | 389 return subset; |
| 371 } | 390 } |
| 372 | 391 |
| 373 } // namespace blink | 392 } // namespace blink |
| OLD | NEW |