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

Unified Diff: src/image/SkImage_Raster.cpp

Issue 951483002: Make SkNewImageFromBitmap take pixel ref origin into account (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-01-deferred-canvas-writepixels-skip
Patch Set: Created 5 years, 10 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 | « src/image/SkImagePriv.cpp ('k') | tests/SkImageTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Raster.cpp
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index e3ecd6875f74dd2544e8390e492dc2cf49232623..1165d1422625c7f0f6522e8e5951afad806c32ea 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -6,11 +6,12 @@
*/
#include "SkImage_Base.h"
-#include "SkImagePriv.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkImageGenerator.h"
+#include "SkImagePriv.h"
+#include "SkPixelRef.h"
#include "SkSurface.h"
class SkImage_Raster : public SkImage_Base {
@@ -60,7 +61,8 @@ public:
bool getROPixels(SkBitmap*) const SK_OVERRIDE;
// exposed for SkSurface_Raster via SkNewImageFromPixelRef
- SkImage_Raster(const SkImageInfo&, SkPixelRef*, size_t rowBytes, const SkSurfaceProps*);
+ SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrigin, size_t rowBytes,
+ const SkSurfaceProps*);
SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
@@ -102,12 +104,12 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes,
fBitmap.lockPixels();
}
-SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, size_t rowBytes,
- const SkSurfaceProps* props)
+SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin,
+ size_t rowBytes, const SkSurfaceProps* props)
: INHERITED(info.width(), info.height(), props)
{
fBitmap.setInfo(info, rowBytes);
- fBitmap.setPixelRef(pr);
+ fBitmap.setPixelRef(pr, pixelRefOrigin);
fBitmap.lockPixels();
}
@@ -193,12 +195,37 @@ SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator) {
return SkNEW_ARGS(SkImage_Raster, (bitmap, NULL));
}
-SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, size_t rowBytes,
+SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
+ const SkIPoint& pixelRefOrigin, size_t rowBytes,
const SkSurfaceProps* props) {
if (!SkImage_Raster::ValidArgs(info, rowBytes)) {
return NULL;
}
- return SkNEW_ARGS(SkImage_Raster, (info, pr, rowBytes, props));
+ return SkNEW_ARGS(SkImage_Raster, (info, pr, pixelRefOrigin, rowBytes, props));
+}
+
+SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef,
+ const SkSurfaceProps* props) {
+ if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes())) {
+ return NULL;
+ }
+
+ SkImage* image = NULL;
+ if (canSharePixelRef || bm.isImmutable()) {
+ image = SkNEW_ARGS(SkImage_Raster, (bm, props));
+ } else {
+ bm.lockPixels();
+ if (bm.getPixels()) {
+ image = SkImage::NewRasterCopy(bm.info(), bm.getPixels(), bm.rowBytes());
+ }
+ bm.unlockPixels();
+
+ // we don't expose props to NewRasterCopy (need a private vers) so post-init it here
+ if (image && props) {
+ as_IB(image)->initWithProps(*props);
+ }
+ }
+ return image;
}
const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* image) {
« no previous file with comments | « src/image/SkImagePriv.cpp ('k') | tests/SkImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698