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

Unified Diff: src/image/SkSurface_Gpu.cpp

Issue 912243004: Make all SkSurface_* -related devices all have a device (Closed) Base URL: https://skia.googlesource.com/skia.git@skimage-filters-03-sksurface-set-root-device
Patch Set: Created 5 years, 10 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/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkSurface_Gpu.cpp
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 01c3bb74474112c94f10932c06a3a02e28543a90..b43a9a13d90aa90e8edea57a6e8b81892105110a 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -20,11 +20,23 @@
SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device)
: INHERITED(device->width(), device->height(), &device->surfaceProps())
- , fDevice(SkRef(device)) {
+ , fDevice(SkRef(device))
+ , fOwnsDevice(true) {
+ fDevice->setSurface(this);
+}
+
+
+SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device, ReverseOwnershipDeprecated)
+ : INHERITED(device->width(), device->height(), &device->surfaceProps())
+ , fDevice(device)
+ , fOwnsDevice(false) {
+ fDevice->setSurface(this);
}
SkSurface_Gpu::~SkSurface_Gpu() {
- fDevice->unref();
+ if (fOwnsDevice) {
+ fDevice->unref();
+ }
}
SkCanvas* SkSurface_Gpu::onNewCanvas() {
@@ -133,6 +145,47 @@ GrRenderTarget* SkSurface_Gpu::CreateRenderTarget(GrContext* context, SkSurface:
return texture->asRenderTarget();
}
+SkGpuDevice* SkSurface_Gpu::createCompatibleDeviceDeprecated(
+ const SkBaseDevice::CreateInfo& cinfo) {
+ GrRenderTarget* rt = fDevice->accessRenderTarget();
+ GrSurfaceDesc desc;
+ desc.fConfig = rt->config();
+ desc.fFlags = kRenderTarget_GrSurfaceFlag;
+ desc.fWidth = cinfo.fInfo.width();
+ desc.fHeight = cinfo.fInfo.height();
+ desc.fSampleCnt = rt->numSamples();
+
+ SkAutoTUnref<GrTexture> texture;
+ // Skia's convention is to only clear a device if it is non-opaque.
+ unsigned flags = cinfo.fInfo.isOpaque() ? 0 : SkGpuDevice::kNeedClear_Flag;
+
+ // layers are never draw in repeat modes, so we can request an approx
+ // match and ignore any padding.
+ const GrContext::ScratchTexMatch match = (SkBaseDevice::kSaveLayer_Usage == cinfo.fUsage) ?
+ GrContext::kApprox_ScratchTexMatch :
+ GrContext::kExact_ScratchTexMatch;
+ texture.reset(rt->getContext()->refScratchTexture(desc, match));
+
+ if (!texture) {
+ SkDebugf("---- failed to create compatible device texture [%d %d]\n",
+ cinfo.fInfo.width(), cinfo.fInfo.height());
+ return NULL;
+ }
+
+ // This is a factory function for SkGpuDevice (not SkSurface_Gpu, at the moment).
+ // Caller requested new instance of device, so caller owns the ref.
+ SkGpuDevice* device = SkGpuDevice::CreateWithReverseOwnershipDeprecated(
+ texture->asRenderTarget(), &this->props(), flags);
+ if (NULL == device) {
+ return NULL;
+ }
+
+ SkNEW_ARGS(SkSurface_Gpu, (device, kReverseOwnershipDeprecated));
+
+ // Device owns the surface.
+
+ return device;
+}
///////////////////////////////////////////////////////////////////////////////
« no previous file with comments | « src/image/SkSurface_Gpu.h ('k') | src/image/SkSurface_Raster.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698