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

Side by Side Diff: include/core/SkShader.h

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: partial update of skia call-sites 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkShader_DEFINED 8 #ifndef SkShader_DEFINED
9 #define SkShader_DEFINED 9 #define SkShader_DEFINED
10 10
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkFlattenable.h" 12 #include "SkFlattenable.h"
13 #include "SkImageInfo.h" 13 #include "SkImageInfo.h"
14 #include "SkMask.h" 14 #include "SkMask.h"
15 #include "SkMatrix.h" 15 #include "SkMatrix.h"
16 #include "SkPaint.h" 16 #include "SkPaint.h"
17 #include "../gpu/GrColor.h" 17 #include "../gpu/GrColor.h"
18 18
19 class SkColorFilter; 19 class SkColorFilter;
20 class SkPath; 20 class SkPath;
21 class SkPicture; 21 class SkPicture;
22 class SkXfermode; 22 class SkXfermode;
23 class GrContext; 23 class GrContext;
24 class GrFragmentProcessor; 24 class GrFragmentProcessor;
25 25
26 //#define SK_SUPPORT_LEGACY_CREATESHADER_PTR
27
26 /** \class SkShader 28 /** \class SkShader
27 * 29 *
28 * Shaders specify the source color(s) for what is being drawn. If a paint 30 * Shaders specify the source color(s) for what is being drawn. If a paint
29 * has no shader, then the paint's color is used. If the paint has a 31 * has no shader, then the paint's color is used. If the paint has a
30 * shader, then the shader's color(s) are use instead, but they are 32 * shader, then the shader's color(s) are use instead, but they are
31 * modulated by the paint's alpha. This makes it easy to create a shader 33 * modulated by the paint's alpha. This makes it easy to create a shader
32 * once (e.g. bitmap tiling or gradient) and then change its transparency 34 * once (e.g. bitmap tiling or gradient) and then change its transparency
33 * w/o having to modify the original shader... only the paint's alpha needs 35 * w/o having to modify the original shader... only the paint's alpha needs
34 * to be modified. 36 * to be modified.
35 */ 37 */
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 * the colorfilter. 330 * the colorfilter.
329 */ 331 */
330 SkShader* newWithColorFilter(SkColorFilter*) const; 332 SkShader* newWithColorFilter(SkColorFilter*) const;
331 333
332 ////////////////////////////////////////////////////////////////////////// 334 //////////////////////////////////////////////////////////////////////////
333 // Factory methods for stock shaders 335 // Factory methods for stock shaders
334 336
335 /** 337 /**
336 * Call this to create a new "empty" shader, that will not draw anything. 338 * Call this to create a new "empty" shader, that will not draw anything.
337 */ 339 */
338 static SkShader* CreateEmptyShader(); 340 static sk_sp<SkShader> MakeEmptyShader();
339 341
340 /** 342 /**
341 * Call this to create a new shader that just draws the specified color. Th is should always 343 * Call this to create a new shader that just draws the specified color. Th is should always
342 * draw the same as a paint with this color (and no shader). 344 * draw the same as a paint with this color (and no shader).
343 */ 345 */
344 static SkShader* CreateColorShader(SkColor); 346 static sk_sp<SkShader> MakeColorShader(SkColor);
345 347
346 static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermod e::Mode); 348 static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader > src,
349 SkXfermode::Mode);
350
351 #ifdef SK_SUPPORT_LEGACY_CREATESHADER_PTR
mtklein 2016/03/08 14:49:11 Wanna make it one more step general to cover all C
reed1 2016/03/08 15:15:19 Could. My thought had been that the effort was so
352 static SkShader* CreateEmptyShader() { return MakeEmptyShader().release(); }
353 static SkShader* CreateColorShader(SkColor c) { return MakeColorShader(c).re lease(); }
354 static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermod e::Mode mode) {
355 return MakeComposeShader(dst, src, mode).release();
356 }
357 static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermod e* xfer) {
358 return MakeComposeShader(dst, src, xfer).release();
359 }
360 static SkShader* CreateBitmapShader(const SkBitmap& src, TileMode tmx, TileM ode tmy,
361 const SkMatrix* localMatrix = nullptr) {
362 return MakeBitmapShader(src, tmx, tmy, localMatrix).release();
363 }
364 static SkShader* CreatePictureShader(const SkPicture* src, TileMode tmx, Til eMode tmy,
365 const SkMatrix* localMatrix, const SkRe ct* tile) {
366 return MakePictureShader(src, tmx, tmy, localMatrix, tile).release();
367 }
368 #endif
347 369
348 /** 370 /**
349 * Create a new compose shader, given shaders dst, src, and a combining xfe rmode mode. 371 * Create a new compose shader, given shaders dst, src, and a combining xfe rmode mode.
350 * The xfermode is called with the output of the two shaders, and its outpu t is returned. 372 * The xfermode is called with the output of the two shaders, and its outpu t is returned.
351 * If xfer is null, SkXfermode::kSrcOver_Mode is assumed. 373 * If xfer is null, SkXfermode::kSrcOver_Mode is assumed.
352 * 374 *
353 * Ownership of the shaders, and the xfermode if not null, is not transfere d, so the caller 375 * Ownership of the shaders, and the xfermode if not null, is not transfere d, so the caller
f(malita) 2016/03/08 15:50:35 Is the ownership comment still useful?
reed1 2016/03/08 20:17:15 Nope. Will remove.
354 * is still responsible for managing its reference-count for those objects. 376 * is still responsible for managing its reference-count for those objects.
355 */ 377 */
356 static SkShader* CreateComposeShader(SkShader* dst, SkShader* src, SkXfermod e* xfer); 378 static sk_sp<SkShader> MakeComposeShader(sk_sp<SkShader> dst, sk_sp<SkShader > src,
379 SkXfermode* xfer);
357 380
358 /** Call this to create a new shader that will draw with the specified bitma p. 381 /** Call this to create a new shader that will draw with the specified bitma p.
359 * 382 *
360 * If the bitmap cannot be used (e.g. has no pixels, or its dimensions 383 * If the bitmap cannot be used (e.g. has no pixels, or its dimensions
361 * exceed implementation limits (currently at 64K - 1)) then SkEmptyShader 384 * exceed implementation limits (currently at 64K - 1)) then SkEmptyShader
362 * may be returned. 385 * may be returned.
363 * 386 *
364 * If the src is kA8_Config then that mask will be colorized using the colo r on 387 * If the src is kA8_Config then that mask will be colorized using the colo r on
365 * the paint. 388 * the paint.
366 * 389 *
367 * @param src The bitmap to use inside the shader 390 * @param src The bitmap to use inside the shader
368 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir ection. 391 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir ection.
369 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir ection. 392 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir ection.
370 * @return Returns a new shader object. Note: this function never retur ns null. 393 * @return Returns a new shader object. Note: this function never retur ns null.
371 */ 394 */
372 static SkShader* CreateBitmapShader(const SkBitmap& src, 395 static sk_sp<SkShader> MakeBitmapShader(const SkBitmap& src, TileMode tmx, T ileMode tmy,
373 TileMode tmx, TileMode tmy, 396 const SkMatrix* localMatrix = nullpt r);
374 const SkMatrix* localMatrix = NULL);
375 397
376 // NOTE: You can create an SkImage Shader with SkImage::newShader(). 398 // NOTE: You can create an SkImage Shader with SkImage::newShader().
377 399
378 /** Call this to create a new shader that will draw with the specified pictu re. 400 /** Call this to create a new shader that will draw with the specified pictu re.
379 * 401 *
380 * @param src The picture to use inside the shader (if not NULL, its ref c ount 402 * @param src The picture to use inside the shader (if not NULL, its ref c ount
381 * is incremented). The SkPicture must not be changed after 403 * is incremented). The SkPicture must not be changed after
382 * successfully creating a picture shader. 404 * successfully creating a picture shader.
383 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir ection. 405 * @param tmx The tiling mode to use when sampling the bitmap in the x-dir ection.
384 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir ection. 406 * @param tmy The tiling mode to use when sampling the bitmap in the y-dir ection.
385 * @param tile The tile rectangle in picture coordinates: this represents t he subset 407 * @param tile The tile rectangle in picture coordinates: this represents t he subset
386 * (or superset) of the picture used when building a tile. It i s not 408 * (or superset) of the picture used when building a tile. It i s not
387 * affected by localMatrix and does not imply scaling (only tra nslation 409 * affected by localMatrix and does not imply scaling (only tra nslation
388 * and cropping). If null, the tile rect is considered equal to the picture 410 * and cropping). If null, the tile rect is considered equal to the picture
389 * bounds. 411 * bounds.
390 * @return Returns a new shader object. Note: this function never retur ns null. 412 * @return Returns a new shader object. Note: this function never retur ns null.
391 */ 413 */
392 static SkShader* CreatePictureShader(const SkPicture* src, 414 static sk_sp<SkShader> MakePictureShader(const SkPicture* src, TileMode tmx, TileMode tmy,
393 TileMode tmx, TileMode tmy, 415 const SkMatrix* localMatrix, const SkRect* tile);
394 const SkMatrix* localMatrix,
395 const SkRect* tile);
396 416
397 /** 417 /**
398 * If this shader can be represented by another shader + a localMatrix, ret urn that shader 418 * If this shader can be represented by another shader + a localMatrix, ret urn that shader
399 * and, if not NULL, the localMatrix. If not, return NULL and ignore the lo calMatrix parameter. 419 * and, if not NULL, the localMatrix. If not, return NULL and ignore the lo calMatrix parameter.
400 * 420 *
401 * Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility 421 * Note: the returned shader (if not NULL) will have been ref'd, and it is the responsibility
402 * of the caller to balance that with unref() when they are done. 422 * of the caller to balance that with unref() when they are done.
403 */ 423 */
404 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const; 424 virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const;
405 425
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 SkMatrix fLocalMatrix; 457 SkMatrix fLocalMatrix;
438 458
439 // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer con structor. 459 // So the SkLocalMatrixShader can whack fLocalMatrix in its SkReadBuffer con structor.
440 friend class SkLocalMatrixShader; 460 friend class SkLocalMatrixShader;
441 friend class SkBitmapProcShader; // for computeTotalInverse() 461 friend class SkBitmapProcShader; // for computeTotalInverse()
442 462
443 typedef SkFlattenable INHERITED; 463 typedef SkFlattenable INHERITED;
444 }; 464 };
445 465
446 #endif 466 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698