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 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s haderMatrix, | 188 sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shader Matrix, |
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 adoptRef(image->newShader(SkShader::kRepeat_TileMode, SkShader::k Repeat_TileMode, &shaderMatrix)); | 192 return sk_sp<SkShader>(image->newShader(SkShader::kRepeat_TileMode, SkSh ader::kRepeat_TileMode, &shaderMatrix)); |
reed1
2016/03/09 21:09:06
I will add SkImage::makeShader(...) NOW
f(malita)
2016/03/10 13:57:58
Thanks, done.
| |
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 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture()) ; | 203 sk_sp<const SkPicture> picture(recorder.endRecordingAsPicture()); |
204 | 204 |
205 return adoptRef(SkShader::CreatePictureShader( | 205 return SkShader::MakePictureShader( |
206 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, & shaderMatrix, nullptr)); | 206 std::move(picture), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMo de, &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 RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix, paint, | 252 auto 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 paint.setShader(std::move(shader)); |
reed1
2016/03/09 21:09:06
move up 2 lines and eliminate named variable shade
f(malita)
2016/03/10 13:57:58
Done.
| |
255 context.drawRect(destRect, paint); | 255 context.drawRect(destRect, paint); |
256 } | 256 } |
257 | 257 |
258 if (currentFrameIsLazyDecoded()) | 258 if (currentFrameIsLazyDecoded()) |
259 PlatformInstrumentation::didDrawLazyPixelRef(imageID); | 259 PlatformInstrumentation::didDrawLazyPixelRef(imageID); |
260 } | 260 } |
261 | 261 |
262 void Image::computeIntrinsicDimensions(FloatSize& intrinsicSize, FloatSize& intr insicRatio) | 262 void Image::computeIntrinsicDimensions(FloatSize& intrinsicSize, FloatSize& intr insicRatio) |
263 { | 263 { |
264 intrinsicSize = intrinsicRatio = FloatSize(size()); | 264 intrinsicSize = intrinsicRatio = FloatSize(size()); |
265 } | 265 } |
266 | 266 |
267 PassRefPtr<Image> Image::imageForDefaultFrame() | 267 PassRefPtr<Image> Image::imageForDefaultFrame() |
268 { | 268 { |
269 RefPtr<Image> image(this); | 269 RefPtr<Image> image(this); |
270 | 270 |
271 return image.release(); | 271 return image.release(); |
272 } | 272 } |
273 | 273 |
274 bool Image::isTextureBacked() | 274 bool Image::isTextureBacked() |
275 { | 275 { |
276 RefPtr<SkImage> image = imageForCurrentFrame(); | 276 RefPtr<SkImage> image = imageForCurrentFrame(); |
277 return image ? image->isTextureBacked() : false; | 277 return image ? image->isTextureBacked() : false; |
278 } | 278 } |
279 | 279 |
280 } // namespace blink | 280 } // namespace blink |
OLD | NEW |