OLD | NEW |
---|---|
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 Loading... | |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 , m_trackTextRegion(false) | 101 , m_trackTextRegion(false) |
101 , m_accelerated(false) | 102 , m_accelerated(false) |
102 , m_isCertainlyOpaque(true) | 103 , m_isCertainlyOpaque(true) |
103 , m_printing(false) | 104 , m_printing(false) |
104 , m_antialiasHairlineImages(false) | 105 , m_antialiasHairlineImages(false) |
105 { | 106 { |
106 // FIXME: Do some tests to determine how many states are typically used, and allocate | 107 // FIXME: Do some tests to determine how many states are typically used, and allocate |
107 // several here. | 108 // several here. |
108 m_paintStateStack.append(GraphicsContextState::create()); | 109 m_paintStateStack.append(GraphicsContextState::create()); |
109 m_paintState = m_paintStateStack.last().get(); | 110 m_paintState = m_paintStateStack.last().get(); |
111 | |
112 if (contextDisabled()) { | |
113 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNull Canvas()))); | |
114 m_canvas = nullCanvas.get(); | |
115 } | |
110 } | 116 } |
111 | 117 |
112 GraphicsContext::~GraphicsContext() | 118 GraphicsContext::~GraphicsContext() |
113 { | 119 { |
114 #if ENABLE(ASSERT) | 120 #if ENABLE(ASSERT) |
115 if (!m_disableDestructionChecks) { | 121 if (!m_disableDestructionChecks) { |
116 ASSERT(!m_paintStateIndex); | 122 ASSERT(!m_paintStateIndex); |
117 ASSERT(!m_paintState->saveCount()); | 123 ASSERT(!m_paintState->saveCount()); |
118 ASSERT(!m_annotationCount); | 124 ASSERT(!m_annotationCount); |
119 ASSERT(!m_layerCount); | 125 ASSERT(!m_layerCount); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 return picture.release(); | 549 return picture.release(); |
544 } | 550 } |
545 | 551 |
546 bool GraphicsContext::isRecording() const | 552 bool GraphicsContext::isRecording() const |
547 { | 553 { |
548 return !m_recordingStateStack.isEmpty(); | 554 return !m_recordingStateStack.isEmpty(); |
549 } | 555 } |
550 | 556 |
551 void GraphicsContext::drawPicture(const SkPicture* picture) | 557 void GraphicsContext::drawPicture(const SkPicture* picture) |
552 { | 558 { |
559 if (contextDisabled()) | |
f(malita)
2015/03/10 19:34:24
Already checked below. Probably just need to reloc
| |
560 return; | |
553 ASSERT(m_canvas); | 561 ASSERT(m_canvas); |
554 | 562 |
555 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp | 563 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a temp |
556 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled | 564 // workaround, but the problem should be fixed: empty-bounds pictures are go ing to be culled |
557 // on playback anyway. | 565 // on playback anyway. |
558 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); | 566 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); |
559 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures)) | 567 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE mptyPictures)) |
560 return; | 568 return; |
561 | 569 |
562 m_canvas->drawPicture(picture); | 570 m_canvas->drawPicture(picture); |
563 } | 571 } |
564 | 572 |
565 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest , const FloatRect& src, SkXfermode::Mode op) | 573 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest , const FloatRect& src, SkXfermode::Mode op) |
566 { | 574 { |
567 ASSERT(m_canvas); | |
568 if (contextDisabled() || !picture) | 575 if (contextDisabled() || !picture) |
569 return; | 576 return; |
577 ASSERT(m_canvas); | |
570 | 578 |
571 SkPaint picturePaint; | 579 SkPaint picturePaint; |
572 picturePaint.setXfermodeMode(op); | 580 picturePaint.setXfermodeMode(op); |
573 m_canvas->save(); | 581 m_canvas->save(); |
574 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); | 582 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); |
575 SkRect skBounds = WebCoreFloatRectToSKRect(dest); | 583 SkRect skBounds = WebCoreFloatRectToSKRect(dest); |
576 SkMatrix pictureTransform; | 584 SkMatrix pictureTransform; |
577 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); | 585 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale ToFit); |
578 m_canvas->concat(pictureTransform); | 586 m_canvas->concat(pictureTransform); |
579 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter:: CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima geInterpolationQuality()))); | 587 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 Loading... | |
753 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor, | 761 drawLooperBuilder->addShadow(shadowOffset, shadowBlur, shadowColor, |
754 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha); | 762 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg noresAlpha); |
755 setDrawLooper(drawLooperBuilder.release()); | 763 setDrawLooper(drawLooperBuilder.release()); |
756 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); | 764 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); |
757 restore(); | 765 restore(); |
758 clearDrawLooper(); | 766 clearDrawLooper(); |
759 } | 767 } |
760 | 768 |
761 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) | 769 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) |
762 { | 770 { |
763 ASSERT(m_canvas); | |
764 if (contextDisabled()) | 771 if (contextDisabled()) |
765 return; | 772 return; |
773 ASSERT(m_canvas); | |
766 | 774 |
767 StrokeStyle penStyle = strokeStyle(); | 775 StrokeStyle penStyle = strokeStyle(); |
768 if (penStyle == NoStroke) | 776 if (penStyle == NoStroke) |
769 return; | 777 return; |
770 | 778 |
771 FloatPoint p1 = point1; | 779 FloatPoint p1 = point1; |
772 FloatPoint p2 = point2; | 780 FloatPoint p2 = point2; |
773 bool isVerticalLine = (p1.x() == p2.x()); | 781 bool isVerticalLine = (p1.x() == p2.x()); |
774 int width = roundf(strokeThickness()); | 782 int width = roundf(strokeThickness()); |
775 | 783 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 const FloatRect* src, SkXfermode::Mode op) | 1097 const FloatRect* src, SkXfermode::Mode op) |
1090 { | 1098 { |
1091 if (contextDisabled() || !image) | 1099 if (contextDisabled() || !image) |
1092 return; | 1100 return; |
1093 | 1101 |
1094 image->draw(this, dest, src, op); | 1102 image->draw(this, dest, src, op); |
1095 } | 1103 } |
1096 | 1104 |
1097 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y) | 1105 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s ize_t rowBytes, int x, int y) |
1098 { | 1106 { |
1099 ASSERT(m_canvas); | |
1100 if (contextDisabled()) | 1107 if (contextDisabled()) |
1101 return; | 1108 return; |
1109 ASSERT(m_canvas); | |
1102 | 1110 |
1103 m_canvas->writePixels(info, pixels, rowBytes, x, y); | 1111 m_canvas->writePixels(info, pixels, rowBytes, x, y); |
1104 } | 1112 } |
1105 | 1113 |
1106 void GraphicsContext::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, const SkPaint* paint) | 1114 void GraphicsContext::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, const SkPaint* paint) |
f(malita)
2015/03/10 19:34:24
I don't think this method is used at all - we shou
Xianzhu
2015/03/11 16:45:10
I'd leave this to another change.
| |
1107 { | 1115 { |
1116 if (contextDisabled()) | |
f(malita)
2015/03/10 19:34:24
Already checked below. Relocate the assert?
Xianzhu
2015/03/11 16:45:10
Done.
| |
1117 return; | |
1108 ASSERT(m_canvas); | 1118 ASSERT(m_canvas); |
1119 | |
1109 // Textures are bound to the blink main-thread GrContext, which can not be | 1120 // Textures are bound to the blink main-thread GrContext, which can not be |
1110 // used on the compositor raster thread. | 1121 // used on the compositor raster thread. |
1111 // FIXME: Mailbox support would make this possible in the GPU-raster case. | 1122 // FIXME: Mailbox support would make this possible in the GPU-raster case. |
1112 ASSERT(!isRecording() || !bitmap.getTexture()); | 1123 ASSERT(!isRecording() || !bitmap.getTexture()); |
1113 if (contextDisabled()) | 1124 if (contextDisabled()) |
1114 return; | 1125 return; |
1115 | 1126 |
1116 m_canvas->drawBitmap(bitmap, left, top, paint); | 1127 m_canvas->drawBitmap(bitmap, left, top, paint); |
1117 } | 1128 } |
1118 | 1129 |
1119 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1130 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1120 const SkRect& dst, const SkPaint* paint) | 1131 const SkRect& dst, const SkPaint* paint) |
1121 { | 1132 { |
1133 if (contextDisabled()) | |
f(malita)
2015/03/10 19:34:24
Note that some of these methods are "internal" ent
| |
1134 return; | |
1122 ASSERT(m_canvas); | 1135 ASSERT(m_canvas); |
1136 | |
1123 // Textures are bound to the blink main-thread GrContext, which can not be | 1137 // Textures are bound to the blink main-thread GrContext, which can not be |
1124 // used on the compositor raster thread. | 1138 // used on the compositor raster thread. |
1125 // FIXME: Mailbox support would make this possible in the GPU-raster case. | 1139 // FIXME: Mailbox support would make this possible in the GPU-raster case. |
1126 ASSERT(!isRecording() || !bitmap.getTexture()); | 1140 ASSERT(!isRecording() || !bitmap.getTexture()); |
1127 if (contextDisabled()) | 1141 if (contextDisabled()) |
1128 return; | 1142 return; |
1129 | 1143 |
1130 SkCanvas::DrawBitmapRectFlags flags = | 1144 SkCanvas::DrawBitmapRectFlags flags = |
1131 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | 1145 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; |
1132 | 1146 |
1133 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 1147 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
1134 } | 1148 } |
1135 | 1149 |
1136 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to p, const SkPaint* paint) | 1150 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to p, const SkPaint* paint) |
1137 { | 1151 { |
1138 ASSERT(m_canvas); | |
1139 if (contextDisabled()) | 1152 if (contextDisabled()) |
1140 return; | 1153 return; |
1154 ASSERT(m_canvas); | |
f(malita)
2015/03/10 19:34:24
Since m_disabledState is effectively const for the
Xianzhu
2015/03/11 16:45:10
This assert is also for m_disabledState==false. m_
| |
1141 | 1155 |
1142 m_canvas->drawImage(image, left, top, paint); | 1156 m_canvas->drawImage(image, left, top, paint); |
1143 } | 1157 } |
1144 | 1158 |
1145 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst, const SkPaint* paint) | 1159 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con st SkRect& dst, const SkPaint* paint) |
1146 { | 1160 { |
1147 ASSERT(m_canvas); | |
1148 if (contextDisabled()) | 1161 if (contextDisabled()) |
1149 return; | 1162 return; |
1163 ASSERT(m_canvas); | |
1150 | 1164 |
1151 m_canvas->drawImageRect(image, src, dst, paint); | 1165 m_canvas->drawImageRect(image, src, dst, paint); |
1152 } | 1166 } |
1153 | 1167 |
1154 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1168 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1155 { | 1169 { |
1156 ASSERT(m_canvas); | |
1157 if (contextDisabled()) | 1170 if (contextDisabled()) |
1158 return; | 1171 return; |
1172 ASSERT(m_canvas); | |
1159 | 1173 |
1160 m_canvas->drawOval(oval, paint); | 1174 m_canvas->drawOval(oval, paint); |
1161 } | 1175 } |
1162 | 1176 |
1163 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) | 1177 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) |
1164 { | 1178 { |
1165 ASSERT(m_canvas); | |
1166 if (contextDisabled()) | 1179 if (contextDisabled()) |
1167 return; | 1180 return; |
1181 ASSERT(m_canvas); | |
1168 | 1182 |
1169 m_canvas->drawPath(path, paint); | 1183 m_canvas->drawPath(path, paint); |
1170 } | 1184 } |
1171 | 1185 |
1172 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) | 1186 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) |
1173 { | 1187 { |
1174 ASSERT(m_canvas); | |
1175 if (contextDisabled()) | 1188 if (contextDisabled()) |
1176 return; | 1189 return; |
1190 ASSERT(m_canvas); | |
1177 | 1191 |
1178 m_canvas->drawRect(rect, paint); | 1192 m_canvas->drawRect(rect, paint); |
1179 } | 1193 } |
1180 | 1194 |
1181 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) | 1195 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) |
1182 { | 1196 { |
1183 ASSERT(m_canvas); | |
1184 if (contextDisabled()) | 1197 if (contextDisabled()) |
1185 return; | 1198 return; |
1199 ASSERT(m_canvas); | |
1186 | 1200 |
1187 m_canvas->drawRRect(rrect, paint); | 1201 m_canvas->drawRRect(rrect, paint); |
1188 } | 1202 } |
1189 | 1203 |
1190 void GraphicsContext::drawPosText(const void* text, size_t byteLength, | 1204 void GraphicsContext::drawPosText(const void* text, size_t byteLength, |
1191 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint) | 1205 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint) |
1192 { | 1206 { |
1193 ASSERT(m_canvas); | |
1194 if (contextDisabled()) | 1207 if (contextDisabled()) |
1195 return; | 1208 return; |
1209 ASSERT(m_canvas); | |
1196 | 1210 |
1197 m_canvas->drawPosText(text, byteLength, pos, paint); | 1211 m_canvas->drawPosText(text, byteLength, pos, paint); |
1198 didDrawTextInRect(textRect); | 1212 didDrawTextInRect(textRect); |
1199 } | 1213 } |
1200 | 1214 |
1201 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, | 1215 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, |
1202 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain t& paint) | 1216 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain t& paint) |
1203 { | 1217 { |
1204 ASSERT(m_canvas); | |
1205 if (contextDisabled()) | 1218 if (contextDisabled()) |
1206 return; | 1219 return; |
1220 ASSERT(m_canvas); | |
1207 | 1221 |
1208 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); | 1222 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); |
1209 didDrawTextInRect(textRect); | 1223 didDrawTextInRect(textRect); |
1210 } | 1224 } |
1211 | 1225 |
1212 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin , const SkPaint& paint) | 1226 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin , const SkPaint& paint) |
1213 { | 1227 { |
1214 ASSERT(m_canvas); | |
1215 if (contextDisabled()) | 1228 if (contextDisabled()) |
1216 return; | 1229 return; |
1230 ASSERT(m_canvas); | |
1217 | 1231 |
1218 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); | 1232 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); |
1219 | 1233 |
1220 SkRect bounds = blob->bounds(); | 1234 SkRect bounds = blob->bounds(); |
1221 bounds.offset(origin); | 1235 bounds.offset(origin); |
1222 didDrawTextInRect(bounds); | 1236 didDrawTextInRect(bounds); |
1223 } | 1237 } |
1224 | 1238 |
1225 void GraphicsContext::fillPath(const Path& pathToFill) | 1239 void GraphicsContext::fillPath(const Path& pathToFill) |
1226 { | 1240 { |
(...skipping 29 matching lines...) Expand all Loading... | |
1256 | 1270 |
1257 SkRect r = rect; | 1271 SkRect r = rect; |
1258 SkPaint paint = immutableState()->fillPaint(); | 1272 SkPaint paint = immutableState()->fillPaint(); |
1259 paint.setColor(color.rgb()); | 1273 paint.setColor(color.rgb()); |
1260 drawRect(r, paint); | 1274 drawRect(r, paint); |
1261 } | 1275 } |
1262 | 1276 |
1263 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto mLeft, const FloatSize& outerBottomRight, | 1277 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto mLeft, const FloatSize& outerBottomRight, |
1264 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color) | 1278 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight, const Color& color) |
1265 { | 1279 { |
1266 ASSERT(m_canvas); | |
1267 if (contextDisabled()) | 1280 if (contextDisabled()) |
1268 return; | 1281 return; |
1282 ASSERT(m_canvas); | |
1269 | 1283 |
1270 SkVector outerRadii[4]; | 1284 SkVector outerRadii[4]; |
1271 SkVector innerRadii[4]; | 1285 SkVector innerRadii[4]; |
1272 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); | 1286 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot tomLeft); |
1273 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); | 1287 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot tomLeft); |
1274 | 1288 |
1275 SkRRect rrOuter; | 1289 SkRRect rrOuter; |
1276 SkRRect rrInner; | 1290 SkRRect rrInner; |
1277 rrOuter.setRectRadii(outer, outerRadii); | 1291 rrOuter.setRectRadii(outer, outerRadii); |
1278 rrInner.setRectRadii(inner, innerRadii); | 1292 rrInner.setRectRadii(inner, innerRadii); |
1279 | 1293 |
1280 SkPaint paint(immutableState()->fillPaint()); | 1294 SkPaint paint(immutableState()->fillPaint()); |
1281 paint.setColor(color.rgb()); | 1295 paint.setColor(color.rgb()); |
1282 | 1296 |
1283 m_canvas->drawDRRect(rrOuter, rrInner, paint); | 1297 m_canvas->drawDRRect(rrOuter, rrInner, paint); |
1284 } | 1298 } |
1285 | 1299 |
1286 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color) | 1300 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con st FloatRoundedRect& inner, const Color& color) |
1287 { | 1301 { |
1288 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), | 1302 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii() .topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), |
1289 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color); | 1303 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r adii().bottomLeft(), inner.radii().bottomRight(), color); |
1290 } | 1304 } |
1291 | 1305 |
1292 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight, | 1306 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to pLeft, const FloatSize& topRight, |
1293 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r) | 1307 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo r) |
1294 { | 1308 { |
1295 ASSERT(m_canvas); | |
1296 if (contextDisabled()) | 1309 if (contextDisabled()) |
1297 return; | 1310 return; |
1311 ASSERT(m_canvas); | |
1298 | 1312 |
1299 if (topLeft.width() + topRight.width() > rect.width() | 1313 if (topLeft.width() + topRight.width() > rect.width() |
1300 || bottomLeft.width() + bottomRight.width() > rect.width() | 1314 || bottomLeft.width() + bottomRight.width() > rect.width() |
1301 || topLeft.height() + bottomLeft.height() > rect.height() | 1315 || topLeft.height() + bottomLeft.height() > rect.height() |
1302 || topRight.height() + bottomRight.height() > rect.height()) { | 1316 || topRight.height() + bottomRight.height() > rect.height()) { |
1303 // Not all the radii fit, return a rect. This matches the behavior of | 1317 // Not all the radii fit, return a rect. This matches the behavior of |
1304 // Path::createRoundedRectangle. Without this we attempt to draw a round | 1318 // Path::createRoundedRectangle. Without this we attempt to draw a round |
1305 // shadow for a square box. | 1319 // shadow for a square box. |
1306 // FIXME: this fallback code is wrong, and also duplicates related code in FloatRoundedRect::constrainRadii, Path and SKRRect. | 1320 // FIXME: this fallback code is wrong, and also duplicates related code in FloatRoundedRect::constrainRadii, Path and SKRRect. |
1307 fillRect(rect, color); | 1321 fillRect(rect, color); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1442 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) | 1456 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) |
1443 { | 1457 { |
1444 if (contextDisabled()) | 1458 if (contextDisabled()) |
1445 return; | 1459 return; |
1446 | 1460 |
1447 clipRoundedRect(rect, SkRegion::kDifference_Op); | 1461 clipRoundedRect(rect, SkRegion::kDifference_Op); |
1448 } | 1462 } |
1449 | 1463 |
1450 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op) | 1464 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion ::Op op) |
1451 { | 1465 { |
1452 ASSERT(m_canvas); | |
1453 if (contextDisabled()) | 1466 if (contextDisabled()) |
1454 return; | 1467 return; |
1468 ASSERT(m_canvas); | |
1455 | 1469 |
1456 m_canvas->clipRect(rect, op, aa == AntiAliased); | 1470 m_canvas->clipRect(rect, op, aa == AntiAliased); |
1457 } | 1471 } |
1458 | 1472 |
1459 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion ::Op op) | 1473 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion ::Op op) |
1460 { | 1474 { |
1461 ASSERT(m_canvas); | |
1462 if (contextDisabled()) | 1475 if (contextDisabled()) |
1463 return; | 1476 return; |
1477 ASSERT(m_canvas); | |
1464 | 1478 |
1465 m_canvas->clipPath(path, op, aa == AntiAliased); | 1479 m_canvas->clipPath(path, op, aa == AntiAliased); |
1466 } | 1480 } |
1467 | 1481 |
1468 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi on::Op op) | 1482 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi on::Op op) |
1469 { | 1483 { |
1470 ASSERT(m_canvas); | |
1471 if (contextDisabled()) | 1484 if (contextDisabled()) |
1472 return; | 1485 return; |
1486 ASSERT(m_canvas); | |
1473 | 1487 |
1474 m_canvas->clipRRect(rect, op, aa == AntiAliased); | 1488 m_canvas->clipRRect(rect, op, aa == AntiAliased); |
1475 } | 1489 } |
1476 | 1490 |
1477 void GraphicsContext::rotate(float angleInRadians) | 1491 void GraphicsContext::rotate(float angleInRadians) |
1478 { | 1492 { |
1479 ASSERT(m_canvas); | |
1480 if (contextDisabled()) | 1493 if (contextDisabled()) |
1481 return; | 1494 return; |
1495 ASSERT(m_canvas); | |
1482 | 1496 |
1483 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926 5f))); | 1497 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926 5f))); |
1484 } | 1498 } |
1485 | 1499 |
1486 void GraphicsContext::translate(float x, float y) | 1500 void GraphicsContext::translate(float x, float y) |
1487 { | 1501 { |
1488 ASSERT(m_canvas); | |
1489 if (contextDisabled()) | 1502 if (contextDisabled()) |
1490 return; | 1503 return; |
1504 ASSERT(m_canvas); | |
1491 | 1505 |
1492 if (!x && !y) | 1506 if (!x && !y) |
1493 return; | 1507 return; |
1494 | 1508 |
1495 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); | 1509 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1496 } | 1510 } |
1497 | 1511 |
1498 void GraphicsContext::scale(float x, float y) | 1512 void GraphicsContext::scale(float x, float y) |
1499 { | 1513 { |
1500 ASSERT(m_canvas); | |
1501 if (contextDisabled()) | 1514 if (contextDisabled()) |
1502 return; | 1515 return; |
1516 ASSERT(m_canvas); | |
1503 | 1517 |
1504 if (x == 1.0f && y == 1.0f) | 1518 if (x == 1.0f && y == 1.0f) |
1505 return; | 1519 return; |
1506 | 1520 |
1507 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); | 1521 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1508 } | 1522 } |
1509 | 1523 |
1510 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) | 1524 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) |
1511 { | 1525 { |
1512 ASSERT(m_canvas); | |
1513 if (contextDisabled()) | 1526 if (contextDisabled()) |
1514 return; | 1527 return; |
1528 ASSERT(m_canvas); | |
1515 | 1529 |
1516 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); | 1530 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); |
1517 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); | 1531 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); |
1518 } | 1532 } |
1519 | 1533 |
1520 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec t& rect) | 1534 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec t& rect) |
1521 { | 1535 { |
1522 ASSERT(m_canvas); | |
1523 if (contextDisabled()) | 1536 if (contextDisabled()) |
1524 return; | 1537 return; |
1538 ASSERT(m_canvas); | |
1525 | 1539 |
1526 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); | 1540 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); |
1527 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); | 1541 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); |
1528 } | 1542 } |
1529 | 1543 |
1530 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po s) | 1544 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po s) |
1531 { | 1545 { |
1532 ASSERT(m_canvas); | |
1533 if (contextDisabled()) | 1546 if (contextDisabled()) |
1534 return; | 1547 return; |
1548 ASSERT(m_canvas); | |
1535 | 1549 |
1536 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); | 1550 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); |
1537 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa ta); | 1551 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa ta); |
1538 } | 1552 } |
1539 | 1553 |
1540 AffineTransform GraphicsContext::getCTM() const | 1554 AffineTransform GraphicsContext::getCTM() const |
1541 { | 1555 { |
1542 if (contextDisabled()) | 1556 if (contextDisabled()) |
1543 return AffineTransform(); | 1557 return AffineTransform(); |
1544 | 1558 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1861 // being returned from computeInterpolationQuality. | 1875 // being returned from computeInterpolationQuality. |
1862 resampling = InterpolationLow; | 1876 resampling = InterpolationLow; |
1863 } | 1877 } |
1864 resampling = limitInterpolationQuality(this, resampling); | 1878 resampling = limitInterpolationQuality(this, resampling); |
1865 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); | 1879 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); |
1866 | 1880 |
1867 return initialSaveCount; | 1881 return initialSaveCount; |
1868 } | 1882 } |
1869 | 1883 |
1870 } // namespace blink | 1884 } // namespace blink |
OLD | NEW |