| 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" |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrContextPriv.h" | 12 #include "GrContextPriv.h" |
| 13 #include "SkDraw.h" | 13 #include "GrDrawContextPriv.h" |
| 14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
| 15 #include "GrGpuResourcePriv.h" | 15 #include "GrGpuResourcePriv.h" |
| 16 #include "GrImageIDTextureAdjuster.h" | 16 #include "GrImageIDTextureAdjuster.h" |
| 17 #include "GrStyle.h" | 17 #include "GrStyle.h" |
| 18 #include "GrTracing.h" | 18 #include "GrTracing.h" |
| 19 |
| 19 #include "SkCanvasPriv.h" | 20 #include "SkCanvasPriv.h" |
| 21 #include "SkDraw.h" |
| 20 #include "SkErrorInternals.h" | 22 #include "SkErrorInternals.h" |
| 21 #include "SkGlyphCache.h" | 23 #include "SkGlyphCache.h" |
| 22 #include "SkGr.h" | 24 #include "SkGr.h" |
| 23 #include "SkGrPriv.h" | 25 #include "SkGrPriv.h" |
| 24 #include "SkImage_Base.h" | 26 #include "SkImage_Base.h" |
| 25 #include "SkImageCacherator.h" | 27 #include "SkImageCacherator.h" |
| 26 #include "SkImageFilter.h" | 28 #include "SkImageFilter.h" |
| 27 #include "SkImageFilterCache.h" | 29 #include "SkImageFilterCache.h" |
| 28 #include "SkLatticeIter.h" | 30 #include "SkLatticeIter.h" |
| 29 #include "SkMaskFilter.h" | 31 #include "SkMaskFilter.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return nullptr; | 142 return nullptr; |
| 141 } | 143 } |
| 142 | 144 |
| 143 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), | 145 return sk_sp<SkGpuDevice>(new SkGpuDevice(std::move(drawContext), |
| 144 info.width(), info.height(), flags
)); | 146 info.width(), info.height(), flags
)); |
| 145 } | 147 } |
| 146 | 148 |
| 147 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) | 149 SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height
, unsigned flags) |
| 148 : INHERITED(drawContext->surfaceProps()) | 150 : INHERITED(drawContext->surfaceProps()) |
| 149 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) | 151 , fContext(SkRef(drawContext->accessRenderTarget()->getContext())) |
| 150 , fRenderTarget(drawContext->renderTarget()) | |
| 151 , fDrawContext(std::move(drawContext)) { | 152 , fDrawContext(std::move(drawContext)) { |
| 152 fSize.set(width, height); | 153 fSize.set(width, height); |
| 153 fOpaque = SkToBool(flags & kIsOpaque_Flag); | 154 fOpaque = SkToBool(flags & kIsOpaque_Flag); |
| 154 | 155 |
| 155 if (flags & kNeedClear_Flag) { | 156 if (flags & kNeedClear_Flag) { |
| 156 this->clearAll(); | 157 this->clearAll(); |
| 157 } | 158 } |
| 158 } | 159 } |
| 159 | 160 |
| 160 sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context, | 161 sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 223 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 223 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps())
; | 224 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo, *fContext->caps())
; |
| 224 if (kUnknown_GrPixelConfig == config) { | 225 if (kUnknown_GrPixelConfig == config) { |
| 225 return false; | 226 return false; |
| 226 } | 227 } |
| 227 | 228 |
| 228 uint32_t flags = 0; | 229 uint32_t flags = 0; |
| 229 if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { | 230 if (kUnpremul_SkAlphaType == dstInfo.alphaType()) { |
| 230 flags = GrContext::kUnpremul_PixelOpsFlag; | 231 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 231 } | 232 } |
| 232 return fRenderTarget->readPixels(x, y, dstInfo.width(), dstInfo.height(), co
nfig, dstPixels, | 233 return fDrawContext->accessRenderTarget()->readPixels(x, y, |
| 233 dstRowBytes, flags); | 234 dstInfo.width(), dstIn
fo.height(), |
| 235 config, dstPixels, |
| 236 dstRowBytes, flags); |
| 234 } | 237 } |
| 235 | 238 |
| 236 bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, | 239 bool SkGpuDevice::onWritePixels(const SkImageInfo& info, const void* pixels, siz
e_t rowBytes, |
| 237 int x, int y) { | 240 int x, int y) { |
| 238 ASSERT_SINGLE_OWNER | 241 ASSERT_SINGLE_OWNER |
| 239 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 242 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
| 240 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); | 243 GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fContext->caps()); |
| 241 if (kUnknown_GrPixelConfig == config) { | 244 if (kUnknown_GrPixelConfig == config) { |
| 242 return false; | 245 return false; |
| 243 } | 246 } |
| 244 uint32_t flags = 0; | 247 uint32_t flags = 0; |
| 245 if (kUnpremul_SkAlphaType == info.alphaType()) { | 248 if (kUnpremul_SkAlphaType == info.alphaType()) { |
| 246 flags = GrContext::kUnpremul_PixelOpsFlag; | 249 flags = GrContext::kUnpremul_PixelOpsFlag; |
| 247 } | 250 } |
| 248 fRenderTarget->writePixels(x, y, info.width(), info.height(), config, pixels
, rowBytes, flags); | 251 fDrawContext->accessRenderTarget()->writePixels(x, y, info.width(), info.hei
ght(), |
| 249 | 252 config, pixels, rowBytes, fl
ags); |
| 250 return true; | 253 return true; |
| 251 } | 254 } |
| 252 | 255 |
| 253 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { | 256 bool SkGpuDevice::onAccessPixels(SkPixmap* pmap) { |
| 254 ASSERT_SINGLE_OWNER | 257 ASSERT_SINGLE_OWNER |
| 255 return false; | 258 return false; |
| 256 } | 259 } |
| 257 | 260 |
| 258 // call this every draw call, to ensure that the context reflects our state, | 261 // call this every draw call, to ensure that the context reflects our state, |
| 259 // and not the state from some other canvas/device | 262 // and not the state from some other canvas/device |
| (...skipping 12 matching lines...) Expand all Loading... |
| 272 ASSERT_SINGLE_OWNER | 275 ASSERT_SINGLE_OWNER |
| 273 GrColor color = 0; | 276 GrColor color = 0; |
| 274 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); | 277 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext); |
| 275 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 278 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 276 fDrawContext->clear(&rect, color, true); | 279 fDrawContext->clear(&rect, color, true); |
| 277 } | 280 } |
| 278 | 281 |
| 279 void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { | 282 void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { |
| 280 ASSERT_SINGLE_OWNER | 283 ASSERT_SINGLE_OWNER |
| 281 | 284 |
| 282 SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); | 285 SkBudgeted budgeted = fDrawContext->drawContextPriv().isBudgeted(); |
| 283 | 286 |
| 284 sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(), | 287 sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(), |
| 285 budgeted, | 288 budgeted, |
| 286 this->imageInfo(), | 289 this->imageInfo(), |
| 287 fDrawContext->numColorSamples(), | 290 fDrawContext->numColorSamples(), |
| 288 fDrawContext->origin(), | 291 fDrawContext->origin(), |
| 289 &this->surfaceProps())); | 292 &this->surfaceProps())); |
| 290 if (!newDC) { | 293 if (!newDC) { |
| 291 return; | 294 return; |
| 292 } | 295 } |
| 293 | 296 |
| 294 if (shouldRetainContent) { | 297 if (shouldRetainContent) { |
| 295 if (fRenderTarget->wasDestroyed()) { | 298 if (fDrawContext->wasAbandoned()) { |
| 296 return; | 299 return; |
| 297 } | 300 } |
| 298 newDC->copySurface(fDrawContext->asTexture().get(), | 301 newDC->copySurface(fDrawContext->asTexture().get(), |
| 299 SkIRect::MakeWH(this->width(), this->height()), | 302 SkIRect::MakeWH(this->width(), this->height()), |
| 300 SkIPoint::Make(0, 0)); | 303 SkIPoint::Make(0, 0)); |
| 301 } | 304 } |
| 302 | 305 |
| 303 SkASSERT(fDrawContext->accessRenderTarget() != newDC->accessRenderTarget()); | |
| 304 | |
| 305 fRenderTarget = newDC->renderTarget(); | |
| 306 | |
| 307 fDrawContext = newDC; | 306 fDrawContext = newDC; |
| 308 } | 307 } |
| 309 | 308 |
| 310 /////////////////////////////////////////////////////////////////////////////// | 309 /////////////////////////////////////////////////////////////////////////////// |
| 311 | 310 |
| 312 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 311 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 313 ASSERT_SINGLE_OWNER | 312 ASSERT_SINGLE_OWNER |
| 314 CHECK_SHOULD_DRAW(draw); | 313 CHECK_SHOULD_DRAW(draw); |
| 315 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); | 314 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext); |
| 316 | 315 |
| (...skipping 1462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1779 } | 1778 } |
| 1780 | 1779 |
| 1781 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { | 1780 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { |
| 1782 ASSERT_SINGLE_OWNER | 1781 ASSERT_SINGLE_OWNER |
| 1783 // We always return a transient cache, so it is freed after each | 1782 // We always return a transient cache, so it is freed after each |
| 1784 // filter traversal. | 1783 // filter traversal. |
| 1785 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); | 1784 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); |
| 1786 } | 1785 } |
| 1787 | 1786 |
| 1788 #endif | 1787 #endif |
| OLD | NEW |