SkASSERT(fTexture->asRenderTarget());
- sk_sp<SkGpuDevice> device(SkGpuDevice::Create(fTexture->asRenderTarget(), width, height,
- props,
- SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(fTexture->asRenderTarget()),
+ width, height, props,
+ SkGpuDevice::kUninit_InitContents));
if (!device) {
return;
}
return true;
}
-SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, const SkSurfaceProps* props,
- InitContents init) {
- return SkGpuDevice::Create(rt, rt->width(), rt->height(), props, init);
+sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* props,
+ InitContents init) {
+ const int width = rt->width();
+ const int height = rt->height();
+ return SkGpuDevice::Make(std::move(rt), width, height, props, init);
}
-SkGpuDevice* SkGpuDevice::Create(GrRenderTarget* rt, int width, int height,
- const SkSurfaceProps* props, InitContents init) {
+sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, int width, int height,
+ const SkSurfaceProps* props, InitContents init) {
if (!rt || rt->wasDestroyed()) {
return nullptr;
}
if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) {
return nullptr;
}
- return new SkGpuDevice(rt, width, height, props, flags);
+ return sk_sp<SkGpuDevice>(new SkGpuDevice(rt.get(), width, height, props, flags));
}
-SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkBudgeted budgeted,
- const SkImageInfo& info, int sampleCount,
- const SkSurfaceProps* props, InitContents init) {
+sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
+ const SkImageInfo& info, int sampleCount,
+ const SkSurfaceProps* props, InitContents init) {
unsigned flags;
if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) {
return nullptr;
}
SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info, sampleCount));
- if (nullptr == rt) {
+ if (!rt) {
return nullptr;
}
- return new SkGpuDevice(rt, info.width(), info.height(), props, flags);
+ return sk_sp<SkGpuDevice>(new SkGpuDevice(rt, info.width(), info.height(), props, flags));
}
SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height,
if (texture) {
SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry);
- return SkGpuDevice::Create(
- texture->asRenderTarget(), cinfo.fInfo.width(), cinfo.fInfo.height(), &props, init);
+ return SkGpuDevice::Make(sk_ref_sp(texture->asRenderTarget()),
+ cinfo.fInfo.width(), cinfo.fInfo.height(),
+ &props, init).release();
} else {
SkErrorInternals::SetError( kInternalError_SkError,
"---- failed to create gpu device texture [%d %d]\n",
/**
* Creates an SkGpuDevice from a GrRenderTarget.
*/
- static SkGpuDevice* Create(GrRenderTarget* target, const SkSurfaceProps*, InitContents);
+ static sk_sp<SkGpuDevice> Make(sk_sp<GrRenderTarget> target,
+ const SkSurfaceProps*,
+ InitContents);
/**
* Creates an SkGpuDevice from a GrRenderTarget whose texture width/height is
* different than its actual width/height (e.g., approx-match scratch texture).
*/
- static SkGpuDevice* Create(GrRenderTarget* target, int width, int height,
- const SkSurfaceProps*, InitContents);
+ static sk_sp<SkGpuDevice> Make(sk_sp<GrRenderTarget> target, int width, int height,
+ const SkSurfaceProps*, InitContents);
/**
* New device that will create an offscreen renderTarget based on the ImageInfo and
* sampleCount. The Budgeted param controls whether the device's backing store counts against
* the resource cache budget. On failure, returns nullptr.
*/
- static SkGpuDevice* Create(GrContext*, SkBudgeted, const SkImageInfo&,
- int sampleCount, const SkSurfaceProps*, InitContents);
+ static sk_sp<SkGpuDevice> Make(GrContext*, SkBudgeted, const SkImageInfo&,
+ int sampleCount, const SkSurfaceProps*, InitContents);
~SkGpuDevice() override {}
#if SK_SUPPORT_GPU
-SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device)
+SkSurface_Gpu::SkSurface_Gpu(sk_sp<SkGpuDevice> device)
: INHERITED(device->width(), device->height(), &device->surfaceProps())
- , fDevice(SkRef(device)) {
+ , fDevice(std::move(device)) {
}
SkSurface_Gpu::~SkSurface_Gpu() {
- fDevice->unref();
}
static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface,
SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags;
flags = static_cast<SkCanvas::InitFlags>(flags | SkCanvas::kConservativeRasterClip_InitFlag);
- return new SkCanvas(fDevice, flags);
+ return new SkCanvas(fDevice.get(), flags);
}
sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) {
sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target,
const SkSurfaceProps* props) {
- SkAutoTUnref<SkGpuDevice> device(
- SkGpuDevice::Create(target, props, SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(
+ SkGpuDevice::Make(sk_ref_sp(target), props, SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
}
- return sk_make_sp<SkSurface_Gpu>(device);
+ return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted,
const SkImageInfo& info, int sampleCount,
const SkSurfaceProps* props) {
- SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Make(
ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitContents));
if (!device) {
return nullptr;
}
- return sk_make_sp<SkSurface_Gpu>(device);
+ return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context,
if (!surface) {
return nullptr;
}
- SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(surface->asRenderTarget(), props,
- SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Make(sk_ref_sp(surface->asRenderTarget()), props,
+ SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
}
- return sk_make_sp<SkSurface_Gpu>(device);
+ return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
const GrBackendRenderTargetDesc& desc,
const SkSurfaceProps* props) {
- if (nullptr == context) {
+ if (!context) {
return nullptr;
}
- SkAutoTUnref<GrRenderTarget> rt(context->textureProvider()->wrapBackendRenderTarget(desc));
+ sk_sp<GrRenderTarget> rt(context->textureProvider()->wrapBackendRenderTarget(desc));
if (!rt) {
return nullptr;
}
- SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props,
- SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
+ SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
}
- return sk_make_sp<SkSurface_Gpu>(device);
+ return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context,
const GrBackendTextureDesc& desc,
const SkSurfaceProps* props) {
- if (nullptr == context) {
+ if (!context) {
return nullptr;
}
- SkAutoTUnref<GrRenderTarget> rt(
- context->resourceProvider()->wrapBackendTextureAsRenderTarget(desc));
+ sk_sp<GrRenderTarget> rt(context->resourceProvider()->wrapBackendTextureAsRenderTarget(desc));
if (!rt) {
return nullptr;
}
- SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props,
- SkGpuDevice::kUninit_InitContents));
+ sk_sp<SkGpuDevice> device(SkGpuDevice::Make(std::move(rt), props,
+ SkGpuDevice::kUninit_InitContents));
if (!device) {
return nullptr;
}
- return sk_make_sp<SkSurface_Gpu>(device);
+ return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
#endif
class SkSurface_Gpu : public SkSurface_Base {
public:
- SkSurface_Gpu(SkGpuDevice*);
+ SkSurface_Gpu(sk_sp<SkGpuDevice>);
virtual ~SkSurface_Gpu();
GrBackendObject onGetTextureHandle(BackendHandleAccess) override;
void onDiscard() override;
void onPrepareForExternalIO() override;
- SkGpuDevice* getDevice() { return fDevice; }
+ SkGpuDevice* getDevice() { return fDevice.get(); }
private:
- SkGpuDevice* fDevice;
+ sk_sp<SkGpuDevice> fDevice;
typedef SkSurface_Base INHERITED;
};