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

Side by Side Diff: Source/platform/graphics/GraphicsContext.cpp

Issue 987383003: Fix ASSERT(m_canvas) failures when contextDisabled() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "third_party/skia/include/core/SkRefCnt.h" 46 #include "third_party/skia/include/core/SkRefCnt.h"
47 #include "third_party/skia/include/core/SkSurface.h" 47 #include "third_party/skia/include/core/SkSurface.h"
48 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" 48 #include "third_party/skia/include/effects/SkBlurMaskFilter.h"
49 #include "third_party/skia/include/effects/SkCornerPathEffect.h" 49 #include "third_party/skia/include/effects/SkCornerPathEffect.h"
50 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" 50 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h"
51 #include "third_party/skia/include/effects/SkLumaColorFilter.h" 51 #include "third_party/skia/include/effects/SkLumaColorFilter.h"
52 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" 52 #include "third_party/skia/include/effects/SkMatrixImageFilter.h"
53 #include "third_party/skia/include/effects/SkPictureImageFilter.h" 53 #include "third_party/skia/include/effects/SkPictureImageFilter.h"
54 #include "third_party/skia/include/gpu/GrRenderTarget.h" 54 #include "third_party/skia/include/gpu/GrRenderTarget.h"
55 #include "third_party/skia/include/gpu/GrTexture.h" 55 #include "third_party/skia/include/gpu/GrTexture.h"
56 #include "third_party/skia/include/utils/SkNullCanvas.h"
56 #include "wtf/Assertions.h" 57 #include "wtf/Assertions.h"
57 #include "wtf/MathExtras.h" 58 #include "wtf/MathExtras.h"
58 59
59 namespace blink { 60 namespace blink {
60 61
61 class GraphicsContext::RecordingState { 62 class GraphicsContext::RecordingState {
62 WTF_MAKE_FAST_ALLOCATED; 63 WTF_MAKE_FAST_ALLOCATED;
63 WTF_MAKE_NONCOPYABLE(RecordingState); 64 WTF_MAKE_NONCOPYABLE(RecordingState);
64 public: 65 public:
65 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix) 66 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m atrix)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 , m_deviceScaleFactor(1.0f) 100 , m_deviceScaleFactor(1.0f)
100 , m_trackTextRegion(false) 101 , m_trackTextRegion(false)
101 , m_accelerated(false) 102 , m_accelerated(false)
102 , m_printing(false) 103 , m_printing(false)
103 , m_antialiasHairlineImages(false) 104 , m_antialiasHairlineImages(false)
104 { 105 {
105 // FIXME: Do some tests to determine how many states are typically used, and allocate 106 // FIXME: Do some tests to determine how many states are typically used, and allocate
106 // several here. 107 // several here.
107 m_paintStateStack.append(GraphicsContextState::create()); 108 m_paintStateStack.append(GraphicsContextState::create());
108 m_paintState = m_paintStateStack.last().get(); 109 m_paintState = m_paintStateStack.last().get();
110
111 if (contextDisabled()) {
f(malita) 2015/03/11 18:20:51 Would it be a lot of duplication to do this at cal
Xianzhu 2015/03/11 19:40:46 Looked at several call sites and that seems more c
112 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull Canvas())));
113 m_canvas = nullCanvas.get();
f(malita) 2015/03/11 18:20:51 If we always allocate a (SkNull) canvas when conte
Xianzhu 2015/03/11 19:40:46 Right.
114 }
109 } 115 }
110 116
111 GraphicsContext::~GraphicsContext() 117 GraphicsContext::~GraphicsContext()
112 { 118 {
113 #if ENABLE(ASSERT) 119 #if ENABLE(ASSERT)
114 if (!m_disableDestructionChecks) { 120 if (!m_disableDestructionChecks) {
115 ASSERT(!m_paintStateIndex); 121 ASSERT(!m_paintStateIndex);
116 ASSERT(!m_paintState->saveCount()); 122 ASSERT(!m_paintState->saveCount());
117 ASSERT(!m_annotationCount); 123 ASSERT(!m_annotationCount);
118 ASSERT(!m_layerCount); 124 ASSERT(!m_layerCount);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 return picture.release(); 530 return picture.release();
525 } 531 }
526 532
527 bool GraphicsContext::isRecording() const 533 bool GraphicsContext::isRecording() const
528 { 534 {
529 return !m_recordingStateStack.isEmpty(); 535 return !m_recordingStateStack.isEmpty();
530 } 536 }
531 537
532 void GraphicsContext::drawPicture(const SkPicture* picture) 538 void GraphicsContext::drawPicture(const SkPicture* picture)
533 { 539 {
534 ASSERT(m_canvas);
535
536 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp 540 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp
537 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled 541 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled
538 // on playback anyway. 542 // on playback anyway.
539 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); 543 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled();
540 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures)) 544 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures))
541 return; 545 return;
542 546
547 ASSERT(m_canvas);
543 m_canvas->drawPicture(picture); 548 m_canvas->drawPicture(picture);
544 } 549 }
545 550
546 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest , const FloatRect& src, SkXfermode::Mode op) 551 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest , const FloatRect& src, SkXfermode::Mode op)
547 { 552 {
548 ASSERT(m_canvas);
549 if (contextDisabled() || !picture) 553 if (contextDisabled() || !picture)
550 return; 554 return;
555 ASSERT(m_canvas);
551 556
552 SkPaint picturePaint; 557 SkPaint picturePaint;
553 picturePaint.setXfermodeMode(op); 558 picturePaint.setXfermodeMode(op);
554 m_canvas->save(); 559 m_canvas->save();
555 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); 560 SkRect sourceBounds = WebCoreFloatRectToSKRect(src);
556 SkRect skBounds = WebCoreFloatRectToSKRect(dest); 561 SkRect skBounds = WebCoreFloatRectToSKRect(dest);
557 SkMatrix pictureTransform; 562 SkMatrix pictureTransform;
558 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); 563 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit);
559 m_canvas->concat(pictureTransform); 564 m_canvas->concat(pictureTransform);
560 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter:: CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima geInterpolationQuality()))); 565 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter:: CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima geInterpolationQuality())));
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor, 739 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor,
735 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha); 740 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha);
736 setDrawLooper(drawLooperBuilder.release()); 741 setDrawLooper(drawLooperBuilder.release());
737 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); 742 fillRectWithRoundedHole(outerRect, roundedHole, fillColor);
738 restore(); 743 restore();
739 clearDrawLooper(); 744 clearDrawLooper();
740 } 745 }
741 746
742 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) 747 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2)
743 { 748 {
744 ASSERT(m_canvas);
745 if (contextDisabled()) 749 if (contextDisabled())
746 return; 750 return;
751 ASSERT(m_canvas);
747 752
748 StrokeStyle penStyle = strokeStyle(); 753 StrokeStyle penStyle = strokeStyle();
749 if (penStyle == NoStroke) 754 if (penStyle == NoStroke)
750 return; 755 return;
751 756
752 FloatPoint p1 = point1; 757 FloatPoint p1 = point1;
753 FloatPoint p2 = point2; 758 FloatPoint p2 = point2;
754 bool isVerticalLine = (p1.x() == p2.x()); 759 bool isVerticalLine = (p1.x() == p2.x());
755 int width = roundf(strokeThickness()); 760 int width = roundf(strokeThickness());
756 761
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 const FloatRect* src, SkXfermode::Mode op) 1075 const FloatRect* src, SkXfermode::Mode op)
1071 { 1076 {
1072 if (contextDisabled() || !image) 1077 if (contextDisabled() || !image)
1073 return; 1078 return;
1074 1079
1075 image->draw(this, dest, src, op); 1080 image->draw(this, dest, src, op);
1076 } 1081 }
1077 1082
1078 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y) 1083 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y)
1079 { 1084 {
1080 ASSERT(m_canvas);
1081 if (contextDisabled()) 1085 if (contextDisabled())
1082 return; 1086 return;
1087 ASSERT(m_canvas);
1083 1088
1084 m_canvas->writePixels(info, pixels, rowBytes, x, y); 1089 m_canvas->writePixels(info, pixels, rowBytes, x, y);
1085 } 1090 }
1086 1091
1087 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, 1092 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
1088 const SkRect& dst, const SkPaint* paint) 1093 const SkRect& dst, const SkPaint* paint)
1089 { 1094 {
1090 ASSERT(m_canvas);
1091 // Textures are bound to the blink main-thread GrContext, which can not be 1095 // Textures are bound to the blink main-thread GrContext, which can not be
1092 // used on the compositor raster thread. 1096 // used on the compositor raster thread.
1093 // FIXME: Mailbox support would make this possible in the GPU-raster case. 1097 // FIXME: Mailbox support would make this possible in the GPU-raster case.
1094 ASSERT(!isRecording() || !bitmap.getTexture()); 1098 ASSERT(!isRecording() || !bitmap.getTexture());
1095 if (contextDisabled()) 1099 if (contextDisabled())
1096 return; 1100 return;
1097 1101
1098 SkCanvas::DrawBitmapRectFlags flags = 1102 SkCanvas::DrawBitmapRectFlags flags =
1099 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; 1103 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag;
1100 1104
1105 ASSERT(m_canvas);
1101 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); 1106 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
1102 } 1107 }
1103 1108
1104 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to p, const SkPaint* paint) 1109 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to p, const SkPaint* paint)
1105 { 1110 {
1106 ASSERT(m_canvas);
1107 if (contextDisabled()) 1111 if (contextDisabled())
1108 return; 1112 return;
1113 ASSERT(m_canvas);
1109 1114
1110 m_canvas->drawImage(image, left, top, paint); 1115 m_canvas->drawImage(image, left, top, paint);
1111 } 1116 }
1112 1117
1113 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst, const SkPaint* paint) 1118 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst, const SkPaint* paint)
1114 { 1119 {
1115 ASSERT(m_canvas);
1116 if (contextDisabled()) 1120 if (contextDisabled())
1117 return; 1121 return;
1122 ASSERT(m_canvas);
1118 1123
1119 m_canvas->drawImageRect(image, src, dst, paint); 1124 m_canvas->drawImageRect(image, src, dst, paint);
1120 } 1125 }
1121 1126
1122 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) 1127 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint)
1123 { 1128 {
1124 ASSERT(m_canvas);
1125 if (contextDisabled()) 1129 if (contextDisabled())
1126 return; 1130 return;
1131 ASSERT(m_canvas);
1127 1132
1128 m_canvas->drawOval(oval, paint); 1133 m_canvas->drawOval(oval, paint);
1129 } 1134 }
1130 1135
1131 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) 1136 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint)
1132 { 1137 {
1133 ASSERT(m_canvas);
1134 if (contextDisabled()) 1138 if (contextDisabled())
1135 return; 1139 return;
1140 ASSERT(m_canvas);
1136 1141
1137 m_canvas->drawPath(path, paint); 1142 m_canvas->drawPath(path, paint);
1138 } 1143 }
1139 1144
1140 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) 1145 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint)
1141 { 1146 {
1142 ASSERT(m_canvas);
1143 if (contextDisabled()) 1147 if (contextDisabled())
1144 return; 1148 return;
1149 ASSERT(m_canvas);
1145 1150
1146 m_canvas->drawRect(rect, paint); 1151 m_canvas->drawRect(rect, paint);
1147 } 1152 }
1148 1153
1149 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) 1154 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint)
1150 { 1155 {
1151 ASSERT(m_canvas);
1152 if (contextDisabled()) 1156 if (contextDisabled())
1153 return; 1157 return;
1158 ASSERT(m_canvas);
1154 1159
1155 m_canvas->drawRRect(rrect, paint); 1160 m_canvas->drawRRect(rrect, paint);
1156 } 1161 }
1157 1162
1158 void GraphicsContext::drawPosText(const void* text, size_t byteLength, 1163 void GraphicsContext::drawPosText(const void* text, size_t byteLength,
1159 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint) 1164 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint)
1160 { 1165 {
1161 ASSERT(m_canvas);
1162 if (contextDisabled()) 1166 if (contextDisabled())
1163 return; 1167 return;
1168 ASSERT(m_canvas);
1164 1169
1165 m_canvas->drawPosText(text, byteLength, pos, paint); 1170 m_canvas->drawPosText(text, byteLength, pos, paint);
1166 didDrawTextInRect(textRect); 1171 didDrawTextInRect(textRect);
1167 } 1172 }
1168 1173
1169 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, 1174 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength,
1170 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain t& paint) 1175 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain t& paint)
1171 { 1176 {
1172 ASSERT(m_canvas);
1173 if (contextDisabled()) 1177 if (contextDisabled())
1174 return; 1178 return;
1179 ASSERT(m_canvas);
1175 1180
1176 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); 1181 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint);
1177 didDrawTextInRect(textRect); 1182 didDrawTextInRect(textRect);
1178 } 1183 }
1179 1184
1180 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin , const SkPaint& paint) 1185 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin , const SkPaint& paint)
1181 { 1186 {
1182 ASSERT(m_canvas);
1183 if (contextDisabled()) 1187 if (contextDisabled())
1184 return; 1188 return;
1189 ASSERT(m_canvas);
1185 1190
1186 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); 1191 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint);
1187 1192
1188 SkRect bounds = blob->bounds(); 1193 SkRect bounds = blob->bounds();
1189 bounds.offset(origin); 1194 bounds.offset(origin);
1190 didDrawTextInRect(bounds); 1195 didDrawTextInRect(bounds);
1191 } 1196 }
1192 1197
1193 void GraphicsContext::fillPath(const Path& pathToFill) 1198 void GraphicsContext::fillPath(const Path& pathToFill)
1194 { 1199 {
(...skipping 29 matching lines...) Expand all
1224 1229
1225 SkRect r = rect; 1230 SkRect r = rect;
1226 SkPaint paint = immutableState()->fillPaint(); 1231 SkPaint paint = immutableState()->fillPaint();
1227 paint.setColor(color.rgb()); 1232 paint.setColor(color.rgb());
1228 drawRect(r, paint); 1233 drawRect(r, paint);
1229 } 1234 }
1230 1235
1231 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto mLeft, const FloatSize& outerBottomRight, 1236 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto mLeft, const FloatSize& outerBottomRight,
1232 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color) 1237 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color)
1233 { 1238 {
1234 ASSERT(m_canvas);
1235 if (contextDisabled()) 1239 if (contextDisabled())
1236 return; 1240 return;
1241 ASSERT(m_canvas);
1237 1242
1238 SkVector outerRadii[4]; 1243 SkVector outerRadii[4];
1239 SkVector innerRadii[4]; 1244 SkVector innerRadii[4];
1240 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); 1245 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft);
1241 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); 1246 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft);
1242 1247
1243 SkRRect rrOuter; 1248 SkRRect rrOuter;
1244 SkRRect rrInner; 1249 SkRRect rrInner;
1245 rrOuter.setRectRadii(outer, outerRadii); 1250 rrOuter.setRectRadii(outer, outerRadii);
1246 rrInner.setRectRadii(inner, innerRadii); 1251 rrInner.setRectRadii(inner, innerRadii);
1247 1252
1248 SkPaint paint(immutableState()->fillPaint()); 1253 SkPaint paint(immutableState()->fillPaint());
1249 paint.setColor(color.rgb()); 1254 paint.setColor(color.rgb());
1250 1255
1251 m_canvas->drawDRRect(rrOuter, rrInner, paint); 1256 m_canvas->drawDRRect(rrOuter, rrInner, paint);
1252 } 1257 }
1253 1258
1254 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color) 1259 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color)
1255 { 1260 {
1256 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), 1261 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(),
1257 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color); 1262 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color);
1258 } 1263 }
1259 1264
1260 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight, 1265 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight,
1261 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r) 1266 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r)
1262 { 1267 {
1263 ASSERT(m_canvas);
1264 if (contextDisabled()) 1268 if (contextDisabled())
1265 return; 1269 return;
1270 ASSERT(m_canvas);
1266 1271
1267 if (topLeft.width() + topRight.width() > rect.width() 1272 if (topLeft.width() + topRight.width() > rect.width()
1268 || bottomLeft.width() + bottomRight.width() > rect.width() 1273 || bottomLeft.width() + bottomRight.width() > rect.width()
1269 || topLeft.height() + bottomLeft.height() > rect.height() 1274 || topLeft.height() + bottomLeft.height() > rect.height()
1270 || topRight.height() + bottomRight.height() > rect.height()) { 1275 || topRight.height() + bottomRight.height() > rect.height()) {
1271 // Not all the radii fit, return a rect. This matches the behavior of 1276 // Not all the radii fit, return a rect. This matches the behavior of
1272 // Path::createRoundedRectangle. Without this we attempt to draw a round 1277 // Path::createRoundedRectangle. Without this we attempt to draw a round
1273 // shadow for a square box. 1278 // shadow for a square box.
1274 // FIXME: this fallback code is wrong, and also duplicates related code in FloatRoundedRect::constrainRadii, Path and SKRRect. 1279 // FIXME: this fallback code is wrong, and also duplicates related code in FloatRoundedRect::constrainRadii, Path and SKRRect.
1275 fillRect(rect, color); 1280 fillRect(rect, color);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1410 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) 1415 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect)
1411 { 1416 {
1412 if (contextDisabled()) 1417 if (contextDisabled())
1413 return; 1418 return;
1414 1419
1415 clipRoundedRect(rect, SkRegion::kDifference_Op); 1420 clipRoundedRect(rect, SkRegion::kDifference_Op);
1416 } 1421 }
1417 1422
1418 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op) 1423 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op)
1419 { 1424 {
1420 ASSERT(m_canvas);
1421 if (contextDisabled()) 1425 if (contextDisabled())
1422 return; 1426 return;
1427 ASSERT(m_canvas);
1423 1428
1424 m_canvas->clipRect(rect, op, aa == AntiAliased); 1429 m_canvas->clipRect(rect, op, aa == AntiAliased);
1425 } 1430 }
1426 1431
1427 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion ::Op op) 1432 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion ::Op op)
1428 { 1433 {
1429 ASSERT(m_canvas);
1430 if (contextDisabled()) 1434 if (contextDisabled())
1431 return; 1435 return;
1436 ASSERT(m_canvas);
1432 1437
1433 m_canvas->clipPath(path, op, aa == AntiAliased); 1438 m_canvas->clipPath(path, op, aa == AntiAliased);
1434 } 1439 }
1435 1440
1436 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi on::Op op) 1441 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi on::Op op)
1437 { 1442 {
1438 ASSERT(m_canvas);
1439 if (contextDisabled()) 1443 if (contextDisabled())
1440 return; 1444 return;
1445 ASSERT(m_canvas);
1441 1446
1442 m_canvas->clipRRect(rect, op, aa == AntiAliased); 1447 m_canvas->clipRRect(rect, op, aa == AntiAliased);
1443 } 1448 }
1444 1449
1445 void GraphicsContext::rotate(float angleInRadians) 1450 void GraphicsContext::rotate(float angleInRadians)
1446 { 1451 {
1447 ASSERT(m_canvas);
1448 if (contextDisabled()) 1452 if (contextDisabled())
1449 return; 1453 return;
1454 ASSERT(m_canvas);
1450 1455
1451 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926 5f))); 1456 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926 5f)));
1452 } 1457 }
1453 1458
1454 void GraphicsContext::translate(float x, float y) 1459 void GraphicsContext::translate(float x, float y)
1455 { 1460 {
1456 ASSERT(m_canvas);
1457 if (contextDisabled()) 1461 if (contextDisabled())
1458 return; 1462 return;
1463 ASSERT(m_canvas);
1459 1464
1460 if (!x && !y) 1465 if (!x && !y)
1461 return; 1466 return;
1462 1467
1463 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); 1468 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y));
1464 } 1469 }
1465 1470
1466 void GraphicsContext::scale(float x, float y) 1471 void GraphicsContext::scale(float x, float y)
1467 { 1472 {
1468 ASSERT(m_canvas);
1469 if (contextDisabled()) 1473 if (contextDisabled())
1470 return; 1474 return;
1475 ASSERT(m_canvas);
1471 1476
1472 if (x == 1.0f && y == 1.0f) 1477 if (x == 1.0f && y == 1.0f)
1473 return; 1478 return;
1474 1479
1475 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); 1480 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y));
1476 } 1481 }
1477 1482
1478 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) 1483 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect)
1479 { 1484 {
1480 ASSERT(m_canvas);
1481 if (contextDisabled()) 1485 if (contextDisabled())
1482 return; 1486 return;
1487 ASSERT(m_canvas);
1483 1488
1484 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); 1489 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data()));
1485 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); 1490 SkAnnotateRectWithURL(m_canvas, destRect, url.get());
1486 } 1491 }
1487 1492
1488 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec t& rect) 1493 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec t& rect)
1489 { 1494 {
1490 ASSERT(m_canvas);
1491 if (contextDisabled()) 1495 if (contextDisabled())
1492 return; 1496 return;
1497 ASSERT(m_canvas);
1493 1498
1494 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); 1499 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data()));
1495 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); 1500 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get());
1496 } 1501 }
1497 1502
1498 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po s) 1503 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po s)
1499 { 1504 {
1500 ASSERT(m_canvas);
1501 if (contextDisabled()) 1505 if (contextDisabled())
1502 return; 1506 return;
1507 ASSERT(m_canvas);
1503 1508
1504 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); 1509 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data()));
1505 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa ta); 1510 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa ta);
1506 } 1511 }
1507 1512
1508 AffineTransform GraphicsContext::getCTM() const 1513 AffineTransform GraphicsContext::getCTM() const
1509 { 1514 {
1510 if (contextDisabled()) 1515 if (contextDisabled())
1511 return AffineTransform(); 1516 return AffineTransform();
1512 1517
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 // being returned from computeInterpolationQuality. 1834 // being returned from computeInterpolationQuality.
1830 resampling = InterpolationLow; 1835 resampling = InterpolationLow;
1831 } 1836 }
1832 resampling = limitInterpolationQuality(this, resampling); 1837 resampling = limitInterpolationQuality(this, resampling);
1833 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); 1838 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling));
1834 1839
1835 return initialSaveCount; 1840 return initialSaveCount;
1836 } 1841 }
1837 1842
1838 } // namespace blink 1843 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698