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