Flutter Engine
The Flutter Engine
Functions
SkImage_Raster.cpp File Reference
#include "src/image/SkImage_Raster.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPixelRef.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkTypes.h"
#include "src/base/SkRectMemcpy.h"
#include "src/core/SkImageInfoPriv.h"
#include "src/core/SkImagePriv.h"
#include "src/image/SkImage_Base.h"
#include <cstddef>
#include <cstdint>
#include <utility>

Go to the source code of this file.

Functions

static bool is_not_subset (const SkBitmap &bm)
 
static void release_data (void *addr, void *context)
 
static SkBitmap copy_bitmap_subset (const SkBitmap &orig, const SkIRect &subset)
 
static sk_sp< SkMipmapcopy_mipmaps (const SkBitmap &src, SkMipmap *srcMips)
 
sk_sp< SkImageSkMakeImageFromRasterBitmapPriv (const SkBitmap &bm, SkCopyPixelsMode cpm, uint32_t idForCopy)
 
sk_sp< SkImageSkMakeImageFromRasterBitmap (const SkBitmap &bm, SkCopyPixelsMode cpm)
 
const SkPixelRefSkBitmapImageGetPixelRef (const SkImage *image)
 

Function Documentation

◆ copy_bitmap_subset()

static SkBitmap copy_bitmap_subset ( const SkBitmap orig,
const SkIRect subset 
)
static

Definition at line 83 of file SkImage_Raster.cpp.

83 {
84 SkImageInfo info = orig.info().makeDimensions(subset.size());
86 if (!bitmap.tryAllocPixels(info)) {
87 return {};
88 }
89
90 void* dst = bitmap.getPixels();
91 void* src = orig.getAddr(subset.x(), subset.y());
92 if (!dst || !src) {
93 SkDEBUGFAIL("SkImage_Raster::onMakeSubset with nullptr src or dst");
94 return {};
95 }
96
97 SkRectMemcpy(dst, bitmap.rowBytes(), src, orig.rowBytes(), bitmap.rowBytes(),
98 subset.height());
99
100 bitmap.setImmutable();
101 return bitmap;
102}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
static void SkRectMemcpy(void *dst, size_t dstRB, const void *src, size_t srcRB, size_t trimRowBytes, int rowCount)
Definition: SkRectMemcpy.h:16
void * getAddr(int x, int y) const
Definition: SkBitmap.cpp:406
size_t rowBytes() const
Definition: SkBitmap.h:238
const SkImageInfo & info() const
Definition: SkBitmap.h:139
Definition: bitmap.py:1
dst
Definition: cp.py:12
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
constexpr SkISize size() const
Definition: SkRect.h:172
constexpr int32_t height() const
Definition: SkRect.h:165
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454

◆ copy_mipmaps()

static sk_sp< SkMipmap > copy_mipmaps ( const SkBitmap src,
SkMipmap srcMips 
)
static

Definition at line 113 of file SkImage_Raster.cpp.

113 {
114 if (!srcMips) {
115 return nullptr;
116 }
117
119 dst.reset(SkMipmap::Build(src.pixmap(),
120 /* factoryProc= */ nullptr,
121 /* computeContents= */ false));
122 if (!dst) {
123 return nullptr;
124 }
125 for (int i = 0; i < dst->countLevels(); ++i) {
126 SkMipmap::Level srcLevel, dstLevel;
127 srcMips->getLevel(i, &srcLevel);
128 dst->getLevel(i, &dstLevel);
129 srcLevel.fPixmap.readPixels(dstLevel.fPixmap);
130 }
131
132 return dst;
133}
static SkMipmap * Build(const SkPixmap &src, SkDiscardableFactoryProc, bool computeContents=true)
Definition: SkMipmap.cpp:45
bool getLevel(int index, Level *) const
Definition: SkMipmap.cpp:280
bool readPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes) const
Definition: SkPixmap.h:592
SkPixmap fPixmap
Definition: SkMipmap.h:71

◆ is_not_subset()

static bool is_not_subset ( const SkBitmap bm)
static

Definition at line 33 of file SkImage_Raster.cpp.

33 {
34 SkASSERT(bm.pixelRef());
35 SkISize dim = SkISize::Make(bm.pixelRef()->width(), bm.pixelRef()->height());
36 SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero());
37 return dim == bm.dimensions();
38}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkIPoint pixelRefOrigin() const
Definition: SkBitmap.cpp:168
SkPixelRef * pixelRef() const
Definition: SkBitmap.h:720
SkISize dimensions() const
Definition: SkBitmap.h:388
int width() const
Definition: SkPixelRef.h:34
int height() const
Definition: SkPixelRef.h:35
bool isZero() const
Definition: SkPoint_impl.h:58
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ release_data()

static void release_data ( void *  addr,
void *  context 
)
static

Definition at line 40 of file SkImage_Raster.cpp.

40 {
41 SkData* data = static_cast<SkData*>(context);
42 data->unref();
43}
Definition: SkData.h:25
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ SkBitmapImageGetPixelRef()

const SkPixelRef * SkBitmapImageGetPixelRef ( const SkImage image)

Definition at line 190 of file SkImage_Raster.cpp.

190 {
191 return ((const SkImage_Raster*)image)->getPixelRef();
192}
sk_sp< const SkImage > image
Definition: SkRecords.h:269

◆ SkMakeImageFromRasterBitmap()

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

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
Definition: SkImage_Base.h:33
sk_sp< SkImage > SkMakeImageFromRasterBitmapPriv(const SkBitmap &bm, SkCopyPixelsMode cpm, uint32_t idForCopy)
size_t minRowBytes() const
Definition: SkImageInfo.h:517

◆ SkMakeImageFromRasterBitmapPriv()

sk_sp< SkImage > SkMakeImageFromRasterBitmapPriv ( const SkBitmap bm,
SkCopyPixelsMode  cpm,
uint32_t  idForCopy 
)

Definition at line 169 of file SkImage_Raster.cpp.

170 {
171 if (kAlways_SkCopyPixelsMode == cpm || (!bm.isImmutable() && kNever_SkCopyPixelsMode != cpm)) {
172 SkPixmap pmap;
173 if (bm.peekPixels(&pmap)) {
174 return MakeRasterCopyPriv(pmap, idForCopy);
175 } else {
176 return sk_sp<SkImage>();
177 }
178 }
179 return sk_make_sp<SkImage_Raster>(bm, kNever_SkCopyPixelsMode == cpm);
180}
@ kNever_SkCopyPixelsMode
never copy src pixels (even if they are marked mutable)
Definition: SkImagePriv.h:20
@ kAlways_SkCopyPixelsMode
always copy src pixels (even if they are marked immutable)
Definition: SkImagePriv.h:19
sk_sp< SkImage > MakeRasterCopyPriv(const SkPixmap &pmap, uint32_t id)
bool isImmutable() const
Definition: SkBitmap.cpp:396
bool peekPixels(SkPixmap *pixmap) const
Definition: SkBitmap.cpp:635