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, SkSurface::RenderTargetFlags fla
gs, |
18 SkSurface::RenderTargetFlags flags); | 18 const SkSurfaceProps&); |
19 virtual ~SkSurface_Gpu(); | 19 virtual ~SkSurface_Gpu(); |
20 | 20 |
21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; | 21 virtual SkCanvas* onNewCanvas() SK_OVERRIDE; |
22 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; | 22 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; | 23 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE; |
24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, | 24 virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y, |
25 const SkPaint*) SK_OVERRIDE; | 25 const SkPaint*) SK_OVERRIDE; |
26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; | 26 virtual void onCopyOnWrite(ContentChangeMode) SK_OVERRIDE; |
27 virtual void onDiscard() SK_OVERRIDE; | 27 virtual void onDiscard() SK_OVERRIDE; |
28 | 28 |
29 private: | 29 private: |
30 SkGpuDevice* fDevice; | 30 SkGpuDevice* fDevice; |
31 | 31 |
32 typedef SkSurface_Base INHERITED; | 32 typedef SkSurface_Base INHERITED; |
33 }; | 33 }; |
34 | 34 |
35 /////////////////////////////////////////////////////////////////////////////// | 35 /////////////////////////////////////////////////////////////////////////////// |
36 | 36 |
37 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, TextRend
erMode trm, | 37 SkSurface_Gpu::SkSurface_Gpu(GrRenderTarget* renderTarget, bool cached, RenderTa
rgetFlags flags, |
38 SkSurface::RenderTargetFlags flags) | 38 const SkSurfaceProps& props) |
39 : INHERITED(renderTarget->width(), renderTarget->height()) { | 39 : INHERITED(renderTarget->width(), renderTarget->height(), &props) |
| 40 { |
40 int deviceFlags = 0; | 41 int deviceFlags = 0; |
41 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; | 42 deviceFlags |= cached ? SkGpuDevice::kCached_Flag : 0; |
42 deviceFlags |= (kDistanceField_TextRenderMode == trm) ? SkGpuDevice::kDFFont
s_Flag : 0; | 43 deviceFlags |= props.useDistanceFieldFonts() ? SkGpuDevice::kDFFonts_Flag :
0; |
43 fDevice = SkGpuDevice::Create(renderTarget, deviceFlags); | 44 fDevice = SkGpuDevice::Create(renderTarget, this->props(), deviceFlags); |
44 | 45 |
45 if (kRGB_565_GrPixelConfig != renderTarget->config() && | 46 if (kRGB_565_GrPixelConfig != renderTarget->config() && |
46 !(flags & kDontClear_RenderTargetFlag)) { | 47 !(flags & kDontClear_RenderTargetFlag)) { |
47 fDevice->clear(0x0); | 48 fDevice->clear(0x0); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
51 SkSurface_Gpu::~SkSurface_Gpu() { | 52 SkSurface_Gpu::~SkSurface_Gpu() { |
52 SkSafeUnref(fDevice); | 53 SkSafeUnref(fDevice); |
53 } | 54 } |
54 | 55 |
55 SkCanvas* SkSurface_Gpu::onNewCanvas() { | 56 SkCanvas* SkSurface_Gpu::onNewCanvas() { |
56 return SkNEW_ARGS(SkCanvas, (fDevice)); | 57 SkCanvas::InitFlags flags = SkCanvas::kDefault_InitFlags; |
| 58 // When we think this works... |
| 59 // flags |= SkCanvas::kConservativeRasterClip_InitFlag; |
| 60 |
| 61 return SkNEW_ARGS(SkCanvas, (fDevice, &this->props(), flags)); |
57 } | 62 } |
58 | 63 |
59 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { | 64 SkSurface* SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { |
60 GrRenderTarget* rt = fDevice->accessRenderTarget(); | 65 GrRenderTarget* rt = fDevice->accessRenderTarget(); |
61 int sampleCount = rt->numSamples(); | 66 int sampleCount = rt->numSamples(); |
62 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); | 67 return SkSurface::NewRenderTarget(fDevice->context(), info, sampleCount); |
63 } | 68 } |
64 | 69 |
65 SkImage* SkSurface_Gpu::onNewImageSnapshot() { | 70 SkImage* SkSurface_Gpu::onNewImageSnapshot() { |
66 return SkImage::NewTexture(fDevice->accessBitmap(false)); | 71 return SkImage::NewTexture(fDevice->accessBitmap(false)); |
(...skipping 30 matching lines...) Expand all Loading... |
97 this->SkSurface_Gpu::onDiscard(); | 102 this->SkSurface_Gpu::onDiscard(); |
98 } | 103 } |
99 } | 104 } |
100 | 105 |
101 void SkSurface_Gpu::onDiscard() { | 106 void SkSurface_Gpu::onDiscard() { |
102 fDevice->accessRenderTarget()->discard(); | 107 fDevice->accessRenderTarget()->discard(); |
103 } | 108 } |
104 | 109 |
105 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
106 | 111 |
| 112 static SkSurfaceProps make_props(SkSurface::TextRenderMode trm) { |
| 113 const SkSurfaceProps legacyProps(SkSurfaceProps::kLegacyFontHost_InitType); |
| 114 |
| 115 uint32_t propsFlags = 0; |
| 116 if (SkSurface::kDistanceField_TextRenderMode == trm) { |
| 117 propsFlags |= SkSurfaceProps::kUseDistanceFieldFonts_Flag; |
| 118 } |
| 119 return SkSurfaceProps(propsFlags, legacyProps.pixelGeometry()); |
| 120 } |
| 121 |
107 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm, | 122 SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMo
de trm, |
108 RenderTargetFlags flags) { | 123 RenderTargetFlags flags) { |
109 if (NULL == target) { | 124 if (NULL == target) { |
110 return NULL; | 125 return NULL; |
111 } | 126 } |
112 return SkNEW_ARGS(SkSurface_Gpu, (target, false, trm, flags)); | 127 return SkNEW_ARGS(SkSurface_Gpu, (target, false, flags, make_props(trm))); |
113 } | 128 } |
114 | 129 |
115 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, | 130 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, |
116 TextRenderMode trm, RenderTargetFlags flag
s) { | 131 TextRenderMode trm, RenderTargetFlags rend
erFlags) { |
| 132 return NewRenderTarget(ctx, info, sampleCount, make_props(trm), renderFlags)
; |
| 133 } |
| 134 |
| 135 SkSurface* SkSurface::NewRenderTarget(GrContext* ctx, const SkImageInfo& info, i
nt sampleCount, |
| 136 const SkSurfaceProps& props, RenderTargetF
lags flags) { |
117 if (NULL == ctx) { | 137 if (NULL == ctx) { |
118 return NULL; | 138 return NULL; |
119 } | 139 } |
120 | 140 |
121 GrTextureDesc desc; | 141 GrTextureDesc desc; |
122 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 142 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
123 desc.fWidth = info.width(); | 143 desc.fWidth = info.width(); |
124 desc.fHeight = info.height(); | 144 desc.fHeight = info.height(); |
125 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 145 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
126 desc.fSampleCnt = sampleCount; | 146 desc.fSampleCnt = sampleCount; |
127 | 147 |
128 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); | 148 SkAutoTUnref<GrTexture> tex(ctx->createUncachedTexture(desc, NULL, 0)); |
129 if (NULL == tex) { | 149 if (NULL == tex) { |
130 return NULL; | 150 return NULL; |
131 } | 151 } |
132 | 152 |
133 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, trm, flags))
; | 153 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), false, flags, props
)); |
134 } | 154 } |
135 | 155 |
136 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, | 156 SkSurface* SkSurface::NewScratchRenderTarget(GrContext* ctx, const SkImageInfo&
info, |
137 int sampleCount, TextRenderMode trm
, | 157 int sampleCount, TextRenderMode trm
, |
138 RenderTargetFlags flags) { | 158 RenderTargetFlags flags) { |
139 if (NULL == ctx) { | 159 if (NULL == ctx) { |
140 return NULL; | 160 return NULL; |
141 } | 161 } |
142 | 162 |
143 GrTextureDesc desc; | 163 GrTextureDesc desc; |
144 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; | 164 desc.fFlags = kRenderTarget_GrTextureFlagBit | kCheckAllocation_GrTextureFla
gBit; |
145 desc.fWidth = info.width(); | 165 desc.fWidth = info.width(); |
146 desc.fHeight = info.height(); | 166 desc.fHeight = info.height(); |
147 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 167 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
148 desc.fSampleCnt = sampleCount; | 168 desc.fSampleCnt = sampleCount; |
149 | 169 |
150 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); | 170 SkAutoTUnref<GrTexture> tex(ctx->lockAndRefScratchTexture(desc, GrContext::k
Exact_ScratchTexMatch)); |
151 | 171 |
152 if (NULL == tex) { | 172 if (NULL == tex) { |
153 return NULL; | 173 return NULL; |
154 } | 174 } |
155 | 175 |
156 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, trm, flags)); | 176 return SkNEW_ARGS(SkSurface_Gpu, (tex->asRenderTarget(), true, flags, make_p
rops(trm))); |
157 } | 177 } |
OLD | NEW |