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

Unified Diff: src/image/SkSurface_Raster.cpp

Issue 1643873002: allow the caller to specified raster-surface rowbytes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox for snapped image rowbytes Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkSurface.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkSurface_Raster.cpp
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index a606656709457699ee998b7ec9a311a755fd7579..52300c3bdee38fc20397f50889c22ec15f70b564 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -31,6 +31,7 @@ public:
private:
SkBitmap fBitmap;
+ size_t fRowBytes;
bool fWeOwnThePixels;
typedef SkSurface_Base INHERITED;
@@ -88,6 +89,7 @@ SkSurface_Raster::SkSurface_Raster(const SkImageInfo& info, void* pixels, size_t
: INHERITED(info, props)
{
fBitmap.installPixels(info, pixels, rb, nullptr, releaseProc, context);
+ fRowBytes = 0; // don't need to track the rowbytes
fWeOwnThePixels = false; // We are "Direct"
}
@@ -96,8 +98,9 @@ SkSurface_Raster::SkSurface_Raster(SkPixelRef* pr, const SkSurfaceProps* props)
{
const SkImageInfo& info = pr->info();
- fBitmap.setInfo(info, info.minRowBytes());
+ fBitmap.setInfo(info, pr->rowBytes());
fBitmap.setPixelRef(pr);
+ fRowBytes = pr->rowBytes(); // we track this, so that subsequent re-allocs will match
fWeOwnThePixels = true;
}
@@ -139,12 +142,17 @@ void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.pixelRef()) {
SkASSERT(fWeOwnThePixels);
if (kDiscard_ContentChangeMode == mode) {
- fBitmap.setPixelRef(nullptr);
fBitmap.allocPixels();
} else {
SkBitmap prev(fBitmap);
- prev.deepCopyTo(&fBitmap);
+ fBitmap.allocPixels();
+ prev.lockPixels();
+ SkASSERT(prev.info() == fBitmap.info());
+ SkASSERT(prev.rowBytes() == fBitmap.rowBytes());
+ memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.getSafeSize());
}
+ SkASSERT(fBitmap.rowBytes() == fRowBytes); // be sure we always use the same value
+
// Now fBitmap is a deep copy of itself (and therefore different from
// what is being used by the image. Next we update the canvas to use
// this as its backend, so we can't modify the image's pixels anymore.
@@ -176,14 +184,22 @@ SkSurface* SkSurface::NewRasterDirect(const SkImageInfo& info, void* pixels, siz
return NewRasterDirectReleaseProc(info, pixels, rowBytes, nullptr, nullptr, props);
}
-SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* props) {
+SkSurface* SkSurface::NewRaster(const SkImageInfo& info, size_t rowBytes,
+ const SkSurfaceProps* props) {
if (!SkSurface_Raster::Valid(info)) {
return nullptr;
}
- SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, 0, nullptr));
+ SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewZeroed(info, rowBytes, nullptr));
if (nullptr == pr.get()) {
return nullptr;
}
+ if (rowBytes) {
+ SkASSERT(pr->rowBytes() == rowBytes);
+ }
return new SkSurface_Raster(pr, props);
}
+
+SkSurface* SkSurface::NewRaster(const SkImageInfo& info, const SkSurfaceProps* props) {
+ return NewRaster(info, 0, props);
+}
« no previous file with comments | « include/core/SkSurface.h ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698