| 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*, const SkSurfaceProps*, bool doClear); | 17 SkSurface_Gpu(GrRenderTarget*, bool cached, const SkSurfaceProps*, bool doCl
ear); |
| 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 virtual void onDiscard() SK_OVERRIDE; | 26 virtual void onDiscard() SK_OVERRIDE; |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 SkGpuDevice* fDevice; | 29 SkGpuDevice* fDevice; |
| 30 | 30 |
| 31 typedef SkSurface_Base INHERITED; | 31 typedef SkSurface_Base INHERITED; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
| 35 | 35 |
| 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, const SkSurfaceProps*
props, bool doClear) | 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, const Sk
SurfaceProps* props, |
| 37 bool doClear) |
| 37 : INHERITED(renderTarget->width(), renderTarget->height(), props) | 38 : INHERITED(renderTarget->width(), renderTarget->height(), props) |
| 38 { | 39 { |
| 39 int deviceFlags = 0; | 40 int deviceFlags = 0; |
| 41 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; |
| 40 deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFon
ts_Flag : 0; | 42 deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFon
ts_Flag : 0; |
| 41 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags); | 43 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags); |
| 42 | 44 |
| 43 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) { | 45 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) { |
| 44 fDevice->clear(0x0); | 46 fDevice->clear(0x0); |
| 45 } | 47 } |
| 46 } | 48 } |
| 47 | 49 |
| 48 SkSurface_Gpu::~SkSurface_Gpu() { | 50 SkSurface_Gpu::~SkSurface_Gpu() { |
| 49 SkSafeUnref(fDevice); | 51 SkSafeUnref(fDevice); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 void SkSurface_Gpu::onDiscard() { | 104 void SkSurface_Gpu::onDiscard() { |
| 103 fDevice->accessRenderTarget()->discard(); | 105 fDevice->accessRenderTarget()->discard(); |
| 104 } | 106 } |
| 105 | 107 |
| 106 /////////////////////////////////////////////////////////////////////////////// | 108 /////////////////////////////////////////////////////////////////////////////// |
| 107 | 109 |
| 108 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf
aceProps* props) { | 110 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf
aceProps* props) { |
| 109 if (NULL == target) { | 111 if (NULL == target) { |
| 110 return NULL; | 112 return NULL; |
| 111 } | 113 } |
| 112 return SkNEW_ARGS(SkSurface_Gpu, (target, props, false)); | 114 return SkNEW_ARGS(SkSurface_Gpu, (target, false, props, false)); |
| 113 } | 115 } |
| 114 | 116 |
| 115 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, | 117 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, |
| 116 const SkSurfaceProps* props) { | 118 const SkSurfaceProps* props) { |
| 117 if (NULL == ctx) { | 119 if (NULL == ctx) { |
| 118 return NULL; | 120 return NULL; |
| 119 } | 121 } |
| 120 | 122 |
| 121 GrTextureDesc desc; | 123 GrTextureDesc desc; |
| 122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 124 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
| 123 desc.fWidth = info.width(); | 125 desc.fWidth = info.width(); |
| 124 desc.fHeight = info.height(); | 126 desc.fHeight = info.height(); |
| 125 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 127 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 126 desc.fSampleCnt = sampleCount; | 128 desc.fSampleCnt = sampleCount; |
| 127 | 129 |
| 128 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 130 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
| 129 if (NULL == tex) { | 131 if (NULL == tex) { |
| 130 return NULL; | 132 return NULL; |
| 131 } | 133 } |
| 132 | 134 |
| 133 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true)); | 135 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, props, true)
); |
| 134 } | 136 } |
| 135 | 137 |
| 136 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, | 138 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, |
| 137 int sampleCount, const SkSurfacePro
ps* props) { | 139 int sampleCount, const SkSurfacePro
ps* props) { |
| 138 if (NULL == ctx) { | 140 if (NULL == ctx) { |
| 139 return NULL; | 141 return NULL; |
| 140 } | 142 } |
| 141 | 143 |
| 142 GrTextureDesc desc; | 144 GrTextureDesc desc; |
| 143 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 145 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
| 144 desc.fWidth = info.width(); | 146 desc.fWidth = info.width(); |
| 145 desc.fHeight = info.height(); | 147 desc.fHeight = info.height(); |
| 146 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 148 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 147 desc.fSampleCnt = sampleCount; | 149 desc.fSampleCnt = sampleCount; |
| 148 | 150 |
| 149 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 151 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
| 150 | 152 |
| 151 if (NULL == tex) { | 153 if (NULL == tex) { |
| 152 return NULL; | 154 return NULL; |
| 153 } | 155 } |
| 154 | 156 |
| 155 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), props, true)); | 157 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, props, true))
; |
| 156 } | 158 } |
| OLD | NEW |