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

Unified Diff: src/image/SkSurface_Gpu.cpp

Issue 201153023: Adding a new SkSurface factory for generating surfaces from the scratch texture pool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: build/typo fix Created 6 years, 9 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
Index: src/image/SkSurface_Gpu.cpp
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index ae05ea8c04609369fcef5279b53fe4c4c630319f..50d6606145a644d9a69be50613555854cc4d6da6 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));
}
« src/gpu/SkGpuDevice.cpp ('K') | « src/gpu/SkGpuDevice.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698