| 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 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); | 1507 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); |
| 1509 } | 1508 } |
| 1510 | 1509 |
| 1511 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1510 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 1512 int x, int y, const SkPaint& paint) { | 1511 int x, int y, const SkPaint& paint) { |
| 1513 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1512 // clear of the source device must occur before CHECK_SHOULD_DRAW |
| 1514 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); | 1513 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); |
| 1515 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | 1514 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
| 1516 if (dev->fFlags & kNeedClear_Flag) { | 1515 if (dev->fFlags & kNeedClear_Flag) { |
| 1517 // TODO: could check here whether we really need to draw at all | 1516 // TODO: could check here whether we really need to draw at all |
| 1518 dev->clearAll(); | 1517 dev->clear(0x0); |
| 1519 } | 1518 } |
| 1520 | 1519 |
| 1521 // drawDevice is defined to be in device coords. | 1520 // drawDevice is defined to be in device coords. |
| 1522 CHECK_SHOULD_DRAW(draw, true); | 1521 CHECK_SHOULD_DRAW(draw, true); |
| 1523 | 1522 |
| 1524 GrRenderTarget* devRT = dev->accessRenderTarget(); | 1523 GrRenderTarget* devRT = dev->accessRenderTarget(); |
| 1525 GrTexture* devTex; | 1524 GrTexture* devTex; |
| 1526 if (NULL == (devTex = devRT->asTexture())) { | 1525 if (NULL == (devTex = devRT->asTexture())) { |
| 1527 return; | 1526 return; |
| 1528 } | 1527 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 return true; | 1879 return true; |
| 1881 } | 1880 } |
| 1882 | 1881 |
| 1883 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1882 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1884 // We always return a transient cache, so it is freed after each | 1883 // We always return a transient cache, so it is freed after each |
| 1885 // filter traversal. | 1884 // filter traversal. |
| 1886 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1885 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1887 } | 1886 } |
| 1888 | 1887 |
| 1889 #endif | 1888 #endif |
| OLD | NEW |