Skip to content

Commit 1434ce1

Browse files
reed-at-googleSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Can we remove volatile from skbitmap?
Change-Id: I0faa324b91f2c291be56f5126361ffe7fd54eb65 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302037 Reviewed-by: Mike Reed <[email protected]> Commit-Queue: Mike Reed <[email protected]>
1 parent ed15b1c commit 1434ce1

File tree

9 files changed

+12
-63
lines changed

9 files changed

+12
-63
lines changed

bench/BitmapBench.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BitmapBench : public Benchmark {
7373
this->onDrawIntoBitmap(bm);
7474

7575
fBitmap = bm;
76-
fBitmap.setIsVolatile(fIsVolatile);
76+
// fBitmap.setIsVolatile(fIsVolatile);
7777
}
7878

7979
void onDraw(int loops, SkCanvas* canvas) override {

docs/examples/Bitmap_isVolatile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ void draw(SkCanvas* canvas) {
77
SkBitmap original;
88
SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
99
if (original.tryAllocPixels(info)) {
10-
original.setIsVolatile(true);
10+
// original.setIsVolatile(true);
1111
SkBitmap copy;
1212
original.extractSubset(&copy, {5, 10, 15, 20});
13-
SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not ");
13+
// SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not ");
1414
SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not ");
1515
}
1616
}

docs/examples/Bitmap_setIsVolatile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void draw(SkCanvas* canvas) {
1212
canvas->drawBitmap(bitmap, 0, 0);
1313
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE);
1414
canvas->drawBitmap(bitmap, 2, 0);
15-
bitmap.setIsVolatile(true);
15+
// bitmap.setIsVolatile(true);
1616
*(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN);
1717
canvas->drawBitmap(bitmap, 4, 0);
1818
}

include/core/SkBitmap.h

-29
Original file line numberDiff line numberDiff line change
@@ -303,30 +303,6 @@ class SK_API SkBitmap {
303303
return SkAlphaTypeIsOpaque(this->alphaType());
304304
}
305305

