| 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*, bool cached, const SkSurfaceProps*, bool doCl
ear); | 17 SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm, bool doClear
); |
| 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, bool cached, const Sk
SurfaceProps* props, | 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend
erMode trm, |
| 37 bool doClear) | 37 bool doClear) |
| 38 : INHERITED(renderTarget->width(), renderTarget->height(), props) | 38 : INHERITED(renderTarget->width(), renderTarget->height()) { |
| 39 { | |
| 40 int deviceFlags = 0; | 39 int deviceFlags = 0; |
| 41 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; | 40 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; |
| 42 deviceFlags |= this->props().isUseDistanceFieldFonts() ? SkGpuDevice::kDFFon
ts_Flag : 0; | 41 deviceFlags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFont
s_Flag : 0; |
| 43 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags); | 42 fDevice = SkGpuDevice::Create(renderTarget, deviceFlags); |
| 44 | 43 |
| 45 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) { | 44 if (kRGB_565_GrPixelConfig != renderTarget->config() && doClear) { |
| 46 fDevice->clear(0x0); | 45 fDevice->clear(0x0); |
| 47 } | 46 } |
| 48 } | 47 } |
| 49 | 48 |
| 50 SkSurface_Gpu::~SkSurface_Gpu() { | 49 SkSurface_Gpu::~SkSurface_Gpu() { |
| 51 SkSafeUnref(fDevice); | 50 SkSafeUnref(fDevice); |
| 52 } | 51 } |
| 53 | 52 |
| 54 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 53 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
| 55 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; | 54 return SkNEW_ARGS(SkCanvas, (fDevice)); |
| 56 // When we think this works... | |
| 57 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; | |
| 58 | |
| 59 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); | |
| 60 } | 55 } |
| 61 | 56 |
| 62 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 57 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
| 63 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 58 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
| 64 int sampleCount = rt->numSamples(); | 59 int sampleCount = rt->numSamples(); |
| 65 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount, &th
is->props()); | 60 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); |
| 66 } | 61 } |
| 67 | 62 |
| 68 SkImage* SkSurface_Gpu::onNewImageSnapshot() { | 63 SkImage* SkSurface_Gpu::onNewImageSnapshot() { |
| 69 return SkImage::NewTexture(fDevice->accessBitmap(false)); | 64 return SkImage::NewTexture(fDevice->accessBitmap(false)); |
| 70 } | 65 } |
| 71 | 66 |
| 72 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, | 67 void SkSurface_Gpu::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, |
| 73 const SkPaint* paint) { | 68 const SkPaint* paint) { |
| 74 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); | 69 canvas->drawBitmap(fDevice->accessBitmap(false), x, y, paint); |
| 75 } | 70 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 100 this->SkSurface_Gpu::onDiscard(); | 95 this->SkSurface_Gpu::onDiscard(); |
| 101 } | 96 } |
| 102 } | 97 } |
| 103 | 98 |
| 104 void SkSurface_Gpu::onDiscard() { | 99 void SkSurface_Gpu::onDiscard() { |
| 105 fDevice->accessRenderTarget()->discard(); | 100 fDevice->accessRenderTarget()->discard(); |
| 106 } | 101 } |
| 107 | 102 |
| 108 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
| 109 | 104 |
| 110 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, const SkSurf
aceProps* props) { | 105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm) { |
| 111 if (NULL == target) { | 106 if (NULL == target) { |
| 112 return NULL; | 107 return NULL; |
| 113 } | 108 } |
| 114 return SkNEW_ARGS(SkSurface_Gpu, (target, false, props, false)); | 109 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm, false)); |
| 115 } | 110 } |
| 116 | 111 |
| 117 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, | 112 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, |
| 118 const SkSurfaceProps* props) { | 113 TextRenderMode trm) { |
| 119 if (NULL == ctx) { | 114 if (NULL == ctx) { |
| 120 return NULL; | 115 return NULL; |
| 121 } | 116 } |
| 122 | 117 |
| 123 GrTextureDesc desc; | 118 GrTextureDesc desc; |
| 124 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 119 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
| 125 desc.fWidth = info.width(); | 120 desc.fWidth = info.width(); |
| 126 desc.fHeight = info.height(); | 121 desc.fHeight = info.height(); |
| 127 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 122 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 128 desc.fSampleCnt = sampleCount; | 123 desc.fSampleCnt = sampleCount; |
| 129 | 124 |
| 130 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 125 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
| 131 if (NULL == tex) { | 126 if (NULL == tex) { |
| 132 return NULL; | 127 return NULL; |
| 133 } | 128 } |
| 134 | 129 |
| 135 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, props, true)
); | 130 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm, true)); |
| 136 } | 131 } |
| 137 | 132 |
| 138 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, | 133 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, |
| 139 int sampleCount, const SkSurfacePro
ps* props) { | 134 int sampleCount, TextRenderMode trm
) { |
| 140 if (NULL == ctx) { | 135 if (NULL == ctx) { |
| 141 return NULL; | 136 return NULL; |
| 142 } | 137 } |
| 143 | 138 |
| 144 GrTextureDesc desc; | 139 GrTextureDesc desc; |
| 145 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 140 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
| 146 desc.fWidth = info.width(); | 141 desc.fWidth = info.width(); |
| 147 desc.fHeight = info.height(); | 142 desc.fHeight = info.height(); |
| 148 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 143 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
| 149 desc.fSampleCnt = sampleCount; | 144 desc.fSampleCnt = sampleCount; |
| 150 | 145 |
| 151 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 146 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
| 152 | 147 |
| 153 if (NULL == tex) { | 148 if (NULL == tex) { |
| 154 return NULL; | 149 return NULL; |
| 155 } | 150 } |
| 156 | 151 |
| 157 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, props, true))
; | 152 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, true)); |
| 158 } | 153 } |
| OLD | NEW |