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

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

Issue 1789063005: Add sk_sp helpers and switch Blink SkShader clients to the new APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fromSkSp, review comments Created 4 years, 9 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 ctxt.setImageInterpolationQuality(previousInterpolationQuality); 178 ctxt.setImageInterpolationQuality(previousInterpolationQuality);
179 } else { 179 } else {
180 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect); 180 drawPattern(ctxt, srcRect, tileScaleFactor, patternPhase, op, dstRect);
181 } 181 }
182 182
183 startAnimation(); 183 startAnimation();
184 } 184 }
185 185
186 namespace { 186 namespace {
187 187
188 PassRefPtr<SkShader> createPatternShader(const SkImage* image, const SkMatrix& s haderMatrix, 188 sk_sp<SkShader> createPatternShader(const SkImage* image, const SkMatrix& shader Matrix,
189 const SkPaint& paint, const FloatSize& spacing) 189 const SkPaint& paint, const FloatSize& spacing)
190 { 190 {
191 if (spacing.isZero()) 191 if (spacing.isZero())
192 return adoptRef(image->newShader(SkShader::kRepeat_TileMode, SkShader::k Repeat_TileMode, &shaderMatrix)); 192 return image->makeShader(SkShader::kRepeat_TileMode, SkShader::kRepeat_T ileMode, &shaderMatrix);
193 193
194 // Arbitrary tiling is currently only supported for SkPictureShader - so we use it instead 194 // Arbitrary tiling is currently only supported for SkPictureShader - so we use it instead
195 // of a plain bitmap shader to implement spacing. 195 // of a plain bitmap shader to implement spacing.
196 const SkRect tileRect = SkRect::MakeWH( 196 const SkRect tileRect = SkRect::MakeWH(
197 image->width() + spacing.width(), 197 image->width() + spacing.width(),
198 image->height() + spacing.height()); 198 image->height() + spacing.height());
199 199
200 SkPictureRecorder recorder; 200 SkPictureRecorder recorder;
201 SkCanvas* canvas = recorder.beginRecording(tileRect); 201 SkCanvas* canvas = recorder.beginRecording(tileRect);
202 canvas->drawImage(image, 0, 0, &paint); 202 canvas->drawImage(image, 0, 0, &paint);
203 RefPtr<const SkPicture> picture = adoptRef(recorder.endRecordingAsPicture()) ; 203 sk_sp<SkPicture> picture(recorder.endRecordingAsPicture());
204 204
205 return adoptRef(SkShader::CreatePictureShader( 205 return SkShader::MakePictureShader(
206 picture.get(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, & shaderMatrix, nullptr)); 206 std::move(picture), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMo de, &shaderMatrix, nullptr);
207 } 207 }
208 208
209 } // anonymous namespace 209 } // anonymous namespace
210 210
211 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, const FloatSize& scale, 211 void Image::drawPattern(GraphicsContext& context, const FloatRect& floatSrcRect, const FloatSize& scale,
212 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest Rect, const FloatSize& repeatSpacing) 212 const FloatPoint& phase, SkXfermode::Mode compositeOp, const FloatRect& dest Rect, const FloatSize& repeatSpacing)
213 { 213 {
214 TRACE_EVENT0("skia", "Image::drawPattern"); 214 TRACE_EVENT0("skia", "Image::drawPattern");
215 215
216 RefPtr<SkImage> image = imageForCurrentFrame(); 216 RefPtr<SkImage> image = imageForCurrentFrame();
(...skipping 25 matching lines...) Expand all
242 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect))); 242 image = adoptRef(image->newSubset(enclosingIntRect(normSrcRect)));
243 if (!image) 243 if (!image)
244 return; 244 return;
245 245
246 { 246 {
247 SkPaint paint = context.fillPaint(); 247 SkPaint paint = context.fillPaint();
248 paint.setColor(SK_ColorBLACK); 248 paint.setColor(SK_ColorBLACK);
249 paint.setXfermodeMode(compositeOp); 249 paint.setXfermodeMode(compositeOp);
250 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm SrcRect)); 250 paint.setFilterQuality(context.computeFilterQuality(this, destRect, norm SrcRect));
251 paint.setAntiAlias(context.shouldAntialias()); 251 paint.setAntiAlias(context.shouldAntialias());
252 RefPtr<SkShader> shader = createPatternShader(image.get(), localMatrix, paint, 252 paint.setShader(createPatternShader(image.get(), localMatrix, paint,
253 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height())); 253 FloatSize(repeatSpacing.width() / scale.width(), repeatSpacing.heigh t() / scale.height())));
254 paint.setShader(shader.get());
255 context.drawRect(destRect, paint); 254 context.drawRect(destRect, paint);
256 } 255 }
257 256
258 if (currentFrameIsLazyDecoded()) 257 if (currentFrameIsLazyDecoded())
259 PlatformInstrumentation::didDrawLazyPixelRef(imageID); 258 PlatformInstrumentation::didDrawLazyPixelRef(imageID);
260 } 259 }
261 260
262 PassRefPtr<Image> Image::imageForDefaultFrame() 261 PassRefPtr<Image> Image::imageForDefaultFrame()
263 { 262 {
264 RefPtr<Image> image(this); 263 RefPtr<Image> image(this);
265 264
266 return image.release(); 265 return image.release();
267 } 266 }
268 267
269 bool Image::isTextureBacked() 268 bool Image::isTextureBacked()
270 { 269 {
271 RefPtr<SkImage> image = imageForCurrentFrame(); 270 RefPtr<SkImage> image = imageForCurrentFrame();
272 return image ? image->isTextureBacked() : false; 271 return image ? image->isTextureBacked() : false;
273 } 272 }
274 273
275 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698