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, TextRenderMode trm); | 17 SkSurface_Gpu(GrRenderTarget*, bool cached, TextRenderMode trm, bool clear); |
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, TextRend
erMode trm) | 36 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend
erMode trm, |
| 37 bool clear) |
37 : INHERITED(renderTarget->width(), renderTarget->height()) { | 38 : INHERITED(renderTarget->width(), renderTarget->height()) { |
38 int flags = 0; | 39 int flags = 0; |
39 flags |= cached ? SkGpuDevice::kCached_Flag : 0; | 40 flags |= cached ? SkGpuDevice::kCached_Flag : 0; |
40 flags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFonts_Flag
: 0; | 41 flags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFonts_Flag
: 0; |
41 fDevice = SkGpuDevice::Create(renderTarget, flags); | 42 fDevice = SkGpuDevice::Create(renderTarget, flags); |
42 | 43 |
43 if (kRGB_565_GrPixelConfig != renderTarget->config()) { | 44 if (kRGB_565_GrPixelConfig != renderTarget->config() && clear) { |
44 fDevice->clear(0x0); | 45 fDevice->clear(0x0); |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 SkSurface_Gpu::~SkSurface_Gpu() { | 49 SkSurface_Gpu::~SkSurface_Gpu() { |
49 SkSafeUnref(fDevice); | 50 SkSafeUnref(fDevice); |
50 } | 51 } |
51 | 52 |
52 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 53 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
53 return SkNEW_ARGS(SkCanvas, (fDevice)); | 54 return SkNEW_ARGS(SkCanvas, (fDevice)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 this->SkSurface_Gpu::onDiscard(); | 95 this->SkSurface_Gpu::onDiscard(); |
95 } | 96 } |
96 } | 97 } |
97 | 98 |
98 void SkSurface_Gpu::onDiscard() { | 99 void SkSurface_Gpu::onDiscard() { |
99 fDevice->accessRenderTarget()->discard(); | 100 fDevice->accessRenderTarget()->discard(); |
100 } | 101 } |
101 | 102 |
102 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
103 | 104 |
104 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm) { | 105 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm, bool clear) { |
105 if (NULL == target) { | 106 if (NULL == target) { |
106 return NULL; | 107 return NULL; |
107 } | 108 } |
108 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm)); | 109 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm, clear)); |
109 } | 110 } |
110 | 111 |
111 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, | 112 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, |
112 TextRenderMode trm) { | 113 TextRenderMode trm) { |
113 if (NULL == ctx) { | 114 if (NULL == ctx) { |
114 return NULL; | 115 return NULL; |
115 } | 116 } |
116 | 117 |
117 GrTextureDesc desc; | 118 GrTextureDesc desc; |
118 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 119 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
119 desc.fWidth = info.width(); | 120 desc.fWidth = info.width(); |
120 desc.fHeight = info.height(); | 121 desc.fHeight = info.height(); |
121 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 122 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
122 desc.fSampleCnt = sampleCount; | 123 desc.fSampleCnt = sampleCount; |
123 | 124 |
124 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 125 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
125 if (NULL == tex) { | 126 if (NULL == tex) { |
126 return NULL; | 127 return NULL; |
127 } | 128 } |
128 | 129 |
129 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm)); | 130 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm, true)); |
130 } | 131 } |
131 | 132 |
132 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, | 133 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, |
133 int sampleCount, TextRenderMode trm
) { | 134 int sampleCount, TextRenderMode trm
) { |
134 if (NULL == ctx) { | 135 if (NULL == ctx) { |
135 return NULL; | 136 return NULL; |
136 } | 137 } |
137 | 138 |
138 GrTextureDesc desc; | 139 GrTextureDesc desc; |
139 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 140 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
140 desc.fWidth = info.width(); | 141 desc.fWidth = info.width(); |
141 desc.fHeight = info.height(); | 142 desc.fHeight = info.height(); |
142 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 143 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
143 desc.fSampleCnt = sampleCount; | 144 desc.fSampleCnt = sampleCount; |
144 | 145 |
145 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 146 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
146 | 147 |
147 if (NULL == tex) { | 148 if (NULL == tex) { |
148 return NULL; | 149 return NULL; |
149 } | 150 } |
150 | 151 |
151 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm)); | 152 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, true)); |
152 } | 153 } |
OLD | NEW |