diff options
Diffstat (limited to 'chromium/third_party/skia/src/image/SkSurface_Gpu.cpp')
-rw-r--r-- | chromium/third_party/skia/src/image/SkSurface_Gpu.cpp | 84 |
1 files changed, 51 insertions, 33 deletions
diff --git a/chromium/third_party/skia/src/image/SkSurface_Gpu.cpp b/chromium/third_party/skia/src/image/SkSurface_Gpu.cpp index e673cef6703..a34b774397b 100644 --- a/chromium/third_party/skia/src/image/SkSurface_Gpu.cpp +++ b/chromium/third_party/skia/src/image/SkSurface_Gpu.cpp @@ -14,8 +14,7 @@ class SkSurface_Gpu : public SkSurface_Base { public: SK_DECLARE_INST_COUNT(SkSurface_Gpu) - SkSurface_Gpu(GrContext*, const SkImageInfo&, int sampleCount); - SkSurface_Gpu(GrContext*, GrRenderTarget*); + SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm); virtual ~SkSurface_Gpu(); virtual SkCanvas* onNewCanvas() SK_OVERRIDE; @@ -24,6 +23,7 @@ public: virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, const SkPaint*) SK_OVERRIDE; virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; + virtual void onDiscard() SK_OVERRIDE; private: SkGpuDevice* fDevice; @@ -33,21 +33,12 @@ private: /////////////////////////////////////////////////////////////////////////////// -SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, const SkImageInfo& info, - int sampleCount) - : INHERITED(info.fWidth, info.fHeight) { - SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - - fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, config, info.fWidth, info.fHeight, sampleCount)); - - if (!SkAlphaTypeIsOpaque(info.fAlphaType)) { - fDevice->clear(0x0); - } -} - -SkSurface_Gpu::SkSurface_Gpu(GrContext* ctx, GrRenderTarget* renderTarget) +SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRenderMode trm) : INHERITED(renderTarget->width(), renderTarget->height()) { - fDevice = SkNEW_ARGS(SkGpuDevice, (ctx, renderTarget)); + int flags = 0; + flags |= cached ? SkGpuDevice::kCached_Flag : 0; + flags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFonts_Flag : 0; + fDevice = SkGpuDevice::Create(renderTarget, flags); if (kRGB_565_GrPixelConfig != renderTarget->config()) { fDevice->clear(0x0); @@ -85,44 +76,49 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { // are we sharing our render target with the image? SkASSERT(NULL != this->getCachedImage()); if (rt->asTexture() == SkTextureImageGetTexture(this->getCachedImage())) { + // We call createCompatibleDevice because it uses the texture cache. This isn't + // necessarily correct (http://skbug.com/2252), but never using the cache causes + // a Chromium regression. (http://crbug.com/344020) SkGpuDevice* newDevice = static_cast<SkGpuDevice*>( - fDevice->createCompatibleDevice(fDevice->config(), fDevice->width(), - fDevice->height(), fDevice->isOpaque())); + fDevice->createCompatibleDevice(fDevice->imageInfo())); SkAutoTUnref<SkGpuDevice> aurd(newDevice); if (kRetain_ContentChangeMode == mode) { - fDevice->context()->copyTexture(rt->asTexture(), - reinterpret_cast<GrRenderTarget*>(newDevice->accessRenderTarget())); + fDevice->context()->copyTexture(rt->asTexture(), newDevice->accessRenderTarget()); } SkASSERT(NULL != this->getCachedCanvas()); SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); - this->getCachedCanvas()->setDevice(newDevice); + + this->getCachedCanvas()->setRootDevice(newDevice); SkRefCnt_SafeAssign(fDevice, newDevice); + } else if (kDiscard_ContentChangeMode == mode) { + this->SkSurface_Gpu::onDiscard(); } } +void SkSurface_Gpu::onDiscard() { + fDevice->accessRenderTarget()->discard(); +} + /////////////////////////////////////////////////////////////////////////////// -SkSurface* SkSurface::NewRenderTargetDirect(GrContext* ctx, - GrRenderTarget* target) { - if (NULL == ctx || NULL == target) { +SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMode trm) { + if (NULL == target) { return NULL; } - - return SkNEW_ARGS(SkSurface_Gpu, (ctx, target)); + return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm)); } -SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount) { +SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, int sampleCount, + TextRenderMode trm) { if (NULL == ctx) { return NULL; } - SkBitmap::Config config = SkImageInfoToBitmapConfig(info); - GrTextureDesc desc; desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFlagBit; - desc.fWidth = info.fWidth; - desc.fHeight = info.fHeight; - desc.fConfig = SkBitmapConfig2GrPixelConfig(config); + desc.fWidth = info.width(); + desc.fHeight = info.height(); + desc.fConfig = SkImageInfo2GrPixelConfig(info); desc.fSampleCnt = sampleCount; SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); @@ -130,5 +126,27 @@ SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i return NULL; } - return SkNEW_ARGS(SkSurface_Gpu, (ctx, tex->asRenderTarget())); + return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm)); +} + +SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& info, + int sampleCount, TextRenderMode trm) { + if (NULL == ctx) { + return NULL; + } + + GrTextureDesc desc; + desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFlagBit; + desc.fWidth = info.width(); + desc.fHeight = info.height(); + desc.fConfig = SkImageInfo2GrPixelConfig(info); + desc.fSampleCnt = sampleCount; + + SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::kExact_ScratchTexMatch)); + + if (NULL == tex) { + return NULL; + } + + return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm)); } |