OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "effects/GrBicubicEffect.h" | 10 #include "GrBitmapTextContext.h" |
11 #include "effects/GrDashingEffect.h" | |
12 #include "effects/GrTextureDomain.h" | |
13 #include "effects/GrSimpleTextureEffect.h" | |
14 | |
15 #include "GrContext.h" | 11 #include "GrContext.h" |
16 #include "GrBitmapTextContext.h" | |
17 #include "GrDistanceFieldTextContext.h" | 12 #include "GrDistanceFieldTextContext.h" |
| 13 #include "GrGpu.h" |
| 14 #include "GrGpuResourcePriv.h" |
18 #include "GrLayerHoister.h" | 15 #include "GrLayerHoister.h" |
19 #include "GrRecordReplaceDraw.h" | 16 #include "GrRecordReplaceDraw.h" |
20 #include "GrStrokeInfo.h" | 17 #include "GrStrokeInfo.h" |
21 #include "GrTracing.h" | 18 #include "GrTracing.h" |
22 #include "GrGpu.h" | |
23 | |
24 #include "SkGrTexturePixelRef.h" | |
25 | |
26 #include "SkCanvasPriv.h" | 19 #include "SkCanvasPriv.h" |
27 #include "SkDeviceImageFilterProxy.h" | 20 #include "SkDeviceImageFilterProxy.h" |
28 #include "SkDrawProcs.h" | 21 #include "SkDrawProcs.h" |
| 22 #include "SkErrorInternals.h" |
29 #include "SkGlyphCache.h" | 23 #include "SkGlyphCache.h" |
| 24 #include "SkGrTexturePixelRef.h" |
30 #include "SkImageFilter.h" | 25 #include "SkImageFilter.h" |
31 #include "SkLayerInfo.h" | 26 #include "SkLayerInfo.h" |
32 #include "SkMaskFilter.h" | 27 #include "SkMaskFilter.h" |
33 #include "SkPathEffect.h" | 28 #include "SkPathEffect.h" |
34 #include "SkPicture.h" | 29 #include "SkPicture.h" |
35 #include "SkPictureData.h" | 30 #include "SkPictureData.h" |
| 31 #include "SkRRect.h" |
36 #include "SkRecord.h" | 32 #include "SkRecord.h" |
37 #include "SkRRect.h" | |
38 #include "SkStroke.h" | 33 #include "SkStroke.h" |
39 #include "SkSurface.h" | 34 #include "SkSurface.h" |
| 35 #include "SkSurface_Gpu.h" |
40 #include "SkTLazy.h" | 36 #include "SkTLazy.h" |
41 #include "SkUtils.h" | 37 #include "SkUtils.h" |
42 #include "SkVertState.h" | 38 #include "SkVertState.h" |
43 #include "SkXfermode.h" | 39 #include "SkXfermode.h" |
44 #include "SkErrorInternals.h" | 40 #include "effects/GrBicubicEffect.h" |
| 41 #include "effects/GrDashingEffect.h" |
| 42 #include "effects/GrSimpleTextureEffect.h" |
| 43 #include "effects/GrTextureDomain.h" |
45 | 44 |
46 #if SK_SUPPORT_GPU | 45 #if SK_SUPPORT_GPU |
47 | 46 |
48 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; | 47 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
49 | 48 |
50 #if 0 | 49 #if 0 |
51 extern bool (*gShouldDrawProc)(); | 50 extern bool (*gShouldDrawProc)(); |
52 #define CHECK_SHOULD_DRAW(draw) \ | 51 #define CHECK_SHOULD_DRAW(draw) \ |
53 do { \ | 52 do { \ |
54 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 53 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 156 |
158 SkImageInfo info = rt->surfacePriv().info(); | 157 SkImageInfo info = rt->surfacePriv().info(); |
159 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); | 158 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); |
160 fLegacyBitmap.setInfo(info); | 159 fLegacyBitmap.setInfo(info); |
161 fLegacyBitmap.setPixelRef(pr)->unref(); | 160 fLegacyBitmap.setPixelRef(pr)->unref(); |
162 | 161 |
163 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); | 162 bool useDFT = fSurfaceProps.isUseDistanceFieldFonts(); |
164 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); | 163 fTextContext = fContext->createTextContext(fRenderTarget, this->getLeakyProp
erties(), useDFT); |
165 } | 164 } |
166 | 165 |
167 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, | 166 GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
udgeted budgeted, |
168 const SkImageInfo& origInfo, int sampleCount, | 167 const SkImageInfo& origInfo, int
sampleCount) { |
169 const SkSurfaceProps* props, unsigned flags) { | |
170 if (kUnknown_SkColorType == origInfo.colorType() || | 168 if (kUnknown_SkColorType == origInfo.colorType() || |
171 origInfo.width() < 0 || origInfo.height() < 0) { | 169 origInfo.width() < 0 || origInfo.height() < 0) { |
172 return NULL; | 170 return NULL; |
173 } | 171 } |
174 | 172 |
175 if (!context) { | 173 if (!context) { |
176 return NULL; | 174 return NULL; |
177 } | 175 } |
178 | 176 |
179 SkColorType ct = origInfo.colorType(); | 177 SkColorType ct = origInfo.colorType(); |
180 SkAlphaType at = origInfo.alphaType(); | 178 SkAlphaType at = origInfo.alphaType(); |
181 if (kRGB_565_SkColorType == ct) { | 179 if (kRGB_565_SkColorType == ct) { |
182 at = kOpaque_SkAlphaType; // force this setting | 180 at = kOpaque_SkAlphaType; // force this setting |
183 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { | 181 } else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) { |
184 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 | 182 // Fall back from whatever ct was to default of kRGBA or kBGRA which is
aliased as kN32 |
185 ct = kN32_SkColorType; | 183 ct = kN32_SkColorType; |
186 } | 184 } |
187 if (kOpaque_SkAlphaType != at) { | 185 if (kOpaque_SkAlphaType != at) { |
188 at = kPremul_SkAlphaType; // force this setting | 186 at = kPremul_SkAlphaType; // force this setting |
189 } | 187 } |
190 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); | 188 const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height
(), ct, at); |
191 | 189 |
192 GrSurfaceDesc desc; | 190 GrSurfaceDesc desc; |
193 desc.fFlags = kRenderTarget_GrSurfaceFlag; | 191 desc.fFlags = kRenderTarget_GrSurfaceFlag; |
194 desc.fWidth = info.width(); | 192 desc.fWidth = info.width(); |
195 desc.fHeight = info.height(); | 193 desc.fHeight = info.height(); |
196 desc.fConfig = SkImageInfo2GrPixelConfig(info); | 194 desc.fConfig = SkImageInfo2GrPixelConfig(info); |
197 desc.fSampleCnt = sampleCount; | 195 desc.fSampleCnt = sampleCount; |
| 196 GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL,
0); |
| 197 if (NULL == texture) { |
| 198 return NULL; |
| 199 } |
| 200 SkASSERT(NULL != texture->asRenderTarget()); |
| 201 return texture->asRenderTarget(); |
| 202 } |
198 | 203 |
199 SkAutoTUnref<GrTexture> texture(context->createTexture(desc, SkToBool(budget
ed), NULL, 0)); | 204 SkGpuDevice* SkGpuDevice::Create(GrContext* context, SkSurface::Budgeted budgete
d, |
200 if (!texture) { | 205 const SkImageInfo& info, int sampleCount, |
| 206 const SkSurfaceProps* props, unsigned flags) { |
| 207 |
| 208 SkAutoTUnref<GrRenderTarget> rt(CreateRenderTarget(context, budgeted, info,
sampleCount)); |
| 209 if (NULL == rt) { |
201 return NULL; | 210 return NULL; |
202 } | 211 } |
203 | 212 |
204 return SkNEW_ARGS(SkGpuDevice, (texture->asRenderTarget(), props, flags)); | 213 return SkNEW_ARGS(SkGpuDevice, (rt, props, flags)); |
205 } | 214 } |
206 | 215 |
207 SkGpuDevice::~SkGpuDevice() { | 216 SkGpuDevice::~SkGpuDevice() { |
208 if (fDrawProcs) { | 217 if (fDrawProcs) { |
209 delete fDrawProcs; | 218 delete fDrawProcs; |
210 } | 219 } |
211 | 220 |
212 delete fTextContext; | 221 delete fTextContext; |
213 | 222 |
214 if (fContext->getClip() == &fClipData) { | 223 if (fContext->getClip() == &fClipData) { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } | 304 } |
296 | 305 |
297 void SkGpuDevice::clearAll() { | 306 void SkGpuDevice::clearAll() { |
298 GrColor color = 0; | 307 GrColor color = 0; |
299 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); | 308 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); |
300 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 309 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
301 fContext->clear(&rect, color, true, fRenderTarget); | 310 fContext->clear(&rect, color, true, fRenderTarget); |
302 fNeedClear = false; | 311 fNeedClear = false; |
303 } | 312 } |
304 | 313 |
| 314 void SkGpuDevice::replaceRenderTarget(bool shouldRetainContent) { |
| 315 // Caller must have accessed the render target, because it knows the rt must
be replaced. |
| 316 SkASSERT(!fNeedClear); |
| 317 |
| 318 SkSurface::Budgeted budgeted = |
| 319 fRenderTarget->resourcePriv().isBudgeted() ? SkSurface::kYes_Budgete
d |
| 320 : SkSurface::kNo_Budgeted
; |
| 321 |
| 322 SkAutoTUnref<GrRenderTarget> newRT(CreateRenderTarget( |
| 323 fRenderTarget->getContext(), budgeted, this->imageInfo(), fRenderTarget-
>numSamples())); |
| 324 |
| 325 if (NULL == newRT) { |
| 326 return; |
| 327 } |
| 328 |
| 329 if (shouldRetainContent) { |
| 330 if (fRenderTarget->wasDestroyed()) { |
| 331 return; |
| 332 } |
| 333 this->context()->copySurface(newRT, fRenderTarget); |
| 334 } |
| 335 |
| 336 SkASSERT(fRenderTarget != newRT); |
| 337 |
| 338 fRenderTarget->unref(); |
| 339 fRenderTarget = newRT.detach(); |
| 340 |
| 341 SkASSERT(fRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); |
| 342 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (fRenderTarget->surfacePriv().info
(), fRenderTarget)); |
| 343 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 344 } |
| 345 |
305 /////////////////////////////////////////////////////////////////////////////// | 346 /////////////////////////////////////////////////////////////////////////////// |
306 | 347 |
307 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); | 348 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
308 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 349 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
309 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 350 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
310 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 351 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
311 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 352 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
312 shader_type_mismatch); | 353 shader_type_mismatch); |
313 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, | 354 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
314 shader_type_mismatch); | 355 shader_type_mismatch); |
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 #endif | 1946 #endif |
1906 } | 1947 } |
1907 | 1948 |
1908 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1949 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1909 // We always return a transient cache, so it is freed after each | 1950 // We always return a transient cache, so it is freed after each |
1910 // filter traversal. | 1951 // filter traversal. |
1911 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1952 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1912 } | 1953 } |
1913 | 1954 |
1914 #endif | 1955 #endif |
OLD | NEW |