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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } else { | 220 } else { |
221 DrawPattern(ctxt, src_rect, tile_scale_factor, pattern_phase, op, dst_rect, | 221 DrawPattern(ctxt, src_rect, tile_scale_factor, pattern_phase, op, dst_rect, |
222 spacing); | 222 spacing); |
223 } | 223 } |
224 | 224 |
225 StartAnimation(); | 225 StartAnimation(); |
226 } | 226 } |
227 | 227 |
228 namespace { | 228 namespace { |
229 | 229 |
230 sk_sp<PaintShader> CreatePatternShader(const PaintImage& image, | 230 std::unique_ptr<PaintShader> CreatePatternShader(const PaintImage& image, |
231 const SkMatrix& shader_matrix, | 231 const SkMatrix& shader_matrix, |
232 const PaintFlags& paint, | 232 const PaintFlags& paint, |
233 const FloatSize& spacing, | 233 const FloatSize& spacing, |
234 SkShader::TileMode tmx, | 234 SkShader::TileMode tmx, |
235 SkShader::TileMode tmy) { | 235 SkShader::TileMode tmy) { |
236 if (spacing.IsZero()) | 236 if (spacing.IsZero()) { |
237 return MakePaintShaderImage(image.sk_image(), tmx, tmy, &shader_matrix); | 237 return WTF::MakeUnique<PaintShader>(image.sk_image(), tmx, tmy, |
| 238 &shader_matrix); |
| 239 } |
238 | 240 |
239 // Arbitrary tiling is currently only supported for SkPictureShader, so we use | 241 // Arbitrary tiling is currently only supported for SkPictureShader, so we use |
240 // that instead of a plain bitmap shader to implement spacing. | 242 // that instead of a plain bitmap shader to implement spacing. |
241 const SkRect tile_rect = | 243 const SkRect tile_rect = |
242 SkRect::MakeWH(image.sk_image()->width() + spacing.Width(), | 244 SkRect::MakeWH(image.sk_image()->width() + spacing.Width(), |
243 image.sk_image()->height() + spacing.Height()); | 245 image.sk_image()->height() + spacing.Height()); |
244 | 246 |
245 PaintRecorder recorder; | 247 PaintRecorder recorder; |
246 PaintCanvas* canvas = recorder.beginRecording(tile_rect); | 248 PaintCanvas* canvas = recorder.beginRecording(tile_rect); |
247 canvas->drawImage(image, 0, 0, &paint); | 249 canvas->drawImage(image, 0, 0, &paint); |
248 | 250 |
249 return MakePaintShaderRecord(recorder.finishRecordingAsPicture(), tile_rect, | 251 return WTF::MakeUnique<PaintShader>(recorder.finishRecordingAsPicture(), |
250 tmx, tmy, &shader_matrix); | 252 tile_rect, tmx, tmy, &shader_matrix); |
251 } | 253 } |
252 | 254 |
253 SkShader::TileMode ComputeTileMode(float left, | 255 SkShader::TileMode ComputeTileMode(float left, |
254 float right, | 256 float right, |
255 float min, | 257 float min, |
256 float max) { | 258 float max) { |
257 DCHECK(left < right); | 259 DCHECK(left < right); |
258 return left >= min && right <= max ? SkShader::kClamp_TileMode | 260 return left >= min && right <= max ? SkShader::kClamp_TileMode |
259 : SkShader::kRepeat_TileMode; | 261 : SkShader::kRepeat_TileMode; |
260 } | 262 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 context.ComputeFilterQuality(this, dest_rect, norm_src_rect)); | 322 context.ComputeFilterQuality(this, dest_rect, norm_src_rect)); |
321 flags.setAntiAlias(context.ShouldAntialias()); | 323 flags.setAntiAlias(context.ShouldAntialias()); |
322 flags.setShader( | 324 flags.setShader( |
323 CreatePatternShader(image, local_matrix, flags, | 325 CreatePatternShader(image, local_matrix, flags, |
324 FloatSize(repeat_spacing.Width() / scale.Width(), | 326 FloatSize(repeat_spacing.Width() / scale.Width(), |
325 repeat_spacing.Height() / scale.Height()), | 327 repeat_spacing.Height() / scale.Height()), |
326 tmx, tmy)); | 328 tmx, tmy)); |
327 // If the shader could not be instantiated (e.g. non-invertible matrix), | 329 // If the shader could not be instantiated (e.g. non-invertible matrix), |
328 // draw transparent. | 330 // draw transparent. |
329 // Note: we can't simply bail, because of arbitrary blend mode. | 331 // Note: we can't simply bail, because of arbitrary blend mode. |
330 if (!flags.getShader()) | 332 if (!flags.HasShader()) |
331 flags.setColor(SK_ColorTRANSPARENT); | 333 flags.setColor(SK_ColorTRANSPARENT); |
332 | 334 |
333 context.DrawRect(dest_rect, flags); | 335 context.DrawRect(dest_rect, flags); |
334 | 336 |
335 if (CurrentFrameIsLazyDecoded()) | 337 if (CurrentFrameIsLazyDecoded()) |
336 PlatformInstrumentation::DidDrawLazyPixelRef(image_id); | 338 PlatformInstrumentation::DidDrawLazyPixelRef(image_id); |
337 } | 339 } |
338 | 340 |
339 PassRefPtr<Image> Image::ImageForDefaultFrame() { | 341 PassRefPtr<Image> Image::ImageForDefaultFrame() { |
340 RefPtr<Image> image(this); | 342 RefPtr<Image> image(this); |
(...skipping 11 matching lines...) Expand all Loading... |
352 completion_state); | 354 completion_state); |
353 } | 355 } |
354 | 356 |
355 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { | 357 bool Image::ApplyShader(PaintFlags& flags, const SkMatrix& local_matrix) { |
356 // Default shader impl: attempt to build a shader based on the current frame | 358 // Default shader impl: attempt to build a shader based on the current frame |
357 // SkImage. | 359 // SkImage. |
358 sk_sp<SkImage> image = ImageForCurrentFrame(); | 360 sk_sp<SkImage> image = ImageForCurrentFrame(); |
359 if (!image) | 361 if (!image) |
360 return false; | 362 return false; |
361 | 363 |
362 flags.setShader(image->makeShader(SkShader::kRepeat_TileMode, | 364 flags.setShader( |
363 SkShader::kRepeat_TileMode, &local_matrix)); | 365 WTF::MakeUnique<PaintShader>(std::move(image), SkShader::kRepeat_TileMode, |
364 if (!flags.getShader()) | 366 SkShader::kRepeat_TileMode, &local_matrix)); |
| 367 if (!flags.HasShader()) |
365 return false; | 368 return false; |
366 | 369 |
367 // Animation is normally refreshed in draw() impls, which we don't call when | 370 // Animation is normally refreshed in draw() impls, which we don't call when |
368 // painting via shaders. | 371 // painting via shaders. |
369 StartAnimation(); | 372 StartAnimation(); |
370 | 373 |
371 return true; | 374 return true; |
372 } | 375 } |
373 | 376 |
374 FloatRect Image::ComputeTileContaining(const FloatPoint& point, | 377 FloatRect Image::ComputeTileContaining(const FloatPoint& point, |
(...skipping 23 matching lines...) Expand all Loading... |
398 FloatRect subset = dest; | 401 FloatRect subset = dest; |
399 subset.SetX((dest.X() - tile.X()) / scale.Width()); | 402 subset.SetX((dest.X() - tile.X()) / scale.Width()); |
400 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); | 403 subset.SetY((dest.Y() - tile.Y()) / scale.Height()); |
401 subset.SetWidth(dest.Width() / scale.Width()); | 404 subset.SetWidth(dest.Width() / scale.Width()); |
402 subset.SetHeight(dest.Height() / scale.Height()); | 405 subset.SetHeight(dest.Height() / scale.Height()); |
403 | 406 |
404 return subset; | 407 return subset; |
405 } | 408 } |
406 | 409 |
407 } // namespace blink | 410 } // namespace blink |
OLD | NEW |