| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkSurface_Gpu.h" | 8 #include "SkSurface_Gpu.h" |
| 9 | 9 |
| 10 #include "GrGpuResourcePriv.h" | 10 #include "GrGpuResourcePriv.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkGpuDevice.h" | 12 #include "SkGpuDevice.h" |
| 13 #include "SkImage_Base.h" | 13 #include "SkImage_Base.h" |
| 14 #include "SkImagePriv.h" | 14 #include "SkImagePriv.h" |
| 15 #include "SkSurface_Base.h" | 15 #include "SkSurface_Base.h" |
| 16 | 16 |
| 17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 | 18 |
| 19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 | 20 |
| 21 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) | 21 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device) |
| 22 : INHERITED(device->width(), device->height(), &device->surfaceProps()) | 22 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
| 23 , fDevice(SkRef(device)) { | 23 , fDevice(SkRef(device)) |
| 24 , fOwnsDevice(true) { |
| 25 fDevice->setSurface(this); |
| 26 } |
| 27 |
| 28 |
| 29 SkSurface_Gpu::SkSurface_Gpu(SkGpuDevice* device, ReverseOwnershipDeprecated) |
| 30 : INHERITED(device->width(), device->height(), &device->surfaceProps()) |
| 31 , fDevice(device) |
| 32 , fOwnsDevice(false) { |
| 33 fDevice->setSurface(this); |
| 24 } | 34 } |
| 25 | 35 |
| 26 SkSurface_Gpu::~SkSurface_Gpu() { | 36 SkSurface_Gpu::~SkSurface_Gpu() { |
| 27 fDevice->unref(); | 37 if (fOwnsDevice) { |
| 38 fDevice->unref(); |
| 39 } |
| 28 } | 40 } |
| 29 | 41 |
| 30 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 42 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 31 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 43 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 32 // When we think this works... | 44 // When we think this works... |
| 33 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 45 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 34 | 46 |
| 35 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); | 47 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); |
| 36 } | 48 } |
| 37 | 49 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 desc.fConfig = SkImageInfo2GrPixelConfig(newInfo); | 138 desc.fConfig = SkImageInfo2GrPixelConfig(newInfo); |
| 127 desc.fSampleCnt = sampleCount; | 139 desc.fSampleCnt = sampleCount; |
| 128 GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL,
0); | 140 GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL,
0); |
| 129 if (NULL == texture) { | 141 if (NULL == texture) { |
| 130 return NULL; | 142 return NULL; |
| 131 } | 143 } |
| 132 SkASSERT(NULL != texture->asRenderTarget()); | 144 SkASSERT(NULL != texture->asRenderTarget()); |
| 133 return texture->asRenderTarget(); | 145 return texture->asRenderTarget(); |
| 134 } | 146 } |
| 135 | 147 |
| 148 SkGpuDevice* SkSurface_Gpu::createCompatibleDeviceDeprecated( |
| 149 const SkBaseDevice::CreateInfo& cinfo) { |
| 150 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 151 GrSurfaceDesc desc; |
| 152 desc.fConfig = rt->config(); |
| 153 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 154 desc.fWidth = cinfo.fInfo.width(); |
| 155 desc.fHeight = cinfo.fInfo.height(); |
| 156 desc.fSampleCnt = rt->numSamples(); |
| 157 |
| 158 SkAutoTUnref<GrTexture> texture; |
| 159 // Skia's convention is to only clear a device if it is non-opaque. |
| 160 unsigned flags = cinfo.fInfo.isOpaque() ? 0 : SkGpuDevice::kNeedClear_Flag; |
| 161 |
| 162 // layers are never draw in repeat modes, so we can request an approx |
| 163 // match and ignore any padding. |
| 164 const GrContext::ScratchTexMatch match = (SkBaseDevice::kSaveLayer_Usage ==
cinfo.fUsage) ? |
| 165 GrContext::kApprox_ScratchTexMat
ch : |
| 166 GrContext::kExact_ScratchTexMatc
h; |
| 167 texture.reset(rt->getContext()->refScratchTexture(desc, match)); |
| 168 |
| 169 if (!texture) { |
| 170 SkDebugf("---- failed to create compatible device texture [%d %d]\n", |
| 171 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 172 return NULL; |
| 173 } |
| 174 |
| 175 // This is a factory function for SkGpuDevice (not SkSurface_Gpu, at the mom
ent). |
| 176 // Caller requested new instance of device, so caller owns the ref. |
| 177 SkGpuDevice* device = SkGpuDevice::CreateWithReverseOwnershipDeprecated( |
| 178 texture->asRenderTarget(), &this->props(), flags); |
| 179 if (NULL == device) { |
| 180 return NULL; |
| 181 } |
| 182 |
| 183 SkNEW_ARGS(SkSurface_Gpu, (device, kReverseOwnershipDeprecated)); |
| 184 |
| 185 // Device owns the surface. |
| 186 |
| 187 return device; |
| 188 } |
| 136 | 189 |
| 137 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// |
| 138 | 191 |
| 139 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf
aceProps* props) { | 192 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf
aceProps* props) { |
| 140 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target, props)); | 193 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target, props)); |
| 141 if (!device) { | 194 if (!device) { |
| 142 return NULL; | 195 return NULL; |
| 143 } | 196 } |
| 144 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 197 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 145 } | 198 } |
| 146 | 199 |
| 147 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, Budgeted budgeted, const S
kImageInfo& info, | 200 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, Budgeted budgeted, const S
kImageInfo& info, |
| 148 int sampleCount, const SkSurfaceProps* pro
ps) { | 201 int sampleCount, const SkSurfaceProps* pro
ps) { |
| 149 SkAutoTUnref<GrRenderTarget> rt(SkSurface_Gpu::CreateRenderTarget(ctx, budge
ted, info, | 202 SkAutoTUnref<GrRenderTarget> rt(SkSurface_Gpu::CreateRenderTarget(ctx, budge
ted, info, |
| 150 sampleCoun
t)); | 203 sampleCoun
t)); |
| 151 if (NULL == rt) { | 204 if (NULL == rt) { |
| 152 return NULL; | 205 return NULL; |
| 153 } | 206 } |
| 154 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, SkGpuDevice:
:kNeedClear_Flag)); | 207 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, SkGpuDevice:
:kNeedClear_Flag)); |
| 155 if (NULL == device) { | 208 if (NULL == device) { |
| 156 return NULL; | 209 return NULL; |
| 157 } | 210 } |
| 158 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 211 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 159 } | 212 } |
| 160 | 213 |
| 161 #endif | 214 #endif |
| 162 | 215 |
| OLD | NEW |