diff options
author | reed <reed@google.com> | 2015-07-30 18:58:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-30 18:58:23 -0700 |
commit | 80c772b2a46aea7efe0632e580fbc8233ff2a190 (patch) | |
tree | 7b9e83cf6aade7c081bafa00189799f32e2c058f /src/image | |
parent | 58b4395b22eb0620605ff0674c6d1254ecd51374 (diff) |
unify pixelref and image ID space, so we can share IDs when we share pixels
I view this as a performance opportunity, not a feature or bug fix per-se.
BUG=skia:
Review URL: https://codereview.chromium.org/1266883002
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage.cpp | 21 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 8 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 14 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.h | 4 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 8 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 2 |
6 files changed, 31 insertions, 26 deletions
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 081785f4b3..a17f336c9c 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -11,6 +11,7 @@ #include "SkImageGenerator.h" #include "SkImagePriv.h" #include "SkImage_Base.h" +#include "SkNextID.h" #include "SkPixelRef.h" #include "SkReadPixelsRec.h" #include "SkString.h" @@ -22,15 +23,13 @@ #include "SkImage_Gpu.h" #endif -uint32_t SkImage::NextUniqueID() { - static int32_t gUniqueID; - - // never return 0; - uint32_t id; - do { - id = sk_atomic_inc(&gUniqueID) + 1; - } while (0 == id); - return id; +SkImage::SkImage(int width, int height, uint32_t uniqueID) + : fWidth(width) + , fHeight(height) + , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : uniqueID) +{ + SkASSERT(width > 0); + SkASSERT(height > 0); } const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const { @@ -248,8 +247,8 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { unrefCopy.reset(tex); } const SkImageInfo info = bm.info(); - return SkNEW_ARGS(SkImage_Gpu, (info.width(), info.height(), info.alphaType(), - tex, 0, SkSurface::kNo_Budgeted)); + return SkNEW_ARGS(SkImage_Gpu, (info.width(), info.height(), bm.getGenerationID(), + info.alphaType(), tex, 0, SkSurface::kNo_Budgeted)); } #endif diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index b3661d99fe..37dcb40d25 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -11,14 +11,18 @@ #include "SkImage.h" #include "SkSurface.h" +enum { + kNeedNewImageUniqueID = 0 +}; + static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry); } class SkImage_Base : public SkImage { public: - SkImage_Base(int width, int height, const SkSurfaceProps* props) - : INHERITED(width, height) + SkImage_Base(int width, int height, uint32_t uniqueID, const SkSurfaceProps* props) + : INHERITED(width, height, uniqueID) , fProps(copy_or_safe_defaults(props)) {} diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 31ae5a90fd..7ce6831b63 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -13,9 +13,9 @@ #include "SkGpuDevice.h" -SkImage_Gpu::SkImage_Gpu(int w, int h, SkAlphaType at, GrTexture* tex, +SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex, int sampleCountForNewSurfaces, SkSurface::Budgeted budgeted) - : INHERITED(w, h, NULL) + : INHERITED(w, h, uniqueID, NULL) , fTexture(SkRef(tex)) , fSampleCountForNewSurfaces(sampleCountForNewSurfaces) , fAlphaType(at) @@ -130,7 +130,8 @@ static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur } const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted; - return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, tex, 0, budgeted)); + return SkNEW_ARGS(SkImage_Gpu, + (desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, 0, budgeted)); } @@ -164,7 +165,8 @@ SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted; const int sampleCount = 0; // todo: make this an explicit parameter to newSurface()? - return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, at, dst, sampleCount, budgeted)); + return SkNEW_ARGS(SkImage_Gpu, (desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, + at, dst, sampleCount, budgeted)); } SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace, @@ -238,8 +240,8 @@ SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS GrDrawContext* drawContext = ctx->drawContext(); drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(), rect); ctx->flushSurfaceWrites(dst); - return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkAlphaType, dst, 0, - budgeted)); + return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID, + kOpaque_SkAlphaType, dst, 0, budgeted)); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index df26f82b74..4c7ebd6f71 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -23,8 +23,8 @@ public: * An "image" can be a subset/window into a larger texture, so we explicit take the * width and height. */ - SkImage_Gpu(int w, int h, SkAlphaType, GrTexture*, int sampleCountForNewSurfaces, - SkSurface::Budgeted); + SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType, GrTexture*, + int sampleCountForNewSurfaces, SkSurface::Budgeted); void applyBudgetDecision() const { GrTexture* tex = this->getTexture(); diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index bde4c347aa..7b5cf9bb1b 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -82,7 +82,7 @@ public: bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props, bool lockPixels = false) - : INHERITED(bm.width(), bm.height(), props) + : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) , fBitmap(bm) { if (lockPixels) { fBitmap.lockPixels(); @@ -91,7 +91,7 @@ public: } private: - SkImage_Raster() : INHERITED(0, 0, NULL) { + SkImage_Raster() : INHERITED(0, 0, fBitmap.getGenerationID(), NULL) { fBitmap.setImmutable(); } @@ -109,7 +109,7 @@ static void release_data(void* addr, void* context) { SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes, SkColorTable* ctable, const SkSurfaceProps* props) - : INHERITED(info.width(), info.height(), props) + : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID, props) { data->ref(); void* addr = const_cast<void*>(data->data()); @@ -121,7 +121,7 @@ SkImage_Raster::SkImage_Raster(const Info& info, SkData* data, size_t rowBytes, SkImage_Raster::SkImage_Raster(const Info& info, SkPixelRef* pr, const SkIPoint& pixelRefOrigin, size_t rowBytes, const SkSurfaceProps* props) - : INHERITED(info.width(), info.height(), props) + : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) { fBitmap.setInfo(info, rowBytes); fBitmap.setPixelRef(pr, pixelRefOrigin); diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 67f54d5bbb..dbe82f8c9f 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -83,7 +83,7 @@ SkImage* SkSurface_Gpu::onNewImageSnapshot(Budgeted budgeted) { GrTexture* tex = fDevice->accessRenderTarget()->asTexture(); if (tex) { image = SkNEW_ARGS(SkImage_Gpu, - (info.width(), info.height(), info.alphaType(), + (info.width(), info.height(), kNeedNewImageUniqueID, info.alphaType(), tex, sampleCount, budgeted)); } if (image) { |