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 "effects/GrBicubicEffect.h" |
11 #include "effects/GrDashingEffect.h" | 11 #include "effects/GrDashingEffect.h" |
12 #include "effects/GrPorterDuffXferProcessor.h" | 12 #include "effects/GrPorterDuffXferProcessor.h" |
13 #include "effects/GrTextureDomain.h" | 13 #include "effects/GrTextureDomain.h" |
14 #include "effects/GrSimpleTextureEffect.h" | 14 #include "effects/GrSimpleTextureEffect.h" |
15 | 15 |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #include "GrBitmapTextContext.h" | 17 #include "GrBitmapTextContext.h" |
18 #include "GrDistanceFieldTextContext.h" | 18 #include "GrDistanceFieldTextContext.h" |
| 19 #include "GrGpuResourcePriv.h" |
19 #include "GrLayerHoister.h" | 20 #include "GrLayerHoister.h" |
20 #include "GrRecordReplaceDraw.h" | 21 #include "GrRecordReplaceDraw.h" |
21 #include "GrStrokeInfo.h" | 22 #include "GrStrokeInfo.h" |
22 #include "GrTracing.h" | 23 #include "GrTracing.h" |
23 #include "GrGpu.h" | 24 #include "GrGpu.h" |
24 | 25 |
25 #include "SkGrTexturePixelRef.h" | 26 #include "SkGrTexturePixelRef.h" |
26 | 27 |
27 #include "SkCanvasPriv.h" | 28 #include "SkCanvasPriv.h" |
28 #include "SkDeviceImageFilterProxy.h" | 29 #include "SkDeviceImageFilterProxy.h" |
29 #include "SkDrawProcs.h" | 30 #include "SkDrawProcs.h" |
30 #include "SkGlyphCache.h" | 31 #include "SkGlyphCache.h" |
31 #include "SkImageFilter.h" | 32 #include "SkImageFilter.h" |
32 #include "SkLayerInfo.h" | 33 #include "SkLayerInfo.h" |
33 #include "SkMaskFilter.h" | 34 #include "SkMaskFilter.h" |
34 #include "SkPathEffect.h" | 35 #include "SkPathEffect.h" |
35 #include "SkPicture.h" | 36 #include "SkPicture.h" |
36 #include "SkPictureData.h" | 37 #include "SkPictureData.h" |
37 #include "SkRecord.h" | 38 #include "SkRecord.h" |
38 #include "SkRRect.h" | 39 #include "SkRRect.h" |
39 #include "SkStroke.h" | 40 #include "SkStroke.h" |
40 #include "SkSurface.h" | 41 #include "SkSurface.h" |
41 #include "SkSurface_Gpu.h" | 42 #include "SkSurface_Gpu.h" |
42 #include "SkTLazy.h" | 43 #include "SkTLazy.h" |
43 #include "SkUtils.h" | 44 #include "SkUtils.h" |
44 #include "SkVertState.h" | 45 #include "SkVertState.h" |
45 #include "SkXfermode.h" | 46 #include "SkXfermode.h" |
46 #include "SkErrorInternals.h" | 47 #include "SkErrorInternals.h" |
47 | 48 |
| 49 |
48 #if SK_SUPPORT_GPU | 50 #if SK_SUPPORT_GPU |
49 | 51 |
50 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; | 52 enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 }; |
51 | 53 |
52 #if 0 | 54 #if 0 |
53 extern bool (*gShouldDrawProc)(); | 55 extern bool (*gShouldDrawProc)(); |
54 #define CHECK_SHOULD_DRAW(draw) \ | 56 #define CHECK_SHOULD_DRAW(draw) \ |
55 do { \ | 57 do { \ |
56 if (gShouldDrawProc && !gShouldDrawProc()) return; \ | 58 if (gShouldDrawProc && !gShouldDrawProc()) return; \ |
57 this->prepareDraw(draw); \ | 59 this->prepareDraw(draw); \ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 if (props) { | 144 if (props) { |
143 return SkSurfaceProps(*props); | 145 return SkSurfaceProps(*props); |
144 } else { | 146 } else { |
145 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); | 147 return SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType); |
146 } | 148 } |
147 } | 149 } |
148 | 150 |
149 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsign
ed flags) | 151 SkGpuDevice::SkGpuDevice(GrRenderTarget* rt, const SkSurfaceProps* props, unsign
ed flags) |
150 : INHERITED(surfaceprops_to_deviceprops(props)) | 152 : INHERITED(surfaceprops_to_deviceprops(props)) |
151 , fSurfaceProps(copy_or_default_props(props)) | 153 , fSurfaceProps(copy_or_default_props(props)) |
| 154 , fSurface(NULL) |
152 { | 155 { |
153 fDrawProcs = NULL; | 156 fDrawProcs = NULL; |
154 | 157 |
155 fContext = SkRef(rt->getContext()); | 158 fContext = SkRef(rt->getContext()); |
156 fNeedClear = flags & kNeedClear_Flag; | 159 fNeedClear = flags & kNeedClear_Flag; |
157 | 160 |
158 fRenderTarget = SkRef(rt); | 161 fRenderTarget = SkRef(rt); |
159 | 162 |
160 SkImageInfo info = rt->surfacePriv().info(); | 163 SkImageInfo info = rt->surfacePriv().info(); |
161 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); | 164 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, rt)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 // The GrContext takes a ref on the target. We don't want to cause the rende
r | 229 // The GrContext takes a ref on the target. We don't want to cause the rende
r |
227 // target to be unnecessarily kept alive. | 230 // target to be unnecessarily kept alive. |
228 if (fContext->getRenderTarget() == fRenderTarget) { | 231 if (fContext->getRenderTarget() == fRenderTarget) { |
229 fContext->setRenderTarget(NULL); | 232 fContext->setRenderTarget(NULL); |
230 } | 233 } |
231 | 234 |
232 if (fContext->getClip() == &fClipData) { | 235 if (fContext->getClip() == &fClipData) { |
233 fContext->setClip(NULL); | 236 fContext->setClip(NULL); |
234 } | 237 } |
235 | 238 |
236 fRenderTarget->unref(); | |
237 fContext->unref(); | 239 fContext->unref(); |
238 } | 240 } |
239 | 241 |
240 /////////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////////// |
241 | 243 |
| 244 void SkGpuDevice::discard() { |
| 245 if (fSurface) { |
| 246 fSurface->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
| 247 } |
| 248 } |
| 249 |
242 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, | 250 bool SkGpuDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size
_t dstRowBytes, |
243 int x, int y) { | 251 int x, int y) { |
244 DO_DEFERRED_CLEAR(); | 252 DO_DEFERRED_CLEAR(); |
245 | 253 |
246 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels | 254 // TODO: teach fRenderTarget to take ImageInfo directly to specify the src p
ixels |
247 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); | 255 GrPixelConfig config = SkImageInfo2GrPixelConfig(dstInfo); |
248 if (kUnknown_GrPixelConfig == config) { | 256 if (kUnknown_GrPixelConfig == config) { |
249 return false; | 257 return false; |
250 } | 258 } |
251 | 259 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 298 |
291 void SkGpuDevice::onDetachFromCanvas() { | 299 void SkGpuDevice::onDetachFromCanvas() { |
292 INHERITED::onDetachFromCanvas(); | 300 INHERITED::onDetachFromCanvas(); |
293 fClipData.fClipStack.reset(NULL); | 301 fClipData.fClipStack.reset(NULL); |
294 } | 302 } |
295 | 303 |
296 // call this every draw call, to ensure that the context reflects our state, | 304 // call this every draw call, to ensure that the context reflects our state, |
297 // and not the state from some other canvas/device | 305 // and not the state from some other canvas/device |
298 void SkGpuDevice::prepareDraw(const SkDraw& draw) { | 306 void SkGpuDevice::prepareDraw(const SkDraw& draw) { |
299 SkASSERT(fClipData.fClipStack); | 307 SkASSERT(fClipData.fClipStack); |
| 308 if (fSurface) { |
| 309 fSurface->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
| 310 } |
300 | 311 |
301 fContext->setRenderTarget(fRenderTarget); | 312 fContext->setRenderTarget(fRenderTarget); |
302 | 313 |
303 SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack); | 314 SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack); |
304 | 315 |
305 fClipData.fOrigin = this->getOrigin(); | 316 fClipData.fOrigin = this->getOrigin(); |
306 | 317 |
307 fContext->setClip(&fClipData); | 318 fContext->setClip(&fClipData); |
308 | 319 |
309 DO_DEFERRED_CLEAR(); | 320 DO_DEFERRED_CLEAR(); |
310 } | 321 } |
311 | 322 |
312 GrRenderTarget* SkGpuDevice::accessRenderTarget() { | 323 GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
313 DO_DEFERRED_CLEAR(); | 324 DO_DEFERRED_CLEAR(); |
314 return fRenderTarget; | 325 return fRenderTarget; |
315 } | 326 } |
316 | 327 |
317 void SkGpuDevice::clearAll() { | 328 void SkGpuDevice::clearAll() { |
318 GrColor color = 0; | 329 GrColor color = 0; |
319 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); | 330 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); |
320 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | 331 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
321 fContext->clear(&rect, color, true, fRenderTarget); | 332 fContext->clear(&rect, color, true, fRenderTarget); |
322 fNeedClear = false; | 333 fNeedClear = false; |
323 } | 334 } |
324 | 335 |
325 void SkGpuDevice::swapRenderTarget(GrRenderTarget* newRenderTarget) { | 336 void SkGpuDevice::detachBackendRenderTarget(bool retainContent) { |
326 SkASSERT(!fNeedClear); | 337 SkASSERT(!fNeedClear); |
327 if (fContext->getRenderTarget() == fRenderTarget) { | 338 if (fContext->getRenderTarget() == fRenderTarget) { |
328 fContext->setRenderTarget(NULL); | 339 fContext->setRenderTarget(NULL); |
329 } | 340 } |
330 SkRefCnt_SafeAssign(fRenderTarget, newRenderTarget); | 341 |
331 SkASSERT(newRenderTarget->surfacePriv().info() == fLegacyBitmap.info()); | 342 GrRenderTarget* oldRT = fRenderTarget; |
332 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (newRenderTarget->surfacePriv().in
fo(), | 343 SkSurface::Budgeted budgeted = oldRT->resourcePriv().isBudgeted() ? SkSurfac
e::kYes_Budgeted : |
333 newRenderTarget)); | 344 SkSurface::kNo_Budgeted; |
334 fLegacyBitmap.setPixelRef(pr)->unref(); | 345 |
| 346 GrRenderTarget* newRT = CreateRenderTarget(oldRT->getContext(), budgeted, th
is->imageInfo(), |
| 347 oldRT->numSamples()); |
| 348 if (newRT) { |
| 349 if (retainContent && !oldRT->wasDestroyed()) { |
| 350 oldRT->getContext()->copySurface(newRT, oldRT); |
| 351 } |
| 352 |
| 353 if (fRenderTarget != newRT) { |
| 354 fRenderTarget->unref(); |
| 355 fRenderTarget = newRT; |
| 356 } |
| 357 |
| 358 SkASSERT(newRT->surfacePriv().info() == fLegacyBitmap.info()); |
| 359 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (newRT->surfacePriv().info(), |
| 360 newRT)); |
| 361 fLegacyBitmap.setPixelRef(pr)->unref(); |
| 362 } |
335 } | 363 } |
336 | 364 |
337 /////////////////////////////////////////////////////////////////////////////// | 365 /////////////////////////////////////////////////////////////////////////////// |
338 | 366 |
339 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); | 367 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
340 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 368 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
341 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 369 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
342 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 370 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
343 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 371 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
344 shader_type_mismatch); | 372 shader_type_mismatch); |
(...skipping 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 #endif | 1955 #endif |
1928 } | 1956 } |
1929 | 1957 |
1930 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1958 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1931 // We always return a transient cache, so it is freed after each | 1959 // We always return a transient cache, so it is freed after each |
1932 // filter traversal. | 1960 // filter traversal. |
1933 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1961 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1934 } | 1962 } |
1935 | 1963 |
1936 #endif | 1964 #endif |
OLD | NEW |