Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Enumerations | Functions
SkImagePriv.h File Reference
#include "include/core/SkImage.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"

Go to the source code of this file.

Enumerations

enum  SkCopyPixelsMode { kIfMutable_SkCopyPixelsMode , kAlways_SkCopyPixelsMode , kNever_SkCopyPixelsMode }
 

Functions

sk_sp< SkShaderSkMakeBitmapShaderForPaint (const SkPaint &paint, const SkBitmap &src, SkTileMode, SkTileMode, const SkSamplingOptions &, const SkMatrix *localMatrix, SkCopyPixelsMode)
 
SkRect SkModifyPaintAndDstForDrawImageRect (const SkImage *image, const SkSamplingOptions &, SkRect src, SkRect dst, bool strictSrcSubset, SkPaint *paint)
 
SK_SPI sk_sp< SkImageSkMakeImageFromRasterBitmap (const SkBitmap &, SkCopyPixelsMode)
 
const SkPixelRefSkBitmapImageGetPixelRef (const SkImage *rasterImage)
 

Enumeration Type Documentation

◆ SkCopyPixelsMode

Enumerator
kIfMutable_SkCopyPixelsMode 

only copy src pixels if they are marked mutable

kAlways_SkCopyPixelsMode 

always copy src pixels (even if they are marked immutable)

kNever_SkCopyPixelsMode 

never copy src pixels (even if they are marked mutable)

Definition at line 17 of file SkImagePriv.h.

17 {
18 kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked mutable
19 kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are marked immutable)
20 kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are marked mutable)
21};
@ kNever_SkCopyPixelsMode
never copy src pixels (even if they are marked mutable)
Definition SkImagePriv.h:20
@ kIfMutable_SkCopyPixelsMode
only copy src pixels if they are marked mutable
Definition SkImagePriv.h:18
@ kAlways_SkCopyPixelsMode
always copy src pixels (even if they are marked immutable)
Definition SkImagePriv.h:19

Function Documentation

◆ SkBitmapImageGetPixelRef()

const SkPixelRef * SkBitmapImageGetPixelRef ( const SkImage rasterImage)
extern

Definition at line 190 of file SkImage_Raster.cpp.

190 {
191 return ((const SkImage_Raster*)image)->getPixelRef();
192}
sk_sp< SkImage > image
Definition examples.cpp:29

◆ SkMakeBitmapShaderForPaint()

sk_sp< SkShader > SkMakeBitmapShaderForPaint ( const SkPaint paint,
const SkBitmap src,
SkTileMode  tmx,
SkTileMode  tmy,
const SkSamplingOptions sampling,
const SkMatrix localMatrix,
SkCopyPixelsMode  mode 
)

Definition at line 365 of file SkImageShader.cpp.

368 {
370 tmx, tmy, sampling, localMatrix);
371 if (!s) {
372 return nullptr;
373 }
374 if (SkColorTypeIsAlphaOnly(src.colorType()) && paint.getShader()) {
375 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
376 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
377 // the source image and dst shader (MakeBlend takes dst first, src second).
378 s = SkShaders::Blend(SkBlendMode::kDstIn, paint.refShader(), std::move(s));
379 }
380 return s;
381}
@ kDstIn
r = d * sa
static bool SkColorTypeIsAlphaOnly(SkColorType ct)
SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap(const SkBitmap &, SkCopyPixelsMode)
static sk_sp< SkShader > Make(sk_sp< SkImage >, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
const Paint & paint
struct MyStruct s
SkTileMode tmy
SkTileMode tmx

◆ SkMakeImageFromRasterBitmap()

SK_SPI sk_sp< SkImage > SkMakeImageFromRasterBitmap ( const SkBitmap bm,
SkCopyPixelsMode  cpm 
)
extern

Examines the bitmap to decide if it can share the existing pixelRef, or if it needs to make a deep-copy of the pixels.

The bitmap's pixelref will be shared if either the bitmap is marked as immutable, or CopyPixelsMode allows it. Shared pixel refs are also locked when kLocked_SharedPixelRefMode is specified.

Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method to succeed, but it will force any lazy decodes/generators to execute if they exist on the pixelref.

It is illegal to call this with a texture-backed bitmap.

If the bitmap's colortype cannot be converted into a corresponding SkImageInfo, or the bitmap's pixels cannot be accessed, this will return nullptr.

Definition at line 182 of file SkImage_Raster.cpp.

182 {
183 if (!SkImageInfoIsValid(bm.info()) || bm.rowBytes() < bm.info().minRowBytes()) {
184 return nullptr;
185 }
186
188}
static bool SkImageInfoIsValid(const SkImageInfo &info)
@ kNeedNewImageUniqueID
sk_sp< SkImage > SkMakeImageFromRasterBitmapPriv(const SkBitmap &bm, SkCopyPixelsMode cpm, uint32_t idForCopy)
size_t rowBytes() const
Definition SkBitmap.h:238
const SkImageInfo & info() const
Definition SkBitmap.h:139
size_t minRowBytes() const

◆ SkModifyPaintAndDstForDrawImageRect()

SkRect SkModifyPaintAndDstForDrawImageRect ( const SkImage image,
const SkSamplingOptions sampling,
SkRect  src,
SkRect  dst,
bool  strictSrcSubset,
SkPaint paint 
)

Definition at line 383 of file SkImageShader.cpp.

388 {
389 // The paint should have already been cleaned for a regular drawImageRect, e.g. no path
390 // effect and is a fill.
392 SkASSERT(paint->getStyle() == SkPaint::kFill_Style && !paint->getPathEffect());
393
395 SkRect imgBounds = SkRect::Make(image->bounds());
396
397 SkASSERT(src.isFinite() && dst.isFinite() && dst.isSorted());
398 SkMatrix localMatrix = SkMatrix::RectToRect(src, dst);
399 if (!imgBounds.contains(src)) {
400 if (!src.intersect(imgBounds)) {
401 return SkRect::MakeEmpty(); // Nothing to draw for this entry
402 }
403 // Update dst to match smaller src
404 dst = localMatrix.mapRect(src);
405 }
406
407 bool imageIsAlphaOnly = SkColorTypeIsAlphaOnly(image->colorType());
408
409 sk_sp<SkShader> imgShader;
410 if (strictSrcSubset) {
411 imgShader = SkImageShader::MakeSubset(sk_ref_sp(image), src,
413 sampling, &localMatrix);
414 } else {
416 sampling, &localMatrix);
417 }
418 if (!imgShader) {
419 return SkRect::MakeEmpty();
420 }
421 if (imageIsAlphaOnly && paint->getShader()) {
422 // Compose the image shader with the paint's shader. Alpha images+shaders should output the
423 // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with
424 // the source image and dst shader (MakeBlend takes dst first, src second).
425 imgShader = SkShaders::Blend(SkBlendMode::kDstIn, paint->refShader(), std::move(imgShader));
426 }
427
428 paint->setShader(std::move(imgShader));
429 return dst;
430}
#define SkASSERT(cond)
Definition SkAssert.h:116
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
static sk_sp< SkShader > MakeSubset(sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
SkColorType colorType() const
Definition SkImage.cpp:152
SkIRect bounds() const
Definition SkImage.h:303
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition SkMatrix.h:157
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
dst
Definition cp.py:12
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19