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

Side by Side Diff: src/gpu/SkGpuDevice.cpp

Issue 2336623002: Match Android framework's non-AA point and line offset (Closed)
Patch Set: fix speeling Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "GrBlurUtils.h" 10 #include "GrBlurUtils.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 274
275 GrPaint grPaint; 275 GrPaint grPaint;
276 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMat rix, &grPaint)) { 276 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMat rix, &grPaint)) {
277 return; 277 return;
278 } 278 }
279 279
280 fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix); 280 fDrawContext->drawPaint(fClip, grPaint, *draw.fMatrix);
281 } 281 }
282 282
283 // must be in SkCanvas::PointMode order 283 // must be in SkCanvas::PointMode order
284 static const GrPrimitiveType gPointMode2PrimtiveType[] = { 284 static const GrPrimitiveType gPointMode2PrimitiveType[] = {
285 kPoints_GrPrimitiveType, 285 kPoints_GrPrimitiveType,
286 kLines_GrPrimitiveType, 286 kLines_GrPrimitiveType,
287 kLineStrip_GrPrimitiveType 287 kLineStrip_GrPrimitiveType
288 }; 288 };
289 289
290 // suppress antialiasing on axis-aligned integer-coordinate lines 290 // suppress antialiasing on axis-aligned integer-coordinate lines
291 static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP oint pts[]) { 291 static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP oint pts[]) {
292 if (mode == SkCanvas::PointMode::kPoints_PointMode) { 292 if (mode == SkCanvas::PointMode::kPoints_PointMode) {
293 return false; 293 return false;
294 } 294 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 return; 328 return;
329 } 329 }
330 SkPath path; 330 SkPath path;
331 path.setIsVolatile(true); 331 path.setIsVolatile(true);
332 path.moveTo(pts[0]); 332 path.moveTo(pts[0]);
333 path.lineTo(pts[1]); 333 path.lineTo(pts[1]);
334 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style); 334 fDrawContext->drawPath(fClip, grPaint, *draw.fMatrix, path, style);
335 return; 335 return;
336 } 336 }
337 337
338 SkScalar scales[2];
339 bool isHairline = (0 == width) || (1 == width && draw.fMatrix->getMinMaxScal es(scales) &&
340 SkScalarNearlyEqual(scales[0], 1.f) &&
341 SkScalarNearlyEqual(scales[1], 1.f));
338 // we only handle non-antialiased hairlines and paints without path effects or mask filters, 342 // we only handle non-antialiased hairlines and paints without path effects or mask filters,
339 // else we let the SkDraw call our drawPath() 343 // else we let the SkDraw call our drawPath()
340 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || 344 if (!isHairline || paint.getPathEffect() || paint.getMaskFilter() ||
341 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { 345 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) {
342 draw.drawPoints(mode, count, pts, paint, true); 346 draw.drawPoints(mode, count, pts, paint, true);
343 return; 347 return;
344 } 348 }
345 349
350 GrPrimitiveType primitiveType = gPointMode2PrimitiveType[mode];
351
352 const SkMatrix* viewMatrix = draw.fMatrix;
353 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
354 // This offsetting in device space matches the expectations of the Android f ramework for non-AA
355 // points and lines.
356 SkMatrix tempMatrix;
357 if (GrIsPrimTypeLines(primitiveType) || kPoints_GrPrimitiveType == primitive Type) {
358 tempMatrix = *viewMatrix;
359 static const SkScalar kOffset = 0.063f; // Just greater than 1/16.
360 tempMatrix.postTranslate(kOffset, kOffset);
361 viewMatrix = &tempMatrix;
362 }
363 #endif
364
346 GrPaint grPaint; 365 GrPaint grPaint;
347 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMat rix, &grPaint)) { 366 if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *viewMatri x, &grPaint)) {
348 return; 367 return;
349 } 368 }
350 369
351 fDrawContext->drawVertices(fClip, 370 fDrawContext->drawVertices(fClip,
352 grPaint, 371 grPaint,
353 *draw.fMatrix, 372 *viewMatrix,
354 gPointMode2PrimtiveType[mode], 373 primitiveType,
355 SkToS32(count), 374 SkToS32(count),
356 (SkPoint*)pts, 375 (SkPoint*)pts,
357 nullptr, 376 nullptr,
358 nullptr, 377 nullptr,
359 nullptr, 378 nullptr,
360 0); 379 0);
361 } 380 }
362 381
363 /////////////////////////////////////////////////////////////////////////////// 382 ///////////////////////////////////////////////////////////////////////////////
364 383
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 } 1817 }
1799 1818
1800 SkImageFilterCache* SkGpuDevice::getImageFilterCache() { 1819 SkImageFilterCache* SkGpuDevice::getImageFilterCache() {
1801 ASSERT_SINGLE_OWNER 1820 ASSERT_SINGLE_OWNER
1802 // We always return a transient cache, so it is freed after each 1821 // We always return a transient cache, so it is freed after each
1803 // filter traversal. 1822 // filter traversal.
1804 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize); 1823 return SkImageFilterCache::Create(kDefaultImageFilterCacheSize);
1805 } 1824 }
1806 1825
1807 #endif 1826 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698