| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 ctxt.setImageInterpolationQuality(previousInterpolationQuality); | 178 ctxt.setImageInterpolationQuality(previousInterpolationQuality); |
| 179 } else { | 179 } else { |
| 180 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); | 180 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); |
| 181 } | 181 } |
| 182 | 182 |
| 183 startAnimation(); | 183 startAnimation(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 namespace { | 186 namespace { |
| 187 | 187 |
| 188 sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shader
Matrix, | 188 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s
haderMatrix, |
| 189 const SkPaint& paint, const FloatSize& spacing) | 189 const SkPaint& paint, const FloatSize& spacing) |
| 190 { | 190 { |
| 191 if (spacing.isZero()) | 191 if (spacing.isZero()) |
| 192 return image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_T
ileMode, &shaderMatrix); | 192 return adoptRef(image->newShader(SkShader::kRepeat_TileMode, SkShader::k
Repeat_TileMode, &shaderMatrix)); |
| 193 | 193 |
| 194 // Arbitrary tiling is currently only supported for SkPictureShader - so we
use it instead | 194 // Arbitrary tiling is currently only supported for SkPictureShader - so we
use it instead |
| 195 // of a plain bitmap shader to implement spacing. | 195 // of a plain bitmap shader to implement spacing. |
| 196 const SkRect tileRect = SkRect::MakeWH( | 196 const SkRect tileRect = SkRect::MakeWH( |
| 197 image->width() + spacing.width(), | 197 image->width() + spacing.width(), |
| 198 image->height() + spacing.height()); | 198 image->height() + spacing.height()); |
| 199 | 199 |
| 200 SkPictureRecorder recorder; | 200 SkPictureRecorder recorder; |
| 201 SkCanvas* canvas = recorder.beginRecording(tileRect); | 201 SkCanvas* canvas = recorder.beginRecording(tileRect); |
| 202 canvas->drawImage(image, 0, 0, &paint); | 202 canvas->drawImage(image, 0, 0, &paint); |
| 203 sk_sp<SkPicture> picture(recorder.endRecordingAsPicture()); | 203 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture())
; |
| 204 | 204 |
| 205 return SkShader::MakePictureShader( | 205 return adoptRef(SkShader::CreatePictureShader( |
| 206 std::move(picture), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMo
de, &shaderMatrix, nullptr); | 206 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &
shaderMatrix, nullptr)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 } // anonymous namespace | 209 } // anonymous namespace |
| 210 | 210 |
| 211 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect,
const FloatSize& scale, | 211 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect,
const FloatSize& scale, |
| 212 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest
Rect, const FloatSize& repeatSpacing) | 212 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest
Rect, const FloatSize& repeatSpacing) |
| 213 { | 213 { |
| 214 TRACE_EVENT0("skia", "Image::drawPattern"); | 214 TRACE_EVENT0("skia", "Image::drawPattern"); |
| 215 | 215 |
| 216 RefPtr<SkImage> image = imageForCurrentFrame(); | 216 RefPtr<SkImage> image = imageForCurrentFrame(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 242 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); | 242 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); |
| 243 if (!image) | 243 if (!image) |
| 244 return; | 244 return; |
| 245 | 245 |
| 246 { | 246 { |
| 247 SkPaint paint = context.fillPaint(); | 247 SkPaint paint = context.fillPaint(); |
| 248 paint.setColor(SK_ColorBLACK); | 248 paint.setColor(SK_ColorBLACK); |
| 249 paint.setXfermodeMode(compositeOp); | 249 paint.setXfermodeMode(compositeOp); |
| 250 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm
SrcRect)); | 250 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm
SrcRect)); |
| 251 paint.setAntiAlias(context.shouldAntialias()); | 251 paint.setAntiAlias(context.shouldAntialias()); |
| 252 paint.setShader(createPatternShader(image.get(), localMatrix, paint, | 252 RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix,
paint, |
| 253 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh
t() / scale.height()))); | 253 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh
t() / scale.height())); |
| 254 paint.setShader(shader.get()); |
| 254 context.drawRect(destRect, paint); | 255 context.drawRect(destRect, paint); |
| 255 } | 256 } |
| 256 | 257 |
| 257 if (currentFrameIsLazyDecoded()) | 258 if (currentFrameIsLazyDecoded()) |
| 258 PlatformInstrumentation::didDrawLazyPixelRef(imageID); | 259 PlatformInstrumentation::didDrawLazyPixelRef(imageID); |
| 259 } | 260 } |
| 260 | 261 |
| 261 PassRefPtr<Image> Image::imageForDefaultFrame() | 262 PassRefPtr<Image> Image::imageForDefaultFrame() |
| 262 { | 263 { |
| 263 RefPtr<Image> image(this); | 264 RefPtr<Image> image(this); |
| 264 | 265 |
| 265 return image.release(); | 266 return image.release(); |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool Image::isTextureBacked() | 269 bool Image::isTextureBacked() |
| 269 { | 270 { |
| 270 RefPtr<SkImage> image = imageForCurrentFrame(); | 271 RefPtr<SkImage> image = imageForCurrentFrame(); |
| 271 return image ? image->isTextureBacked() : false; | 272 return image ? image->isTextureBacked() : false; |
| 272 } | 273 } |
| 273 | 274 |
| 274 } // namespace blink | 275 } // namespace blink |
| OLD | NEW |