| 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->clear(SK_ColorTRANSPARENT); \ | 71 this->clearAll(); \ |
| 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 |
| 297 /////////////////////////////////////////////////////////////////////////////// | 305 /////////////////////////////////////////////////////////////////////////////// |
| 298 | 306 |
| 299 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); | 307 SK_COMPILE_ASSERT(SkShader::kNone_BitmapType == 0, shader_type_mismatch); |
| 300 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); | 308 SK_COMPILE_ASSERT(SkShader::kDefault_BitmapType == 1, shader_type_mismatch); |
| 301 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); | 309 SK_COMPILE_ASSERT(SkShader::kRadial_BitmapType == 2, shader_type_mismatch); |
| 302 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); | 310 SK_COMPILE_ASSERT(SkShader::kSweep_BitmapType == 3, shader_type_mismatch); |
| 303 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, | 311 SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4, |
| 304 shader_type_mismatch); | 312 shader_type_mismatch); |
| 305 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, | 313 SK_COMPILE_ASSERT(SkShader::kTwoPointConical_BitmapType == 5, |
| 306 shader_type_mismatch); | 314 shader_type_mismatch); |
| 307 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); | 315 SK_COMPILE_ASSERT(SkShader::kLinear_BitmapType == 6, shader_type_mismatch); |
| 308 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); | 316 SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 6, shader_type_mismatch); |
| 309 | 317 |
| 310 /////////////////////////////////////////////////////////////////////////////// | 318 /////////////////////////////////////////////////////////////////////////////// |
| 311 | 319 |
| 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 | |
| 319 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { | 320 void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 320 CHECK_SHOULD_DRAW(draw, false); | 321 CHECK_SHOULD_DRAW(draw, false); |
| 321 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); | 322 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawPaint", fContext); |
| 322 | 323 |
| 323 GrPaint grPaint; | 324 GrPaint grPaint; |
| 324 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); | 325 SkPaint2GrPaintShader(this->context(), paint, true, &grPaint); |
| 325 | 326 |
| 326 fContext->drawPaint(grPaint); | 327 fContext->drawPaint(grPaint); |
| 327 } | 328 } |
| 328 | 329 |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1507 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); | 1508 this->drawBitmapCommon(*draw, bitmap, &tmpSrc, &dstSize, paint, flags); |
| 1508 } | 1509 } |
| 1509 | 1510 |
| 1510 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, | 1511 void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 1511 int x, int y, const SkPaint& paint) { | 1512 int x, int y, const SkPaint& paint) { |
| 1512 // clear of the source device must occur before CHECK_SHOULD_DRAW | 1513 // clear of the source device must occur before CHECK_SHOULD_DRAW |
| 1513 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); | 1514 GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice::drawDevice", fContext); |
| 1514 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); | 1515 SkGpuDevice* dev = static_cast<SkGpuDevice*>(device); |
| 1515 if (dev->fFlags & kNeedClear_Flag) { | 1516 if (dev->fFlags & kNeedClear_Flag) { |
| 1516 // TODO: could check here whether we really need to draw at all | 1517 // TODO: could check here whether we really need to draw at all |
| 1517 dev->clear(0x0); | 1518 dev->clearAll(); |
| 1518 } | 1519 } |
| 1519 | 1520 |
| 1520 // drawDevice is defined to be in device coords. | 1521 // drawDevice is defined to be in device coords. |
| 1521 CHECK_SHOULD_DRAW(draw, true); | 1522 CHECK_SHOULD_DRAW(draw, true); |
| 1522 | 1523 |
| 1523 GrRenderTarget* devRT = dev->accessRenderTarget(); | 1524 GrRenderTarget* devRT = dev->accessRenderTarget(); |
| 1524 GrTexture* devTex; | 1525 GrTexture* devTex; |
| 1525 if (NULL == (devTex = devRT->asTexture())) { | 1526 if (NULL == (devTex = devRT->asTexture())) { |
| 1526 return; | 1527 return; |
| 1527 } | 1528 } |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 return true; | 1876 return true; |
| 1876 } | 1877 } |
| 1877 | 1878 |
| 1878 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1879 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
| 1879 // We always return a transient cache, so it is freed after each | 1880 // We always return a transient cache, so it is freed after each |
| 1880 // filter traversal. | 1881 // filter traversal. |
| 1881 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1882 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
| 1882 } | 1883 } |
| 1883 | 1884 |
| 1884 #endif | 1885 #endif |
| OLD | NEW |