diff options
author | 2016-12-14 15:12:15 -0500 | |
---|---|---|
committer | 2016-12-14 20:48:32 +0000 | |
commit | 31c2608e859b1f1c25eeea429f5ab2fee1529fac (patch) | |
tree | c3d18923a555d95551b6fa44df53f940545c42d8 /src/gpu | |
parent | 56ff9a1c9dfdaf1cd6db3b62a5c2b739cd242032 (diff) |
Demote savePixels to save_pixels
This CL again only really makes sense in the bigger picture of moving readPixels off of GrTexture
Change-Id: Ib76482d8a773144e8fc7c6e55b2c7fa7b3ea0ecf
Reviewed-on: https://skia-review.googlesource.com/6086
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 12 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 2 | ||||
-rw-r--r-- | src/gpu/GrSurface.cpp | 36 | ||||
-rw-r--r-- | src/gpu/GrSurfacePriv.h | 6 | ||||
-rw-r--r-- | src/gpu/text/GrBatchFontCache.cpp | 65 | ||||
-rw-r--r-- | src/gpu/text/GrBatchFontCache.h | 2 |
6 files changed, 77 insertions, 46 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 65503420c9..78435d0813 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -642,11 +642,9 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeWrappedRenderTargetContext( surfaceProps); } -sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface> surface) { +sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy) { ASSERT_SINGLE_OWNER_PRIV - sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface))); - if (proxy->asRenderTargetProxy()) { return this->drawingManager()->makeRenderTargetContext(std::move(proxy), nullptr, nullptr); } else { @@ -655,6 +653,14 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface } } +sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurface> surface) { + ASSERT_SINGLE_OWNER_PRIV + + sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(surface))); + + return this->makeWrappedSurfaceContext(std::move(proxy)); +} + sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext( const GrBackendTextureDesc& desc, sk_sp<SkColorSpace> colorSpace, diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index 7d7cbb0e52..75effa3848 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -26,6 +26,8 @@ public: // Create a surfaceContext that wraps an existing texture or renderTarget sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurface> tex); + sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy); + sk_sp<GrSurfaceContext> makeDeferredSurfaceContext(const GrSurfaceDesc& dstDesc, SkBackingFit dstFit, SkBudgeted isDstBudgeted); diff --git a/src/gpu/GrSurface.cpp b/src/gpu/GrSurface.cpp index 83e5a05aec..b9787892f0 100644 --- a/src/gpu/GrSurface.cpp +++ b/src/gpu/GrSurface.cpp @@ -10,12 +10,8 @@ #include "GrOpList.h" #include "GrSurfacePriv.h" -#include "SkBitmap.h" #include "SkGrPriv.h" -#include "SkImageEncoder.h" #include "SkMathPriv.h" -#include "SkStream.h" -#include <stdio.h> GrSurface::~GrSurface() { if (fLastOpList) { @@ -166,38 +162,6 @@ bool GrSurface::readPixels(int left, int top, int width, int height, rowBytes, pixelOpsFlags); } -static bool encode_image_to_file(const char* path, const SkBitmap& src) { - SkFILEWStream file(path); - return file.isValid() && SkEncodeImage(&file, src, SkEncodedImageFormat::kPNG, 100); -} - -// TODO: This should probably be a non-member helper function. It might only be needed in -// debug or developer builds. -bool GrSurface::savePixels(const char* filename) { - SkBitmap bm; - if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->height()))) { - return false; - } - - bool result = this->readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPixelConfig, - bm.getPixels()); - if (!result) { - SkDebugf("------ failed to read pixels for %s\n", filename); - return false; - } - - // remove any previous version of this file - remove(filename); - - if (!encode_image_to_file(filename, bm)) { - SkDebugf("------ failed to encode %s\n", filename); - remove(filename); // remove any partial file - return false; - } - - return true; -} - void GrSurface::flushWrites() { if (!this->wasDestroyed()) { this->getContext()->flushSurfaceWrites(this); diff --git a/src/gpu/GrSurfacePriv.h b/src/gpu/GrSurfacePriv.h index f2ba7baca4..c7ae6a4149 100644 --- a/src/gpu/GrSurfacePriv.h +++ b/src/gpu/GrSurfacePriv.h @@ -33,12 +33,6 @@ public: const void** data, size_t* rowBytes); - /** - * Write the contents of the surface to a PNG. Returns true if successful. - * @param filename Full path to desired file - */ - bool savePixels(const char* filename) { return fSurface->savePixels(filename); } - bool hasPendingRead() const { return fSurface->hasPendingRead(); } bool hasPendingWrite() const { return fSurface->hasPendingWrite(); } bool hasPendingIO() const { return fSurface->hasPendingIO(); } diff --git a/src/gpu/text/GrBatchFontCache.cpp b/src/gpu/text/GrBatchFontCache.cpp index baf56a4322..04acdd2406 100644 --- a/src/gpu/text/GrBatchFontCache.cpp +++ b/src/gpu/text/GrBatchFontCache.cpp @@ -102,6 +102,65 @@ void GrBatchFontCache::HandleEviction(GrBatchAtlas::AtlasID id, void* ptr) { } } +#ifdef SK_DEBUG +#include "GrContextPriv.h" +#include "GrSurfaceProxy.h" +#include "GrSurfaceContext.h" +#include "GrTextureProxy.h" + +#include "SkBitmap.h" +#include "SkImageEncoder.h" +#include "SkStream.h" +#include <stdio.h> + +/** + * Write the contents of the surface proxy to a PNG. Returns true if successful. + * @param filename Full path to desired file + */ +static bool save_pixels(GrContext* context, GrSurfaceProxy* sProxy, const char* filename) { + SkBitmap bm; + if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(sProxy->width(), sProxy->height()))) { + return false; + } + + sk_sp<GrSurfaceContext> sContext(context->contextPriv().makeWrappedSurfaceContext( + sk_ref_sp(sProxy))); + if (!sContext || !sContext->asDeferredTexture()) { + return false; + } + + // TODO: remove this instantiation when readPixels is on SurfaceContext + GrTexture* tex = sContext->asDeferredTexture()->instantiate(context->textureProvider()); + if (!tex) { + return false; + } + + bool result = tex->readPixels(0, 0, sProxy->width(), sProxy->height(), kSkia8888_GrPixelConfig, + bm.getPixels(), bm.rowBytes()); + if (!result) { + SkDebugf("------ failed to read pixels for %s\n", filename); + return false; + } + + // remove any previous version of this file + remove(filename); + + SkFILEWStream file(filename); + if (!file.isValid()) { + SkDebugf("------ failed to create file: %s\n", filename); + remove(filename); // remove any partial file + return false; + } + + if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) { + SkDebugf("------ failed to encode %s\n", filename); + remove(filename); // remove any partial file + return false; + } + + return true; +} + void GrBatchFontCache::dump() const { static int gDumpCount = 0; for (int i = 0; i < kMaskFormatCount; ++i) { @@ -114,12 +173,16 @@ void GrBatchFontCache::dump() const { #else filename.printf("fontcache_%d%d.png", gDumpCount, i); #endif - texture->surfacePriv().savePixels(filename.c_str()); + + sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(sk_ref_sp(texture))); + + save_pixels(fContext, sProxy.get(), filename.c_str()); } } } ++gDumpCount; } +#endif void GrBatchFontCache::setAtlasSizes_ForTesting(const GrBatchAtlasConfig configs[3]) { // Delete any old atlases. diff --git a/src/gpu/text/GrBatchFontCache.h b/src/gpu/text/GrBatchFontCache.h index b5cfaf2cff..a06652b967 100644 --- a/src/gpu/text/GrBatchFontCache.h +++ b/src/gpu/text/GrBatchFontCache.h @@ -182,7 +182,9 @@ public: /////////////////////////////////////////////////////////////////////////// // Functions intended debug only +#ifdef SK_DEBUG void dump() const; +#endif void setAtlasSizes_ForTesting(const GrBatchAtlasConfig configs[3]); |