diff options
author | 2014-03-19 21:19:16 +0000 | |
---|---|---|
committer | 2014-03-19 21:19:16 +0000 | |
commit | d8a57af725e8fa8905207df3cf7465be50598752 (patch) | |
tree | 031131651c13db23570e5a69a495b02322e394d9 /src/image/SkSurface_Gpu.cpp | |
parent | b9c95978c614e8f6bc00bdf565cff57388d8c659 (diff) |
Adding a new SkSurface factory for generating surfaces from the scratch texture pool.
TEST=Surface unit test
BUG=crbug.com/351798
R=bsalomon@google.com, robertphillips@google.com, reed@google.com
Author: junov@chromium.org
Review URL: https://codereview.chromium.org/201153023
git-svn-id: http://skia.googlecode.com/svn/trunk@13864 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/image/SkSurface_Gpu.cpp')
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index ae05ea8c04..50d6606145 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -14,7 +14,7 @@ class SkSurface_Gpu : public SkSurface_Base { public: SK_DECLARE_INST_COUNT(SkSurface_Gpu) - SkSurface_Gpu(GrRenderTarget*); + SkSurface_Gpu(GrRenderTarget*, bool cached); virtual ~SkSurface_Gpu(); virtual SkCanvas* onNewCanvas() SK_OVERRIDE; @@ -32,9 +32,9 @@ private: /////////////////////////////////////////////////////////////////////////////// -SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget) +SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) : INHERITED(renderTarget->width(), renderTarget->height()) { - fDevice = SkNEW_ARGS(SkGpuDevice, (renderTarget->getContext(), renderTarget)); + fDevice = SkGpuDevice::Create(renderTarget, cached ? SkGpuDevice::kCached_Flag : 0); if (kRGB_565_GrPixelConfig != renderTarget->config()) { fDevice->clear(0x0); @@ -95,7 +95,7 @@ SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { if (NULL == target) { return NULL; } - return SkNEW_ARGS(SkSurface_Gpu, (target)); + return SkNEW_ARGS(SkSurface_Gpu, (target, false)); } SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { @@ -117,5 +117,28 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i return NULL; } - return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); + return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false)); +} + +SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { + if (NULL == ctx) { + return NULL; + } + + SkBitmap::Config config = SkImageInfoToBitmapConfig(info); + + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFlagBit; + desc.fWidth = info.fWidth; + desc.fHeight = info.fHeight; + desc.fConfig = SkBitmapConfig2GrPixelConfig(config); + desc.fSampleCnt = sampleCount; + + SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::kExact_ScratchTexMatch)); + + if (NULL == tex) { + return NULL; + } + + return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); } |