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

Side by Side Diff: src/core/SkCanvas.cpp

Issue 1304883004: Change saveLayer() semantics to take unfiltered bounds. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Update to ToT Created 5 years, 1 month 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 | « no previous file | no next file » | 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 2008 The Android Open Source Project 2 * Copyright 2008 The Android Open Source Project
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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c olorfilter(imgCF) 405 // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-c olorfilter(imgCF)
406 // and we need to combine them into a single colorfilter. 406 // and we need to combine them into a single colorfilter.
407 SkAutoTUnref<SkColorFilter> autoImgCF(imgCF); 407 SkAutoTUnref<SkColorFilter> autoImgCF(imgCF);
408 return SkColorFilter::CreateComposeFilter(imgCF, paintCF); 408 return SkColorFilter::CreateComposeFilter(imgCF, paintCF);
409 } 409 }
410 410
411 class AutoDrawLooper { 411 class AutoDrawLooper {
412 public: 412 public:
413 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint, 413 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint,
414 bool skipLayerForImageFilter = false, 414 bool skipLayerForImageFilter = false,
415 const SkRect* bounds = nullptr) : fOrigPaint(paint) { 415 const SkRect* bounds = nullptr) : fOrigPaint(paint) {
reed1 2015/10/27 20:05:40 Lets rename this parameter somehow, so it is clear
Stephen White 2015/10/27 20:59:55 Done.
416 fCanvas = canvas; 416 fCanvas = canvas;
417 fFilter = canvas->getDrawFilter(); 417 fFilter = canvas->getDrawFilter();
418 fPaint = &fOrigPaint; 418 fPaint = &fOrigPaint;
419 fSaveCount = canvas->getSaveCount(); 419 fSaveCount = canvas->getSaveCount();
420 fTempLayerForImageFilter = false; 420 fTempLayerForImageFilter = false;
421 fDone = false; 421 fDone = false;
422 422
423 SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint); 423 SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint);
424 if (simplifiedCF) { 424 if (simplifiedCF) {
425 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint); 425 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
(...skipping 14 matching lines...) Expand all
440 * return (fPaint). We then draw the primitive (using srcover) into a cleared 440 * return (fPaint). We then draw the primitive (using srcover) into a cleared
441 * buffer/surface. 441 * buffer/surface.
442 * 3. Restore the layer created in #1 442 * 3. Restore the layer created in #1
443 * The imagefilter is passed the buffer/surface from the layer (now filled with the 443 * The imagefilter is passed the buffer/surface from the layer (now filled with the
444 * src pixels of the primitive). It returns a new "filtered" bu ffer, which we 444 * src pixels of the primitive). It returns a new "filtered" bu ffer, which we
445 * draw onto the previous layer using the xfermode from the ori ginal paint. 445 * draw onto the previous layer using the xfermode from the ori ginal paint.
446 */ 446 */
447 SkPaint tmp; 447 SkPaint tmp;
448 tmp.setImageFilter(fPaint->getImageFilter()); 448 tmp.setImageFilter(fPaint->getImageFilter());
449 tmp.setXfermode(fPaint->getXfermode()); 449 tmp.setXfermode(fPaint->getXfermode());
450 #ifndef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
451 SkRect storage;
reed1 2015/10/27 20:05:40 one way to make the intent of this block clear, co
Stephen White 2015/10/27 20:59:55 Done.
452 if (bounds) {
453 SkPaint tmpUnfiltered(*fPaint);
454 tmpUnfiltered.setImageFilter(nullptr);
455 if (tmpUnfiltered.canComputeFastBounds()) {
456 bounds = &tmpUnfiltered.computeFastBounds(*bounds, &storage) ;
457 }
458 }
459 #endif
450 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag, 460 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag,
451 SkCanvas::kFullLayer_SaveLayerStrate gy); 461 SkCanvas::kFullLayer_SaveLayerStrate gy);
452 fTempLayerForImageFilter = true; 462 fTempLayerForImageFilter = true;
453 // we remove the imagefilter/xfermode inside doNext() 463 // we remove the imagefilter/xfermode inside doNext()
454 } 464 }
455 465
456 if (SkDrawLooper* looper = paint.getLooper()) { 466 if (SkDrawLooper* looper = paint.getLooper()) {
457 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 467 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
458 looper->contextSize()); 468 looper->contextSize());
459 fLooperContext = looper->createContext(canvas, buffer); 469 fLooperContext = looper->createContext(canvas, buffer);
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 1022
1013 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags, 1023 bool SkCanvas::clipRectBounds(const SkRect* bounds, SaveFlags flags,
1014 SkIRect* intersection, const SkImageFilter* imageF ilter) { 1024 SkIRect* intersection, const SkImageFilter* imageF ilter) {
1015 SkIRect clipBounds; 1025 SkIRect clipBounds;
1016 if (!this->getClipDeviceBounds(&clipBounds)) { 1026 if (!this->getClipDeviceBounds(&clipBounds)) {
1017 return false; 1027 return false;
1018 } 1028 }
1019 1029
1020 const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix() 1030 const SkMatrix& ctm = fMCRec->fMatrix; // this->getTotalMatrix()
1021 1031
1032 #ifndef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
1033 SkRect storage;
1034 #endif
1022 if (imageFilter) { 1035 if (imageFilter) {
1023 imageFilter->filterBounds(clipBounds, ctm, &clipBounds); 1036 imageFilter->filterBounds(clipBounds, ctm, &clipBounds);
1037 #ifndef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
reed1 2015/10/27 20:05:40 This bock of code exists solely as a temporary hac
Stephen White 2015/10/27 20:59:55 Done.
1038 if (bounds && imageFilter->canComputeFastBounds()) {
1039 imageFilter->computeFastBounds(*bounds, &storage);
1040 bounds = &storage;
1041 } else {
1042 bounds = nullptr;
reed1 2015/10/27 20:05:40 I presume we set this to null because we assume th
Stephen White 2015/10/27 20:59:55 Should we just rename canComputeFastBounds(), then
1043 }
1044 #endif
1024 } 1045 }
1025 SkIRect ir; 1046 SkIRect ir;
1026 if (bounds) { 1047 if (bounds) {
1027 SkRect r; 1048 SkRect r;
1028 1049
1029 ctm.mapRect(&r, *bounds); 1050 ctm.mapRect(&r, *bounds);
1030 r.roundOut(&ir); 1051 r.roundOut(&ir);
1031 // early exit if the layer's bounds are clipped out 1052 // early exit if the layer's bounds are clipped out
1032 if (!ir.intersect(clipBounds)) { 1053 if (!ir.intersect(clipBounds)) {
1033 if (bounds_affects_clip(flags)) { 1054 if (bounds_affects_clip(flags)) {
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 1979
1959 SkRect r, storage; 1980 SkRect r, storage;
1960 const SkRect* bounds = nullptr; 1981 const SkRect* bounds = nullptr;
1961 if (paint.canComputeFastBounds()) { 1982 if (paint.canComputeFastBounds()) {
1962 // special-case 2 points (common for drawing a single line) 1983 // special-case 2 points (common for drawing a single line)
1963 if (2 == count) { 1984 if (2 == count) {
1964 r.set(pts[0], pts[1]); 1985 r.set(pts[0], pts[1]);
1965 } else { 1986 } else {
1966 r.set(pts, SkToInt(count)); 1987 r.set(pts, SkToInt(count));
1967 } 1988 }
1989 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
1968 bounds = &paint.computeFastStrokeBounds(r, &storage); 1990 bounds = &paint.computeFastStrokeBounds(r, &storage);
1969 if (this->quickReject(*bounds)) { 1991 if (this->quickReject(*bounds)) {
1970 return; 1992 return;
1971 } 1993 }
1994 #else
1995 if (this->quickReject(paint.computeFastStrokeBounds(r, &storage))) {
1996 return;
1997 }
1998 SkPaint unfiltered(paint);
1999 unfiltered.setImageFilter(nullptr);
2000 bounds = &unfiltered.computeFastStrokeBounds(r, &storage);
reed1 2015/10/27 20:05:40 don't we just want r here? bounds = &r;
Stephen White 2015/10/27 20:59:55 Hmm, yeah. Done.
2001 #endif
1972 } 2002 }
1973 2003
1974 SkASSERT(pts != nullptr); 2004 SkASSERT(pts != nullptr);
1975 2005
1976 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) 2006 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds)
1977 2007
1978 while (iter.next()) { 2008 while (iter.next()) {
1979 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); 2009 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint());
1980 } 2010 }
1981 2011
1982 LOOPER_END 2012 LOOPER_END
1983 } 2013 }
1984 2014
1985 void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) { 2015 void SkCanvas::onDrawRect(const SkRect& r, const SkPaint& paint) {
1986 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRect()"); 2016 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRect()");
1987 SkRect storage; 2017 SkRect storage;
1988 const SkRect* bounds = nullptr; 2018 const SkRect* bounds = nullptr;
1989 if (paint.canComputeFastBounds()) { 2019 if (paint.canComputeFastBounds()) {
1990 // Skia will draw an inverted rect, because it explicitly "sorts" it dow nstream. 2020 // Skia will draw an inverted rect, because it explicitly "sorts" it dow nstream.
1991 // To prevent accidental rejecting at this stage, we have to sort it bef ore we check. 2021 // To prevent accidental rejecting at this stage, we have to sort it bef ore we check.
1992 SkRect tmp(r); 2022 SkRect tmp(r);
1993 tmp.sort(); 2023 tmp.sort();
1994 2024
2025 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
1995 bounds = &paint.computeFastBounds(tmp, &storage); 2026 bounds = &paint.computeFastBounds(tmp, &storage);
1996 if (this->quickReject(*bounds)) { 2027 if (this->quickReject(*bounds)) {
1997 return; 2028 return;
1998 } 2029 }
2030 #else
2031 if (this->quickReject(paint.computeFastBounds(tmp, &storage))) {
2032 return;
2033 }
2034 bounds = &r;
2035 #endif
1999 } 2036 }
2000 2037
2001 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, bound s, false) 2038 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(paint, SkDrawFilter::kRect_Type, bound s, false)
2002 2039
2003 while (iter.next()) { 2040 while (iter.next()) {
2004 iter.fDevice->drawRect(iter, r, looper.paint()); 2041 iter.fDevice->drawRect(iter, r, looper.paint());
2005 } 2042 }
2006 2043
2007 LOOPER_END 2044 LOOPER_END
2008 } 2045 }
2009 2046
2010 void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) { 2047 void SkCanvas::onDrawOval(const SkRect& oval, const SkPaint& paint) {
2011 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawOval()"); 2048 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawOval()");
2012 SkRect storage; 2049 SkRect storage;
2013 const SkRect* bounds = nullptr; 2050 const SkRect* bounds = nullptr;
2014 if (paint.canComputeFastBounds()) { 2051 if (paint.canComputeFastBounds()) {
2052 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2015 bounds = &paint.computeFastBounds(oval, &storage); 2053 bounds = &paint.computeFastBounds(oval, &storage);
2016 if (this->quickReject(*bounds)) { 2054 if (this->quickReject(*bounds)) {
2017 return; 2055 return;
2018 } 2056 }
2057 #else
2058 if (this->quickReject(paint.computeFastBounds(oval, &storage))) {
2059 return;
2060 }
2061 bounds = &oval;
2062 #endif
2019 } 2063 }
2020 2064
2021 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) 2065 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds)
2022 2066
2023 while (iter.next()) { 2067 while (iter.next()) {
2024 iter.fDevice->drawOval(iter, oval, looper.paint()); 2068 iter.fDevice->drawOval(iter, oval, looper.paint());
2025 } 2069 }
2026 2070
2027 LOOPER_END 2071 LOOPER_END
2028 } 2072 }
2029 2073
2030 void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 2074 void SkCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
2031 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRRect()"); 2075 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawRRect()");
2032 SkRect storage; 2076 SkRect storage;
2033 const SkRect* bounds = nullptr; 2077 const SkRect* bounds = nullptr;
2034 if (paint.canComputeFastBounds()) { 2078 if (paint.canComputeFastBounds()) {
2079 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2035 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); 2080 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage);
2036 if (this->quickReject(*bounds)) { 2081 if (this->quickReject(*bounds)) {
2037 return; 2082 return;
2038 } 2083 }
2084 #else
2085 if (this->quickReject(paint.computeFastBounds(rrect.getBounds(), &storag e))) {
2086 return;
2087 }
2088 bounds = &rrect.getBounds();
2089 #endif
2039 } 2090 }
2040 2091
2041 if (rrect.isRect()) { 2092 if (rrect.isRect()) {
2042 // call the non-virtual version 2093 // call the non-virtual version
2043 this->SkCanvas::drawRect(rrect.getBounds(), paint); 2094 this->SkCanvas::drawRect(rrect.getBounds(), paint);
2044 return; 2095 return;
2045 } else if (rrect.isOval()) { 2096 } else if (rrect.isOval()) {
2046 // call the non-virtual version 2097 // call the non-virtual version
2047 this->SkCanvas::drawOval(rrect.getBounds(), paint); 2098 this->SkCanvas::drawOval(rrect.getBounds(), paint);
2048 return; 2099 return;
2049 } 2100 }
2050 2101
2051 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) 2102 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds)
2052 2103
2053 while (iter.next()) { 2104 while (iter.next()) {
2054 iter.fDevice->drawRRect(iter, rrect, looper.paint()); 2105 iter.fDevice->drawRRect(iter, rrect, looper.paint());
2055 } 2106 }
2056 2107
2057 LOOPER_END 2108 LOOPER_END
2058 } 2109 }
2059 2110
2060 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 2111 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
2061 const SkPaint& paint) { 2112 const SkPaint& paint) {
2062 SkRect storage; 2113 SkRect storage;
2063 const SkRect* bounds = nullptr; 2114 const SkRect* bounds = nullptr;
2064 if (paint.canComputeFastBounds()) { 2115 if (paint.canComputeFastBounds()) {
2116 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2065 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); 2117 bounds = &paint.computeFastBounds(outer.getBounds(), &storage);
2066 if (this->quickReject(*bounds)) { 2118 if (this->quickReject(*bounds)) {
2067 return; 2119 return;
2068 } 2120 }
2121 #else
2122 if (this->quickReject(paint.computeFastBounds(outer.getBounds(), &storag e))) {
2123 return;
2124 }
2125 bounds = &outer.getBounds();
2126 #endif
2069 } 2127 }
2070 2128
2071 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) 2129 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds)
2072 2130
2073 while (iter.next()) { 2131 while (iter.next()) {
2074 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); 2132 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint());
2075 } 2133 }
2076 2134
2077 LOOPER_END 2135 LOOPER_END
2078 } 2136 }
2079 2137
2080 void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 2138 void SkCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
2081 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPath()"); 2139 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPath()");
2082 if (!path.isFinite()) { 2140 if (!path.isFinite()) {
2083 return; 2141 return;
2084 } 2142 }
2085 2143
2086 SkRect storage; 2144 SkRect storage;
2087 const SkRect* bounds = nullptr; 2145 const SkRect* bounds = nullptr;
2088 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { 2146 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
2089 const SkRect& pathBounds = path.getBounds(); 2147 const SkRect& pathBounds = path.getBounds();
2148 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2090 bounds = &paint.computeFastBounds(pathBounds, &storage); 2149 bounds = &paint.computeFastBounds(pathBounds, &storage);
2091 if (this->quickReject(*bounds)) { 2150 if (this->quickReject(*bounds)) {
2092 return; 2151 return;
2093 } 2152 }
2153 #else
2154 if (this->quickReject(paint.computeFastBounds(pathBounds, &storage))) {
2155 return;
2156 }
2157 bounds = &pathBounds;
2158 #endif
2094 } 2159 }
2095 2160
2096 const SkRect& r = path.getBounds(); 2161 const SkRect& r = path.getBounds();
2097 if (r.width() <= 0 && r.height() <= 0) { 2162 if (r.width() <= 0 && r.height() <= 0) {
2098 if (path.isInverseFillType()) { 2163 if (path.isInverseFillType()) {
2099 this->internalDrawPaint(paint); 2164 this->internalDrawPaint(paint);
2100 return; 2165 return;
2101 } 2166 }
2102 } 2167 }
2103 2168
2104 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) 2169 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds)
2105 2170
2106 while (iter.next()) { 2171 while (iter.next()) {
2107 iter.fDevice->drawPath(iter, path, looper.paint()); 2172 iter.fDevice->drawPath(iter, path, looper.paint());
2108 } 2173 }
2109 2174
2110 LOOPER_END 2175 LOOPER_END
2111 } 2176 }
2112 2177
2113 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { 2178 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) {
2114 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); 2179 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()");
2115 SkRect bounds = SkRect::MakeXYWH(x, y, 2180 SkRect bounds = SkRect::MakeXYWH(x, y,
2116 SkIntToScalar(image->width()), SkIntToScala r(image->height())); 2181 SkIntToScalar(image->width()), SkIntToScala r(image->height()));
2117 if (nullptr == paint || paint->canComputeFastBounds()) { 2182 if (nullptr == paint || paint->canComputeFastBounds()) {
2183 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2118 if (paint) { 2184 if (paint) {
2119 paint->computeFastBounds(bounds, &bounds); 2185 paint->computeFastBounds(bounds, &bounds);
2120 } 2186 }
2121 if (this->quickReject(bounds)) { 2187 if (this->quickReject(bounds)) {
2122 return; 2188 return;
2123 } 2189 }
2190 #else
2191 SkRect tmp = bounds;
2192 if (paint) {
2193 paint->computeFastBounds(tmp, &tmp);
2194 }
2195 if (this->quickReject(tmp)) {
2196 return;
2197 }
2198 #endif
2124 } 2199 }
2125 2200
2126 SkLazyPaint lazy; 2201 SkLazyPaint lazy;
2127 if (nullptr == paint) { 2202 if (nullptr == paint) {
2128 paint = lazy.init(); 2203 paint = lazy.init();
2129 } 2204 }
2130 2205
2131 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) 2206 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds)
2132 2207
2133 while (iter.next()) { 2208 while (iter.next()) {
2134 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); 2209 iter.fDevice->drawImage(iter, image, x, y, looper.paint());
2135 } 2210 }
2136 2211
2137 LOOPER_END 2212 LOOPER_END
2138 } 2213 }
2139 2214
2140 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, 2215 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst,
2141 const SkPaint* paint, SrcRectConstraint constrain t) { 2216 const SkPaint* paint, SrcRectConstraint constrain t) {
2142 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); 2217 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()");
2143 SkRect storage; 2218 SkRect storage;
2144 const SkRect* bounds = &dst; 2219 const SkRect* bounds = &dst;
2145 if (nullptr == paint || paint->canComputeFastBounds()) { 2220 if (nullptr == paint || paint->canComputeFastBounds()) {
2221 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2146 if (paint) { 2222 if (paint) {
2147 bounds = &paint->computeFastBounds(dst, &storage); 2223 bounds = &paint->computeFastBounds(dst, &storage);
2148 } 2224 }
2149 if (this->quickReject(*bounds)) { 2225 if (this->quickReject(*bounds)) {
2150 return; 2226 return;
2151 } 2227 }
2228 #else
2229 storage = dst;
2230 if (paint) {
2231 paint->computeFastBounds(dst, &storage);
2232 }
2233 if (this->quickReject(storage)) {
2234 return;
2235 }
2236 #endif
2152 } 2237 }
2153 SkLazyPaint lazy; 2238 SkLazyPaint lazy;
2154 if (nullptr == paint) { 2239 if (nullptr == paint) {
2155 paint = lazy.init(); 2240 paint = lazy.init();
2156 } 2241 }
2157 2242
2158 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds, 2243 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds,
2159 image->isOpaque()) 2244 image->isOpaque())
2160 2245
2161 while (iter.next()) { 2246 while (iter.next()) {
(...skipping 16 matching lines...) Expand all
2178 paint = lazy.init(); 2263 paint = lazy.init();
2179 } 2264 }
2180 2265
2181 const SkMatrix matrix = SkMatrix::MakeTrans(x, y); 2266 const SkMatrix matrix = SkMatrix::MakeTrans(x, y);
2182 2267
2183 SkRect storage; 2268 SkRect storage;
2184 const SkRect* bounds = nullptr; 2269 const SkRect* bounds = nullptr;
2185 if (paint->canComputeFastBounds()) { 2270 if (paint->canComputeFastBounds()) {
2186 bitmap.getBounds(&storage); 2271 bitmap.getBounds(&storage);
2187 matrix.mapRect(&storage); 2272 matrix.mapRect(&storage);
2273 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2188 bounds = &paint->computeFastBounds(storage, &storage); 2274 bounds = &paint->computeFastBounds(storage, &storage);
2189 if (this->quickReject(*bounds)) { 2275 if (this->quickReject(*bounds)) {
2190 return; 2276 return;
2191 } 2277 }
2278 #else
2279 SkRect tmp = storage;
2280 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) {
2281 return;
2282 }
2283 bounds = &storage;
2284 #endif
2192 } 2285 }
2193 2286
2194 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 2287 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
2195 2288
2196 while (iter.next()) { 2289 while (iter.next()) {
2197 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); 2290 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint());
2198 } 2291 }
2199 2292
2200 LOOPER_END 2293 LOOPER_END
2201 } 2294 }
2202 2295
2203 // this one is non-virtual, so it can be called safely by other canvas apis 2296 // this one is non-virtual, so it can be called safely by other canvas apis
2204 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 2297 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
2205 const SkRect& dst, const SkPaint* paint, 2298 const SkRect& dst, const SkPaint* paint,
2206 SrcRectConstraint constraint) { 2299 SrcRectConstraint constraint) {
2207 if (bitmap.drawsNothing() || dst.isEmpty()) { 2300 if (bitmap.drawsNothing() || dst.isEmpty()) {
2208 return; 2301 return;
2209 } 2302 }
2210 2303
2211 SkRect storage; 2304 SkRect storage;
2212 const SkRect* bounds = &dst; 2305 const SkRect* bounds = &dst;
2213 if (nullptr == paint || paint->canComputeFastBounds()) { 2306 if (nullptr == paint || paint->canComputeFastBounds()) {
2307 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2214 if (paint) { 2308 if (paint) {
2215 bounds = &paint->computeFastBounds(dst, &storage); 2309 bounds = &paint->computeFastBounds(dst, &storage);
2216 } 2310 }
2217 if (this->quickReject(*bounds)) { 2311 if (this->quickReject(*bounds)) {
2218 return; 2312 return;
2219 } 2313 }
2314 #else
2315 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2316 return;
2317 }
2318 #endif
2220 } 2319 }
2221 2320
2222 SkLazyPaint lazy; 2321 SkLazyPaint lazy;
2223 if (nullptr == paint) { 2322 if (nullptr == paint) {
2224 paint = lazy.init(); 2323 paint = lazy.init();
2225 } 2324 }
2226 2325
2227 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds, 2326 LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, bo unds,
2228 bitmap.isOpaque()) 2327 bitmap.isOpaque())
2229 2328
(...skipping 11 matching lines...) Expand all
2241 this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint); 2340 this->internalDrawBitmapRect(bitmap, src, dst, paint, constraint);
2242 } 2341 }
2243 2342
2244 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons t SkRect& dst, 2343 void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons t SkRect& dst,
2245 const SkPaint* paint) { 2344 const SkPaint* paint) {
2246 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()"); 2345 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageNine()");
2247 2346
2248 SkRect storage; 2347 SkRect storage;
2249 const SkRect* bounds = &dst; 2348 const SkRect* bounds = &dst;
2250 if (nullptr == paint || paint->canComputeFastBounds()) { 2349 if (nullptr == paint || paint->canComputeFastBounds()) {
2350 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2251 if (paint) { 2351 if (paint) {
2252 bounds = &paint->computeFastBounds(dst, &storage); 2352 bounds = &paint->computeFastBounds(dst, &storage);
2253 } 2353 }
2254 if (this->quickReject(*bounds)) { 2354 if (this->quickReject(*bounds)) {
2255 return; 2355 return;
2256 } 2356 }
2357 #else
2358 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2359 return;
2360 }
2361 #endif
2257 } 2362 }
2258 2363
2259 SkLazyPaint lazy; 2364 SkLazyPaint lazy;
2260 if (nullptr == paint) { 2365 if (nullptr == paint) {
2261 paint = lazy.init(); 2366 paint = lazy.init();
2262 } 2367 }
2263 2368
2264 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 2369 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
2265 2370
2266 while (iter.next()) { 2371 while (iter.next()) {
2267 iter.fDevice->drawImageNine(iter, image, center, dst, looper.paint()); 2372 iter.fDevice->drawImageNine(iter, image, center, dst, looper.paint());
2268 } 2373 }
2269 2374
2270 LOOPER_END 2375 LOOPER_END
2271 } 2376 }
2272 2377
2273 void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c onst SkRect& dst, 2378 void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c onst SkRect& dst,
2274 const SkPaint* paint) { 2379 const SkPaint* paint) {
2275 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapNine()"); 2380 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawBitmapNine()");
2276 SkDEBUGCODE(bitmap.validate();) 2381 SkDEBUGCODE(bitmap.validate();)
2277 2382
2278 SkRect storage; 2383 SkRect storage;
2279 const SkRect* bounds = &dst; 2384 const SkRect* bounds = &dst;
2280 if (nullptr == paint || paint->canComputeFastBounds()) { 2385 if (nullptr == paint || paint->canComputeFastBounds()) {
2386 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2281 if (paint) { 2387 if (paint) {
2282 bounds = &paint->computeFastBounds(dst, &storage); 2388 bounds = &paint->computeFastBounds(dst, &storage);
2283 } 2389 }
2284 if (this->quickReject(*bounds)) { 2390 if (this->quickReject(*bounds)) {
2285 return; 2391 return;
2286 } 2392 }
2393 #else
2394 if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
2395 return;
2396 }
2397 #endif
2287 } 2398 }
2288 2399
2289 SkLazyPaint lazy; 2400 SkLazyPaint lazy;
2290 if (nullptr == paint) { 2401 if (nullptr == paint) {
2291 paint = lazy.init(); 2402 paint = lazy.init();
2292 } 2403 }
2293 2404
2294 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) 2405 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds)
2295 2406
2296 while (iter.next()) { 2407 while (iter.next()) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 LOOPER_END 2560 LOOPER_END
2450 } 2561 }
2451 2562
2452 void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 2563 void SkCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
2453 const SkPaint& paint) { 2564 const SkPaint& paint) {
2454 2565
2455 SkRect storage; 2566 SkRect storage;
2456 const SkRect* bounds = nullptr; 2567 const SkRect* bounds = nullptr;
2457 if (paint.canComputeFastBounds()) { 2568 if (paint.canComputeFastBounds()) {
2458 storage = blob->bounds().makeOffset(x, y); 2569 storage = blob->bounds().makeOffset(x, y);
2570 #ifdef SK_SAVE_LAYER_BOUNDS_ARE_FILTERED
2459 bounds = &paint.computeFastBounds(storage, &storage); 2571 bounds = &paint.computeFastBounds(storage, &storage);
2460 2572
2461 if (this->quickReject(*bounds)) { 2573 if (this->quickReject(*bounds)) {
2462 return; 2574 return;
2463 } 2575 }
2576 #else
2577 SkRect tmp;
2578 if (this->quickReject(paint.computeFastBounds(storage, &tmp))) {
2579 return;
2580 }
2581 bounds = &storage;
2582 #endif
2464 } 2583 }
2465 2584
2466 // We cannot filter in the looper as we normally do, because the paint is 2585 // We cannot filter in the looper as we normally do, because the paint is
2467 // incomplete at this point (text-related attributes are embedded within blo b run paints). 2586 // incomplete at this point (text-related attributes are embedded within blo b run paints).
2468 SkDrawFilter* drawFilter = fMCRec->fFilter; 2587 SkDrawFilter* drawFilter = fMCRec->fFilter;
2469 fMCRec->fFilter = nullptr; 2588 fMCRec->fFilter = nullptr;
2470 2589
2471 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds) 2590 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, bounds)
2472 2591
2473 while (iter.next()) { 2592 while (iter.next()) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
2882 } 3001 }
2883 3002
2884 if (matrix) { 3003 if (matrix) {
2885 canvas->concat(*matrix); 3004 canvas->concat(*matrix);
2886 } 3005 }
2887 } 3006 }
2888 3007
2889 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3008 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2890 fCanvas->restoreToCount(fSaveCount); 3009 fCanvas->restoreToCount(fSaveCount);
2891 } 3010 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698