306-
/** Provides a hint to caller that pixels should not be cached. Only true if
307-
setIsVolatile() has been called to mark as volatile.
308-
309-
Volatile state is not shared by other bitmaps sharing the same SkPixelRef.
310-
311-
@return true if marked volatile
312-
313-
example: https://fiddle.skia.org/c/@Bitmap_isVolatile
314-
*/
315-
bool isVolatile() const;
316-
317-
/** Sets if pixels should be read from SkPixelRef on every access. SkBitmap are not
318-
volatile by default; a GPU back end may upload pixel values expecting them to be
319-
accessed repeatedly. Marking temporary SkBitmap as volatile provides a hint to
320-
SkBaseDevice that the SkBitmap pixels should not be cached. This can
321-
improve performance by avoiding overhead and reducing resource
322-
consumption on SkBaseDevice.
323-
324-
@param isVolatile true if backing pixels are temporary
325-
326-
example: https://fiddle.skia.org/c/@Bitmap_setIsVolatile
327-
*/
328-
void setIsVolatile(bool isVolatile);
329-
330306
/** Resets to its initial state; all fields are set to zero, as if SkBitmap had
331307
been initialized by SkBitmap().
332308
@@ -1188,13 +1164,8 @@ class SK_API SkBitmap {
11881164
};
11891165

11901166
private:
1191-
enum Flags {
1192-
kImageIsVolatile_Flag = 0x02,
1193-
};
1194-
11951167
sk_sp<SkPixelRef> fPixelRef;
11961168
SkPixmap fPixmap;
1197-
uint8_t fFlags;
11981169

11991170
friend class SkReadBuffer; // unflatten
12001171
};

samplecode/SampleAAGeometry.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ class AAGeometryView : public Sample {
13151315

13161316
static uint8_t* set_up_dist_map(const SkImageInfo& imageInfo, SkBitmap* distMap) {
13171317
distMap->setInfo(imageInfo);
1318-
distMap->setIsVolatile(true);
1318+
// distMap->setIsVolatile(true);
13191319
SkAssertResult(distMap->tryAllocPixels());
13201320
SkASSERT((int) distMap->rowBytes() == imageInfo.width());
13211321
return distMap->getAddr8(0, 0);

src/core/SkBitmap.cpp

+1-23
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ static bool reset_return_false(SkBitmap* bm) {
3737
return false;
3838
}
3939

40-
SkBitmap::SkBitmap() : fFlags(0) {}
40+
SkBitmap::SkBitmap() {}
4141

4242
SkBitmap::SkBitmap(const SkBitmap& src)
4343
: fPixelRef (src.fPixelRef)
4444
, fPixmap (src.fPixmap)
45-
, fFlags (src.fFlags)
4645
{
4746
SkDEBUGCODE(src.validate();)
4847
SkDEBUGCODE(this->validate();)
@@ -51,11 +50,9 @@ SkBitmap::SkBitmap(const SkBitmap& src)
5150
SkBitmap::SkBitmap(SkBitmap&& other)
5251
: fPixelRef (std::move(other.fPixelRef))
5352
, fPixmap (std::move(other.fPixmap))
54-
, fFlags (other.fFlags)
5553
{
5654
SkASSERT(!other.fPixelRef);
5755
other.fPixmap.reset();
58-
other.fFlags = 0;
5956
}
6057

6158
SkBitmap::~SkBitmap() {}
@@ -64,7 +61,6 @@ SkBitmap& SkBitmap::operator=(const SkBitmap& src) {
6461
if (this != &src) {
6562
fPixelRef = src.fPixelRef;
6663
fPixmap = src.fPixmap;
67-
fFlags = src.fFlags;
6864
}
6965
SkDEBUGCODE(this->validate();)
7066
return *this;
@@ -74,10 +70,8 @@ SkBitmap& SkBitmap::operator=(SkBitmap&& other) {
7470
if (this != &other) {
7571
fPixelRef = std::move(other.fPixelRef);
7672
fPixmap = std::move(other.fPixmap);
77-
fFlags = other.fFlags;
7873
SkASSERT(!other.fPixelRef);
7974
other.fPixmap.reset();
80-
other.fFlags = 0;
8175
}
8276
return *this;
8377
}
@@ -91,7 +85,6 @@ void SkBitmap::swap(SkBitmap& other) {
9185
void SkBitmap::reset() {
9286
fPixelRef = nullptr; // Free pixels.
9387
fPixmap.reset();
94-
fFlags = 0;
9588
}
9689

9790
void SkBitmap::getBounds(SkRect* bounds) const {
@@ -381,18 +374,6 @@ void SkBitmap::setImmutable() {
381374
}
382375
}
383376

384-
bool SkBitmap::isVolatile() const {
385-
return (fFlags & kImageIsVolatile_Flag) != 0;
386-
}
387-
388-
void SkBitmap::setIsVolatile(bool isVolatile) {
389-
if (isVolatile) {
390-
fFlags |= kImageIsVolatile_Flag;
391-
} else {
392-
fFlags &= ~kImageIsVolatile_Flag;
393-
}
394-
}
395-
396377
void* SkBitmap::getAddr(int x, int y) const {
397378
SkASSERT((unsigned)x < (unsigned)this->width());
398379
SkASSERT((unsigned)y < (unsigned)this->height());
@@ -452,7 +433,6 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const {
452433

453434
SkBitmap dst;
454435
dst.setInfo(this->info().makeDimensions(r.size()), this->rowBytes());
455-
dst.setIsVolatile(this->isVolatile());
456436

457437
if (fPixelRef) {
458438
SkIPoint origin = this->pixelRefOrigin();
@@ -595,8 +575,6 @@ void SkBitmap::validate() const {
595575
this->info().validate();
596576

597577
SkASSERT(this->info().validRowBytes(this->rowBytes()));
598-
uint8_t allFlags = kImageIsVolatile_Flag;
599-
SkASSERT((~allFlags & fFlags) == 0);
600578

601579
if (fPixelRef && fPixelRef->pixels()) {
602580
SkASSERT(this->getPixels());

src/core/SkPixmap.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ bool SkPixmap::scalePixels(const SkPixmap& actualDst, SkFilterQuality quality) c
232232
return false;
233233
}
234234
bitmap.setImmutable(); // Don't copy when we create an image.
235-
bitmap.setIsVolatile(true); // Disable any caching.
235+
// bitmap.setIsVolatile(true); // Disable any caching.
236236

237237
SkMatrix scale = SkMatrix::MakeRectToRect(SkRect::Make(src.bounds()),
238238
SkRect::Make(dst.bounds()),

src/gpu/GrBitmapTextureMaker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context,
4646
, fBudgeted(cachePolicy == GrImageTexGenPolicy::kNew_Uncached_Unbudgeted
4747
? SkBudgeted::kNo
4848
: SkBudgeted::kYes) {
49-
if (!bitmap.isVolatile() && cachePolicy == GrImageTexGenPolicy::kDraw) {
49+
if (/*!bitmap.isVolatile() && */ cachePolicy == GrImageTexGenPolicy::kDraw) {
5050
SkIPoint origin = bitmap.pixelRefOrigin();
5151
SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(),
5252
bitmap.height());

tests/BitmapCopyTest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ DEF_TEST(BitmapCopy_extractSubset, reporter) {
9191
// Extract a subset which has the same width as the original. This
9292
// catches a bug where we cloned the genID incorrectly.
9393
r.setLTRB(0, 1, W, 3);
94-
bitmap.setIsVolatile(true);
94+
// bitmap.setIsVolatile(true);
9595
// Relies on old behavior of extractSubset failing if colortype is unknown
9696
if (kUnknown_SkColorType != bitmap.colorType() && bitmap.extractSubset(&subset, r)) {
9797
REPORTER_ASSERT(reporter, subset.width() == W);
9898
REPORTER_ASSERT(reporter, subset.height() == 2);
9999
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
100-
REPORTER_ASSERT(reporter, subset.isVolatile() == true);
100+
// REPORTER_ASSERT(reporter, subset.isVolatile() == true);
101101

102102
// Test copying an extracted subset.
103103
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
@@ -120,10 +120,10 @@ DEF_TEST(BitmapCopy_extractSubset, reporter) {
120120
}
121121

122122
bitmap = srcPremul;
123-
bitmap.setIsVolatile(false);
123+
// bitmap.setIsVolatile(false);
124124
if (bitmap.extractSubset(&subset, r)) {
125125
REPORTER_ASSERT(reporter, subset.alphaType() == bitmap.alphaType());
126-
REPORTER_ASSERT(reporter, subset.isVolatile() == false);
126+
// REPORTER_ASSERT(reporter, subset.isVolatile() == false);
127127
}
128128
}
129129
}

0 commit comments

Comments
 (0)