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

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

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fixed build on win and mac Created 7 years, 7 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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 int m_restoreCount; 62 int m_restoreCount;
63 }; 63 };
64 64
65 GraphicsContext::GraphicsContext(SkCanvas* canvas) 65 GraphicsContext::GraphicsContext(SkCanvas* canvas)
66 : m_canvas(canvas) 66 : m_canvas(canvas)
67 , m_deferredSaveFlags(0) 67 , m_deferredSaveFlags(0)
68 #if !ASSERT_DISABLED 68 #if !ASSERT_DISABLED
69 , m_transparencyCount(0) 69 , m_transparencyCount(0)
70 #endif 70 #endif
71 , m_trackOpaqueRegion(false) 71 , m_trackOpaqueRegion(false)
72 , m_trackTextRegion(false)
72 , m_useHighResMarker(false) 73 , m_useHighResMarker(false)
73 , m_updatingControlTints(false) 74 , m_updatingControlTints(false)
74 , m_accelerated(false) 75 , m_accelerated(false)
75 , m_isCertainlyOpaque(true) 76 , m_isCertainlyOpaque(true)
76 , m_printing(false) 77 , m_printing(false)
77 { 78 {
78 if (!canvas) 79 if (!canvas)
79 setPaintingDisabled(true); 80 setPaintingDisabled(true);
80 81
81 m_stateStack.append(PlatformContextSkiaState()); 82 m_stateStack.append(PlatformContextSkiaState());
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 drawRect(topBorder, paint); 1094 drawRect(topBorder, paint);
1094 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; 1095 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom };
1095 drawRect(bottomBorder, paint); 1096 drawRect(bottomBorder, paint);
1096 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; 1097 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 };
1097 drawRect(leftBorder, paint); 1098 drawRect(leftBorder, paint);
1098 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; 1099 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 };
1099 drawRect(rightBorder, paint); 1100 drawRect(rightBorder, paint);
1100 } 1101 }
1101 } 1102 }
1102 1103
1103 void GraphicsContext::drawText(const Font& font, const TextRun& run, const Float Point& point, int from, int to) 1104 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo , const FloatPoint& point)
1104 { 1105 {
1105 if (paintingDisabled()) 1106 if (paintingDisabled())
1106 return; 1107 return;
1107 1108
1108 font.drawText(this, run, point, from, to); 1109 font.drawText(this, runInfo, point);
1109 } 1110 }
1110 1111
1111 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRun& run, co nst AtomicString& mark, const FloatPoint& point, int from, int to) 1112 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo & runInfo, const AtomicString& mark, const FloatPoint& point)
1112 { 1113 {
1113 if (paintingDisabled()) 1114 if (paintingDisabled())
1114 return; 1115 return;
1115 1116
1116 font.drawEmphasisMarks(this, run, mark, point, from, to); 1117 font.drawEmphasisMarks(this, runInfo, mark, point);
1117 } 1118 }
1118 1119
1119 void GraphicsContext::drawBidiText(const Font& font, const TextRun& run, const F loatPoint& point, Font::CustomFontNotReadyAction customFontNotReadyAction) 1120 void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& run Info, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReady Action)
1120 { 1121 {
1121 if (paintingDisabled()) 1122 if (paintingDisabled())
1122 return; 1123 return;
1123 1124
1125 // sub-run painting is not supported for Bidi text.
1126 const TextRun& run = runInfo.run;
1127 ASSERT((runInfo.from == 0) && (runInfo.to == run.length()));
1124 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver; 1128 BidiResolver<TextRunIterator, BidiCharacterRun> bidiResolver;
1125 bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride() )); 1129 bidiResolver.setStatus(BidiStatus(run.direction(), run.directionalOverride() ));
1126 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0)); 1130 bidiResolver.setPositionIgnoringNestedIsolates(TextRunIterator(&run, 0));
1127 1131
1128 // FIXME: This ownership should be reversed. We should pass BidiRunList 1132 // FIXME: This ownership should be reversed. We should pass BidiRunList
1129 // to BidiResolver in createBidiRunsForLine. 1133 // to BidiResolver in createBidiRunsForLine.
1130 BidiRunList<BidiCharacterRun>& bidiRuns = bidiResolver.runs(); 1134 BidiRunList<BidiCharacterRun>& bidiRuns = bidiResolver.runs();
1131 bidiResolver.createBidiRunsForLine(TextRunIterator(&run, run.length())); 1135 bidiResolver.createBidiRunsForLine(TextRunIterator(&run, run.length()));
1132 if (!bidiRuns.runCount()) 1136 if (!bidiRuns.runCount())
1133 return; 1137 return;
1134 1138
1135 FloatPoint currPoint = point; 1139 FloatPoint currPoint = point;
1136 BidiCharacterRun* bidiRun = bidiRuns.firstRun(); 1140 BidiCharacterRun* bidiRun = bidiRuns.firstRun();
1137 while (bidiRun) { 1141 while (bidiRun) {
1138 TextRun subrun = run.subRun(bidiRun->start(), bidiRun->stop() - bidiRun- >start()); 1142 TextRun subrun = run.subRun(bidiRun->start(), bidiRun->stop() - bidiRun- >start());
1139 bool isRTL = bidiRun->level() % 2; 1143 bool isRTL = bidiRun->level() % 2;
1140 subrun.setDirection(isRTL ? RTL : LTR); 1144 subrun.setDirection(isRTL ? RTL : LTR);
1141 subrun.setDirectionalOverride(bidiRun->dirOverride(false)); 1145 subrun.setDirectionalOverride(bidiRun->dirOverride(false));
1142 1146
1143 font.drawText(this, subrun, currPoint, 0, -1, customFontNotReadyAction); 1147 TextRunPaintInfo subrunInfo(subrun);
1148 subrunInfo.bounds = runInfo.bounds;
1149 font.drawText(this, subrunInfo, currPoint, customFontNotReadyAction);
1144 1150
1145 bidiRun = bidiRun->next(); 1151 bidiRun = bidiRun->next();
1146 // FIXME: Have Font::drawText return the width of what it drew so that w e don't have to re-measure here. 1152 // FIXME: Have Font::drawText return the width of what it drew so that w e don't have to re-measure here.
1147 if (bidiRun) 1153 if (bidiRun)
1148 currPoint.move(font.width(subrun), 0); 1154 currPoint.move(font.width(subrun), 0);
1149 } 1155 }
1150 1156
1151 bidiRuns.deleteRuns(); 1157 bidiRuns.deleteRuns();
1152 } 1158 }
1153 1159
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 m_opaqueRegion.didDrawRect(this, rect, paint, 0); 1350 m_opaqueRegion.didDrawRect(this, rect, paint, 0);
1345 } 1351 }
1346 1352
1347 void GraphicsContext::didDrawRect(const SkRect& rect, const SkPaint& paint, cons t SkBitmap* bitmap) 1353 void GraphicsContext::didDrawRect(const SkRect& rect, const SkPaint& paint, cons t SkBitmap* bitmap)
1348 { 1354 {
1349 if (m_trackOpaqueRegion) 1355 if (m_trackOpaqueRegion)
1350 m_opaqueRegion.didDrawRect(this, rect, paint, bitmap); 1356 m_opaqueRegion.didDrawRect(this, rect, paint, bitmap);
1351 } 1357 }
1352 1358
1353 void GraphicsContext::drawPosText(const void* text, size_t byteLength, 1359 void GraphicsContext::drawPosText(const void* text, size_t byteLength,
1354 const SkPoint pos[], const SkPaint& paint) 1360 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint)
1355 { 1361 {
1356 m_canvas->drawPosText(text, byteLength, pos, paint); 1362 m_canvas->drawPosText(text, byteLength, pos, paint);
1363 didDrawTextInRect(textRect);
1357 1364
1358 // FIXME: compute bounds for positioned text. 1365 // FIXME: compute bounds for positioned text.
1359 if (m_trackOpaqueRegion) 1366 if (m_trackOpaqueRegion)
1360 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 1367 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
1361 } 1368 }
1362 1369
1363 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, 1370 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength,
1364 const SkScalar xpos[], SkScalar constY, const SkPaint& paint) 1371 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPai nt& paint)
1365 { 1372 {
1366 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); 1373 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint);
1374 didDrawTextInRect(textRect);
1367 1375
1368 // FIXME: compute bounds for positioned text. 1376 // FIXME: compute bounds for positioned text.
1369 if (m_trackOpaqueRegion) 1377 if (m_trackOpaqueRegion)
1370 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 1378 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
1371 } 1379 }
1372 1380
1373 void GraphicsContext::drawTextOnPath(const void* text, size_t byteLength, 1381 void GraphicsContext::drawTextOnPath(const void* text, size_t byteLength,
1374 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) 1382 const SkPath& path, const SkRect& textRect, const SkMatrix* matrix, const S kPaint& paint)
1375 { 1383 {
1376 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint); 1384 m_canvas->drawTextOnPath(text, byteLength, path, matrix, paint);
1385 didDrawTextInRect(textRect);
1377 1386
1378 // FIXME: compute bounds for positioned text. 1387 // FIXME: compute bounds for positioned text.
1379 if (m_trackOpaqueRegion) 1388 if (m_trackOpaqueRegion)
1380 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke); 1389 m_opaqueRegion.didDrawUnbounded(this, paint, OpaqueRegionSkia::FillOrStr oke);
1381 } 1390 }
1382 1391
1383 void GraphicsContext::fillPath(const Path& pathToFill) 1392 void GraphicsContext::fillPath(const Path& pathToFill)
1384 { 1393 {
1385 if (paintingDisabled() || pathToFill.isEmpty()) 1394 if (paintingDisabled() || pathToFill.isEmpty())
1386 return; 1395 return;
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
2116 // only look at the alpha when compositing. I'm not 100% sure this is what W ebKit expects for image clipping. 2125 // only look at the alpha when compositing. I'm not 100% sure this is what W ebKit expects for image clipping.
2117 SkPaint paint; 2126 SkPaint paint;
2118 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); 2127 paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
2119 realizeSave(SkCanvas::kMatrixClip_SaveFlag); 2128 realizeSave(SkCanvas::kMatrixClip_SaveFlag);
2120 m_canvas->save(SkCanvas::kMatrix_SaveFlag); 2129 m_canvas->save(SkCanvas::kMatrix_SaveFlag);
2121 m_canvas->resetMatrix(); 2130 m_canvas->resetMatrix();
2122 m_canvas->drawBitmapRect(imageBuffer, 0, rect, &paint); 2131 m_canvas->drawBitmapRect(imageBuffer, 0, rect, &paint);
2123 m_canvas->restore(); 2132 m_canvas->restore();
2124 } 2133 }
2125 2134
2135 void GraphicsContext::didDrawTextInRect(const SkRect& textRect)
2136 {
2137 if (m_trackTextRegion) {
2138 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion");
2139 m_textRegion.join(textRect);
2140 }
2126 } 2141 }
2142
2143 }
OLDNEW
« no previous file with comments | « Source/core/platform/graphics/GraphicsContext.h ('k') | Source/core/platform/graphics/TextRun.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698