| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
| 9 | 9 |
| 10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 if (kClear_InitContents == init) { | 124 if (kClear_InitContents == init) { |
| 125 *flags |= kNeedClear_Flag; | 125 *flags |= kNeedClear_Flag; |
| 126 } | 126 } |
| 127 return true; | 127 return true; |
| 128 } | 128 } |
| 129 | 129 |
| 130 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfacePr
ops* props, | 130 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, const SkSurfacePr
ops* props, |
| 131 InitContents init) { | 131 InitContents init) { |
| 132 const int width = rt->width(); | 132 if (!rt || rt->wasDestroyed() || !rt->getContext()) { |
| 133 const int height = rt->height(); | |
| 134 return SkGpuDevice::Make(std::move(rt), width, height, props, init); | |
| 135 } | |
| 136 | |
| 137 sk_sp<SkGpuDevice> SkGpuDevice::Make(sk_sp<GrRenderTarget> rt, int width, int he
ight, | |
| 138 const SkSurfaceProps* props, InitContents i
nit) { | |
| 139 if (!rt || rt->wasDestroyed()) { | |
| 140 return nullptr; | 133 return nullptr; |
| 141 } | 134 } |
| 142 unsigned flags; | 135 unsigned flags; |
| 143 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { | 136 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 144 return nullptr; | 137 return nullptr; |
| 145 } | 138 } |
| 146 return sk_sp<SkGpuDevice>(new SkGpuDevice(rt.get(), width, height, props, fl
ags)); | 139 |
| 140 const int width = rt->width(); |
| 141 const int height = rt->height(); |
| 142 |
| 143 GrContext* context = rt->getContext(); |
| 144 |
| 145 sk_sp<GrDrawContext> drawContext(context->drawContext(std::move(rt), props))
; |
| 146 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), width, hei
ght, flags)); |
| 147 } |
| 148 |
| 149 sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, |
| 150 int width, int height, |
| 151 InitContents init) { |
| 152 if (!drawContext || drawContext->wasAbandoned()) { |
| 153 return nullptr; |
| 154 } |
| 155 unsigned flags; |
| 156 if (!CheckAlphaTypeAndGetFlags(nullptr, init, &flags)) { |
| 157 return nullptr; |
| 158 } |
| 159 return sk_sp<SkBaseDevice>(new SkGpuDevice(std::move(drawContext), width, he
ight, flags)); |
| 147 } | 160 } |
| 148 | 161 |
| 149 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, | 162 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, |
| 150 const SkImageInfo& info, int sampleCount, | 163 const SkImageInfo& info, int sampleCount, |
| 151 const SkSurfaceProps* props, InitContents i
nit) { | 164 const SkSurfaceProps* props, InitContents i
nit) { |
| 152 unsigned flags; | 165 unsigned flags; |
| 153 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { | 166 if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { |
| 154 return nullptr; | 167 return nullptr; |
| 155 } | 168 } |
| 156 | 169 |
| 157 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); | 170 sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info, |
| 158 if (!rt) { | 171 sampleCount, props)); |
| 172 if (!drawContext) { |
| 159 return nullptr; | 173 return nullptr; |
| 160 } | 174 } |
| 161 | 175 |
| 162 return sk_sp<SkGpuDevice>(new SkGpuDevice(rt, info.width(), info.height(), p
rops, flags)); | 176 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), |
| 177 info.width(), info.height(), flags
)); |
| 163 } | 178 } |
| 164 | 179 |
| 165 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, int width, int height, | 180 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) |
| 166 const SkSurfaceProps* props, unsigned flags) | 181 : INHERITED(drawContext->surfaceProps()) |
| 167 : INHERITED(SkSurfacePropsCopyOrDefault(props)) | 182 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) |
| 168 , fContext(SkRef(rt->getContext())) | 183 , fRenderTarget(drawContext->renderTarget()) |
| 169 , fRenderTarget(SkRef(rt)) { | 184 , fDrawContext(std::move(drawContext)) { |
| 170 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 185 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 171 | 186 |
| 172 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; | 187 SkAlphaType at = fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; |
| 173 SkImageInfo info = rt->surfacePriv().info(at).makeWH(width, height); | 188 SkImageInfo info = fRenderTarget->surfacePriv().info(at).makeWH(width, heigh
t); |
| 174 SkPixelRef* pr = new SkGrPixelRef(info, rt); | 189 SkPixelRef* pr = new SkGrPixelRef(info, fRenderTarget.get()); |
| 175 fLegacyBitmap.setInfo(info); | 190 fLegacyBitmap.setInfo(info); |
| 176 fLegacyBitmap.setPixelRef(pr)->unref(); | 191 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 177 | 192 |
| 178 fDrawContext = this->context()->drawContext(sk_ref_sp(rt), &this->surfacePro
ps()); | |
| 179 if (flags & kNeedClear_Flag) { | 193 if (flags & kNeedClear_Flag) { |
| 180 this->clearAll(); | 194 this->clearAll(); |
| 181 } | 195 } |
| 182 } | 196 } |
| 183 | 197 |
| 184 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkBudgeted b
udgeted, | 198 sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, |
| 185 const SkImageInfo& origInfo, int
sampleCount) { | 199 SkBudgeted budgeted, |
| 200 const SkImageInfo& origInfo, |
| 201 int sampleCount, |
| 202 const SkSurfaceProps* surfac
eProps) { |
| 186 if (kUnknown_SkColorType == origInfo.colorType() || | 203 if (kUnknown_SkColorType == origInfo.colorType() || |
| 187 origInfo.width() < 0 || origInfo.height() < 0) { | 204 origInfo.width() < 0 || origInfo.height() < 0) { |
| 188 return nullptr; | 205 return nullptr; |
| 189 } | 206 } |
| 190 | 207 |
| 191 if (!context) { | 208 if (!context) { |
| 192 return nullptr; | 209 return nullptr; |
| 193 } | 210 } |
| 194 | 211 |
| 195 SkColorType ct = origInfo.colorType(); | 212 SkColorType ct = origInfo.colorType(); |
| 196 SkAlphaType at = origInfo.alphaType(); | 213 SkAlphaType at = origInfo.alphaType(); |
| 197 SkColorProfileType pt = origInfo.profileType(); | 214 SkColorProfileType pt = origInfo.profileType(); |
| 198 if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) { | 215 if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) { |
| 199 at = kOpaque_SkAlphaType; // force this setting | 216 at = kOpaque_SkAlphaType; // force this setting |
| 200 } | 217 } |
| 201 if (kOpaque_SkAlphaType != at) { | 218 if (kOpaque_SkAlphaType != at) { |
| 202 at = kPremul_SkAlphaType; // force this setting | 219 at = kPremul_SkAlphaType; // force this setting |
| 203 } | 220 } |
| 204 | 221 |
| 205 GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, pt, *context->c
aps()); | 222 GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, pt, *context->c
aps()); |
| 206 if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) { | 223 if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) { |
| 207 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 224 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
| 208 ct = kN32_SkColorType; | 225 ct = kN32_SkColorType; |
| 209 } | 226 } |
| 210 | 227 |
| 211 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at, pt); | 228 GrPixelConfig config = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps(
)); |
| 212 | 229 |
| 213 GrSurfaceDesc desc; | 230 return context->newDrawContext(SkBackingFit::kExact, // Why ex
act? |
| 214 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 231 origInfo.width(), origInfo.height(), |
| 215 desc.fWidth = info.width(); | 232 config, sampleCount, |
| 216 desc.fHeight = info.height(); | 233 kDefault_GrSurfaceOrigin, surfaceProps, budge
ted); |
| 217 desc.fConfig = SkImageInfo2GrPixelConfig(info, *context->caps()); | 234 |
| 218 desc.fSampleCnt = sampleCount; | |
| 219 desc.fIsMipMapped = false; | |
| 220 GrTexture* texture = context->textureProvider()->createTexture(desc, budgete
d, nullptr, 0); | |
| 221 if (nullptr == texture) { | |
| 222 return nullptr; | |
| 223 } | |
| 224 SkASSERT(nullptr != texture->asRenderTarget()); | |
| 225 return texture->asRenderTarget(); | |
| 226 } | 235 } |
| 227 | 236 |
| 228 // This method ensures that we always have a texture-backed "bitmap" when we fin
ally | 237 // This method ensures that we always have a texture-backed "bitmap" when we fin
ally |
| 229 // call through to the base impl so that the image filtering code will take the | 238 // call through to the base impl so that the image filtering code will take the |
| 230 // gpu-specific paths. This mirrors SkCanvas::internalDrawDevice (the other | 239 // gpu-specific paths. This mirrors SkCanvas::internalDrawDevice (the other |
| 231 // use of SkImageFilter::filterImage) in that the source and dest will have | 240 // use of SkImageFilter::filterImage) in that the source and dest will have |
| 232 // homogenous backing (e.g., raster or gpu). | 241 // homogenous backing (e.g., raster or gpu). |
| 233 void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma
p, | 242 void SkGpuDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitma
p, |
| 234 int x, int y, const SkPaint& paint) { | 243 int x, int y, const SkPaint& paint) { |
| 235 ASSERT_SINGLE_OWNER | 244 ASSERT_SINGLE_OWNER |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 ASSERT_SINGLE_OWNER | 348 ASSERT_SINGLE_OWNER |
| 340 SkASSERT(fClipStack.get()); | 349 SkASSERT(fClipStack.get()); |
| 341 | 350 |
| 342 SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack); | 351 SkASSERT(draw.fClipStack && draw.fClipStack == fClipStack); |
| 343 | 352 |
| 344 fClip.reset(fClipStack, &this->getOrigin()); | 353 fClip.reset(fClipStack, &this->getOrigin()); |
| 345 } | 354 } |
| 346 | 355 |
| 347 GrRenderTarget* SkGpuDevice::accessRenderTarget() { | 356 GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
| 348 ASSERT_SINGLE_OWNER | 357 ASSERT_SINGLE_OWNER |
| 349 return fRenderTarget; | 358 return fRenderTarget.get(); |
| 350 } | 359 } |
| 351 | 360 |
| 352 GrDrawContext* SkGpuDevice::accessDrawContext() { | 361 GrDrawContext* SkGpuDevice::accessDrawContext() { |
| 353 ASSERT_SINGLE_OWNER | 362 ASSERT_SINGLE_OWNER |
| 354 return fDrawContext.get(); | 363 return fDrawContext.get(); |
| 355 } | 364 } |
| 356 | 365 |
| 357 void SkGpuDevice::clearAll() { | 366 void SkGpuDevice::clearAll() { |
| 358 ASSERT_SINGLE_OWNER | 367 ASSERT_SINGLE_OWNER |
| 359 GrColor color = 0; | 368 GrColor color = 0; |
| 360 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); | 369 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); |
| 361 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 370 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 362 fDrawContext->clear(&rect, color, true); | 371 fDrawContext->clear(&rect, color, true); |
| 363 } | 372 } |
| 364 | 373 |
| 365 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { | 374 void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { |
| 366 ASSERT_SINGLE_OWNER | 375 ASSERT_SINGLE_OWNER |
| 367 | 376 |
| 368 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); | 377 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); |
| 369 | 378 |
| 370 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( | 379 sk_sp<GrDrawContext> newDC(CreateDrawContext(this->context(), |
| 371 this->context(), budgeted, this->imageInfo(), fRenderTarget->desc().fSam
pleCnt)); | 380 budgeted, |
| 372 | 381 this->imageInfo(), |
| 373 if (nullptr == newRT) { | 382 fDrawContext->numColorSamples()
, |
| 383 &this->surfaceProps())); |
| 384 if (!newDC) { |
| 374 return; | 385 return; |
| 375 } | 386 } |
| 376 | 387 |
| 377 if (shouldRetainContent) { | 388 if (shouldRetainContent) { |
| 378 if (fRenderTarget->wasDestroyed()) { | 389 if (fRenderTarget->wasDestroyed()) { |
| 379 return; | 390 return; |
| 380 } | 391 } |
| 381 this->context()->copySurface(newRT, fRenderTarget); | 392 newDC->copySurface(fDrawContext->asTexture().get(), |
| 393 SkIRect::MakeWH(this->width(), this->height()), |
| 394 SkIPoint::Make(0, 0)); |
| 382 } | 395 } |
| 383 | 396 |
| 384 SkASSERT(fRenderTarget != newRT); | 397 SkASSERT(fDrawContext->accessRenderTarget() != newDC->accessRenderTarget()); |
| 385 | 398 |
| 386 fRenderTarget.reset(newRT.release()); | 399 fRenderTarget = newDC->renderTarget(); |
| 387 | 400 |
| 388 #ifdef SK_DEBUG | 401 #ifdef SK_DEBUG |
| 389 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : | 402 SkImageInfo info = fRenderTarget->surfacePriv().info(fOpaque ? kOpaque_SkAlp
haType : |
| 390 kPremul_SkAlp
haType); | 403 kPremul_SkAlp
haType); |
| 391 SkASSERT(info == fLegacyBitmap.info()); | 404 SkASSERT(info == fLegacyBitmap.info()); |
| 392 #endif | 405 #endif |
| 393 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget); | 406 SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget.get())
; |
| 394 fLegacyBitmap.setPixelRef(pr)->unref(); | 407 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 395 | 408 |
| 396 fDrawContext = this->context()->drawContext(sk_ref_sp(fRenderTarget.get()), | 409 fDrawContext = newDC; |
| 397 &this->surfaceProps()); | |
| 398 } | 410 } |
| 399 | 411 |
| 400 /////////////////////////////////////////////////////////////////////////////// | 412 /////////////////////////////////////////////////////////////////////////////// |
| 401 | 413 |
| 402 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 414 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 403 ASSERT_SINGLE_OWNER | 415 ASSERT_SINGLE_OWNER |
| 404 CHECK_SHOULD_DRAW(draw); | 416 CHECK_SHOULD_DRAW(draw); |
| 405 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); | 417 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); |
| 406 | 418 |
| 407 GrPaint grPaint; | 419 GrPaint grPaint; |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1324 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 1313 int x, int y, const SkPaint& paint) { | 1325 int x, int y, const SkPaint& paint) { |
| 1314 ASSERT_SINGLE_OWNER | 1326 ASSERT_SINGLE_OWNER |
| 1315 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1327 // clear of the source device must occur before CHECK_SHOULD_DRAW |
| 1316 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); | 1328 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDevice", fContext); |
| 1317 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | 1329 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
| 1318 | 1330 |
| 1319 // drawDevice is defined to be in device coords. | 1331 // drawDevice is defined to be in device coords. |
| 1320 CHECK_SHOULD_DRAW(draw); | 1332 CHECK_SHOULD_DRAW(draw); |
| 1321 | 1333 |
| 1322 GrRenderTarget* devRT = dev->accessRenderTarget(); | 1334 sk_sp<GrTexture> devTex(dev->accessDrawContext()->asTexture()); |
| 1323 GrTexture* devTex; | 1335 if (!devTex) { |
| 1324 if (nullptr == (devTex = devRT->asTexture())) { | |
| 1325 return; | 1336 return; |
| 1326 } | 1337 } |
| 1327 | 1338 |
| 1328 const SkImageInfo ii = dev->imageInfo(); | 1339 const SkImageInfo ii = dev->imageInfo(); |
| 1329 int w = ii.width(); | 1340 int w = ii.width(); |
| 1330 int h = ii.height(); | 1341 int h = ii.height(); |
| 1331 | 1342 |
| 1332 SkASSERT(!paint.getImageFilter()); | 1343 SkASSERT(!paint.getImageFilter()); |
| 1333 | 1344 |
| 1334 GrPaint grPaint; | 1345 GrPaint grPaint; |
| 1335 SkAutoTUnref<const GrFragmentProcessor> fp( | 1346 SkAutoTUnref<const GrFragmentProcessor> fp( |
| 1336 GrSimpleTextureEffect::Create(devTex, SkMatrix::I())); | 1347 GrSimpleTextureEffect::Create(devTex.get(), SkMatrix::I())); |
| 1337 if (GrPixelConfigIsAlphaOnly(devTex->config())) { | 1348 if (GrPixelConfigIsAlphaOnly(devTex->config())) { |
| 1338 // Can this happen? | 1349 // Can this happen? |
| 1339 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); | 1350 fp.reset(GrFragmentProcessor::MulOutputByInputUnpremulColor(fp)); |
| 1340 } else { | 1351 } else { |
| 1341 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); | 1352 fp.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp)); |
| 1342 } | 1353 } |
| 1343 | 1354 |
| 1344 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, | 1355 if (!SkPaintToGrPaintReplaceShader(this->context(), paint, fp, |
| 1345 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { | 1356 this->surfaceProps().isGammaCorrect(), &g
rPaint)) { |
| 1346 return; | 1357 return; |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 void SkGpuDevice::flush() { | 1739 void SkGpuDevice::flush() { |
| 1729 ASSERT_SINGLE_OWNER | 1740 ASSERT_SINGLE_OWNER |
| 1730 | 1741 |
| 1731 fRenderTarget->prepareForExternalIO(); | 1742 fRenderTarget->prepareForExternalIO(); |
| 1732 } | 1743 } |
| 1733 | 1744 |
| 1734 /////////////////////////////////////////////////////////////////////////////// | 1745 /////////////////////////////////////////////////////////////////////////////// |
| 1735 | 1746 |
| 1736 SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
*) { | 1747 SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
*) { |
| 1737 ASSERT_SINGLE_OWNER | 1748 ASSERT_SINGLE_OWNER |
| 1738 GrSurfaceDesc desc; | |
| 1739 desc.fConfig = fRenderTarget->config(); | |
| 1740 desc.fFlags = kRenderTarget_GrSurfaceFlag; | |
| 1741 desc.fWidth = cinfo.fInfo.width(); | |
| 1742 desc.fHeight = cinfo.fInfo.height(); | |
| 1743 desc.fSampleCnt = fRenderTarget->desc().fSampleCnt; | |
| 1744 | 1749 |
| 1745 SkAutoTUnref<GrTexture> texture; | 1750 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
| 1751 |
| 1752 // layers are never drawn in repeat modes, so we can request an approx |
| 1753 // match and ignore any padding. |
| 1754 SkBackingFit fit = kNever_TileUsage == cinfo.fTileUsage ? SkBackingFit::kApp
rox |
| 1755 : SkBackingFit::kExa
ct; |
| 1756 |
| 1757 sk_sp<GrDrawContext> dc(fContext->newDrawContext(fit, |
| 1758 cinfo.fInfo.width(), cinfo.
fInfo.height(), |
| 1759 fDrawContext->config(), |
| 1760 fDrawContext->desc().fSampl
eCnt, |
| 1761 kDefault_GrSurfaceOrigin, |
| 1762 &props)); |
| 1763 if (!dc) { |
| 1764 SkErrorInternals::SetError( kInternalError_SkError, |
| 1765 "---- failed to create gpu device texture [%
d %d]\n", |
| 1766 cinfo.fInfo.width(), cinfo.fInfo.height()); |
| 1767 return nullptr; |
| 1768 } |
| 1769 |
| 1746 // Skia's convention is to only clear a device if it is non-opaque. | 1770 // Skia's convention is to only clear a device if it is non-opaque. |
| 1747 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I
nitContents; | 1771 InitContents init = cinfo.fInfo.isOpaque() ? kUninit_InitContents : kClear_I
nitContents; |
| 1748 | 1772 |
| 1749 // layers are never draw in repeat modes, so we can request an approx | 1773 return SkGpuDevice::Make(std::move(dc), |
| 1750 // match and ignore any padding. | 1774 cinfo.fInfo.width(), cinfo.fInfo.height(), |
| 1751 if (kNever_TileUsage == cinfo.fTileUsage) { | 1775 init).release(); |
| 1752 texture.reset(fContext->textureProvider()->createApproxTexture(desc)); | |
| 1753 } else { | |
| 1754 texture.reset(fContext->textureProvider()->createTexture(desc, SkBudgete
d::kYes)); | |
| 1755 } | |
| 1756 | |
| 1757 if (texture) { | |
| 1758 SkSurfaceProps props(this->surfaceProps().flags(), cinfo.fPixelGeometry)
; | |
| 1759 return SkGpuDevice::Make(sk_ref_sp(texture->asRenderTarget()), | |
| 1760 cinfo.fInfo.width(), cinfo.fInfo.height(), | |
| 1761 &props, init).release(); | |
| 1762 } else { | |
| 1763 SkErrorInternals::SetError( kInternalError_SkError, | |
| 1764 "---- failed to create gpu device texture [%
d %d]\n", | |
| 1765 cinfo.fInfo.width(), cinfo.fInfo.height()); | |
| 1766 return nullptr; | |
| 1767 } | |
| 1768 } | 1776 } |
| 1769 | 1777 |
| 1770 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { | 1778 sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa
ceProps& props) { |
| 1771 ASSERT_SINGLE_OWNER | 1779 ASSERT_SINGLE_OWNER |
| 1772 // TODO: Change the signature of newSurface to take a budgeted parameter. | 1780 // TODO: Change the signature of newSurface to take a budgeted parameter. |
| 1773 static const SkBudgeted kBudgeted = SkBudgeted::kNo; | 1781 static const SkBudgeted kBudgeted = SkBudgeted::kNo; |
| 1774 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->
desc().fSampleCnt, | 1782 return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->
desc().fSampleCnt, |
| 1775 &props); | 1783 &props); |
| 1776 } | 1784 } |
| 1777 | 1785 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1849 } | 1857 } |
| 1850 | 1858 |
| 1851 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1859 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1852 ASSERT_SINGLE_OWNER | 1860 ASSERT_SINGLE_OWNER |
| 1853 // We always return a transient cache, so it is freed after each | 1861 // We always return a transient cache, so it is freed after each |
| 1854 // filter traversal. | 1862 // filter traversal. |
| 1855 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1863 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1856 } | 1864 } |
| 1857 | 1865 |
| 1858 #endif | 1866 #endif |
| OLD | NEW |