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

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

Issue 241283003: Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 8 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/core/SkBlitter_RGB16.cpp ('k') | src/core/SkComposeShader.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 /* 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
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
94 #define CHECK_LOCKCOUNT_BALANCE(bitmap) AutoCheckLockCountBalance clcb(bitmap) 114 #define CHECK_LOCKCOUNT_BALANCE(bitmap) AutoCheckLockCountBalance clcb(bitmap)
115 #define CHECK_SHADER_NOSETCONTEXT(paint) AutoCheckNoSetContext cshsc(paint)
95 116
96 #else 117 #else
97 #define CHECK_LOCKCOUNT_BALANCE(bitmap) 118 #define CHECK_LOCKCOUNT_BALANCE(bitmap)
119 #define CHECK_SHADER_NOSETCONTEXT(paint)
98 #endif 120 #endif
99 121
100 typedef SkTLazy<SkPaint> SkLazyPaint; 122 typedef SkTLazy<SkPaint> SkLazyPaint;
101 123
102 void SkCanvas::predrawNotify() { 124 void SkCanvas::predrawNotify() {
103 if (fSurfaceBase) { 125 if (fSurfaceBase) {
104 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); 126 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode);
105 } 127 }
106 } 128 }
107 129
(...skipping 1798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 if (NULL != fSurfaceBase) { 1928 if (NULL != fSurfaceBase) {
1907 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode); 1929 fSurfaceBase->aboutToDraw(SkSurface::kDiscard_ContentChangeMode);
1908 } 1930 }
1909 } 1931 }
1910 1932
1911 void SkCanvas::drawPaint(const SkPaint& paint) { 1933 void SkCanvas::drawPaint(const SkPaint& paint) {
1912 this->internalDrawPaint(paint); 1934 this->internalDrawPaint(paint);
1913 } 1935 }
1914 1936
1915 void SkCanvas::internalDrawPaint(const SkPaint& paint) { 1937 void SkCanvas::internalDrawPaint(const SkPaint& paint) {
1938 CHECK_SHADER_NOSETCONTEXT(paint);
1939
1916 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL) 1940 LOOPER_BEGIN(paint, SkDrawFilter::kPaint_Type, NULL)
1917 1941
1918 while (iter.next()) { 1942 while (iter.next()) {
1919 iter.fDevice->drawPaint(iter, looper.paint()); 1943 iter.fDevice->drawPaint(iter, looper.paint());
1920 } 1944 }
1921 1945
1922 LOOPER_END 1946 LOOPER_END
1923 } 1947 }
1924 1948
1925 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], 1949 void SkCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
1926 const SkPaint& paint) { 1950 const SkPaint& paint) {
1927 if ((long)count <= 0) { 1951 if ((long)count <= 0) {
1928 return; 1952 return;
1929 } 1953 }
1930 1954
1955 CHECK_SHADER_NOSETCONTEXT(paint);
1956
1931 SkRect r, storage; 1957 SkRect r, storage;
1932 const SkRect* bounds = NULL; 1958 const SkRect* bounds = NULL;
1933 if (paint.canComputeFastBounds()) { 1959 if (paint.canComputeFastBounds()) {
1934 // special-case 2 points (common for drawing a single line) 1960 // special-case 2 points (common for drawing a single line)
1935 if (2 == count) { 1961 if (2 == count) {
1936 r.set(pts[0], pts[1]); 1962 r.set(pts[0], pts[1]);
1937 } else { 1963 } else {
1938 r.set(pts, SkToInt(count)); 1964 r.set(pts, SkToInt(count));
1939 } 1965 }
1940 bounds = &paint.computeFastStrokeBounds(r, &storage); 1966 bounds = &paint.computeFastStrokeBounds(r, &storage);
1941 if (this->quickReject(*bounds)) { 1967 if (this->quickReject(*bounds)) {
1942 return; 1968 return;
1943 } 1969 }
1944 } 1970 }
1945 1971
1946 SkASSERT(pts != NULL); 1972 SkASSERT(pts != NULL);
1947 1973
1948 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds) 1974 LOOPER_BEGIN(paint, SkDrawFilter::kPoint_Type, bounds)
1949 1975
1950 while (iter.next()) { 1976 while (iter.next()) {
1951 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint()); 1977 iter.fDevice->drawPoints(iter, mode, count, pts, looper.paint());
1952 } 1978 }
1953 1979
1954 LOOPER_END 1980 LOOPER_END
1955 } 1981 }
1956 1982
1957 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) { 1983 void SkCanvas::drawRect(const SkRect& r, const SkPaint& paint) {
1984 CHECK_SHADER_NOSETCONTEXT(paint);
1985
1958 SkRect storage; 1986 SkRect storage;
1959 const SkRect* bounds = NULL; 1987 const SkRect* bounds = NULL;
1960 if (paint.canComputeFastBounds()) { 1988 if (paint.canComputeFastBounds()) {
1961 bounds = &paint.computeFastBounds(r, &storage); 1989 bounds = &paint.computeFastBounds(r, &storage);
1962 if (this->quickReject(*bounds)) { 1990 if (this->quickReject(*bounds)) {
1963 return; 1991 return;
1964 } 1992 }
1965 } 1993 }
1966 1994
1967 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds) 1995 LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, bounds)
1968 1996
1969 while (iter.next()) { 1997 while (iter.next()) {
1970 iter.fDevice->drawRect(iter, r, looper.paint()); 1998 iter.fDevice->drawRect(iter, r, looper.paint());
1971 } 1999 }
1972 2000
1973 LOOPER_END 2001 LOOPER_END
1974 } 2002 }
1975 2003
1976 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) { 2004 void SkCanvas::drawOval(const SkRect& oval, const SkPaint& paint) {
2005 CHECK_SHADER_NOSETCONTEXT(paint);
2006
1977 SkRect storage; 2007 SkRect storage;
1978 const SkRect* bounds = NULL; 2008 const SkRect* bounds = NULL;
1979 if (paint.canComputeFastBounds()) { 2009 if (paint.canComputeFastBounds()) {
1980 bounds = &paint.computeFastBounds(oval, &storage); 2010 bounds = &paint.computeFastBounds(oval, &storage);
1981 if (this->quickReject(*bounds)) { 2011 if (this->quickReject(*bounds)) {
1982 return; 2012 return;
1983 } 2013 }
1984 } 2014 }
1985 2015
1986 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds) 2016 LOOPER_BEGIN(paint, SkDrawFilter::kOval_Type, bounds)
1987 2017
1988 while (iter.next()) { 2018 while (iter.next()) {
1989 iter.fDevice->drawOval(iter, oval, looper.paint()); 2019 iter.fDevice->drawOval(iter, oval, looper.paint());
1990 } 2020 }
1991 2021
1992 LOOPER_END 2022 LOOPER_END
1993 } 2023 }
1994 2024
1995 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 2025 void SkCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
2026 CHECK_SHADER_NOSETCONTEXT(paint);
2027
1996 SkRect storage; 2028 SkRect storage;
1997 const SkRect* bounds = NULL; 2029 const SkRect* bounds = NULL;
1998 if (paint.canComputeFastBounds()) { 2030 if (paint.canComputeFastBounds()) {
1999 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage); 2031 bounds = &paint.computeFastBounds(rrect.getBounds(), &storage);
2000 if (this->quickReject(*bounds)) { 2032 if (this->quickReject(*bounds)) {
2001 return; 2033 return;
2002 } 2034 }
2003 } 2035 }
2004 2036
2005 if (rrect.isRect()) { 2037 if (rrect.isRect()) {
(...skipping 10 matching lines...) Expand all
2016 2048
2017 while (iter.next()) { 2049 while (iter.next()) {
2018 iter.fDevice->drawRRect(iter, rrect, looper.paint()); 2050 iter.fDevice->drawRRect(iter, rrect, looper.paint());
2019 } 2051 }
2020 2052
2021 LOOPER_END 2053 LOOPER_END
2022 } 2054 }
2023 2055
2024 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 2056 void SkCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
2025 const SkPaint& paint) { 2057 const SkPaint& paint) {
2058 CHECK_SHADER_NOSETCONTEXT(paint);
2059
2026 SkRect storage; 2060 SkRect storage;
2027 const SkRect* bounds = NULL; 2061 const SkRect* bounds = NULL;
2028 if (paint.canComputeFastBounds()) { 2062 if (paint.canComputeFastBounds()) {
2029 bounds = &paint.computeFastBounds(outer.getBounds(), &storage); 2063 bounds = &paint.computeFastBounds(outer.getBounds(), &storage);
2030 if (this->quickReject(*bounds)) { 2064 if (this->quickReject(*bounds)) {
2031 return; 2065 return;
2032 } 2066 }
2033 } 2067 }
2034 2068
2035 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds) 2069 LOOPER_BEGIN(paint, SkDrawFilter::kRRect_Type, bounds)
2036 2070
2037 while (iter.next()) { 2071 while (iter.next()) {
2038 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint()); 2072 iter.fDevice->drawDRRect(iter, outer, inner, looper.paint());
2039 } 2073 }
2040 2074
2041 LOOPER_END 2075 LOOPER_END
2042 } 2076 }
2043 2077
2044 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { 2078 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
2079 CHECK_SHADER_NOSETCONTEXT(paint);
2080
2045 if (!path.isFinite()) { 2081 if (!path.isFinite()) {
2046 return; 2082 return;
2047 } 2083 }
2048 2084
2049 SkRect storage; 2085 SkRect storage;
2050 const SkRect* bounds = NULL; 2086 const SkRect* bounds = NULL;
2051 if (!path.isInverseFillType() && paint.canComputeFastBounds()) { 2087 if (!path.isInverseFillType() && paint.canComputeFastBounds()) {
2052 const SkRect& pathBounds = path.getBounds(); 2088 const SkRect& pathBounds = path.getBounds();
2053 bounds = &paint.computeFastBounds(pathBounds, &storage); 2089 bounds = &paint.computeFastBounds(pathBounds, &storage);
2054 if (this->quickReject(*bounds)) { 2090 if (this->quickReject(*bounds)) {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 start.fY); 2346 start.fY);
2311 r.fTop = offset; 2347 r.fTop = offset;
2312 r.fBottom = offset + height; 2348 r.fBottom = offset + height;
2313 DrawRect(draw, paint, r, textSize); 2349 DrawRect(draw, paint, r, textSize);
2314 } 2350 }
2315 } 2351 }
2316 } 2352 }
2317 2353
2318 void SkCanvas::drawText(const void* text, size_t byteLength, 2354 void SkCanvas::drawText(const void* text, size_t byteLength,
2319 SkScalar x, SkScalar y, const SkPaint& paint) { 2355 SkScalar x, SkScalar y, const SkPaint& paint) {
2356 CHECK_SHADER_NOSETCONTEXT(paint);
2357
2320 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2358 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
2321 2359
2322 while (iter.next()) { 2360 while (iter.next()) {
2323 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2361 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2324 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint()); 2362 iter.fDevice->drawText(iter, text, byteLength, x, y, dfp.paint());
2325 DrawTextDecorations(iter, dfp.paint(), 2363 DrawTextDecorations(iter, dfp.paint(),
2326 static_cast<const char*>(text), byteLength, x, y); 2364 static_cast<const char*>(text), byteLength, x, y);
2327 } 2365 }
2328 2366
2329 LOOPER_END 2367 LOOPER_END
2330 } 2368 }
2331 2369
2332 void SkCanvas::drawPosText(const void* text, size_t byteLength, 2370 void SkCanvas::drawPosText(const void* text, size_t byteLength,
2333 const SkPoint pos[], const SkPaint& paint) { 2371 const SkPoint pos[], const SkPaint& paint) {
2372 CHECK_SHADER_NOSETCONTEXT(paint);
2373
2334 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2374 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
2335 2375
2336 while (iter.next()) { 2376 while (iter.next()) {
2337 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2377 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2338 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2, 2378 iter.fDevice->drawPosText(iter, text, byteLength, &pos->fX, 0, 2,
2339 dfp.paint()); 2379 dfp.paint());
2340 } 2380 }
2341 2381
2342 LOOPER_END 2382 LOOPER_END
2343 } 2383 }
2344 2384
2345 void SkCanvas::drawPosTextH(const void* text, size_t byteLength, 2385 void SkCanvas::drawPosTextH(const void* text, size_t byteLength,
2346 const SkScalar xpos[], SkScalar constY, 2386 const SkScalar xpos[], SkScalar constY,
2347 const SkPaint& paint) { 2387 const SkPaint& paint) {
2388 CHECK_SHADER_NOSETCONTEXT(paint);
2389
2348 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2390 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
2349 2391
2350 while (iter.next()) { 2392 while (iter.next()) {
2351 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint()); 2393 SkDeviceFilteredPaint dfp(iter.fDevice, looper.paint());
2352 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1, 2394 iter.fDevice->drawPosText(iter, text, byteLength, xpos, constY, 1,
2353 dfp.paint()); 2395 dfp.paint());
2354 } 2396 }
2355 2397
2356 LOOPER_END 2398 LOOPER_END
2357 } 2399 }
2358 2400
2359 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, 2401 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength,
2360 const SkPath& path, const SkMatrix* matrix, 2402 const SkPath& path, const SkMatrix* matrix,
2361 const SkPaint& paint) { 2403 const SkPaint& paint) {
2404 CHECK_SHADER_NOSETCONTEXT(paint);
2405
2362 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL) 2406 LOOPER_BEGIN(paint, SkDrawFilter::kText_Type, NULL)
2363 2407
2364 while (iter.next()) { 2408 while (iter.next()) {
2365 iter.fDevice->drawTextOnPath(iter, text, byteLength, path, 2409 iter.fDevice->drawTextOnPath(iter, text, byteLength, path,
2366 matrix, looper.paint()); 2410 matrix, looper.paint());
2367 } 2411 }
2368 2412
2369 LOOPER_END 2413 LOOPER_END
2370 } 2414 }
2371 2415
2372 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, 2416 void SkCanvas::drawVertices(VertexMode vmode, int vertexCount,
2373 const SkPoint verts[], const SkPoint texs[], 2417 const SkPoint verts[], const SkPoint texs[],
2374 const SkColor colors[], SkXfermode* xmode, 2418 const SkColor colors[], SkXfermode* xmode,
2375 const uint16_t indices[], int indexCount, 2419 const uint16_t indices[], int indexCount,
2376 const SkPaint& paint) { 2420 const SkPaint& paint) {
2421 CHECK_SHADER_NOSETCONTEXT(paint);
2422
2377 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL) 2423 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, NULL)
2378 2424
2379 while (iter.next()) { 2425 while (iter.next()) {
2380 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs, 2426 iter.fDevice->drawVertices(iter, vmode, vertexCount, verts, texs,
2381 colors, xmode, indices, indexCount, 2427 colors, xmode, indices, indexCount,
2382 looper.paint()); 2428 looper.paint());
2383 } 2429 }
2384 2430
2385 LOOPER_END 2431 LOOPER_END
2386 } 2432 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 if (!bitmap.installPixels(info, pixels, rowBytes)) { 2667 if (!bitmap.installPixels(info, pixels, rowBytes)) {
2622 return NULL; 2668 return NULL;
2623 } 2669 }
2624 2670
2625 // should this functionality be moved into allocPixels()? 2671 // should this functionality be moved into allocPixels()?
2626 if (!bitmap.info().isOpaque()) { 2672 if (!bitmap.info().isOpaque()) {
2627 bitmap.eraseColor(0); 2673 bitmap.eraseColor(0);
2628 } 2674 }
2629 return SkNEW_ARGS(SkCanvas, (bitmap)); 2675 return SkNEW_ARGS(SkCanvas, (bitmap));
2630 } 2676 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter_RGB16.cpp ('k') | src/core/SkComposeShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698