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