Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 544233002: "NULL !=" = NULL (Closed) Base URL: https://skia.googlesource.com/skia.git@are
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrTextureAccess.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 : fDevice(NULL) 83 : fDevice(NULL)
84 , fTexture(NULL) { 84 , fTexture(NULL) {
85 } 85 }
86 86
87 SkAutoCachedTexture(SkGpuDevice* device, 87 SkAutoCachedTexture(SkGpuDevice* device,
88 const SkBitmap& bitmap, 88 const SkBitmap& bitmap,
89 const GrTextureParams* params, 89 const GrTextureParams* params,
90 GrTexture** texture) 90 GrTexture** texture)
91 : fDevice(NULL) 91 : fDevice(NULL)
92 , fTexture(NULL) { 92 , fTexture(NULL) {
93 SkASSERT(NULL != texture); 93 SkASSERT(texture);
94 *texture = this->set(device, bitmap, params); 94 *texture = this->set(device, bitmap, params);
95 } 95 }
96 96
97 ~SkAutoCachedTexture() { 97 ~SkAutoCachedTexture() {
98 if (NULL != fTexture) { 98 if (fTexture) {
99 GrUnlockAndUnrefCachedBitmapTexture(fTexture); 99 GrUnlockAndUnrefCachedBitmapTexture(fTexture);
100 } 100 }
101 } 101 }
102 102
103 GrTexture* set(SkGpuDevice* device, 103 GrTexture* set(SkGpuDevice* device,
104 const SkBitmap& bitmap, 104 const SkBitmap& bitmap,
105 const GrTextureParams* params) { 105 const GrTextureParams* params) {
106 if (NULL != fTexture) { 106 if (fTexture) {
107 GrUnlockAndUnrefCachedBitmapTexture(fTexture); 107 GrUnlockAndUnrefCachedBitmapTexture(fTexture);
108 fTexture = NULL; 108 fTexture = NULL;
109 } 109 }
110 fDevice = device; 110 fDevice = device;
111 GrTexture* result = (GrTexture*)bitmap.getTexture(); 111 GrTexture* result = (GrTexture*)bitmap.getTexture();
112 if (NULL == result) { 112 if (NULL == result) {
113 // Cannot return the native texture so look it up in our cache 113 // Cannot return the native texture so look it up in our cache
114 fTexture = GrLockAndRefCachedBitmapTexture(device->context(), bitmap , params); 114 fTexture = GrLockAndRefCachedBitmapTexture(device->context(), bitmap , params);
115 result = fTexture; 115 result = fTexture;
116 } 116 }
(...skipping 10 matching lines...) Expand all
127 struct GrSkDrawProcs : public SkDrawProcs { 127 struct GrSkDrawProcs : public SkDrawProcs {
128 public: 128 public:
129 GrContext* fContext; 129 GrContext* fContext;
130 GrTextContext* fTextContext; 130 GrTextContext* fTextContext;
131 GrFontScaler* fFontScaler; // cached in the skia glyphcache 131 GrFontScaler* fFontScaler; // cached in the skia glyphcache
132 }; 132 };
133 133
134 /////////////////////////////////////////////////////////////////////////////// 134 ///////////////////////////////////////////////////////////////////////////////
135 135
136 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { 136 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) {
137 SkASSERT(NULL != surface); 137 SkASSERT(surface);
138 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) { 138 if (NULL == surface->asRenderTarget() || surface->wasDestroyed()) {
139 return NULL; 139 return NULL;
140 } 140 }
141 return SkNEW_ARGS(SkGpuDevice, (surface, flags)); 141 return SkNEW_ARGS(SkGpuDevice, (surface, flags));
142 } 142 }
143 143
144 SkGpuDevice::SkGpuDevice(GrSurface* surface, unsigned flags) { 144 SkGpuDevice::SkGpuDevice(GrSurface* surface, unsigned flags) {
145 145
146 fDrawProcs = NULL; 146 fDrawProcs = NULL;
147 147
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 271 }
272 272
273 void SkGpuDevice::onDetachFromCanvas() { 273 void SkGpuDevice::onDetachFromCanvas() {
274 INHERITED::onDetachFromCanvas(); 274 INHERITED::onDetachFromCanvas();
275 fClipData.fClipStack = NULL; 275 fClipData.fClipStack = NULL;
276 } 276 }
277 277
278 // call this every draw call, to ensure that the context reflects our state, 278 // call this every draw call, to ensure that the context reflects our state,
279 // and not the state from some other canvas/device 279 // and not the state from some other canvas/device
280 void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) { 280 void SkGpuDevice::prepareDraw(const SkDraw& draw, bool forceIdentity) {
281 SkASSERT(NULL != fClipData.fClipStack); 281 SkASSERT(fClipData.fClipStack);
282 282
283 fContext->setRenderTarget(fRenderTarget); 283 fContext->setRenderTarget(fRenderTarget);
284 284
285 SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack); 285 SkASSERT(draw.fClipStack && draw.fClipStack == fClipData.fClipStack);
286 286
287 if (forceIdentity) { 287 if (forceIdentity) {
288 fContext->setIdentityMatrix(); 288 fContext->setIdentityMatrix();
289 } else { 289 } else {
290 fContext->setMatrix(*draw.fMatrix); 290 fContext->setMatrix(*draw.fMatrix);
291 } 291 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 #endif 418 #endif
419 } 419 }
420 // until we can both stroke and fill rectangles 420 // until we can both stroke and fill rectangles
421 if (paint.getStyle() == SkPaint::kStrokeAndFill_Style) { 421 if (paint.getStyle() == SkPaint::kStrokeAndFill_Style) {
422 usePath = true; 422 usePath = true;
423 } 423 }
424 424
425 GrStrokeInfo strokeInfo(paint); 425 GrStrokeInfo strokeInfo(paint);
426 426
427 const SkPathEffect* pe = paint.getPathEffect(); 427 const SkPathEffect* pe = paint.getPathEffect();
428 if (!usePath && NULL != pe && !strokeInfo.isDashed()) { 428 if (!usePath && pe && !strokeInfo.isDashed()) {
429 usePath = true; 429 usePath = true;
430 } 430 }
431 431
432 if (usePath) { 432 if (usePath) {
433 SkPath path; 433 SkPath path;
434 path.addRect(rect); 434 path.addRect(rect);
435 this->drawPath(draw, path, paint, NULL, true); 435 this->drawPath(draw, path, paint, NULL, true);
436 return; 436 return;
437 } 437 }
438 438
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 482 }
483 483
484 } 484 }
485 485
486 bool usePath = false; 486 bool usePath = false;
487 487
488 if (paint.getMaskFilter()) { 488 if (paint.getMaskFilter()) {
489 usePath = true; 489 usePath = true;
490 } else { 490 } else {
491 const SkPathEffect* pe = paint.getPathEffect(); 491 const SkPathEffect* pe = paint.getPathEffect();
492 if (NULL != pe && !strokeInfo.isDashed()) { 492 if (pe && !strokeInfo.isDashed()) {
493 usePath = true; 493 usePath = true;
494 } 494 }
495 } 495 }
496 496
497 497
498 if (usePath) { 498 if (usePath) {
499 SkPath path; 499 SkPath path;
500 path.addRRect(rect); 500 path.addRRect(rect);
501 this->drawPath(draw, path, paint, NULL, true); 501 this->drawPath(draw, path, paint, NULL, true);
502 return; 502 return;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 CHECK_SHOULD_DRAW(draw, false); 540 CHECK_SHOULD_DRAW(draw, false);
541 541
542 GrStrokeInfo strokeInfo(paint); 542 GrStrokeInfo strokeInfo(paint);
543 543
544 bool usePath = false; 544 bool usePath = false;
545 // some basic reasons we might need to call drawPath... 545 // some basic reasons we might need to call drawPath...
546 if (paint.getMaskFilter()) { 546 if (paint.getMaskFilter()) {
547 usePath = true; 547 usePath = true;
548 } else { 548 } else {
549 const SkPathEffect* pe = paint.getPathEffect(); 549 const SkPathEffect* pe = paint.getPathEffect();
550 if (NULL != pe && !strokeInfo.isDashed()) { 550 if (pe && !strokeInfo.isDashed()) {
551 usePath = true; 551 usePath = true;
552 } 552 }
553 } 553 }
554 554
555 if (usePath) { 555 if (usePath) {
556 SkPath path; 556 SkPath path;
557 path.addOval(oval); 557 path.addOval(oval);
558 this->drawPath(draw, path, paint, NULL, true); 558 this->drawPath(draw, path, paint, NULL, true);
559 return; 559 return;
560 } 560 }
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 SkIRect* clippedSrcIRect) { 852 SkIRect* clippedSrcIRect) {
853 const GrClipData* clip = context->getClip(); 853 const GrClipData* clip = context->getClip();
854 clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NUL L); 854 clip->getConservativeBounds(context->getRenderTarget(), clippedSrcIRect, NUL L);
855 SkMatrix inv; 855 SkMatrix inv;
856 if (!context->getMatrix().invert(&inv)) { 856 if (!context->getMatrix().invert(&inv)) {
857 clippedSrcIRect->setEmpty(); 857 clippedSrcIRect->setEmpty();
858 return; 858 return;
859 } 859 }
860 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect); 860 SkRect clippedSrcRect = SkRect::Make(*clippedSrcIRect);
861 inv.mapRect(&clippedSrcRect); 861 inv.mapRect(&clippedSrcRect);
862 if (NULL != srcRectPtr) { 862 if (srcRectPtr) {
863 // we've setup src space 0,0 to map to the top left of the src rect. 863 // we've setup src space 0,0 to map to the top left of the src rect.
864 clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop); 864 clippedSrcRect.offset(srcRectPtr->fLeft, srcRectPtr->fTop);
865 if (!clippedSrcRect.intersect(*srcRectPtr)) { 865 if (!clippedSrcRect.intersect(*srcRectPtr)) {
866 clippedSrcIRect->setEmpty(); 866 clippedSrcIRect->setEmpty();
867 return; 867 return;
868 } 868 }
869 } 869 }
870 clippedSrcRect.roundOut(clippedSrcIRect); 870 clippedSrcRect.roundOut(clippedSrcIRect);
871 SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 871 SkIRect bmpBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
872 if (!clippedSrcIRect->intersect(bmpBounds)) { 872 if (!clippedSrcIRect->intersect(bmpBounds)) {
873 clippedSrcIRect->setEmpty(); 873 clippedSrcIRect->setEmpty();
874 } 874 }
875 } 875 }
876 876
877 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap, 877 bool SkGpuDevice::shouldTileBitmap(const SkBitmap& bitmap,
878 const GrTextureParams& params, 878 const GrTextureParams& params,
879 const SkRect* srcRectPtr, 879 const SkRect* srcRectPtr,
880 int maxTileSize, 880 int maxTileSize,
881 int* tileSize, 881 int* tileSize,
882 SkIRect* clippedSrcRect) const { 882 SkIRect* clippedSrcRect) const {
883 // if bitmap is explictly texture backed then just use the texture 883 // if bitmap is explictly texture backed then just use the texture
884 if (NULL != bitmap.getTexture()) { 884 if (bitmap.getTexture()) {
885 return false; 885 return false;
886 } 886 }
887 887
888 // if it's larger than the max tile size, then we have no choice but tiling. 888 // if it's larger than the max tile size, then we have no choice but tiling.
889 if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) { 889 if (bitmap.width() > maxTileSize || bitmap.height() > maxTileSize) {
890 determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect) ; 890 determine_clipped_src_rect(fContext, bitmap, srcRectPtr, clippedSrcRect) ;
891 *tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize); 891 *tileSize = determine_tile_size(bitmap, *clippedSrcRect, maxTileSize);
892 return true; 892 return true;
893 } 893 }
894 894
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 // If there is no src rect, or the src rect contains the entire bitmap then we're effectively 1051 // If there is no src rect, or the src rect contains the entire bitmap then we're effectively
1052 // in the (easier) bleed case, so update flags. 1052 // in the (easier) bleed case, so update flags.
1053 if (NULL == srcRectPtr) { 1053 if (NULL == srcRectPtr) {
1054 SkScalar w = SkIntToScalar(bitmap.width()); 1054 SkScalar w = SkIntToScalar(bitmap.width());
1055 SkScalar h = SkIntToScalar(bitmap.height()); 1055 SkScalar h = SkIntToScalar(bitmap.height());
1056 dstSize.fWidth = w; 1056 dstSize.fWidth = w;
1057 dstSize.fHeight = h; 1057 dstSize.fHeight = h;
1058 srcRect.set(0, 0, w, h); 1058 srcRect.set(0, 0, w, h);
1059 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBi tmapRectFlag); 1059 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_DrawBi tmapRectFlag);
1060 } else { 1060 } else {
1061 SkASSERT(NULL != dstSizePtr); 1061 SkASSERT(dstSizePtr);
1062 srcRect = *srcRectPtr; 1062 srcRect = *srcRectPtr;
1063 dstSize = *dstSizePtr; 1063 dstSize = *dstSizePtr;
1064 if (srcRect.fLeft <= 0 && srcRect.fTop <= 0 && 1064 if (srcRect.fLeft <= 0 && srcRect.fTop <= 0 &&
1065 srcRect.fRight >= bitmap.width() && srcRect.fBottom >= bitmap.height ()) { 1065 srcRect.fRight >= bitmap.width() && srcRect.fBottom >= bitmap.height ()) {
1066 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_Dr awBitmapRectFlag); 1066 flags = (SkCanvas::DrawBitmapRectFlags) (flags | SkCanvas::kBleed_Dr awBitmapRectFlag);
1067 } 1067 }
1068 } 1068 }
1069 1069
1070 if (paint.getMaskFilter()){ 1070 if (paint.getMaskFilter()){
1071 // Convert the bitmap to a shader so that the rect can be drawn 1071 // Convert the bitmap to a shader so that the rect can be drawn
1072 // through drawRect, which supports mask filters. 1072 // through drawRect, which supports mask filters.
1073 SkBitmap tmp; // subset of bitmap, if necessary 1073 SkBitmap tmp; // subset of bitmap, if necessary
1074 const SkBitmap* bitmapPtr = &bitmap; 1074 const SkBitmap* bitmapPtr = &bitmap;
1075 SkMatrix localM; 1075 SkMatrix localM;
1076 if (NULL != srcRectPtr) { 1076 if (srcRectPtr) {
1077 localM.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop); 1077 localM.setTranslate(-srcRectPtr->fLeft, -srcRectPtr->fTop);
1078 localM.postScale(dstSize.fWidth / srcRectPtr->width(), 1078 localM.postScale(dstSize.fWidth / srcRectPtr->width(),
1079 dstSize.fHeight / srcRectPtr->height()); 1079 dstSize.fHeight / srcRectPtr->height());
1080 // In bleed mode we position and trim the bitmap based on the src re ct which is 1080 // In bleed mode we position and trim the bitmap based on the src re ct which is
1081 // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out 1081 // already accounted for in 'm' and 'srcRect'. In clamp mode we need to chop out
1082 // the desired portion of the bitmap and then update 'm' and 'srcRec t' to 1082 // the desired portion of the bitmap and then update 'm' and 'srcRec t' to
1083 // compensate. 1083 // compensate.
1084 if (!(SkCanvas::kBleed_DrawBitmapRectFlag & flags)) { 1084 if (!(SkCanvas::kBleed_DrawBitmapRectFlag & flags)) {
1085 SkIRect iSrc; 1085 SkIRect iSrc;
1086 srcRect.roundOut(&iSrc); 1086 srcRect.roundOut(&iSrc);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 int h = bitmap.height(); 1385 int h = bitmap.height();
1386 1386
1387 GrTexture* texture; 1387 GrTexture* texture;
1388 // draw sprite uses the default texture params 1388 // draw sprite uses the default texture params
1389 SkAutoCachedTexture act(this, bitmap, NULL, &texture); 1389 SkAutoCachedTexture act(this, bitmap, NULL, &texture);
1390 1390
1391 SkImageFilter* filter = paint.getImageFilter(); 1391 SkImageFilter* filter = paint.getImageFilter();
1392 // This bitmap will own the filtered result as a texture. 1392 // This bitmap will own the filtered result as a texture.
1393 SkBitmap filteredBitmap; 1393 SkBitmap filteredBitmap;
1394 1394
1395 if (NULL != filter) { 1395 if (filter) {
1396 SkIPoint offset = SkIPoint::Make(0, 0); 1396 SkIPoint offset = SkIPoint::Make(0, 0);
1397 SkMatrix matrix(*draw.fMatrix); 1397 SkMatrix matrix(*draw.fMatrix);
1398 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top)); 1398 matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
1399 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height()); 1399 SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
1400 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); 1400 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1401 // This cache is transient, and is freed (along with all its contained 1401 // This cache is transient, and is freed (along with all its contained
1402 // textures) when it goes out of scope. 1402 // textures) when it goes out of scope.
1403 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1403 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1404 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered Bitmap, 1404 if (filter_texture(this, fContext, texture, filter, w, h, ctx, &filtered Bitmap,
1405 &offset)) { 1405 &offset)) {
(...skipping 29 matching lines...) Expand all
1435 const SkPaint& paint, 1435 const SkPaint& paint,
1436 SkCanvas::DrawBitmapRectFlags flags) { 1436 SkCanvas::DrawBitmapRectFlags flags) {
1437 SkMatrix matrix; 1437 SkMatrix matrix;
1438 SkRect bitmapBounds, tmpSrc; 1438 SkRect bitmapBounds, tmpSrc;
1439 1439
1440 bitmapBounds.set(0, 0, 1440 bitmapBounds.set(0, 0,
1441 SkIntToScalar(bitmap.width()), 1441 SkIntToScalar(bitmap.width()),
1442 SkIntToScalar(bitmap.height())); 1442 SkIntToScalar(bitmap.height()));
1443 1443
1444 // Compute matrix from the two rectangles 1444 // Compute matrix from the two rectangles
1445 if (NULL != src) { 1445 if (src) {
1446 tmpSrc = *src; 1446 tmpSrc = *src;
1447 } else { 1447 } else {
1448 tmpSrc = bitmapBounds; 1448 tmpSrc = bitmapBounds;
1449 } 1449 }
1450 1450
1451 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); 1451 matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit);
1452 1452
1453 // clip the tmpSrc to the bounds of the bitmap. No check needed if src==null . 1453 // clip the tmpSrc to the bounds of the bitmap. No check needed if src==null .
1454 if (NULL != src) { 1454 if (src) {
1455 if (!bitmapBounds.contains(tmpSrc)) { 1455 if (!bitmapBounds.contains(tmpSrc)) {
1456 if (!tmpSrc.intersect(bitmapBounds)) { 1456 if (!tmpSrc.intersect(bitmapBounds)) {
1457 return; // nothing to draw 1457 return; // nothing to draw
1458 } 1458 }
1459 } 1459 }
1460 } 1460 }
1461 1461
1462 SkRect tmpDst; 1462 SkRect tmpDst;
1463 matrix.mapRect(&tmpDst, tmpSrc); 1463 matrix.mapRect(&tmpDst, tmpSrc);
1464 1464
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 } 1496 }
1497 1497
1498 const SkBitmap& bm = dev->accessBitmap(false); 1498 const SkBitmap& bm = dev->accessBitmap(false);
1499 int w = bm.width(); 1499 int w = bm.width();
1500 int h = bm.height(); 1500 int h = bm.height();
1501 1501
1502 SkImageFilter* filter = paint.getImageFilter(); 1502 SkImageFilter* filter = paint.getImageFilter();
1503 // This bitmap will own the filtered result as a texture. 1503 // This bitmap will own the filtered result as a texture.
1504 SkBitmap filteredBitmap; 1504 SkBitmap filteredBitmap;
1505 1505
1506 if (NULL != filter) { 1506 if (filter) {
1507 SkIPoint offset = SkIPoint::Make(0, 0); 1507 SkIPoint offset = SkIPoint::Make(0, 0);
1508 SkMatrix matrix(*draw.fMatrix); 1508 SkMatrix matrix(*draw.fMatrix);
1509 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); 1509 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
1510 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height()); 1510 SkIRect clipBounds = SkIRect::MakeWH(devTex->width(), devTex->height());
1511 // This cache is transient, and is freed (along with all its contained 1511 // This cache is transient, and is freed (along with all its contained
1512 // textures) when it goes out of scope. 1512 // textures) when it goes out of scope.
1513 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache()); 1513 SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
1514 SkImageFilter::Context ctx(matrix, clipBounds, cache); 1514 SkImageFilter::Context ctx(matrix, clipBounds, cache);
1515 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB itmap, 1515 if (filter_texture(this, fContext, devTex, filter, w, h, ctx, &filteredB itmap,
1516 &offset)) { 1516 &offset)) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 1644
1645 if (NULL == texs || NULL == paint.getShader()) { 1645 if (NULL == texs || NULL == paint.getShader()) {
1646 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(pain t.getColor()), 1646 SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColor(pain t.getColor()),
1647 NULL == colors, &grPaint); 1647 NULL == colors, &grPaint);
1648 } else { 1648 } else {
1649 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPai nt); 1649 SkPaint2GrPaintShader(this->context(), paint, NULL == colors, &grPai nt);
1650 } 1650 }
1651 } 1651 }
1652 1652
1653 #if 0 1653 #if 0
1654 if (NULL != xmode && NULL != texs && NULL != colors) { 1654 if (xmode && texs && colors) {
1655 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) { 1655 if (!SkXfermode::IsMode(xmode, SkXfermode::kModulate_Mode)) {
1656 SkDebugf("Unsupported vertex-color/texture xfer mode.\n"); 1656 SkDebugf("Unsupported vertex-color/texture xfer mode.\n");
1657 return; 1657 return;
1658 } 1658 }
1659 } 1659 }
1660 #endif 1660 #endif
1661 1661
1662 SkAutoSTMalloc<128, GrColor> convertedColors(0); 1662 SkAutoSTMalloc<128, GrColor> convertedColors(0);
1663 if (NULL != colors) { 1663 if (colors) {
1664 // need to convert byte order and from non-PM to PM 1664 // need to convert byte order and from non-PM to PM
1665 convertedColors.reset(vertexCount); 1665 convertedColors.reset(vertexCount);
1666 SkColor color; 1666 SkColor color;
1667 for (int i = 0; i < vertexCount; ++i) { 1667 for (int i = 0; i < vertexCount; ++i) {
1668 color = colors[i]; 1668 color = colors[i];
1669 if (paint.getAlpha() != 255) { 1669 if (paint.getAlpha() != 255) {
1670 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha())); 1670 color = SkColorSetA(color, SkMulDiv255Round(SkColorGetA(color), paint.getAlpha()));
1671 } 1671 }
1672 convertedColors[i] = SkColor2GrColor(color); 1672 convertedColors[i] = SkColor2GrColor(color);
1673 } 1673 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 // layers are never draw in repeat modes, so we can request an approx 1797 // layers are never draw in repeat modes, so we can request an approx
1798 // match and ignore any padding. 1798 // match and ignore any padding.
1799 flags |= kCached_Flag; 1799 flags |= kCached_Flag;
1800 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ? 1800 const GrContext::ScratchTexMatch match = (kSaveLayer_Usage == usage) ?
1801 GrContext::kApprox_ScratchTexMat ch : 1801 GrContext::kApprox_ScratchTexMat ch :
1802 GrContext::kExact_ScratchTexMatc h; 1802 GrContext::kExact_ScratchTexMatc h;
1803 texture.reset(fContext->lockAndRefScratchTexture(desc, match)); 1803 texture.reset(fContext->lockAndRefScratchTexture(desc, match));
1804 #else 1804 #else
1805 texture.reset(fContext->createUncachedTexture(desc, NULL, 0)); 1805 texture.reset(fContext->createUncachedTexture(desc, NULL, 0));
1806 #endif 1806 #endif
1807 if (NULL != texture.get()) { 1807 if (texture.get()) {
1808 return SkGpuDevice::Create(texture, flags); 1808 return SkGpuDevice::Create(texture, flags);
1809 } else { 1809 } else {
1810 GrPrintf("---- failed to create compatible device texture [%d %d]\n", 1810 GrPrintf("---- failed to create compatible device texture [%d %d]\n",
1811 info.width(), info.height()); 1811 info.width(), info.height());
1812 return NULL; 1812 return NULL;
1813 } 1813 }
1814 } 1814 }
1815 1815
1816 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) { 1816 SkSurface* SkGpuDevice::newSurface(const SkImageInfo& info) {
1817 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples( )); 1817 return SkSurface::NewRenderTarget(fContext, info, fRenderTarget->numSamples( ));
1818 } 1818 }
1819 1819
1820 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) { 1820 void SkGpuDevice::EXPERIMENTAL_optimize(const SkPicture* picture) {
1821 fContext->getLayerCache()->processDeletedPictures(); 1821 fContext->getLayerCache()->processDeletedPictures();
1822 1822
1823 if (NULL != picture->fData.get() && !picture->fData->suitableForLayerOptimiz ation()) { 1823 if (picture->fData.get() && !picture->fData->suitableForLayerOptimization()) {
1824 return; 1824 return;
1825 } 1825 }
1826 1826
1827 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); 1827 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
1828 1828
1829 const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(ke y); 1829 const SkPicture::AccelData* existing = picture->EXPERIMENTAL_getAccelData(ke y);
1830 if (NULL != existing) { 1830 if (existing) {
1831 return; 1831 return;
1832 } 1832 }
1833 1833
1834 GPUOptimize(picture); 1834 GPUOptimize(picture);
1835 1835
1836 fContext->getLayerCache()->trackPicture(picture); 1836 fContext->getLayerCache()->trackPicture(picture);
1837 } 1837 }
1838 1838
1839 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re sult) { 1839 static void wrap_texture(GrTexture* texture, int width, int height, SkBitmap* re sult) {
1840 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 1840 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture); 1941 GrLayerHoister::UnlockLayers(fContext->getLayerCache(), picture);
1942 1942
1943 return true; 1943 return true;
1944 } 1944 }
1945 1945
1946 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { 1946 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() {
1947 // We always return a transient cache, so it is freed after each 1947 // We always return a transient cache, so it is freed after each
1948 // filter traversal. 1948 // filter traversal.
1949 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); 1949 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize);
1950 } 1950 }
OLDNEW
« no previous file with comments | « src/gpu/GrTextureAccess.cpp ('k') | src/gpu/SkGr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698