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

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

Issue 1949253004: Rounded background image fast path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: todo Created 4 years, 7 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/platform/graphics/Image.h ('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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 { 99 {
100 FloatSize intrinsicTileSize = FloatSize(size()); 100 FloatSize intrinsicTileSize = FloatSize(size());
101 if (hasRelativeSize()) { 101 if (hasRelativeSize()) {
102 intrinsicTileSize.setWidth(scaledTileSize.width()); 102 intrinsicTileSize.setWidth(scaledTileSize.width());
103 intrinsicTileSize.setHeight(scaledTileSize.height()); 103 intrinsicTileSize.setHeight(scaledTileSize.height());
104 } 104 }
105 105
106 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(), 106 FloatSize scale(scaledTileSize.width() / intrinsicTileSize.width(),
107 scaledTileSize.height() / intrinsicTileSize.height()); 107 scaledTileSize.height() / intrinsicTileSize.height());
108 108
109 FloatSize actualTileSize(scaledTileSize.width() + repeatSpacing.width(), sca ledTileSize.height() + repeatSpacing.height()); 109 const FloatRect oneTileRect =
110 FloatRect oneTileRect; 110 computeTileContaining(destRect.location(), scaledTileSize, srcPoint, rep eatSpacing);
111 oneTileRect.setX(destRect.x() + fmodf(fmodf(-srcPoint.x(), actualTileSize.wi dth()) - actualTileSize.width(), actualTileSize.width()));
112 oneTileRect.setY(destRect.y() + fmodf(fmodf(-srcPoint.y(), actualTileSize.he ight()) - actualTileSize.height(), actualTileSize.height()));
113 oneTileRect.setSize(scaledTileSize);
114 111
115 // Check and see if a single draw of the image can cover the entire area we are supposed to tile. 112 // Check and see if a single draw of the image can cover the entire area we are supposed to tile.
116 if (oneTileRect.contains(destRect)) { 113 if (oneTileRect.contains(destRect)) {
117 FloatRect visibleSrcRect; 114 const FloatRect visibleSrcRect = computeSubsetForTile(oneTileRect, destR ect, intrinsicTileSize);
118 visibleSrcRect.setX((destRect.x() - oneTileRect.x()) / scale.width());
119 visibleSrcRect.setY((destRect.y() - oneTileRect.y()) / scale.height());
120 visibleSrcRect.setWidth(destRect.width() / scale.width());
121 visibleSrcRect.setHeight(destRect.height() / scale.height());
122 ctxt.drawImage(this, destRect, &visibleSrcRect, op, DoNotRespectImageOri entation); 115 ctxt.drawImage(this, destRect, &visibleSrcRect, op, DoNotRespectImageOri entation);
123 return; 116 return;
124 } 117 }
125 118
126 FloatRect tileRect(FloatPoint(), intrinsicTileSize); 119 FloatRect tileRect(FloatPoint(), intrinsicTileSize);
127 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing); 120 drawPattern(ctxt, tileRect, scale, oneTileRect.location(), op, destRect, rep eatSpacing);
128 121
129 startAnimation(); 122 startAnimation();
130 } 123 }
131 124
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 256
264 return image.release(); 257 return image.release();
265 } 258 }
266 259
267 bool Image::isTextureBacked() 260 bool Image::isTextureBacked()
268 { 261 {
269 RefPtr<SkImage> image = imageForCurrentFrame(); 262 RefPtr<SkImage> image = imageForCurrentFrame();
270 return image ? image->isTextureBacked() : false; 263 return image ? image->isTextureBacked() : false;
271 } 264 }
272 265
266 bool Image::applyShader(SkPaint& paint, const SkMatrix* localMatrix)
267 {
268 // Default shader impl: attempt to build a shader based on the current frame SkImage.
269 RefPtr<SkImage> image = imageForCurrentFrame();
270 if (!image)
271 return false;
272
273 paint.setShader(
274 image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode , localMatrix));
275
276 return true;
277 }
278
279 FloatRect Image::computeTileContaining(const FloatPoint& point,
280 const FloatSize& tileSize, const FloatPoint& tilePhase, const FloatSize& til eSpacing)
281 {
282 const FloatSize actualTileSize(tileSize + tileSpacing);
283 return FloatRect(
284 FloatPoint(
285 point.x() + fmodf(fmodf(-tilePhase.x(), actualTileSize.width()) - ac tualTileSize.width(), actualTileSize.width()),
286 point.y() + fmodf(fmodf(-tilePhase.y(), actualTileSize.height()) - a ctualTileSize.height(), actualTileSize.height())
287 ),
288 tileSize);
289 }
290
291 FloatRect Image::computeSubsetForTile(const FloatRect& tile, const FloatRect& de st,
292 const FloatSize& imageSize)
293 {
294 DCHECK(tile.contains(dest));
295
296 const FloatSize scale(tile.width() / imageSize.width(), tile.height() / imag eSize.height());
297
298 FloatRect subset = dest;
299 subset.setX((dest.x() - tile.x()) / scale.width());
300 subset.setY((dest.y() - tile.y()) / scale.height());
301 subset.setWidth(dest.width() / scale.width());
302 subset.setHeight(dest.height() / scale.height());
303
304 return subset;
305 }
306
273 } // namespace blink 307 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Image.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698