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

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

Issue 2677633004: Handle shader construction failures gracefully (Closed)
Patch Set: comment Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return; 296 return;
297 297
298 const FloatSize tileSize( 298 const FloatSize tileSize(
299 image->width() * scale.width() + repeatSpacing.width(), 299 image->width() * scale.width() + repeatSpacing.width(),
300 image->height() * scale.height() + repeatSpacing.height()); 300 image->height() * scale.height() + repeatSpacing.height());
301 const auto tmx = computeTileMode(destRect.x(), destRect.maxX(), adjustedX, 301 const auto tmx = computeTileMode(destRect.x(), destRect.maxX(), adjustedX,
302 adjustedX + tileSize.width()); 302 adjustedX + tileSize.width());
303 const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY, 303 const auto tmy = computeTileMode(destRect.y(), destRect.maxY(), adjustedY,
304 adjustedY + tileSize.height()); 304 adjustedY + tileSize.height());
305 305
306 { 306 PaintFlags paint = context.fillPaint();
307 PaintFlags paint = context.fillPaint(); 307 paint.setColor(SK_ColorBLACK);
308 paint.setColor(SK_ColorBLACK); 308 paint.setBlendMode(compositeOp);
309 paint.setBlendMode(compositeOp); 309 paint.setFilterQuality(
310 paint.setFilterQuality( 310 context.computeFilterQuality(this, destRect, normSrcRect));
311 context.computeFilterQuality(this, destRect, normSrcRect)); 311 paint.setAntiAlias(context.shouldAntialias());
312 paint.setAntiAlias(context.shouldAntialias()); 312 paint.setShader(
313 paint.setShader( 313 createPatternShader(image.get(), localMatrix, paint,
314 createPatternShader(image.get(), localMatrix, paint, 314 FloatSize(repeatSpacing.width() / scale.width(),
315 FloatSize(repeatSpacing.width() / scale.width(), 315 repeatSpacing.height() / scale.height()),
316 repeatSpacing.height() / scale.height()), 316 tmx, tmy));
317 tmx, tmy)); 317 // If the shader could not be instantiated (e.g. non-invertible matrix),
318 context.drawRect(destRect, paint); 318 // draw transparent.
319 } 319 // Note: we can't simply bail, because of arbitrary blend mode.
320 if (!paint.getShader())
321 paint.setColor(SK_ColorTRANSPARENT);
322
323 context.drawRect(destRect, paint);
320 324
321 if (currentFrameIsLazyDecoded()) 325 if (currentFrameIsLazyDecoded())
322 PlatformInstrumentation::didDrawLazyPixelRef(imageID); 326 PlatformInstrumentation::didDrawLazyPixelRef(imageID);
323 } 327 }
324 328
325 PassRefPtr<Image> Image::imageForDefaultFrame() { 329 PassRefPtr<Image> Image::imageForDefaultFrame() {
326 RefPtr<Image> image(this); 330 RefPtr<Image> image(this);
327 331
328 return image.release(); 332 return image.release();
329 } 333 }
330 334
331 bool Image::applyShader(SkPaint& paint, 335 bool Image::applyShader(SkPaint& paint,
332 const SkMatrix& localMatrix, 336 const SkMatrix& localMatrix,
333 const ColorBehavior& colorBehavior) { 337 const ColorBehavior& colorBehavior) {
334 // Default shader impl: attempt to build a shader based on the current frame 338 // Default shader impl: attempt to build a shader based on the current frame
335 // SkImage. 339 // SkImage.
336 sk_sp<SkImage> image = imageForCurrentFrame(colorBehavior); 340 sk_sp<SkImage> image = imageForCurrentFrame(colorBehavior);
337 if (!image) 341 if (!image)
338 return false; 342 return false;
339 343
340 paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, 344 paint.setShader(image->makeShader(SkShader::kRepeat_TileMode,
341 SkShader::kRepeat_TileMode, &localMatrix)); 345 SkShader::kRepeat_TileMode, &localMatrix));
346 if (!paint.getShader())
347 return false;
342 348
343 // Animation is normally refreshed in draw() impls, which we don't call when 349 // Animation is normally refreshed in draw() impls, which we don't call when
344 // painting via shaders. 350 // painting via shaders.
345 startAnimation(); 351 startAnimation();
346 352
347 return true; 353 return true;
348 } 354 }
349 355
350 FloatRect Image::computeTileContaining(const FloatPoint& point, 356 FloatRect Image::computeTileContaining(const FloatPoint& point,
351 const FloatSize& tileSize, 357 const FloatSize& tileSize,
(...skipping 22 matching lines...) Expand all
374 FloatRect subset = dest; 380 FloatRect subset = dest;
375 subset.setX((dest.x() - tile.x()) / scale.width()); 381 subset.setX((dest.x() - tile.x()) / scale.width());
376 subset.setY((dest.y() - tile.y()) / scale.height()); 382 subset.setY((dest.y() - tile.y()) / scale.height());
377 subset.setWidth(dest.width() / scale.width()); 383 subset.setWidth(dest.width() / scale.width());
378 subset.setHeight(dest.height() / scale.height()); 384 subset.setHeight(dest.height() / scale.height());
379 385
380 return subset; 386 return subset;
381 } 387 }
382 388
383 } // namespace blink 389 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/graphics/SVGImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698