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

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

Issue 2290903002: Change (Pass)RefPtr<SkXxx> into sk_sp<SkXxx>. (Closed)
Patch Set: Rebasing... Created 4 years, 3 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, n ullptr); 198 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &shaderMatrix, n ullptr);
199 } 199 }
200 200
201 } // anonymous namespace 201 } // anonymous namespace
202 202
203 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, const FloatSize& scale, 203 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, const FloatSize& scale,
204 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest Rect, const FloatSize& repeatSpacing) 204 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest Rect, const FloatSize& repeatSpacing)
205 { 205 {
206 TRACE_EVENT0("skia", "Image::drawPattern"); 206 TRACE_EVENT0("skia", "Image::drawPattern");
207 207
208 RefPtr<SkImage> image = imageForCurrentFrame(); 208 sk_sp<SkImage> image = imageForCurrentFrame();
209 if (!image) 209 if (!image)
210 return; 210 return;
211 211
212 FloatRect normSrcRect = floatSrcRect; 212 FloatRect normSrcRect = floatSrcRect;
213 213
214 normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height())); 214 normSrcRect.intersect(FloatRect(0, 0, image->width(), image->height()));
215 if (destRect.isEmpty() || normSrcRect.isEmpty()) 215 if (destRect.isEmpty() || normSrcRect.isEmpty())
216 return; // nothing to draw 216 return; // nothing to draw
217 217
218 SkMatrix localMatrix; 218 SkMatrix localMatrix;
219 // We also need to translate it such that the origin of the pattern is the 219 // We also need to translate it such that the origin of the pattern is the
220 // origin of the destination rect, which is what WebKit expects. Skia uses 220 // origin of the destination rect, which is what WebKit expects. Skia uses
221 // the coordinate system origin as the base for the pattern. If WebKit wants 221 // the coordinate system origin as the base for the pattern. If WebKit wants
222 // a shifted image, it will shift it from there using the localMatrix. 222 // a shifted image, it will shift it from there using the localMatrix.
223 const float adjustedX = phase.x() + normSrcRect.x() * scale.width(); 223 const float adjustedX = phase.x() + normSrcRect.x() * scale.width();
224 const float adjustedY = phase.y() + normSrcRect.y() * scale.height(); 224 const float adjustedY = phase.y() + normSrcRect.y() * scale.height();
225 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY)); 225 localMatrix.setTranslate(SkFloatToScalar(adjustedX), SkFloatToScalar(adjuste dY));
226 226
227 // Because no resizing occurred, the shader transform should be 227 // Because no resizing occurred, the shader transform should be
228 // set to the pattern's transform, which just includes scale. 228 // set to the pattern's transform, which just includes scale.
229 localMatrix.preScale(scale.width(), scale.height()); 229 localMatrix.preScale(scale.width(), scale.height());
230 230
231 // Fetch this now as subsetting may swap the image. 231 // Fetch this now as subsetting may swap the image.
232 auto imageID = image->uniqueID(); 232 auto imageID = image->uniqueID();
233 233
234 image = fromSkSp(image->makeSubset(enclosingIntRect(normSrcRect))); 234 image = image->makeSubset(enclosingIntRect(normSrcRect));
235 if (!image) 235 if (!image)
236 return; 236 return;
237 237
238 { 238 {
239 SkPaint paint = context.fillPaint(); 239 SkPaint paint = context.fillPaint();
240 paint.setColor(SK_ColorBLACK); 240 paint.setColor(SK_ColorBLACK);
241 paint.setXfermodeMode(compositeOp); 241 paint.setXfermodeMode(compositeOp);
242 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm SrcRect)); 242 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm SrcRect));
243 paint.setAntiAlias(context.shouldAntialias()); 243 paint.setAntiAlias(context.shouldAntialias());
244 paint.setShader(createPatternShader(image.get(), localMatrix, paint, 244 paint.setShader(createPatternShader(image.get(), localMatrix, paint,
245 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height()))); 245 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height())));
246 context.drawRect(destRect, paint); 246 context.drawRect(destRect, paint);
247 } 247 }
248 248
249 if (currentFrameIsLazyDecoded()) 249 if (currentFrameIsLazyDecoded())
250 PlatformInstrumentation::didDrawLazyPixelRef(imageID); 250 PlatformInstrumentation::didDrawLazyPixelRef(imageID);
251 } 251 }
252 252
253 PassRefPtr<Image> Image::imageForDefaultFrame() 253 PassRefPtr<Image> Image::imageForDefaultFrame()
254 { 254 {
255 RefPtr<Image> image(this); 255 RefPtr<Image> image(this);
256 256
257 return image.release(); 257 return image.release();
258 } 258 }
259 259
260 bool Image::isTextureBacked() 260 bool Image::isTextureBacked()
261 { 261 {
262 RefPtr<SkImage> image = imageForCurrentFrame(); 262 sk_sp<SkImage> image = imageForCurrentFrame();
263 return image ? image->isTextureBacked() : false; 263 return image ? image->isTextureBacked() : false;
264 } 264 }
265 265
266 bool Image::applyShader(SkPaint& paint, const SkMatrix& localMatrix) 266 bool Image::applyShader(SkPaint& paint, const SkMatrix& localMatrix)
267 { 267 {
268 // Default shader impl: attempt to build a shader based on the current frame SkImage. 268 // Default shader impl: attempt to build a shader based on the current frame SkImage.
269 RefPtr<SkImage> image = imageForCurrentFrame(); 269 sk_sp<SkImage> image = imageForCurrentFrame();
270 if (!image) 270 if (!image)
271 return false; 271 return false;
272 272
273 paint.setShader( 273 paint.setShader(
274 image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode , &localMatrix)); 274 image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode , &localMatrix));
275 275
276 return true; 276 return true;
277 } 277 }
278 278
279 FloatRect Image::computeTileContaining(const FloatPoint& point, 279 FloatRect Image::computeTileContaining(const FloatPoint& point,
(...skipping 18 matching lines...) Expand all
298 FloatRect subset = dest; 298 FloatRect subset = dest;
299 subset.setX((dest.x() - tile.x()) / scale.width()); 299 subset.setX((dest.x() - tile.x()) / scale.width());
300 subset.setY((dest.y() - tile.y()) / scale.height()); 300 subset.setY((dest.y() - tile.y()) / scale.height());
301 subset.setWidth(dest.width() / scale.width()); 301 subset.setWidth(dest.width() / scale.width());
302 subset.setHeight(dest.height() / scale.height()); 302 subset.setHeight(dest.height() / scale.height());
303 303
304 return subset; 304 return subset;
305 } 305 }
306 306
307 } // namespace blink 307 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/Image.h ('k') | third_party/WebKit/Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698