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 14 matching lines...) Expand all Loading... |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #include "platform/graphics/GraphicsContext.h" | 28 #include "platform/graphics/GraphicsContext.h" |
29 | 29 |
30 #include "platform/RuntimeEnabledFeatures.h" | 30 #include "platform/RuntimeEnabledFeatures.h" |
31 #include "platform/TraceEvent.h" | 31 #include "platform/TraceEvent.h" |
32 #include "platform/geometry/IntRect.h" | 32 #include "platform/geometry/IntRect.h" |
33 #include "platform/graphics/BitmapImage.h" | 33 #include "platform/graphics/BitmapImage.h" |
34 #include "platform/graphics/Gradient.h" | 34 #include "platform/graphics/Gradient.h" |
35 #include "platform/graphics/GraphicsContextClient.h" | |
36 #include "platform/graphics/ImageBuffer.h" | 35 #include "platform/graphics/ImageBuffer.h" |
37 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 36 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
38 #include "platform/text/BidiResolver.h" | 37 #include "platform/text/BidiResolver.h" |
39 #include "platform/text/TextRunIterator.h" | 38 #include "platform/text/TextRunIterator.h" |
40 #include "platform/weborigin/KURL.h" | 39 #include "platform/weborigin/KURL.h" |
41 #include "third_party/skia/include/core/SkAnnotation.h" | 40 #include "third_party/skia/include/core/SkAnnotation.h" |
42 #include "third_party/skia/include/core/SkClipStack.h" | 41 #include "third_party/skia/include/core/SkClipStack.h" |
43 #include "third_party/skia/include/core/SkColorFilter.h" | 42 #include "third_party/skia/include/core/SkColorFilter.h" |
44 #include "third_party/skia/include/core/SkData.h" | 43 #include "third_party/skia/include/core/SkData.h" |
45 #include "third_party/skia/include/core/SkDevice.h" | 44 #include "third_party/skia/include/core/SkDevice.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 , m_savedMatrix(matrix) | 79 , m_savedMatrix(matrix) |
81 { } | 80 { } |
82 | 81 |
83 SkPictureRecorder m_recorder; | 82 SkPictureRecorder m_recorder; |
84 SkCanvas* m_savedCanvas; | 83 SkCanvas* m_savedCanvas; |
85 const SkMatrix m_savedMatrix; | 84 const SkMatrix m_savedMatrix; |
86 }; | 85 }; |
87 | 86 |
88 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting) | 87 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting) |
89 : m_canvas(canvas) | 88 : m_canvas(canvas) |
90 , m_client(0) | |
91 , m_displayItemList(displayItemList) | 89 , m_displayItemList(displayItemList) |
92 , m_clipRecorderStack(0) | 90 , m_clipRecorderStack(0) |
93 , m_paintStateStack() | 91 , m_paintStateStack() |
94 , m_paintStateIndex(0) | 92 , m_paintStateIndex(0) |
95 , m_annotationMode(0) | 93 , m_annotationMode(0) |
96 , m_layerCount(0) | 94 , m_layerCount(0) |
97 #if ENABLE(ASSERT) | 95 #if ENABLE(ASSERT) |
98 , m_annotationCount(0) | 96 , m_annotationCount(0) |
99 , m_disableDestructionChecks(false) | 97 , m_disableDestructionChecks(false) |
100 , m_inDrawingRecorder(false) | 98 , m_inDrawingRecorder(false) |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 | 1125 |
1128 image->draw(this, dest, src, op); | 1126 image->draw(this, dest, src, op); |
1129 } | 1127 } |
1130 | 1128 |
1131 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) | 1129 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) |
1132 { | 1130 { |
1133 ASSERT(m_canvas); | 1131 ASSERT(m_canvas); |
1134 if (contextDisabled()) | 1132 if (contextDisabled()) |
1135 return; | 1133 return; |
1136 | 1134 |
1137 if (m_client) { | |
1138 SkRect rect = SkRect::MakeXYWH(x, y, info.width(), info.height()); | |
1139 m_client->willDrawRect(this, rect, 0, GraphicsContextClient::NoImage, Gr
aphicsContextClient::UntransformedUnclippedFill); | |
1140 } | |
1141 | |
1142 m_canvas->writePixels(info, pixels, rowBytes, x, y); | 1135 m_canvas->writePixels(info, pixels, rowBytes, x, y); |
1143 } | 1136 } |
1144 | 1137 |
1145 template<typename T> | |
1146 inline GraphicsContextClient::ImageType toImageType(T* image) | |
1147 { | |
1148 if (!image) | |
1149 return GraphicsContextClient::NoImage; | |
1150 if (image->isOpaque()) | |
1151 return GraphicsContextClient::OpaqueImage; | |
1152 return GraphicsContextClient::NonOpaqueImage; | |
1153 } | |
1154 | |
1155 void GraphicsContext::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, const SkPaint* paint) | 1138 void GraphicsContext::drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar
top, const SkPaint* paint) |
1156 { | 1139 { |
1157 ASSERT(m_canvas); | 1140 ASSERT(m_canvas); |
1158 // Textures are bound to the blink main-thread GrContext, which can not be | 1141 // Textures are bound to the blink main-thread GrContext, which can not be |
1159 // used on the compositor raster thread. | 1142 // used on the compositor raster thread. |
1160 // FIXME: Mailbox support would make this possible in the GPU-raster case. | 1143 // FIXME: Mailbox support would make this possible in the GPU-raster case. |
1161 ASSERT(!isRecording() || !bitmap.getTexture()); | 1144 ASSERT(!isRecording() || !bitmap.getTexture()); |
1162 if (contextDisabled()) | 1145 if (contextDisabled()) |
1163 return; | 1146 return; |
1164 | 1147 |
1165 if (m_client) { | |
1166 SkRect rect = SkRect::MakeXYWH(left, top, bitmap.width(), bitmap.height(
)); | |
1167 m_client->willDrawRect(this, rect, paint, toImageType(&bitmap), Graphics
ContextClient::Fill); | |
1168 } | |
1169 | |
1170 m_canvas->drawBitmap(bitmap, left, top, paint); | 1148 m_canvas->drawBitmap(bitmap, left, top, paint); |
1171 } | 1149 } |
1172 | 1150 |
1173 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1151 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1174 const SkRect& dst, const SkPaint* paint) | 1152 const SkRect& dst, const SkPaint* paint) |
1175 { | 1153 { |
1176 ASSERT(m_canvas); | 1154 ASSERT(m_canvas); |
1177 // Textures are bound to the blink main-thread GrContext, which can not be | 1155 // Textures are bound to the blink main-thread GrContext, which can not be |
1178 // used on the compositor raster thread. | 1156 // used on the compositor raster thread. |
1179 // FIXME: Mailbox support would make this possible in the GPU-raster case. | 1157 // FIXME: Mailbox support would make this possible in the GPU-raster case. |
1180 ASSERT(!isRecording() || !bitmap.getTexture()); | 1158 ASSERT(!isRecording() || !bitmap.getTexture()); |
1181 if (contextDisabled()) | 1159 if (contextDisabled()) |
1182 return; | 1160 return; |
1183 | 1161 |
1184 SkCanvas::DrawBitmapRectFlags flags = | 1162 SkCanvas::DrawBitmapRectFlags flags = |
1185 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap
RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | 1163 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap
RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; |
1186 | 1164 |
1187 if (m_client) | |
1188 m_client->willDrawRect(this, dst, paint, toImageType(&bitmap), GraphicsC
ontextClient::Fill); | |
1189 | |
1190 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 1165 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
1191 } | 1166 } |
1192 | 1167 |
1193 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to
p, const SkPaint* paint) | 1168 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to
p, const SkPaint* paint) |
1194 { | 1169 { |
1195 ASSERT(m_canvas); | 1170 ASSERT(m_canvas); |
1196 if (contextDisabled()) | 1171 if (contextDisabled()) |
1197 return; | 1172 return; |
1198 | 1173 |
1199 if (m_client) | |
1200 m_client->willDrawRect(this, SkRect::MakeXYWH(left, top, image->width(),
image->height()), paint, toImageType(image), GraphicsContextClient::Fill); | |
1201 | |
1202 m_canvas->drawImage(image, left, top, paint); | 1174 m_canvas->drawImage(image, left, top, paint); |
1203 } | 1175 } |
1204 | 1176 |
1205 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con
st SkRect& dst, const SkPaint* paint) | 1177 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con
st SkRect& dst, const SkPaint* paint) |
1206 { | 1178 { |
1207 ASSERT(m_canvas); | 1179 ASSERT(m_canvas); |
1208 if (contextDisabled()) | 1180 if (contextDisabled()) |
1209 return; | 1181 return; |
1210 | 1182 |
1211 if (m_client) | |
1212 m_client->willDrawRect(this, dst, paint, toImageType(image), GraphicsCon
textClient::Fill); | |
1213 | |
1214 m_canvas->drawImageRect(image, src, dst, paint); | 1183 m_canvas->drawImageRect(image, src, dst, paint); |
1215 } | 1184 } |
1216 | 1185 |
1217 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1186 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1218 { | 1187 { |
1219 ASSERT(m_canvas); | 1188 ASSERT(m_canvas); |
1220 if (contextDisabled()) | 1189 if (contextDisabled()) |
1221 return; | 1190 return; |
1222 | 1191 |
1223 m_canvas->drawOval(oval, paint); | 1192 m_canvas->drawOval(oval, paint); |
1224 } | 1193 } |
1225 | 1194 |
1226 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) | 1195 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) |
1227 { | 1196 { |
1228 ASSERT(m_canvas); | 1197 ASSERT(m_canvas); |
1229 if (contextDisabled()) | 1198 if (contextDisabled()) |
1230 return; | 1199 return; |
1231 | 1200 |
1232 m_canvas->drawPath(path, paint); | 1201 m_canvas->drawPath(path, paint); |
1233 } | 1202 } |
1234 | 1203 |
1235 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) | 1204 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) |
1236 { | 1205 { |
1237 ASSERT(m_canvas); | 1206 ASSERT(m_canvas); |
1238 if (contextDisabled()) | 1207 if (contextDisabled()) |
1239 return; | 1208 return; |
1240 | 1209 |
1241 if (m_client) | |
1242 m_client->willDrawRect(this, rect, &paint, GraphicsContextClient::NoImag
e, GraphicsContextClient::FillOrStroke); | |
1243 | |
1244 m_canvas->drawRect(rect, paint); | 1210 m_canvas->drawRect(rect, paint); |
1245 } | 1211 } |
1246 | 1212 |
1247 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) | 1213 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) |
1248 { | 1214 { |
1249 ASSERT(m_canvas); | 1215 ASSERT(m_canvas); |
1250 if (contextDisabled()) | 1216 if (contextDisabled()) |
1251 return; | 1217 return; |
1252 | 1218 |
1253 m_canvas->drawRRect(rrect, paint); | 1219 m_canvas->drawRRect(rrect, paint); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 | 1478 |
1513 clipRoundedRect(rect, SkRegion::kDifference_Op); | 1479 clipRoundedRect(rect, SkRegion::kDifference_Op); |
1514 } | 1480 } |
1515 | 1481 |
1516 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion
::Op op) | 1482 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion
::Op op) |
1517 { | 1483 { |
1518 ASSERT(m_canvas); | 1484 ASSERT(m_canvas); |
1519 if (contextDisabled()) | 1485 if (contextDisabled()) |
1520 return; | 1486 return; |
1521 | 1487 |
1522 if (op != SkRegion::kIntersect_Op && op != SkRegion::kReplace_Op) | |
1523 setHasComplexClip(); | |
1524 | |
1525 m_canvas->clipRect(rect, op, aa == AntiAliased); | 1488 m_canvas->clipRect(rect, op, aa == AntiAliased); |
1526 } | 1489 } |
1527 | 1490 |
1528 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion
::Op op) | 1491 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion
::Op op) |
1529 { | 1492 { |
1530 ASSERT(m_canvas); | 1493 ASSERT(m_canvas); |
1531 if (contextDisabled()) | 1494 if (contextDisabled()) |
1532 return; | 1495 return; |
1533 | 1496 |
1534 if (!path.isRect(0) || (op != SkRegion::kIntersect_Op && op != SkRegion::kRe
place_Op)) | |
1535 setHasComplexClip(); | |
1536 | |
1537 m_canvas->clipPath(path, op, aa == AntiAliased); | 1497 m_canvas->clipPath(path, op, aa == AntiAliased); |
1538 } | 1498 } |
1539 | 1499 |
1540 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi
on::Op op) | 1500 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi
on::Op op) |
1541 { | 1501 { |
1542 ASSERT(m_canvas); | 1502 ASSERT(m_canvas); |
1543 if (contextDisabled()) | 1503 if (contextDisabled()) |
1544 return; | 1504 return; |
1545 | 1505 |
1546 if (!rect.isRect() || (op != SkRegion::kIntersect_Op && op != SkRegion::kRep
lace_Op)) | |
1547 setHasComplexClip(); | |
1548 | |
1549 m_canvas->clipRRect(rect, op, aa == AntiAliased); | 1506 m_canvas->clipRRect(rect, op, aa == AntiAliased); |
1550 } | 1507 } |
1551 | 1508 |
1552 void GraphicsContext::rotate(float angleInRadians) | 1509 void GraphicsContext::rotate(float angleInRadians) |
1553 { | 1510 { |
1554 ASSERT(m_canvas); | 1511 ASSERT(m_canvas); |
1555 if (contextDisabled()) | 1512 if (contextDisabled()) |
1556 return; | 1513 return; |
1557 | 1514 |
1558 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); | 1515 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1935 // being set to true). We need to decide if we respect InterpolationNone | 1892 // being set to true). We need to decide if we respect InterpolationNone |
1936 // being returned from computeInterpolationQuality. | 1893 // being returned from computeInterpolationQuality. |
1937 resampling = InterpolationLow; | 1894 resampling = InterpolationLow; |
1938 } | 1895 } |
1939 resampling = limitInterpolationQuality(this, resampling); | 1896 resampling = limitInterpolationQuality(this, resampling); |
1940 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); | 1897 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); |
1941 | 1898 |
1942 return initialSaveCount; | 1899 return initialSaveCount; |
1943 } | 1900 } |
1944 | 1901 |
1945 void GraphicsContext::setClient(GraphicsContextClient* client) | |
1946 { | |
1947 ASSERT(client == 0 || m_client == 0); // No clobbering | |
1948 m_client = client; | |
1949 } | |
1950 | |
1951 } // namespace blink | 1902 } // namespace blink |
OLD | NEW |