OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "platform/geometry/FloatRect.h" | 33 #include "platform/geometry/FloatRect.h" |
34 #include "platform/geometry/LayoutRect.h" | 34 #include "platform/geometry/LayoutRect.h" |
35 #include "platform/geometry/Region.h" | 35 #include "platform/geometry/Region.h" |
36 #include "platform/graphics/BitmapImage.h" | 36 #include "platform/graphics/BitmapImage.h" |
37 #include "platform/graphics/CompositorFilterOperations.h" | 37 #include "platform/graphics/CompositorFilterOperations.h" |
38 #include "platform/graphics/FirstPaintInvalidationTracking.h" | 38 #include "platform/graphics/FirstPaintInvalidationTracking.h" |
39 #include "platform/graphics/GraphicsContext.h" | 39 #include "platform/graphics/GraphicsContext.h" |
40 #include "platform/graphics/Image.h" | 40 #include "platform/graphics/Image.h" |
41 #include "platform/graphics/LinkHighlight.h" | 41 #include "platform/graphics/LinkHighlight.h" |
42 #include "platform/graphics/paint/DrawingRecorder.h" | 42 #include "platform/graphics/paint/DrawingRecorder.h" |
| 43 #include "platform/graphics/paint/PaintCanvas.h" |
43 #include "platform/graphics/paint/PaintController.h" | 44 #include "platform/graphics/paint/PaintController.h" |
44 #include "platform/graphics/paint/RasterInvalidationTracking.h" | 45 #include "platform/graphics/paint/RasterInvalidationTracking.h" |
45 #include "platform/instrumentation/tracing/TraceEvent.h" | 46 #include "platform/instrumentation/tracing/TraceEvent.h" |
46 #include "platform/json/JSONValues.h" | 47 #include "platform/json/JSONValues.h" |
47 #include "platform/scroll/ScrollableArea.h" | 48 #include "platform/scroll/ScrollableArea.h" |
48 #include "platform/text/TextStream.h" | 49 #include "platform/text/TextStream.h" |
49 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
50 #include "public/platform/WebCompositorSupport.h" | 51 #include "public/platform/WebCompositorSupport.h" |
51 #include "public/platform/WebFloatPoint.h" | 52 #include "public/platform/WebFloatPoint.h" |
52 #include "public/platform/WebFloatRect.h" | 53 #include "public/platform/WebFloatRect.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 IntRect GraphicsLayer::interestRect() { | 292 IntRect GraphicsLayer::interestRect() { |
292 return m_previousInterestRect; | 293 return m_previousInterestRect; |
293 } | 294 } |
294 | 295 |
295 void GraphicsLayer::paint(const IntRect* interestRect, | 296 void GraphicsLayer::paint(const IntRect* interestRect, |
296 GraphicsContext::DisabledMode disabledMode) { | 297 GraphicsContext::DisabledMode disabledMode) { |
297 if (paintWithoutCommit(interestRect, disabledMode)) { | 298 if (paintWithoutCommit(interestRect, disabledMode)) { |
298 getPaintController().commitNewDisplayItems( | 299 getPaintController().commitNewDisplayItems( |
299 offsetFromLayoutObjectWithSubpixelAccumulation()); | 300 offsetFromLayoutObjectWithSubpixelAccumulation()); |
300 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { | 301 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
301 sk_sp<SkPicture> newPicture = capturePicture(); | 302 sk_sp<PaintRecord> newPicture = capturePicture(); |
302 checkPaintUnderInvalidations(*newPicture); | 303 checkPaintUnderInvalidations(*newPicture); |
303 RasterInvalidationTracking& tracking = | 304 RasterInvalidationTracking& tracking = |
304 rasterInvalidationTrackingMap().add(this); | 305 rasterInvalidationTrackingMap().add(this); |
305 tracking.lastPaintedPicture = std::move(newPicture); | 306 tracking.lastPaintedPicture = std::move(newPicture); |
306 tracking.lastInterestRect = m_previousInterestRect; | 307 tracking.lastInterestRect = m_previousInterestRect; |
307 tracking.rasterInvalidationRegionSinceLastPaint = Region(); | 308 tracking.rasterInvalidationRegionSinceLastPaint = Region(); |
308 } | 309 } |
309 } | 310 } |
310 } | 311 } |
311 | 312 |
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (WebLayer* layer = platformLayer()) | 1204 if (WebLayer* layer = platformLayer()) |
1204 return layer->elementId(); | 1205 return layer->elementId(); |
1205 return CompositorElementId(); | 1206 return CompositorElementId(); |
1206 } | 1207 } |
1207 | 1208 |
1208 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) { | 1209 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) { |
1209 if (WebLayer* layer = platformLayer()) | 1210 if (WebLayer* layer = platformLayer()) |
1210 layer->setCompositorMutableProperties(properties); | 1211 layer->setCompositorMutableProperties(properties); |
1211 } | 1212 } |
1212 | 1213 |
1213 sk_sp<SkPicture> GraphicsLayer::capturePicture() { | 1214 sk_sp<PaintRecord> GraphicsLayer::capturePicture() { |
1214 if (!drawsContent()) | 1215 if (!drawsContent()) |
1215 return nullptr; | 1216 return nullptr; |
1216 | 1217 |
1217 IntSize intSize = expandedIntSize(size()); | 1218 IntSize intSize = expandedIntSize(size()); |
1218 GraphicsContext graphicsContext(getPaintController(), | 1219 GraphicsContext graphicsContext(getPaintController(), |
1219 GraphicsContext::NothingDisabled, nullptr, | 1220 GraphicsContext::NothingDisabled, nullptr, |
1220 m_colorBehavior); | 1221 m_colorBehavior); |
1221 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize)); | 1222 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize)); |
1222 getPaintController().paintArtifact().replay(graphicsContext); | 1223 getPaintController().paintArtifact().replay(graphicsContext); |
1223 return graphicsContext.endRecording(); | 1224 return graphicsContext.endRecording(); |
1224 } | 1225 } |
1225 | 1226 |
1226 static bool pixelComponentsDiffer(int c1, int c2) { | 1227 static bool pixelComponentsDiffer(int c1, int c2) { |
1227 // Compare strictly for saturated values. | 1228 // Compare strictly for saturated values. |
1228 if (c1 == 0 || c1 == 255 || c2 == 0 || c2 == 255) | 1229 if (c1 == 0 || c1 == 255 || c2 == 0 || c2 == 255) |
1229 return c1 != c2; | 1230 return c1 != c2; |
1230 // Tolerate invisible differences that may occur in gradients etc. | 1231 // Tolerate invisible differences that may occur in gradients etc. |
1231 return abs(c1 - c2) > 2; | 1232 return abs(c1 - c2) > 2; |
1232 } | 1233 } |
1233 | 1234 |
1234 static bool pixelsDiffer(SkColor p1, SkColor p2) { | 1235 static bool pixelsDiffer(SkColor p1, SkColor p2) { |
1235 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) || | 1236 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) || |
1236 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) || | 1237 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) || |
1237 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) || | 1238 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) || |
1238 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2)); | 1239 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2)); |
1239 } | 1240 } |
1240 | 1241 |
1241 void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture) { | 1242 void GraphicsLayer::checkPaintUnderInvalidations( |
| 1243 const PaintRecord& newPicture) { |
1242 if (!drawsContent()) | 1244 if (!drawsContent()) |
1243 return; | 1245 return; |
1244 | 1246 |
1245 RasterInvalidationTracking* tracking = | 1247 RasterInvalidationTracking* tracking = |
1246 rasterInvalidationTrackingMap().find(this); | 1248 rasterInvalidationTrackingMap().find(this); |
1247 if (!tracking) | 1249 if (!tracking) |
1248 return; | 1250 return; |
1249 | 1251 |
1250 if (!tracking->lastPaintedPicture) | 1252 if (!tracking->lastPaintedPicture) |
1251 return; | 1253 return; |
1252 | 1254 |
1253 IntRect rect = intersection(tracking->lastInterestRect, interestRect()); | 1255 IntRect rect = intersection(tracking->lastInterestRect, interestRect()); |
1254 if (rect.isEmpty()) | 1256 if (rect.isEmpty()) |
1255 return; | 1257 return; |
1256 | 1258 |
1257 SkBitmap oldBitmap; | 1259 SkBitmap oldBitmap; |
1258 oldBitmap.allocPixels( | 1260 oldBitmap.allocPixels( |
1259 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 1261 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |
1260 { | 1262 { |
1261 SkCanvas canvas(oldBitmap); | 1263 SkCanvas bitmapCanvas(oldBitmap); |
| 1264 PaintCanvasPassThrough canvas(&bitmapCanvas); |
1262 canvas.clear(SK_ColorTRANSPARENT); | 1265 canvas.clear(SK_ColorTRANSPARENT); |
1263 canvas.translate(-rect.x(), -rect.y()); | 1266 canvas.translate(-rect.x(), -rect.y()); |
1264 canvas.drawPicture(tracking->lastPaintedPicture.get()); | 1267 canvas.drawPicture(tracking->lastPaintedPicture.get()); |
1265 } | 1268 } |
1266 | 1269 |
1267 SkBitmap newBitmap; | 1270 SkBitmap newBitmap; |
1268 newBitmap.allocPixels( | 1271 newBitmap.allocPixels( |
1269 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); | 1272 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); |
1270 { | 1273 { |
1271 SkCanvas canvas(newBitmap); | 1274 SkCanvas bitmapCanvas(newBitmap); |
| 1275 PaintCanvasPassThrough canvas(&bitmapCanvas); |
1272 canvas.clear(SK_ColorTRANSPARENT); | 1276 canvas.clear(SK_ColorTRANSPARENT); |
1273 canvas.translate(-rect.x(), -rect.y()); | 1277 canvas.translate(-rect.x(), -rect.y()); |
1274 canvas.drawPicture(&newPicture); | 1278 canvas.drawPicture(&newPicture); |
1275 } | 1279 } |
1276 | 1280 |
1277 oldBitmap.lockPixels(); | 1281 oldBitmap.lockPixels(); |
1278 newBitmap.lockPixels(); | 1282 newBitmap.lockPixels(); |
1279 int mismatchingPixels = 0; | 1283 int mismatchingPixels = 0; |
1280 static const int maxMismatchesToReport = 50; | 1284 static const int maxMismatchesToReport = 50; |
1281 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) { | 1285 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) { |
(...skipping 23 matching lines...) Expand all Loading... |
1305 *newBitmap.getAddr32(bitmapX, bitmapY) = SK_ColorTRANSPARENT; | 1309 *newBitmap.getAddr32(bitmapX, bitmapY) = SK_ColorTRANSPARENT; |
1306 } | 1310 } |
1307 } | 1311 } |
1308 } | 1312 } |
1309 oldBitmap.unlockPixels(); | 1313 oldBitmap.unlockPixels(); |
1310 newBitmap.unlockPixels(); | 1314 newBitmap.unlockPixels(); |
1311 | 1315 |
1312 // Visualize under-invalidations by overlaying the new bitmap (containing red | 1316 // Visualize under-invalidations by overlaying the new bitmap (containing red |
1313 // pixels indicating under-invalidations, and transparent pixels otherwise) | 1317 // pixels indicating under-invalidations, and transparent pixels otherwise) |
1314 // onto the painting. | 1318 // onto the painting. |
1315 SkPictureRecorder recorder; | 1319 PaintRecorder recorder; |
1316 recorder.beginRecording(rect); | 1320 recorder.beginRecording(rect); |
1317 recorder.getRecordingCanvas()->drawBitmap(newBitmap, rect.x(), rect.y()); | 1321 recorder.getRecordingCanvas()->drawBitmap(newBitmap, rect.x(), rect.y()); |
1318 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); | 1322 sk_sp<PaintRecord> picture = recorder.finishRecordingAsPicture(); |
1319 getPaintController().appendDebugDrawingAfterCommit( | 1323 getPaintController().appendDebugDrawingAfterCommit( |
1320 *this, picture, offsetFromLayoutObjectWithSubpixelAccumulation()); | 1324 *this, picture, offsetFromLayoutObjectWithSubpixelAccumulation()); |
1321 } | 1325 } |
1322 | 1326 |
1323 } // namespace blink | 1327 } // namespace blink |
1324 | 1328 |
1325 #ifndef NDEBUG | 1329 #ifndef NDEBUG |
1326 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) { | 1330 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) { |
1327 if (!layer) { | 1331 if (!layer) { |
1328 LOG(INFO) << "Cannot showGraphicsLayerTree for (nil)."; | 1332 LOG(INFO) << "Cannot showGraphicsLayerTree for (nil)."; |
1329 return; | 1333 return; |
1330 } | 1334 } |
1331 | 1335 |
1332 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); | 1336 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); |
1333 LOG(INFO) << output.utf8().data(); | 1337 LOG(INFO) << output.utf8().data(); |
1334 } | 1338 } |
1335 #endif | 1339 #endif |
OLD | NEW |