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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/GraphicsLayer.cpp

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 3 years, 12 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
OLDNEW
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "platform/scroll/ScrollableArea.h" 46 #include "platform/scroll/ScrollableArea.h"
47 #include "platform/text/TextStream.h" 47 #include "platform/text/TextStream.h"
48 #include "platform/tracing/TraceEvent.h" 48 #include "platform/tracing/TraceEvent.h"
49 #include "public/platform/Platform.h" 49 #include "public/platform/Platform.h"
50 #include "public/platform/WebCompositorSupport.h" 50 #include "public/platform/WebCompositorSupport.h"
51 #include "public/platform/WebFloatPoint.h" 51 #include "public/platform/WebFloatPoint.h"
52 #include "public/platform/WebFloatRect.h" 52 #include "public/platform/WebFloatRect.h"
53 #include "public/platform/WebLayer.h" 53 #include "public/platform/WebLayer.h"
54 #include "public/platform/WebPoint.h" 54 #include "public/platform/WebPoint.h"
55 #include "public/platform/WebSize.h" 55 #include "public/platform/WebSize.h"
56 #include "skia/ext/cdl_canvas.h"
56 #include "wtf/CurrentTime.h" 57 #include "wtf/CurrentTime.h"
57 #include "wtf/HashMap.h" 58 #include "wtf/HashMap.h"
58 #include "wtf/HashSet.h" 59 #include "wtf/HashSet.h"
59 #include "wtf/MathExtras.h" 60 #include "wtf/MathExtras.h"
60 #include "wtf/PtrUtil.h" 61 #include "wtf/PtrUtil.h"
61 #include "wtf/text/StringUTF8Adaptor.h" 62 #include "wtf/text/StringUTF8Adaptor.h"
62 #include "wtf/text/WTFString.h" 63 #include "wtf/text/WTFString.h"
63 #include <algorithm> 64 #include <algorithm>
64 #include <cmath> 65 #include <cmath>
65 #include <memory> 66 #include <memory>
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 IntRect GraphicsLayer::interestRect() { 286 IntRect GraphicsLayer::interestRect() {
286 return m_previousInterestRect; 287 return m_previousInterestRect;
287 } 288 }
288 289
289 void GraphicsLayer::paint(const IntRect* interestRect, 290 void GraphicsLayer::paint(const IntRect* interestRect,
290 GraphicsContext::DisabledMode disabledMode) { 291 GraphicsContext::DisabledMode disabledMode) {
291 if (paintWithoutCommit(interestRect, disabledMode)) { 292 if (paintWithoutCommit(interestRect, disabledMode)) {
292 getPaintController().commitNewDisplayItems( 293 getPaintController().commitNewDisplayItems(
293 offsetFromLayoutObjectWithSubpixelAccumulation()); 294 offsetFromLayoutObjectWithSubpixelAccumulation());
294 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { 295 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) {
295 sk_sp<SkPicture> newPicture = capturePicture(); 296 sk_sp<CdlPicture> newPicture = capturePicture();
296 checkPaintUnderInvalidations(*newPicture); 297 checkPaintUnderInvalidations(*newPicture);
297 RasterInvalidationTracking& tracking = 298 RasterInvalidationTracking& tracking =
298 rasterInvalidationTrackingMap().add(this); 299 rasterInvalidationTrackingMap().add(this);
299 tracking.lastPaintedPicture = std::move(newPicture); 300 tracking.lastPaintedPicture = std::move(newPicture);
300 tracking.lastInterestRect = m_previousInterestRect; 301 tracking.lastInterestRect = m_previousInterestRect;
301 tracking.rasterInvalidationRegionSinceLastPaint = Region(); 302 tracking.rasterInvalidationRegionSinceLastPaint = Region();
302 } 303 }
303 } 304 }
304 } 305 }
305 306
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 if (WebLayer* layer = platformLayer()) 1199 if (WebLayer* layer = platformLayer())
1199 return layer->elementId(); 1200 return layer->elementId();
1200 return CompositorElementId(); 1201 return CompositorElementId();
1201 } 1202 }
1202 1203
1203 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) { 1204 void GraphicsLayer::setCompositorMutableProperties(uint32_t properties) {
1204 if (WebLayer* layer = platformLayer()) 1205 if (WebLayer* layer = platformLayer())
1205 layer->setCompositorMutableProperties(properties); 1206 layer->setCompositorMutableProperties(properties);
1206 } 1207 }
1207 1208
1208 sk_sp<SkPicture> GraphicsLayer::capturePicture() { 1209 sk_sp<CdlPicture> GraphicsLayer::capturePicture() {
1209 if (!drawsContent()) 1210 if (!drawsContent())
1210 return nullptr; 1211 return nullptr;
1211 1212
1212 IntSize intSize = expandedIntSize(size()); 1213 IntSize intSize = expandedIntSize(size());
1213 GraphicsContext graphicsContext(getPaintController()); 1214 GraphicsContext graphicsContext(getPaintController());
1214 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize)); 1215 graphicsContext.beginRecording(IntRect(IntPoint(0, 0), intSize));
1215 getPaintController().paintArtifact().replay(graphicsContext); 1216 getPaintController().paintArtifact().replay(graphicsContext);
1216 return graphicsContext.endRecording(); 1217 return graphicsContext.endRecording();
1217 } 1218 }
1218 1219
1219 static bool pixelComponentsDiffer(int c1, int c2) { 1220 static bool pixelComponentsDiffer(int c1, int c2) {
1220 // Compare strictly for saturated values. 1221 // Compare strictly for saturated values.
1221 if (c1 == 0 || c1 == 255 || c2 == 0 || c2 == 255) 1222 if (c1 == 0 || c1 == 255 || c2 == 0 || c2 == 255)
1222 return c1 != c2; 1223 return c1 != c2;
1223 // Tolerate invisible differences that may occur in gradients etc. 1224 // Tolerate invisible differences that may occur in gradients etc.
1224 return abs(c1 - c2) > 2; 1225 return abs(c1 - c2) > 2;
1225 } 1226 }
1226 1227
1227 static bool pixelsDiffer(SkColor p1, SkColor p2) { 1228 static bool pixelsDiffer(SkColor p1, SkColor p2) {
1228 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) || 1229 return pixelComponentsDiffer(SkColorGetA(p1), SkColorGetA(p2)) ||
1229 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) || 1230 pixelComponentsDiffer(SkColorGetR(p1), SkColorGetR(p2)) ||
1230 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) || 1231 pixelComponentsDiffer(SkColorGetG(p1), SkColorGetG(p2)) ||
1231 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2)); 1232 pixelComponentsDiffer(SkColorGetB(p1), SkColorGetB(p2));
1232 } 1233 }
1233 1234
1234 void GraphicsLayer::checkPaintUnderInvalidations(const SkPicture& newPicture) { 1235 void GraphicsLayer::checkPaintUnderInvalidations(const CdlPicture& newPicture) {
1235 if (!drawsContent()) 1236 if (!drawsContent())
1236 return; 1237 return;
1237 1238
1238 RasterInvalidationTracking* tracking = 1239 RasterInvalidationTracking* tracking =
1239 rasterInvalidationTrackingMap().find(this); 1240 rasterInvalidationTrackingMap().find(this);
1240 if (!tracking) 1241 if (!tracking)
1241 return; 1242 return;
1242 1243
1243 if (!tracking->lastPaintedPicture) 1244 if (!tracking->lastPaintedPicture)
1244 return; 1245 return;
1245 1246
1246 IntRect rect = intersection(tracking->lastInterestRect, interestRect()); 1247 IntRect rect = intersection(tracking->lastInterestRect, interestRect());
1247 if (rect.isEmpty()) 1248 if (rect.isEmpty())
1248 return; 1249 return;
1249 1250
1250 SkBitmap oldBitmap; 1251 SkBitmap oldBitmap;
1251 oldBitmap.allocPixels( 1252 oldBitmap.allocPixels(
1252 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); 1253 SkImageInfo::MakeN32Premul(rect.width(), rect.height()));
1253 { 1254 {
1254 SkCanvas canvas(oldBitmap); 1255 SkCanvas sk_canvas(oldBitmap);
1256 CdlPassThroughCanvas canvas(&sk_canvas);
1255 canvas.clear(SK_ColorTRANSPARENT); 1257 canvas.clear(SK_ColorTRANSPARENT);
1256 canvas.translate(-rect.x(), -rect.y()); 1258 canvas.translate(-rect.x(), -rect.y());
1257 canvas.drawPicture(tracking->lastPaintedPicture.get()); 1259 canvas.drawPicture(tracking->lastPaintedPicture.get());
1258 } 1260 }
1259 1261
1260 SkBitmap newBitmap; 1262 SkBitmap newBitmap;
1261 newBitmap.allocPixels( 1263 newBitmap.allocPixels(
1262 SkImageInfo::MakeN32Premul(rect.width(), rect.height())); 1264 SkImageInfo::MakeN32Premul(rect.width(), rect.height()));
1263 { 1265 {
1264 SkCanvas canvas(newBitmap); 1266 SkCanvas sk_canvas(newBitmap);
1267 CdlPassThroughCanvas canvas(&sk_canvas);
1265 canvas.clear(SK_ColorTRANSPARENT); 1268 canvas.clear(SK_ColorTRANSPARENT);
1266 canvas.translate(-rect.x(), -rect.y()); 1269 canvas.translate(-rect.x(), -rect.y());
1267 canvas.drawPicture(&newPicture); 1270 canvas.drawPicture(&newPicture);
1268 } 1271 }
1269 1272
1270 oldBitmap.lockPixels(); 1273 oldBitmap.lockPixels();
1271 newBitmap.lockPixels(); 1274 newBitmap.lockPixels();
1272 int mismatchingPixels = 0; 1275 int mismatchingPixels = 0;
1273 static const int maxMismatchesToReport = 50; 1276 static const int maxMismatchesToReport = 50;
1274 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) { 1277 for (int bitmapY = 0; bitmapY < rect.height(); ++bitmapY) {
(...skipping 23 matching lines...) Expand all
1298 *newBitmap.getAddr32(bitmapX, bitmapY) = SK_ColorTRANSPARENT; 1301 *newBitmap.getAddr32(bitmapX, bitmapY) = SK_ColorTRANSPARENT;
1299 } 1302 }
1300 } 1303 }
1301 } 1304 }
1302 oldBitmap.unlockPixels(); 1305 oldBitmap.unlockPixels();
1303 newBitmap.unlockPixels(); 1306 newBitmap.unlockPixels();
1304 1307
1305 // Visualize under-invalidations by overlaying the new bitmap (containing red 1308 // Visualize under-invalidations by overlaying the new bitmap (containing red
1306 // pixels indicating under-invalidations, and transparent pixels otherwise) 1309 // pixels indicating under-invalidations, and transparent pixels otherwise)
1307 // onto the painting. 1310 // onto the painting.
1308 SkPictureRecorder recorder; 1311 CdlPictureRecorder recorder;
1309 recorder.beginRecording(rect); 1312 recorder.beginRecording(rect);
1310 recorder.getRecordingCanvas()->drawBitmap(newBitmap, rect.x(), rect.y()); 1313 recorder.getRecordingCanvas()->drawBitmap(newBitmap, rect.x(), rect.y());
1311 sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); 1314 sk_sp<CdlPicture> picture = recorder.finishRecordingAsPicture();
1312 getPaintController().appendDebugDrawingAfterCommit( 1315 getPaintController().appendDebugDrawingAfterCommit(
1313 *this, picture, offsetFromLayoutObjectWithSubpixelAccumulation()); 1316 *this, picture, offsetFromLayoutObjectWithSubpixelAccumulation());
1314 } 1317 }
1315 1318
1316 } // namespace blink 1319 } // namespace blink
1317 1320
1318 #ifndef NDEBUG 1321 #ifndef NDEBUG
1319 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) { 1322 void showGraphicsLayerTree(const blink::GraphicsLayer* layer) {
1320 if (!layer) { 1323 if (!layer) {
1321 LOG(INFO) << "Cannot showGraphicsLayerTree for (nil)."; 1324 LOG(INFO) << "Cannot showGraphicsLayerTree for (nil).";
1322 return; 1325 return;
1323 } 1326 }
1324 1327
1325 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo); 1328 String output = layer->layerTreeAsText(blink::LayerTreeIncludesDebugInfo);
1326 LOG(INFO) << output.utf8().data(); 1329 LOG(INFO) << output.utf8().data();
1327 } 1330 }
1328 #endif 1331 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698