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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #endif | 61 #endif |
62 | 62 |
63 // This constant represents the screen alignment criterion in texels for | 63 // This constant represents the screen alignment criterion in texels for |
64 // requiring texture domain clamping to prevent color bleeding when drawing | 64 // requiring texture domain clamping to prevent color bleeding when drawing |
65 // a sub region of a larger source image. | 65 // a sub region of a larger source image. |
66 #define COLOR_BLEED_TOLERANCE 0.001f | 66 #define COLOR_BLEED_TOLERANCE 0.001f |
67 | 67 |
68 #define DO_DEFERRED_CLEAR() \ | 68 #define DO_DEFERRED_CLEAR() \ |
69 do { \ | 69 do { \ |
70 if (fFlags & kNeedClear_Flag) { \ | 70 if (fFlags & kNeedClear_Flag) { \ |
71 this->clearAll(); \ | 71 this->clear(SK_ColorTRANSPARENT); \ |
72 } \ | 72 } \ |
73 } while (false) \ | 73 } while (false) \ |
74 | 74 |
75 /////////////////////////////////////////////////////////////////////////////// | 75 /////////////////////////////////////////////////////////////////////////////// |
76 | 76 |
77 #define CHECK_FOR_ANNOTATION(paint) \ | 77 #define CHECK_FOR_ANNOTATION(paint) \ |
78 do { if (paint.getAnnotation()) { return; } } while (0) | 78 do { if (paint.getAnnotation()) { return; } } while (0) |
79 | 79 |
80 /////////////////////////////////////////////////////////////////////////////// | 80 /////////////////////////////////////////////////////////////////////////////// |
81 | 81 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 fContext->setClip(&fClipData); | 287 fContext->setClip(&fClipData); |
288 | 288 |
289 DO_DEFERRED_CLEAR(); | 289 DO_DEFERRED_CLEAR(); |
290 } | 290 } |
291 | 291 |
292 GrRenderTarget* SkGpuDevice::accessRenderTarget() { | 292 GrRenderTarget* SkGpuDevice::accessRenderTarget() { |
293 DO_DEFERRED_CLEAR(); | 293 DO_DEFERRED_CLEAR(); |
294 return fRenderTarget; | 294 return fRenderTarget; |
295 } | 295 } |
296 | 296 |
297 void SkGpuDevice::clearAll() { | |
298 GrColor color = 0; | |
299 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clearAll", fContext); | |
300 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); | |
301 fContext->clear(&rect, color, true, fRenderTarget); | |
302 fFlags &= ~kNeedClear_Flag; | |
303 } | |
304 | |
305 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
306 | 298 |
307 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); | 299 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
308 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 300 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
309 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 301 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
310 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 302 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
311 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 303 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
312 shader_type_mismatch); | 304 shader_type_mismatch); |
313 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, | 305 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
314 shader_type_mismatch); | 306 shader_type_mismatch); |
315 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); | 307 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); |
316 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); | 308 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); |
317 | 309 |
318 /////////////////////////////////////////////////////////////////////////////// | 310 /////////////////////////////////////////////////////////////////////////////// |
319 | 311 |
| 312 void SkGpuDevice::clear(SkColor color) { |
| 313 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::clear", fContext); |
| 314 SkIRect rect = SkIRect::MakeWH(this->width(), this->height()); |
| 315 fContext->clear(&rect, SkColor2GrColor(color), true, fRenderTarget); |
| 316 fFlags &= ~kNeedClear_Flag; |
| 317 } |
| 318 |
320 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 319 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
321 CHECK_SHOULD_DRAW(draw, false); | 320 CHECK_SHOULD_DRAW(draw, false); |
322 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 321 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
323 | 322 |
324 GrPaint grPaint; | 323 GrPaint grPaint; |
325 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 324 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
326 | 325 |
327 fContext->drawPaint(grPaint); | 326 fContext->drawPaint(grPaint); |
328 } | 327 } |
329 | 328 |
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); | 1474 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); |
1476 } | 1475 } |
1477 | 1476 |
1478 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1477 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
1479 int x, int y, const SkPaint& paint) { | 1478 int x, int y, const SkPaint& paint) { |
1480 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1479 // clear of the source device must occur before CHECK_SHOULD_DRAW |
1481 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); | 1480 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); |
1482 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | 1481 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
1483 if (dev->fFlags & kNeedClear_Flag) { | 1482 if (dev->fFlags & kNeedClear_Flag) { |
1484 // TODO: could check here whether we really need to draw at all | 1483 // TODO: could check here whether we really need to draw at all |
1485 dev->clearAll(); | 1484 dev->clear(0x0); |
1486 } | 1485 } |
1487 | 1486 |
1488 // drawDevice is defined to be in device coords. | 1487 // drawDevice is defined to be in device coords. |
1489 CHECK_SHOULD_DRAW(draw, true); | 1488 CHECK_SHOULD_DRAW(draw, true); |
1490 | 1489 |
1491 GrRenderTarget* devRT = dev->accessRenderTarget(); | 1490 GrRenderTarget* devRT = dev->accessRenderTarget(); |
1492 GrTexture* devTex; | 1491 GrTexture* devTex; |
1493 if (NULL == (devTex = devRT->asTexture())) { | 1492 if (NULL == (devTex = devRT->asTexture())) { |
1494 return; | 1493 return; |
1495 } | 1494 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 return true; | 1846 return true; |
1848 } | 1847 } |
1849 | 1848 |
1850 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1849 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1851 // We always return a transient cache, so it is freed after each | 1850 // We always return a transient cache, so it is freed after each |
1852 // filter traversal. | 1851 // filter traversal. |
1853 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1852 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1854 } | 1853 } |
1855 | 1854 |
1856 #endif | 1855 #endif |
OLD | NEW |