| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const int count = fPixelRef ? fPixelRef->getLockCount() : 0; | 84 const int count = fPixelRef ? fPixelRef->getLockCount() : 0; |
| 85 SkASSERT(count == fLockCount); | 85 SkASSERT(count == fLockCount); |
| 86 } | 86 } |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 const SkPixelRef* fPixelRef; | 89 const SkPixelRef* fPixelRef; |
| 90 int fLockCount; | 90 int fLockCount; |
| 91 }; | 91 }; |
| 92 #endif | 92 #endif |
| 93 | 93 |
| 94 class AutoCheckNoSetContext { | |
| 95 public: | |
| 96 AutoCheckNoSetContext(const SkPaint& paint) : fPaint(paint) { | |
| 97 this->assertNoSetContext(fPaint); | |
| 98 } | |
| 99 ~AutoCheckNoSetContext() { | |
| 100 this->assertNoSetContext(fPaint); | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 const SkPaint& fPaint; | |
| 105 | |
| 106 void assertNoSetContext(const SkPaint& paint) { | |
| 107 SkShader* s = paint.getShader(); | |
| 108 if (s) { | |
| 109 SkASSERT(!s->setContextHasBeenCalled()); | |
| 110 } | |
| 111 } | |
| 112 }; | |
| 113 | |
| 114 #define CHECK_LOCKCOUNT_BALANCE(bitmap) AutoCheckLockCountBalance clcb(bitmap) | 94 #define CHECK_LOCKCOUNT_BALANCE(bitmap) AutoCheckLockCountBalance clcb(bitmap) |
| 115 #define CHECK_SHADER_NOSETCONTEXT(paint) AutoCheckNoSetContext cshsc(paint) | |
| 116 | 95 |
| 117 #else | 96 #else |
| 118 #define CHECK_LOCKCOUNT_BALANCE(bitmap) | 97 #define CHECK_LOCKCOUNT_BALANCE(bitmap) |
| 119 #define CHECK_SHADER_NOSETCONTEXT(paint) | |
| 120 #endif | 98 #endif |
| 121 | 99 |
| 122 typedef SkTLazy<SkPaint> SkLazyPaint; | 100 typedef SkTLazy<SkPaint> SkLazyPaint; |
| 123 | 101 |
| 124 void SkCanvas::predrawNotify() { | 102 void SkCanvas::predrawNotify() { |
| 125 if (fSurfaceBase) { | 103 if (fSurfaceBase) { |
| 126 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); | 104 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
| 127 } | 105 } |
| 128 } | 106 } |
| 129 | 107 |
| (...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 if (NULL != fSurfaceBase) { | 1894 if (NULL != fSurfaceBase) { |
| 1917 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); | 1895 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
| 1918 } | 1896 } |
| 1919 } | 1897 } |
| 1920 | 1898 |
| 1921 void SkCanvas::drawPaint(const SkPaint& paint) { | 1899 void SkCanvas::drawPaint(const SkPaint& paint) { |
| 1922 this->internalDrawPaint(paint); | 1900 this->internalDrawPaint(paint); |
| 1923 } | 1901 } |
| 1924 | 1902 |
| 1925 void SkCanvas::internalDrawPaint(const SkPaint& paint) { | 1903 void SkCanvas::internalDrawPaint(const SkPaint& paint) { |
| 1926 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 1927 | |
| 1928 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) | 1904 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) |
| 1929 | 1905 |
| 1930 while (iter.next()) { | 1906 while (iter.next()) { |
| 1931 iter.fDevice->drawPaint(iter, looper.paint()); | 1907 iter.fDevice->drawPaint(iter, looper.paint()); |
| 1932 } | 1908 } |
| 1933 | 1909 |
| 1934 LOOPER_END | 1910 LOOPER_END |
| 1935 } | 1911 } |
| 1936 | 1912 |
| 1937 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], | 1913 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 1938 const SkPaint& paint) { | 1914 const SkPaint& paint) { |
| 1939 if ((long)count <= 0) { | 1915 if ((long)count <= 0) { |
| 1940 return; | 1916 return; |
| 1941 } | 1917 } |
| 1942 | 1918 |
| 1943 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 1944 | |
| 1945 SkRect r, storage; | 1919 SkRect r, storage; |
| 1946 const SkRect* bounds = NULL; | 1920 const SkRect* bounds = NULL; |
| 1947 if (paint.canComputeFastBounds()) { | 1921 if (paint.canComputeFastBounds()) { |
| 1948 // special-case 2 points (common for drawing a single line) | 1922 // special-case 2 points (common for drawing a single line) |
| 1949 if (2 == count) { | 1923 if (2 == count) { |
| 1950 r.set(pts[0], pts[1]); | 1924 r.set(pts[0], pts[1]); |
| 1951 } else { | 1925 } else { |
| 1952 r.set(pts, SkToInt(count)); | 1926 r.set(pts, SkToInt(count)); |
| 1953 } | 1927 } |
| 1954 bounds = &paint.computeFastStrokeBounds(r, &storage); | 1928 bounds = &paint.computeFastStrokeBounds(r, &storage); |
| 1955 if (this->quickReject(*bounds)) { | 1929 if (this->quickReject(*bounds)) { |
| 1956 return; | 1930 return; |
| 1957 } | 1931 } |
| 1958 } | 1932 } |
| 1959 | 1933 |
| 1960 SkASSERT(pts != NULL); | 1934 SkASSERT(pts != NULL); |
| 1961 | 1935 |
| 1962 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) | 1936 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) |
| 1963 | 1937 |
| 1964 while (iter.next()) { | 1938 while (iter.next()) { |
| 1965 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); | 1939 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); |
| 1966 } | 1940 } |
| 1967 | 1941 |
| 1968 LOOPER_END | 1942 LOOPER_END |
| 1969 } | 1943 } |
| 1970 | 1944 |
| 1971 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { | 1945 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { |
| 1972 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 1973 | |
| 1974 SkRect storage; | 1946 SkRect storage; |
| 1975 const SkRect* bounds = NULL; | 1947 const SkRect* bounds = NULL; |
| 1976 if (paint.canComputeFastBounds()) { | 1948 if (paint.canComputeFastBounds()) { |
| 1977 bounds = &paint.computeFastBounds(r, &storage); | 1949 bounds = &paint.computeFastBounds(r, &storage); |
| 1978 if (this->quickReject(*bounds)) { | 1950 if (this->quickReject(*bounds)) { |
| 1979 return; | 1951 return; |
| 1980 } | 1952 } |
| 1981 } | 1953 } |
| 1982 | 1954 |
| 1983 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) | 1955 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) |
| 1984 | 1956 |
| 1985 while (iter.next()) { | 1957 while (iter.next()) { |
| 1986 iter.fDevice->drawRect(iter, r, looper.paint()); | 1958 iter.fDevice->drawRect(iter, r, looper.paint()); |
| 1987 } | 1959 } |
| 1988 | 1960 |
| 1989 LOOPER_END | 1961 LOOPER_END |
| 1990 } | 1962 } |
| 1991 | 1963 |
| 1992 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | 1964 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
| 1993 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 1994 | |
| 1995 SkRect storage; | 1965 SkRect storage; |
| 1996 const SkRect* bounds = NULL; | 1966 const SkRect* bounds = NULL; |
| 1997 if (paint.canComputeFastBounds()) { | 1967 if (paint.canComputeFastBounds()) { |
| 1998 bounds = &paint.computeFastBounds(oval, &storage); | 1968 bounds = &paint.computeFastBounds(oval, &storage); |
| 1999 if (this->quickReject(*bounds)) { | 1969 if (this->quickReject(*bounds)) { |
| 2000 return; | 1970 return; |
| 2001 } | 1971 } |
| 2002 } | 1972 } |
| 2003 | 1973 |
| 2004 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) | 1974 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) |
| 2005 | 1975 |
| 2006 while (iter.next()) { | 1976 while (iter.next()) { |
| 2007 iter.fDevice->drawOval(iter, oval, looper.paint()); | 1977 iter.fDevice->drawOval(iter, oval, looper.paint()); |
| 2008 } | 1978 } |
| 2009 | 1979 |
| 2010 LOOPER_END | 1980 LOOPER_END |
| 2011 } | 1981 } |
| 2012 | 1982 |
| 2013 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 1983 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
| 2014 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2015 | |
| 2016 SkRect storage; | 1984 SkRect storage; |
| 2017 const SkRect* bounds = NULL; | 1985 const SkRect* bounds = NULL; |
| 2018 if (paint.canComputeFastBounds()) { | 1986 if (paint.canComputeFastBounds()) { |
| 2019 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); | 1987 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); |
| 2020 if (this->quickReject(*bounds)) { | 1988 if (this->quickReject(*bounds)) { |
| 2021 return; | 1989 return; |
| 2022 } | 1990 } |
| 2023 } | 1991 } |
| 2024 | 1992 |
| 2025 if (rrect.isRect()) { | 1993 if (rrect.isRect()) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2036 | 2004 |
| 2037 while (iter.next()) { | 2005 while (iter.next()) { |
| 2038 iter.fDevice->drawRRect(iter, rrect, looper.paint()); | 2006 iter.fDevice->drawRRect(iter, rrect, looper.paint()); |
| 2039 } | 2007 } |
| 2040 | 2008 |
| 2041 LOOPER_END | 2009 LOOPER_END |
| 2042 } | 2010 } |
| 2043 | 2011 |
| 2044 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, | 2012 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
| 2045 const SkPaint& paint) { | 2013 const SkPaint& paint) { |
| 2046 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2047 | |
| 2048 SkRect storage; | 2014 SkRect storage; |
| 2049 const SkRect* bounds = NULL; | 2015 const SkRect* bounds = NULL; |
| 2050 if (paint.canComputeFastBounds()) { | 2016 if (paint.canComputeFastBounds()) { |
| 2051 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); | 2017 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); |
| 2052 if (this->quickReject(*bounds)) { | 2018 if (this->quickReject(*bounds)) { |
| 2053 return; | 2019 return; |
| 2054 } | 2020 } |
| 2055 } | 2021 } |
| 2056 | 2022 |
| 2057 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) | 2023 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) |
| 2058 | 2024 |
| 2059 while (iter.next()) { | 2025 while (iter.next()) { |
| 2060 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); | 2026 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); |
| 2061 } | 2027 } |
| 2062 | 2028 |
| 2063 LOOPER_END | 2029 LOOPER_END |
| 2064 } | 2030 } |
| 2065 | 2031 |
| 2066 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 2032 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 2067 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2068 | |
| 2069 if (!path.isFinite()) { | 2033 if (!path.isFinite()) { |
| 2070 return; | 2034 return; |
| 2071 } | 2035 } |
| 2072 | 2036 |
| 2073 SkRect storage; | 2037 SkRect storage; |
| 2074 const SkRect* bounds = NULL; | 2038 const SkRect* bounds = NULL; |
| 2075 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { | 2039 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
| 2076 const SkRect& pathBounds = path.getBounds(); | 2040 const SkRect& pathBounds = path.getBounds(); |
| 2077 bounds = &paint.computeFastBounds(pathBounds, &storage); | 2041 bounds = &paint.computeFastBounds(pathBounds, &storage); |
| 2078 if (this->quickReject(*bounds)) { | 2042 if (this->quickReject(*bounds)) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 start.fY); | 2298 start.fY); |
| 2335 r.fTop = offset; | 2299 r.fTop = offset; |
| 2336 r.fBottom = offset + height; | 2300 r.fBottom = offset + height; |
| 2337 DrawRect(draw, paint, r, textSize); | 2301 DrawRect(draw, paint, r, textSize); |
| 2338 } | 2302 } |
| 2339 } | 2303 } |
| 2340 } | 2304 } |
| 2341 | 2305 |
| 2342 void SkCanvas::drawText(const void* text, size_t byteLength, | 2306 void SkCanvas::drawText(const void* text, size_t byteLength, |
| 2343 SkScalar x, SkScalar y, const SkPaint& paint) { | 2307 SkScalar x, SkScalar y, const SkPaint& paint) { |
| 2344 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2345 | |
| 2346 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2308 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
| 2347 | 2309 |
| 2348 while (iter.next()) { | 2310 while (iter.next()) { |
| 2349 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2311 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
| 2350 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); | 2312 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); |
| 2351 DrawTextDecorations(iter, dfp.paint(), | 2313 DrawTextDecorations(iter, dfp.paint(), |
| 2352 static_cast<const char*>(text), byteLength, x, y); | 2314 static_cast<const char*>(text), byteLength, x, y); |
| 2353 } | 2315 } |
| 2354 | 2316 |
| 2355 LOOPER_END | 2317 LOOPER_END |
| 2356 } | 2318 } |
| 2357 | 2319 |
| 2358 void SkCanvas::drawPosText(const void* text, size_t byteLength, | 2320 void SkCanvas::drawPosText(const void* text, size_t byteLength, |
| 2359 const SkPoint pos[], const SkPaint& paint) { | 2321 const SkPoint pos[], const SkPaint& paint) { |
| 2360 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2361 | |
| 2362 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2322 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
| 2363 | 2323 |
| 2364 while (iter.next()) { | 2324 while (iter.next()) { |
| 2365 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2325 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
| 2366 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, | 2326 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, |
| 2367 dfp.paint()); | 2327 dfp.paint()); |
| 2368 } | 2328 } |
| 2369 | 2329 |
| 2370 LOOPER_END | 2330 LOOPER_END |
| 2371 } | 2331 } |
| 2372 | 2332 |
| 2373 void SkCanvas::drawPosTextH(const void* text, size_t byteLength, | 2333 void SkCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 2374 const SkScalar xpos[], SkScalar constY, | 2334 const SkScalar xpos[], SkScalar constY, |
| 2375 const SkPaint& paint) { | 2335 const SkPaint& paint) { |
| 2376 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2377 | |
| 2378 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2336 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
| 2379 | 2337 |
| 2380 while (iter.next()) { | 2338 while (iter.next()) { |
| 2381 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2339 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
| 2382 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, | 2340 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, |
| 2383 dfp.paint()); | 2341 dfp.paint()); |
| 2384 } | 2342 } |
| 2385 | 2343 |
| 2386 LOOPER_END | 2344 LOOPER_END |
| 2387 } | 2345 } |
| 2388 | 2346 |
| 2389 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, | 2347 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 2390 const SkPath& path, const SkMatrix* matrix, | 2348 const SkPath& path, const SkMatrix* matrix, |
| 2391 const SkPaint& paint) { | 2349 const SkPaint& paint) { |
| 2392 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2393 | |
| 2394 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2350 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
| 2395 | 2351 |
| 2396 while (iter.next()) { | 2352 while (iter.next()) { |
| 2397 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, | 2353 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, |
| 2398 matrix, looper.paint()); | 2354 matrix, looper.paint()); |
| 2399 } | 2355 } |
| 2400 | 2356 |
| 2401 LOOPER_END | 2357 LOOPER_END |
| 2402 } | 2358 } |
| 2403 | 2359 |
| 2404 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, | 2360 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 2405 const SkPoint verts[], const SkPoint texs[], | 2361 const SkPoint verts[], const SkPoint texs[], |
| 2406 const SkColor colors[], SkXfermode* xmode, | 2362 const SkColor colors[], SkXfermode* xmode, |
| 2407 const uint16_t indices[], int indexCount, | 2363 const uint16_t indices[], int indexCount, |
| 2408 const SkPaint& paint) { | 2364 const SkPaint& paint) { |
| 2409 CHECK_SHADER_NOSETCONTEXT(paint); | |
| 2410 | |
| 2411 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) | 2365 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) |
| 2412 | 2366 |
| 2413 while (iter.next()) { | 2367 while (iter.next()) { |
| 2414 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, | 2368 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, |
| 2415 colors, xmode, indices, indexCount, | 2369 colors, xmode, indices, indexCount, |
| 2416 looper.paint()); | 2370 looper.paint()); |
| 2417 } | 2371 } |
| 2418 | 2372 |
| 2419 LOOPER_END | 2373 LOOPER_END |
| 2420 } | 2374 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2648 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2602 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
| 2649 return NULL; | 2603 return NULL; |
| 2650 } | 2604 } |
| 2651 | 2605 |
| 2652 // should this functionality be moved into allocPixels()? | 2606 // should this functionality be moved into allocPixels()? |
| 2653 if (!bitmap.info().isOpaque()) { | 2607 if (!bitmap.info().isOpaque()) { |
| 2654 bitmap.eraseColor(0); | 2608 bitmap.eraseColor(0); |
| 2655 } | 2609 } |
| 2656 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2610 return SkNEW_ARGS(SkCanvas, (bitmap)); |
| 2657 } | 2611 } |
| OLD | NEW |