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

Unified Diff: src/image/SkImage.cpp

Issue 1217053003: add SkImage::NewFromBitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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/core/SkRecorder.cpp ('k') | src/image/SkImagePriv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 1d61438707fd274b9165062c6831b1ebf941815f..d3533a9a4a58cd7ab7d87ada6ec5bc4931314f65 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -11,12 +11,15 @@
#include "SkImageGenerator.h"
#include "SkImagePriv.h"
#include "SkImage_Base.h"
+#include "SkPixelRef.h"
#include "SkReadPixelsRec.h"
#include "SkString.h"
#include "SkSurface.h"
+
#if SK_SUPPORT_GPU
#include "GrTexture.h"
#include "GrContext.h"
+#include "SkImage_Gpu.h"
#endif
uint32_t SkImage::NextUniqueID() {
@@ -227,6 +230,41 @@ bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const {
///////////////////////////////////////////////////////////////////////////////////////////////////
+SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
+ SkPixelRef* pr = bm.pixelRef();
+ if (NULL == pr) {
+ return NULL;
+ }
+
+#if SK_SUPPORT_GPU
+ if (GrTexture* tex = pr->getTexture()) {
+ SkAutoTUnref<GrTexture> unrefCopy;
+ if (!bm.isImmutable()) {
+ const bool notBudgeted = false;
+ tex = GrDeepCopyTexture(tex, notBudgeted);
+ if (NULL == tex) {
+ return NULL;
+ }
+ unrefCopy.reset(tex);
+ }
+ const SkImageInfo info = bm.info();
+ return SkNEW_ARGS(SkImage_Gpu, (info.width(), info.height(), info.alphaType(),
+ tex, 0, SkSurface::kNo_Budgeted));
+ }
+#endif
+
+ // Encoded version?
+ if (SkData* encoded = pr->refEncodedData()) {
+ SkAutoTUnref<SkData> data(encoded);
+ return SkImage::NewFromEncoded(encoded); // todo: add origin/subset/etc?
+ }
+
+ // This will check for immutable (share or copy)
+ return SkNewImageFromRasterBitmap(bm, false, NULL);
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+
#if !SK_SUPPORT_GPU
SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
« no previous file with comments | « src/core/SkRecorder.cpp ('k') | src/image/SkImagePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698