Chromium Code Reviews| 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 } | 24 } |
| 25 | 25 |
| 26 SkSurface_Gpu::~SkSurface_Gpu() { | 26 SkSurface_Gpu::~SkSurface_Gpu() { |
| 27 SkSafeUnref(fDevice); | 27 fDevice->unref(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 30 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 31 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 31 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 32 // When we think this works... | 32 // When we think this works... |
| 33 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | 33 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 34 | 34 |
| 35 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); | 35 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); |
| 36 } | 36 } |
| 37 | 37 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 52 as_IB(image)->initWithProps(this->props()); | 52 as_IB(image)->initWithProps(this->props()); |
| 53 } | 53 } |
| 54 return image; | 54 return image; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 57 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 58 const SkPaint* paint) { | 58 const SkPaint* paint) { |
| 59 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 59 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
| 60 } | 60 } |
| 61 | 61 |
| 62 // Create a new SkGpuDevice and, if necessary, copy the contents of the old | 62 // Create a new render target and, if necessary, copy the contents of the old |
| 63 // device into it. Note that this flushes the SkGpuDevice but | 63 // render target into it. Note that this flushes the SkGpuDevice but |
| 64 // doesn't force an OpenGL flush. | 64 // doesn't force an OpenGL flush. |
| 65 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { | 65 void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) { |
| 66 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 66 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 67 // are we sharing our render target with the image? Note this call should ne ver create a new | 67 // are we sharing our render target with the image? Note this call should ne ver create a new |
| 68 // image because onCopyOnWrite is only called when there is a cached image. | 68 // image because onCopyOnWrite is only called when there is a cached image. |
| 69 SkImage* image = this->getCachedImage(kNo_Budgeted); | 69 SkImage* image = this->getCachedImage(kNo_Budgeted); |
| 70 SkASSERT(image); | 70 SkASSERT(image); |
| 71 if (rt->asTexture() == SkTextureImageGetTexture(image)) { | 71 if (rt->asTexture() == SkTextureImageGetTexture(image)) { |
| 72 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); | 72 GrRenderTarget* oldRT = this->fDevice->accessRenderTarget(); |
| 73 SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes _Budgeted : | 73 SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? kYes _Budgeted : |
| 74 kNo_ Budgeted; | 74 kNo_Budgeted; |
| 75 SkAutoTUnref<SkGpuDevice> newDevice( | 75 SkAutoTUnref<GrRenderTarget> newRT( |
| 76 SkGpuDevice::Create(oldRT->getContext(), budgeted, fDevice->imageInf o(), | 76 SkGpuDevice::CreateRenderTarget(oldRT->getContext(), budgeted, fDevi ce->imageInfo(), |
| 77 oldRT->numSamples(), &this->props(), 0)); | 77 oldRT->numSamples())); |
| 78 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newDe vice) { | 78 |
| 79 oldRT->getContext()->copySurface(newDevice->accessRenderTarget(), ol dRT); | 79 if (kRetain_ContentChangeMode == mode && !oldRT->wasDestroyed() && newRT ) { |
| 80 oldRT->getContext()->copySurface(newRT, oldRT); | |
| 80 } | 81 } |
| 81 | 82 |
| 82 SkASSERT(this->getCachedCanvas()); | 83 SkASSERT(this->getCachedCanvas()); |
| 83 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); | 84 SkASSERT(this->getCachedCanvas()->getDevice() == fDevice); |
| 84 | 85 |
| 85 this->getCachedCanvas()->setRootDevice(newDevice); | 86 this->fDevice->swapRenderTarget(newRT); |
| 86 SkRefCnt_SafeAssign(fDevice, newDevice.get()); | |
| 87 | 87 |
| 88 SkTextureImageApplyBudgetedDecision(image); | 88 SkTextureImageApplyBudgetedDecision(image); |
| 89 } else if (kDiscard_ContentChangeMode == mode) { | 89 } else if (kDiscard_ContentChangeMode == mode) { |
| 90 this->SkSurface_Gpu::onDiscard(); | 90 this->SkSurface_Gpu::onDiscard(); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void SkSurface_Gpu::onDiscard() { | 94 void SkSurface_Gpu::onDiscard() { |
| 95 fDevice->accessRenderTarget()->discard(); | 95 fDevice->accessRenderTarget()->discard(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 | |
| 98 /////////////////////////////////////////////////////////////////////////////// | 99 /////////////////////////////////////////////////////////////////////////////// |
| 99 | 100 |
| 100 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf aceProps* props) { | 101 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf aceProps* props) { |
| 101 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target, props)); | 102 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(target, props)); |
| 102 if (!device) { | 103 if (!device) { |
| 103 return NULL; | 104 return NULL; |
| 104 } | 105 } |
| 105 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 106 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, Budgeted budgeted, const S kImageInfo& info, | 109 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, Budgeted budgeted, const S kImageInfo& info, |
| 109 int sampleCount, const SkSurfaceProps* pro ps) { | 110 int sampleCount, const SkSurfaceProps* pro ps) { |
| 110 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(ctx, budgeted, info, sa mpleCount, props, | 111 SkAutoTUnref<GrRenderTarget> rt(SkGpuDevice::CreateRenderTarget(ctx, budgete d, info, |
|
bsalomon
2015/02/18 14:29:37
It seems a tad unfortunate to require this two ste
Kimmo Kinnunen
2015/02/18 15:06:46
Yeah.. Once the texture creation succeeds, the SkG
Kimmo Kinnunen
2015/02/19 15:52:18
Done.
| |
| 111 SkGpuDevice::kNeedClear _Flag)); | 112 sampleCount) ); |
| 112 if (!device) { | 113 if (NULL == rt) { |
| 114 return NULL; | |
| 115 } | |
| 116 SkAutoTUnref<SkGpuDevice> device(SkGpuDevice::Create(rt, props, SkGpuDevice: :kNeedClear_Flag)); | |
| 117 if (NULL == device) { | |
| 113 return NULL; | 118 return NULL; |
| 114 } | 119 } |
| 115 return SkNEW_ARGS(SkSurface_Gpu, (device)); | 120 return SkNEW_ARGS(SkSurface_Gpu, (device)); |
| 116 } | 121 } |
| 117 | 122 |
| 118 #endif | 123 #endif |
| OLD | NEW |