| 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_Base.h" | 8 #include "SkSurface_Base.h" | 
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" | 
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" | 
| 11 #include "SkGpuDevice.h" | 11 #include "SkGpuDevice.h" | 
| 12 | 12 | 
| 13 class SkSurface_Gpu : public SkSurface_Base { | 13 class SkSurface_Gpu : public SkSurface_Base { | 
| 14 public: | 14 public: | 
| 15     SK_DECLARE_INST_COUNT(SkSurface_Gpu) | 15     SK_DECLARE_INST_COUNT(SkSurface_Gpu) | 
| 16 | 16 | 
| 17     SkSurface_Gpu(GrRenderTarget*); | 17     SkSurface_Gpu(GrRenderTarget*, bool cached); | 
| 18     virtual ~SkSurface_Gpu(); | 18     virtual ~SkSurface_Gpu(); | 
| 19 | 19 | 
| 20     virtual SkCanvas* onNewCanvas() SK_OVERRIDE; | 20     virtual SkCanvas* onNewCanvas() SK_OVERRIDE; | 
| 21     virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; | 21     virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; | 
| 22     virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; | 22     virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; | 
| 23     virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, | 23     virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, | 
| 24                         const SkPaint*) SK_OVERRIDE; | 24                         const SkPaint*) SK_OVERRIDE; | 
| 25     virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; | 25     virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; | 
| 26 | 26 | 
| 27 private: | 27 private: | 
| 28     SkGpuDevice* fDevice; | 28     SkGpuDevice* fDevice; | 
| 29 | 29 | 
| 30     typedef SkSurface_Base INHERITED; | 30     typedef SkSurface_Base INHERITED; | 
| 31 }; | 31 }; | 
| 32 | 32 | 
| 33 /////////////////////////////////////////////////////////////////////////////// | 33 /////////////////////////////////////////////////////////////////////////////// | 
| 34 | 34 | 
| 35 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget) | 35 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached) | 
| 36         : INHERITED(renderTarget->width(), renderTarget->height()) { | 36         : INHERITED(renderTarget->width(), renderTarget->height()) { | 
| 37     fDevice = SkNEW_ARGS(SkGpuDevice, (renderTarget->getContext(), renderTarget)
     ); | 37     fDevice = SkGpuDevice::Create(renderTarget, cached ? SkGpuDevice::kCached_Fl
     ag : 0); | 
| 38 | 38 | 
| 39     if (kRGB_565_GrPixelConfig != renderTarget->config()) { | 39     if (kRGB_565_GrPixelConfig != renderTarget->config()) { | 
| 40         fDevice->clear(0x0); | 40         fDevice->clear(0x0); | 
| 41     } | 41     } | 
| 42 } | 42 } | 
| 43 | 43 | 
| 44 SkSurface_Gpu::~SkSurface_Gpu() { | 44 SkSurface_Gpu::~SkSurface_Gpu() { | 
| 45     SkSafeUnref(fDevice); | 45     SkSafeUnref(fDevice); | 
| 46 } | 46 } | 
| 47 | 47 | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 88         SkRefCnt_SafeAssign(fDevice, newDevice); | 88         SkRefCnt_SafeAssign(fDevice, newDevice); | 
| 89     } | 89     } | 
| 90 } | 90 } | 
| 91 | 91 | 
| 92 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// | 
| 93 | 93 | 
| 94 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { | 94 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target) { | 
| 95     if (NULL == target) { | 95     if (NULL == target) { | 
| 96         return NULL; | 96         return NULL; | 
| 97     } | 97     } | 
| 98     return SkNEW_ARGS(SkSurface_Gpu, (target)); | 98     return SkNEW_ARGS(SkSurface_Gpu, (target, false)); | 
| 99 } | 99 } | 
| 100 | 100 | 
| 101 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
     nt sampleCount) { | 101 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
     nt sampleCount) { | 
| 102     if (NULL == ctx) { | 102     if (NULL == ctx) { | 
| 103         return NULL; | 103         return NULL; | 
| 104     } | 104     } | 
| 105 | 105 | 
| 106     SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | 106     SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | 
| 107 | 107 | 
| 108     GrTextureDesc desc; | 108     GrTextureDesc desc; | 
| 109     desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
     gBit; | 109     desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
     gBit; | 
| 110     desc.fWidth = info.fWidth; | 110     desc.fWidth = info.fWidth; | 
| 111     desc.fHeight = info.fHeight; | 111     desc.fHeight = info.fHeight; | 
| 112     desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 112     desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 
| 113     desc.fSampleCnt = sampleCount; | 113     desc.fSampleCnt = sampleCount; | 
| 114 | 114 | 
| 115     SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 115     SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 
| 116     if (NULL == tex) { | 116     if (NULL == tex) { | 
| 117         return NULL; | 117         return NULL; | 
| 118     } | 118     } | 
| 119 | 119 | 
| 120     return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget())); | 120     return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false)); | 
| 121 } | 121 } | 
|  | 122 | 
|  | 123 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo& 
     info, int sampleCount) { | 
|  | 124     if (NULL == ctx) { | 
|  | 125         return NULL; | 
|  | 126     } | 
|  | 127 | 
|  | 128     SkBitmap::Config config = SkImageInfoToBitmapConfig(info); | 
|  | 129 | 
|  | 130     GrTextureDesc desc; | 
|  | 131     desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
     gBit; | 
|  | 132     desc.fWidth = info.fWidth; | 
|  | 133     desc.fHeight = info.fHeight; | 
|  | 134     desc.fConfig = SkBitmapConfig2GrPixelConfig(config); | 
|  | 135     desc.fSampleCnt = sampleCount; | 
|  | 136 | 
|  | 137     SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
     Exact_ScratchTexMatch)); | 
|  | 138 | 
|  | 139     if (NULL == tex) { | 
|  | 140         return NULL; | 
|  | 141     } | 
|  | 142 | 
|  | 143     return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true)); | 
|  | 144 } | 
| OLD | NEW | 
|---|