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

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

Issue 1568613008: unify how canvas checks for null on skia objects (images, blobs, pictures) (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: CAPITALIZE the macro, update test now that we don't record the null-image Created 4 years, 11 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 | « no previous file | tests/PictureTest.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 * 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 24 matching lines...) Expand all
35 #include "SkTraceEvent.h" 35 #include "SkTraceEvent.h"
36 36
37 #include <new> 37 #include <new>
38 38
39 #if SK_SUPPORT_GPU 39 #if SK_SUPPORT_GPU
40 #include "GrContext.h" 40 #include "GrContext.h"
41 #include "GrRenderTarget.h" 41 #include "GrRenderTarget.h"
42 #include "SkGr.h" 42 #include "SkGr.h"
43 #endif 43 #endif
44 44
45 #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
46
45 /* 47 /*
46 * Return true if the drawing this rect would hit every pixels in the canvas. 48 * Return true if the drawing this rect would hit every pixels in the canvas.
47 * 49 *
48 * Returns false if 50 * Returns false if
49 * - rect does not contain the canvas' bounds 51 * - rect does not contain the canvas' bounds
50 * - paint is not fill 52 * - paint is not fill
51 * - paint would blur or otherwise change the coverage of the rect 53 * - paint would blur or otherwise change the coverage of the rect
52 */ 54 */
53 bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa int, 55 bool SkCanvas::wouldOverwriteEntireSurface(const SkRect* rect, const SkPaint* pa int,
54 ShaderOverrideOpacity overrideOpacity ) const { 56 ShaderOverrideOpacity overrideOpacity ) const {
(...skipping 1867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1922 const uint16_t indices[], int indexCount, const SkPa int& paint) { 1924 const uint16_t indices[], int indexCount, const SkPa int& paint) {
1923 this->onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode, 1925 this->onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
1924 indices, indexCount, paint); 1926 indices, indexCount, paint);
1925 } 1927 }
1926 1928
1927 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) { 1929 void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
1928 this->onDrawPath(path, paint); 1930 this->onDrawPath(path, paint);
1929 } 1931 }
1930 1932
1931 void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP aint* paint) { 1933 void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP aint* paint) {
1934 RETURN_ON_NULL(image);
1932 this->onDrawImage(image, x, y, paint); 1935 this->onDrawImage(image, x, y, paint);
1933 } 1936 }
1934 1937
1935 void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRe ct& dst, 1938 void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRe ct& dst,
1936 const SkPaint* paint, SrcRectConstraint constraint) { 1939 const SkPaint* paint, SrcRectConstraint constraint) {
1940 RETURN_ON_NULL(image);
1937 if (dst.isEmpty() || src.isEmpty()) { 1941 if (dst.isEmpty() || src.isEmpty()) {
1938 return; 1942 return;
1939 } 1943 }
1940 this->onDrawImageRect(image, &src, dst, paint, constraint); 1944 this->onDrawImageRect(image, &src, dst, paint, constraint);
1941 } 1945 }
1942 1946
1943 void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const Sk Rect& dst, 1947 void SkCanvas::drawImageRect(const SkImage* image, const SkIRect& isrc, const Sk Rect& dst,
1944 const SkPaint* paint, SrcRectConstraint constraint) { 1948 const SkPaint* paint, SrcRectConstraint constraint) {
1949 RETURN_ON_NULL(image);
1945 this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint); 1950 this->drawImageRect(image, SkRect::Make(isrc), dst, paint, constraint);
1946 } 1951 }
1947 1952
1948 void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPa int* paint, 1953 void SkCanvas::drawImageRect(const SkImage* image, const SkRect& dst, const SkPa int* paint,
1949 SrcRectConstraint constraint) { 1954 SrcRectConstraint constraint) {
1955 RETURN_ON_NULL(image);
1950 this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint, 1956 this->drawImageRect(image, SkRect::MakeIWH(image->width(), image->height()), dst, paint,
1951 constraint); 1957 constraint);
1952 } 1958 }
1953 1959
1954 void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, 1960 void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
1955 const SkPaint* paint) { 1961 const SkPaint* paint) {
1962 RETURN_ON_NULL(image);
1956 if (dst.isEmpty()) { 1963 if (dst.isEmpty()) {
1957 return; 1964 return;
1958 } 1965 }
1959 if (!SkNinePatchIter::Valid(image->width(), image->height(), center)) { 1966 if (!SkNinePatchIter::Valid(image->width(), image->height(), center)) {
1960 this->drawImageRect(image, dst, paint); 1967 this->drawImageRect(image, dst, paint);
1961 } 1968 }
1962 this->onDrawImageNine(image, center, dst, paint); 1969 this->onDrawImageNine(image, center, dst, paint);
1963 } 1970 }
1964 1971
1965 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) { 1972 void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, cons t SkPaint* paint) {
(...skipping 29 matching lines...) Expand all
1995 } 2002 }
1996 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) { 2003 if (!SkNinePatchIter::Valid(bitmap.width(), bitmap.height(), center)) {
1997 this->drawBitmapRect(bitmap, dst, paint); 2004 this->drawBitmapRect(bitmap, dst, paint);
1998 } 2005 }
1999 this->onDrawBitmapNine(bitmap, center, dst, paint); 2006 this->onDrawBitmapNine(bitmap, center, dst, paint);
2000 } 2007 }
2001 2008
2002 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[], 2009 void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk Rect tex[],
2003 const SkColor colors[], int count, SkXfermode::Mode mod e, 2010 const SkColor colors[], int count, SkXfermode::Mode mod e,
2004 const SkRect* cull, const SkPaint* paint) { 2011 const SkRect* cull, const SkPaint* paint) {
2012 RETURN_ON_NULL(atlas);
2005 if (count <= 0) { 2013 if (count <= 0) {
2006 return; 2014 return;
2007 } 2015 }
2008 SkASSERT(atlas); 2016 SkASSERT(atlas);
2009 SkASSERT(xform); 2017 SkASSERT(xform);
2010 SkASSERT(tex); 2018 SkASSERT(tex);
2011 this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint); 2019 this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
2012 } 2020 }
2013 2021
2014 void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst, 2022 void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst,
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2637 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPosTextH()"); 2645 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPosTextH()");
2638 this->onDrawPosTextH(text, byteLength, xpos, constY, paint); 2646 this->onDrawPosTextH(text, byteLength, xpos, constY, paint);
2639 } 2647 }
2640 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath& path, 2648 void SkCanvas::drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
2641 const SkMatrix* matrix, const SkPaint& paint) { 2649 const SkMatrix* matrix, const SkPaint& paint) {
2642 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextOnPath()"); 2650 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextOnPath()");
2643 this->onDrawTextOnPath(text, byteLength, path, matrix, paint); 2651 this->onDrawTextOnPath(text, byteLength, path, matrix, paint);
2644 } 2652 }
2645 void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 2653 void SkCanvas::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
2646 const SkPaint& paint) { 2654 const SkPaint& paint) {
2655 RETURN_ON_NULL(blob);
2647 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextBlob()"); 2656 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawTextBlob()");
2648 if (blob) { 2657 this->onDrawTextBlob(blob, x, y, paint);
2649 this->onDrawTextBlob(blob, x, y, paint);
2650 }
2651 } 2658 }
2652 2659
2653 void SkCanvas::onDrawVertices(VertexMode vmode, int vertexCount, 2660 void SkCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
2654 const SkPoint verts[], const SkPoint texs[], 2661 const SkPoint verts[], const SkPoint texs[],
2655 const SkColor colors[], SkXfermode* xmode, 2662 const SkColor colors[], SkXfermode* xmode,
2656 const uint16_t indices[], int indexCount, 2663 const uint16_t indices[], int indexCount,
2657 const SkPaint& paint) { 2664 const SkPaint& paint) {
2658 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawVertices()"); 2665 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawVertices()");
2659 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) 2666 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr)
2660 2667
(...skipping 30 matching lines...) Expand all
2691 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr) 2698 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr)
2692 2699
2693 while (iter.next()) { 2700 while (iter.next()) {
2694 iter.fDevice->drawPatch(iter, cubics, colors, texCoords, xmode, paint); 2701 iter.fDevice->drawPatch(iter, cubics, colors, texCoords, xmode, paint);
2695 } 2702 }
2696 2703
2697 LOOPER_END 2704 LOOPER_END
2698 } 2705 }
2699 2706
2700 void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) { 2707 void SkCanvas::drawDrawable(SkDrawable* dr, SkScalar x, SkScalar y) {
2701 if (dr) { 2708 RETURN_ON_NULL(dr);
2702 if (x || y) { 2709 if (x || y) {
2703 SkMatrix matrix = SkMatrix::MakeTrans(x, y); 2710 SkMatrix matrix = SkMatrix::MakeTrans(x, y);
2704 this->onDrawDrawable(dr, &matrix); 2711 this->onDrawDrawable(dr, &matrix);
2705 } else { 2712 } else {
2706 this->onDrawDrawable(dr, nullptr); 2713 this->onDrawDrawable(dr, nullptr);
2707 }
2708 } 2714 }
2709 } 2715 }
2710 2716
2711 void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) { 2717 void SkCanvas::drawDrawable(SkDrawable* dr, const SkMatrix* matrix) {
2712 if (dr) { 2718 RETURN_ON_NULL(dr);
2713 if (matrix && matrix->isIdentity()) { 2719 if (matrix && matrix->isIdentity()) {
2714 matrix = nullptr; 2720 matrix = nullptr;
2715 }
2716 this->onDrawDrawable(dr, matrix);
2717 } 2721 }
2722 this->onDrawDrawable(dr, matrix);
2718 } 2723 }
2719 2724
2720 void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) { 2725 void SkCanvas::onDrawDrawable(SkDrawable* dr, const SkMatrix* matrix) {
2721 SkRect bounds = dr->getBounds(); 2726 SkRect bounds = dr->getBounds();
2722 if (matrix) { 2727 if (matrix) {
2723 matrix->mapRect(&bounds); 2728 matrix->mapRect(&bounds);
2724 } 2729 }
2725 if (this->quickReject(bounds)) { 2730 if (this->quickReject(bounds)) {
2726 return; 2731 return;
2727 } 2732 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 /** 2882 /**
2878 * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture, 2883 * This constant is trying to balance the speed of ref'ing a subpicture into a parent picture,
2879 * against the playback cost of recursing into the subpicture to get at its act ual ops. 2884 * against the playback cost of recursing into the subpicture to get at its act ual ops.
2880 * 2885 *
2881 * For now we pick a conservatively small value, though measurement (and other heuristics like 2886 * For now we pick a conservatively small value, though measurement (and other heuristics like
2882 * the type of ops contained) may justify changing this value. 2887 * the type of ops contained) may justify changing this value.
2883 */ 2888 */
2884 #define kMaxPictureOpsToUnrollInsteadOfRef 1 2889 #define kMaxPictureOpsToUnrollInsteadOfRef 1
2885 2890
2886 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con st SkPaint* paint) { 2891 void SkCanvas::drawPicture(const SkPicture* picture, const SkMatrix* matrix, con st SkPaint* paint) {
2892 RETURN_ON_NULL(picture);
2893
2887 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPicture()"); 2894 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawPicture()");
2888 if (picture) { 2895 if (matrix && matrix->isIdentity()) {
2889 if (matrix && matrix->isIdentity()) { 2896 matrix = nullptr;
2890 matrix = nullptr; 2897 }
2891 } 2898 if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) {
2892 if (picture->approximateOpCount() <= kMaxPictureOpsToUnrollInsteadOfRef) { 2899 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
2893 SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect( )); 2900 picture->playback(this);
2894 picture->playback(this); 2901 } else {
2895 } else { 2902 this->onDrawPicture(picture, matrix, paint);
2896 this->onDrawPicture(picture, matrix, paint);
2897 }
2898 } 2903 }
2899 } 2904 }
2900 2905
2901 void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, 2906 void SkCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
2902 const SkPaint* paint) { 2907 const SkPaint* paint) {
2903 if (!paint || paint->canComputeFastBounds()) { 2908 if (!paint || paint->canComputeFastBounds()) {
2904 SkRect bounds = picture->cullRect(); 2909 SkRect bounds = picture->cullRect();
2905 if (paint) { 2910 if (paint) {
2906 paint->computeFastBounds(bounds, &bounds); 2911 paint->computeFastBounds(bounds, &bounds);
2907 } 2912 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3023 } 3028 }
3024 3029
3025 if (matrix) { 3030 if (matrix) {
3026 canvas->concat(*matrix); 3031 canvas->concat(*matrix);
3027 } 3032 }
3028 } 3033 }
3029 3034
3030 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3035 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
3031 fCanvas->restoreToCount(fSaveCount); 3036 fCanvas->restoreToCount(fSaveCount);
3032 } 3037 }
OLDNEW
« no previous file with comments | « no previous file | tests/PictureTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698