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 1803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 if (NULL != fSurfaceBase) { | 1911 if (NULL != fSurfaceBase) { |
1934 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); | 1912 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); |
1935 } | 1913 } |
1936 } | 1914 } |
1937 | 1915 |
1938 void SkCanvas::drawPaint(const SkPaint& paint) { | 1916 void SkCanvas::drawPaint(const SkPaint& paint) { |
1939 this->internalDrawPaint(paint); | 1917 this->internalDrawPaint(paint); |
1940 } | 1918 } |
1941 | 1919 |
1942 void SkCanvas::internalDrawPaint(const SkPaint& paint) { | 1920 void SkCanvas::internalDrawPaint(const SkPaint& paint) { |
1943 CHECK_SHADER_NOSETCONTEXT(paint); | |
1944 | |
1945 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) | 1921 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) |
1946 | 1922 |
1947 while (iter.next()) { | 1923 while (iter.next()) { |
1948 iter.fDevice->drawPaint(iter, looper.paint()); | 1924 iter.fDevice->drawPaint(iter, looper.paint()); |
1949 } | 1925 } |
1950 | 1926 |
1951 LOOPER_END | 1927 LOOPER_END |
1952 } | 1928 } |
1953 | 1929 |
1954 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], | 1930 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
1955 const SkPaint& paint) { | 1931 const SkPaint& paint) { |
1956 if ((long)count <= 0) { | 1932 if ((long)count <= 0) { |
1957 return; | 1933 return; |
1958 } | 1934 } |
1959 | 1935 |
1960 CHECK_SHADER_NOSETCONTEXT(paint); | |
1961 | |
1962 SkRect r, storage; | 1936 SkRect r, storage; |
1963 const SkRect* bounds = NULL; | 1937 const SkRect* bounds = NULL; |
1964 if (paint.canComputeFastBounds()) { | 1938 if (paint.canComputeFastBounds()) { |
1965 // special-case 2 points (common for drawing a single line) | 1939 // special-case 2 points (common for drawing a single line) |
1966 if (2 == count) { | 1940 if (2 == count) { |
1967 r.set(pts[0], pts[1]); | 1941 r.set(pts[0], pts[1]); |
1968 } else { | 1942 } else { |
1969 r.set(pts, SkToInt(count)); | 1943 r.set(pts, SkToInt(count)); |
1970 } | 1944 } |
1971 bounds = &paint.computeFastStrokeBounds(r, &storage); | 1945 bounds = &paint.computeFastStrokeBounds(r, &storage); |
1972 if (this->quickReject(*bounds)) { | 1946 if (this->quickReject(*bounds)) { |
1973 return; | 1947 return; |
1974 } | 1948 } |
1975 } | 1949 } |
1976 | 1950 |
1977 SkASSERT(pts != NULL); | 1951 SkASSERT(pts != NULL); |
1978 | 1952 |
1979 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) | 1953 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) |
1980 | 1954 |
1981 while (iter.next()) { | 1955 while (iter.next()) { |
1982 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); | 1956 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); |
1983 } | 1957 } |
1984 | 1958 |
1985 LOOPER_END | 1959 LOOPER_END |
1986 } | 1960 } |
1987 | 1961 |
1988 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { | 1962 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { |
1989 CHECK_SHADER_NOSETCONTEXT(paint); | |
1990 | |
1991 SkRect storage; | 1963 SkRect storage; |
1992 const SkRect* bounds = NULL; | 1964 const SkRect* bounds = NULL; |
1993 if (paint.canComputeFastBounds()) { | 1965 if (paint.canComputeFastBounds()) { |
1994 bounds = &paint.computeFastBounds(r, &storage); | 1966 bounds = &paint.computeFastBounds(r, &storage); |
1995 if (this->quickReject(*bounds)) { | 1967 if (this->quickReject(*bounds)) { |
1996 return; | 1968 return; |
1997 } | 1969 } |
1998 } | 1970 } |
1999 | 1971 |
2000 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) | 1972 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) |
2001 | 1973 |
2002 while (iter.next()) { | 1974 while (iter.next()) { |
2003 iter.fDevice->drawRect(iter, r, looper.paint()); | 1975 iter.fDevice->drawRect(iter, r, looper.paint()); |
2004 } | 1976 } |
2005 | 1977 |
2006 LOOPER_END | 1978 LOOPER_END |
2007 } | 1979 } |
2008 | 1980 |
2009 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { | 1981 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { |
2010 CHECK_SHADER_NOSETCONTEXT(paint); | |
2011 | |
2012 SkRect storage; | 1982 SkRect storage; |
2013 const SkRect* bounds = NULL; | 1983 const SkRect* bounds = NULL; |
2014 if (paint.canComputeFastBounds()) { | 1984 if (paint.canComputeFastBounds()) { |
2015 bounds = &paint.computeFastBounds(oval, &storage); | 1985 bounds = &paint.computeFastBounds(oval, &storage); |
2016 if (this->quickReject(*bounds)) { | 1986 if (this->quickReject(*bounds)) { |
2017 return; | 1987 return; |
2018 } | 1988 } |
2019 } | 1989 } |
2020 | 1990 |
2021 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) | 1991 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) |
2022 | 1992 |
2023 while (iter.next()) { | 1993 while (iter.next()) { |
2024 iter.fDevice->drawOval(iter, oval, looper.paint()); | 1994 iter.fDevice->drawOval(iter, oval, looper.paint()); |
2025 } | 1995 } |
2026 | 1996 |
2027 LOOPER_END | 1997 LOOPER_END |
2028 } | 1998 } |
2029 | 1999 |
2030 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { | 2000 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
2031 CHECK_SHADER_NOSETCONTEXT(paint); | |
2032 | |
2033 SkRect storage; | 2001 SkRect storage; |
2034 const SkRect* bounds = NULL; | 2002 const SkRect* bounds = NULL; |
2035 if (paint.canComputeFastBounds()) { | 2003 if (paint.canComputeFastBounds()) { |
2036 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); | 2004 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); |
2037 if (this->quickReject(*bounds)) { | 2005 if (this->quickReject(*bounds)) { |
2038 return; | 2006 return; |
2039 } | 2007 } |
2040 } | 2008 } |
2041 | 2009 |
2042 if (rrect.isRect()) { | 2010 if (rrect.isRect()) { |
(...skipping 10 matching lines...) Expand all Loading... |
2053 | 2021 |
2054 while (iter.next()) { | 2022 while (iter.next()) { |
2055 iter.fDevice->drawRRect(iter, rrect, looper.paint()); | 2023 iter.fDevice->drawRRect(iter, rrect, looper.paint()); |
2056 } | 2024 } |
2057 | 2025 |
2058 LOOPER_END | 2026 LOOPER_END |
2059 } | 2027 } |
2060 | 2028 |
2061 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, | 2029 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, |
2062 const SkPaint& paint) { | 2030 const SkPaint& paint) { |
2063 CHECK_SHADER_NOSETCONTEXT(paint); | |
2064 | |
2065 SkRect storage; | 2031 SkRect storage; |
2066 const SkRect* bounds = NULL; | 2032 const SkRect* bounds = NULL; |
2067 if (paint.canComputeFastBounds()) { | 2033 if (paint.canComputeFastBounds()) { |
2068 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); | 2034 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); |
2069 if (this->quickReject(*bounds)) { | 2035 if (this->quickReject(*bounds)) { |
2070 return; | 2036 return; |
2071 } | 2037 } |
2072 } | 2038 } |
2073 | 2039 |
2074 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) | 2040 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) |
2075 | 2041 |
2076 while (iter.next()) { | 2042 while (iter.next()) { |
2077 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); | 2043 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); |
2078 } | 2044 } |
2079 | 2045 |
2080 LOOPER_END | 2046 LOOPER_END |
2081 } | 2047 } |
2082 | 2048 |
2083 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { | 2049 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
2084 CHECK_SHADER_NOSETCONTEXT(paint); | |
2085 | |
2086 if (!path.isFinite()) { | 2050 if (!path.isFinite()) { |
2087 return; | 2051 return; |
2088 } | 2052 } |
2089 | 2053 |
2090 SkRect storage; | 2054 SkRect storage; |
2091 const SkRect* bounds = NULL; | 2055 const SkRect* bounds = NULL; |
2092 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { | 2056 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { |
2093 const SkRect& pathBounds = path.getBounds(); | 2057 const SkRect& pathBounds = path.getBounds(); |
2094 bounds = &paint.computeFastBounds(pathBounds, &storage); | 2058 bounds = &paint.computeFastBounds(pathBounds, &storage); |
2095 if (this->quickReject(*bounds)) { | 2059 if (this->quickReject(*bounds)) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 start.fY); | 2315 start.fY); |
2352 r.fTop = offset; | 2316 r.fTop = offset; |
2353 r.fBottom = offset + height; | 2317 r.fBottom = offset + height; |
2354 DrawRect(draw, paint, r, textSize); | 2318 DrawRect(draw, paint, r, textSize); |
2355 } | 2319 } |
2356 } | 2320 } |
2357 } | 2321 } |
2358 | 2322 |
2359 void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca
lar y, | 2323 void SkCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkSca
lar y, |
2360 const SkPaint& paint) { | 2324 const SkPaint& paint) { |
2361 CHECK_SHADER_NOSETCONTEXT(paint); | |
2362 | |
2363 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2325 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
2364 | 2326 |
2365 while (iter.next()) { | 2327 while (iter.next()) { |
2366 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2328 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
2367 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); | 2329 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); |
2368 DrawTextDecorations(iter, dfp.paint(), | 2330 DrawTextDecorations(iter, dfp.paint(), |
2369 static_cast<const char*>(text), byteLength, x, y); | 2331 static_cast<const char*>(text), byteLength, x, y); |
2370 } | 2332 } |
2371 | 2333 |
2372 LOOPER_END | 2334 LOOPER_END |
2373 } | 2335 } |
2374 | 2336 |
2375 void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint
pos[], | 2337 void SkCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint
pos[], |
2376 const SkPaint& paint) { | 2338 const SkPaint& paint) { |
2377 CHECK_SHADER_NOSETCONTEXT(paint); | |
2378 | |
2379 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2339 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
2380 | 2340 |
2381 while (iter.next()) { | 2341 while (iter.next()) { |
2382 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2342 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
2383 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, | 2343 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, |
2384 dfp.paint()); | 2344 dfp.paint()); |
2385 } | 2345 } |
2386 | 2346 |
2387 LOOPER_END | 2347 LOOPER_END |
2388 } | 2348 } |
2389 | 2349 |
2390 void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScala
r xpos[], | 2350 void SkCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScala
r xpos[], |
2391 SkScalar constY, const SkPaint& paint) { | 2351 SkScalar constY, const SkPaint& paint) { |
2392 CHECK_SHADER_NOSETCONTEXT(paint); | |
2393 | |
2394 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2352 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
2395 | 2353 |
2396 while (iter.next()) { | 2354 while (iter.next()) { |
2397 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); | 2355 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); |
2398 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, | 2356 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, |
2399 dfp.paint()); | 2357 dfp.paint()); |
2400 } | 2358 } |
2401 | 2359 |
2402 LOOPER_END | 2360 LOOPER_END |
2403 } | 2361 } |
2404 | 2362 |
2405 void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPat
h& path, | 2363 void SkCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPat
h& path, |
2406 const SkMatrix* matrix, const SkPaint& paint) { | 2364 const SkMatrix* matrix, const SkPaint& paint) { |
2407 CHECK_SHADER_NOSETCONTEXT(paint); | |
2408 | |
2409 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) | 2365 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) |
2410 | 2366 |
2411 while (iter.next()) { | 2367 while (iter.next()) { |
2412 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, | 2368 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, |
2413 matrix, looper.paint()); | 2369 matrix, looper.paint()); |
2414 } | 2370 } |
2415 | 2371 |
2416 LOOPER_END | 2372 LOOPER_END |
2417 } | 2373 } |
2418 | 2374 |
2419 // These will become non-virtual, so they always call the (virtual) onDraw... me
thod | 2375 // These will become non-virtual, so they always call the (virtual) onDraw... me
thod |
2420 void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScala
r y, | 2376 void SkCanvas::drawText(const void* text, size_t byteLength, SkScalar x, SkScala
r y, |
(...skipping 11 matching lines...) Expand all Loading... |
2432 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath&
path, | 2388 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath&
path, |
2433 const SkMatrix* matrix, const SkPaint& paint) { | 2389 const SkMatrix* matrix, const SkPaint& paint) { |
2434 this->onDrawTextOnPath(text, byteLength, path, matrix, paint); | 2390 this->onDrawTextOnPath(text, byteLength, path, matrix, paint); |
2435 } | 2391 } |
2436 | 2392 |
2437 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, | 2393 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, |
2438 const SkPoint verts[], const SkPoint texs[], | 2394 const SkPoint verts[], const SkPoint texs[], |
2439 const SkColor colors[], SkXfermode* xmode, | 2395 const SkColor colors[], SkXfermode* xmode, |
2440 const uint16_t indices[], int indexCount, | 2396 const uint16_t indices[], int indexCount, |
2441 const SkPaint& paint) { | 2397 const SkPaint& paint) { |
2442 CHECK_SHADER_NOSETCONTEXT(paint); | |
2443 | |
2444 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) | 2398 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) |
2445 | 2399 |
2446 while (iter.next()) { | 2400 while (iter.next()) { |
2447 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, | 2401 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, |
2448 colors, xmode, indices, indexCount, | 2402 colors, xmode, indices, indexCount, |
2449 looper.paint()); | 2403 looper.paint()); |
2450 } | 2404 } |
2451 | 2405 |
2452 LOOPER_END | 2406 LOOPER_END |
2453 } | 2407 } |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2683 if (!supported_for_raster_canvas(info)) { | 2637 if (!supported_for_raster_canvas(info)) { |
2684 return NULL; | 2638 return NULL; |
2685 } | 2639 } |
2686 | 2640 |
2687 SkBitmap bitmap; | 2641 SkBitmap bitmap; |
2688 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2642 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
2689 return NULL; | 2643 return NULL; |
2690 } | 2644 } |
2691 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2645 return SkNEW_ARGS(SkCanvas, (bitmap)); |
2692 } | 2646 } |
OLD | NEW |