Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Image.cpp

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

Powered by Google App Engine
This is Rietveld 408576698