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

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

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