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