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

Unified Diff: src/core/SkMipMap.cpp

Issue 1598803002: use pixmaps in mipmap api (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkMipMap.h ('k') | tests/MipMapTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkMipMap.cpp
diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp
index eba50bcb4d2a10f11dcd8cb910289505533a8ed6..5ea40f404832e26bce59dd854b38e6b41b35a859 100644
--- a/src/core/SkMipMap.cpp
+++ b/src/core/SkMipMap.cpp
@@ -183,7 +183,7 @@ size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) {
typedef void SkDownSampleProc(void*, int x, int y, const void* srcPtr, const SkPixmap& srcPM);
-SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
+SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDiscardableFactoryProc fact) {
SkDownSampleProc* proc_nocheck, *proc_check;
const SkColorType ct = src.colorType();
@@ -236,16 +236,6 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
return nullptr;
}
- SkAutoPixmapUnlock srcUnlocker;
- if (!src.requestLock(&srcUnlocker)) {
- return nullptr;
- }
- const SkPixmap& srcPixmap = srcUnlocker.pixmap();
- // Try to catch where we might have returned nullptr for src crbug.com/492818
- if (nullptr == srcPixmap.addr()) {
- sk_throw();
- }
-
SkMipMap* mipmap;
if (fact) {
SkDiscardableMemory* dm = fact(storageSize);
@@ -267,17 +257,14 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
int width = src.width();
int height = src.height();
uint32_t rowBytes;
- SkPixmap srcPM(srcPixmap);
+ SkPixmap srcPM(src);
for (int i = 0; i < countLevels; ++i) {
width >>= 1;
height >>= 1;
rowBytes = SkToU32(SkColorTypeMinRowBytes(ct, width));
- levels[i].fPixels = addr;
- levels[i].fWidth = width;
- levels[i].fHeight = height;
- levels[i].fRowBytes = rowBytes;
+ levels[i].fPixmap = SkPixmap(SkImageInfo::Make(width, height, ct, at), addr, rowBytes);
levels[i].fScale = (float)width / src.width();
SkPixmap dstPM(SkImageInfo::Make(width, height, ct, at), addr, rowBytes);
@@ -487,7 +474,7 @@ size_t SkMipMap::AllocLevelsSize(int levelCount, size_t pixelSize) {
return sk_64_asS32(size);
}
-SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
+SkMipMap* SkMipMap::Build(const SkPixmap& src, SkDiscardableFactoryProc fact) {
typedef void FilterProc(void*, const void* srcPtr, size_t srcRB, int count);
FilterProc* proc_2_2 = nullptr;
@@ -555,16 +542,6 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
return nullptr;
}
- SkAutoPixmapUnlock srcUnlocker;
- if (!src.requestLock(&srcUnlocker)) {
- return nullptr;
- }
- const SkPixmap& srcPixmap = srcUnlocker.pixmap();
- // Try to catch where we might have returned nullptr for src crbug.com/492818
- if (nullptr == srcPixmap.addr()) {
- sk_throw();
- }
-
SkMipMap* mipmap;
if (fact) {
SkDiscardableMemory* dm = fact(storageSize);
@@ -586,7 +563,7 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
int width = src.width();
int height = src.height();
uint32_t rowBytes;
- SkPixmap srcPM(srcPixmap);
+ SkPixmap srcPM(src);
for (int i = 0; i < countLevels; ++i) {
FilterProc* proc;
@@ -607,14 +584,10 @@ SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
height >>= 1;
rowBytes = SkToU32(SkColorTypeMinRowBytes(ct, width));
- levels[i].fPixels = addr;
- levels[i].fWidth = width;
- levels[i].fHeight = height;
- levels[i].fRowBytes = rowBytes;
- levels[i].fScale = (float)width / src.width();
-
- SkPixmap dstPM(SkImageInfo::Make(width, height, ct, at), addr, rowBytes);
+ levels[i].fPixmap = SkPixmap(SkImageInfo::Make(width, height, ct, at), addr, rowBytes);
+ levels[i].fScale = (float)width / src.width();
+ const SkPixmap& dstPM = levels[i].fPixmap;
const void* srcBasePtr = srcPM.addr();
void* dstBasePtr = dstPM.writable_addr();
@@ -666,3 +639,19 @@ bool SkMipMap::extractLevel(SkScalar scale, Level* levelPtr) const {
}
return true;
}
+
+// Helper which extacts a pixmap from the src bitmap
+//
+SkMipMap* SkMipMap::Build(const SkBitmap& src, SkDiscardableFactoryProc fact) {
+ SkAutoPixmapUnlock srcUnlocker;
+ if (!src.requestLock(&srcUnlocker)) {
+ return nullptr;
+ }
+ const SkPixmap& srcPixmap = srcUnlocker.pixmap();
+ // Try to catch where we might have returned nullptr for src crbug.com/492818
+ if (nullptr == srcPixmap.addr()) {
+ sk_throw();
+ }
+ return Build(srcPixmap, fact);
+}
+
« no previous file with comments | « src/core/SkMipMap.h ('k') | tests/MipMapTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698