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

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

Issue 1129083005: AADistanceFieldPathRenderer unit tests (Closed) Base URL: https://skia.googlesource.com/skia.git@randbatch7
Patch Set: tweaks Created 5 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
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
11 #include "GrBatch.h" 11 #include "GrBatch.h"
12 #include "GrBatchTarget.h" 12 #include "GrBatchTarget.h"
13 #include "GrBatchTest.h"
13 #include "GrContext.h" 14 #include "GrContext.h"
14 #include "GrPipelineBuilder.h" 15 #include "GrPipelineBuilder.h"
15 #include "GrResourceProvider.h" 16 #include "GrResourceProvider.h"
16 #include "GrSurfacePriv.h" 17 #include "GrSurfacePriv.h"
17 #include "GrSWMaskHelper.h" 18 #include "GrSWMaskHelper.h"
18 #include "GrTexturePriv.h" 19 #include "GrTexturePriv.h"
19 #include "GrVertexBuffer.h" 20 #include "GrVertexBuffer.h"
20 #include "effects/GrDistanceFieldGeoProc.h" 21 #include "effects/GrDistanceFieldGeoProc.h"
21 22
22 #include "SkDistanceFieldGen.h" 23 #include "SkDistanceFieldGen.h"
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 bool fCoverageIgnored; 547 bool fCoverageIgnored;
547 }; 548 };
548 549
549 BatchTracker fBatch; 550 BatchTracker fBatch;
550 SkSTArray<1, Geometry, true> fGeoData; 551 SkSTArray<1, Geometry, true> fGeoData;
551 GrBatchAtlas* fAtlas; 552 GrBatchAtlas* fAtlas;
552 PathCache* fPathCache; 553 PathCache* fPathCache;
553 PathDataList* fPathList; 554 PathDataList* fPathList;
554 }; 555 };
555 556
557 static GrBatchAtlas* create_atlas(GrContext* context, GrBatchAtlas::EvictionFunc func, void* data) {
558 GrBatchAtlas* atlas;
559 // Create a new atlas
560 GrSurfaceDesc desc;
561 desc.fFlags = kNone_GrSurfaceFlags;
562 desc.fWidth = ATLAS_TEXTURE_WIDTH;
563 desc.fHeight = ATLAS_TEXTURE_HEIGHT;
564 desc.fConfig = kAlpha_8_GrPixelConfig;
565
566 // We don't want to flush the context so we claim we're in the middle of flu shing so as to
567 // guarantee we do not recieve a texture with pending IO
568 GrTexture* texture = context->textureProvider()->refScratchTexture(
569 desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
570 if (texture) {
571 atlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y));
572 } else {
573 return NULL;
574 }
575 atlas->registerEvictionCallback(func, data);
576 return atlas;
577 }
578
556 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, 579 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target,
557 GrPipelineBuilder* pipelineBuilde r, 580 GrPipelineBuilder* pipelineBuilde r,
558 GrColor color, 581 GrColor color,
559 const SkMatrix& viewMatrix, 582 const SkMatrix& viewMatrix,
560 const SkPath& path, 583 const SkPath& path,
561 const GrStrokeInfo& stroke, 584 const GrStrokeInfo& stroke,
562 bool antiAlias) { 585 bool antiAlias) {
563 // we've already bailed on inverse filled paths, so this is safe 586 // we've already bailed on inverse filled paths, so this is safe
564 if (path.isEmpty()) { 587 if (path.isEmpty()) {
565 return true; 588 return true;
566 } 589 }
567 590
568 SkASSERT(fContext); 591 SkASSERT(fContext);
569 592
570 if (!fAtlas) { 593 if (!fAtlas) {
571 // Create a new atlas 594 fAtlas = create_atlas(fContext, &GrAADistanceFieldPathRenderer::HandleEv iction,
572 GrSurfaceDesc desc; 595 (void*)this);
573 desc.fFlags = kNone_GrSurfaceFlags; 596 if (!fAtlas) {
574 desc.fWidth = ATLAS_TEXTURE_WIDTH;
575 desc.fHeight = ATLAS_TEXTURE_HEIGHT;
576 desc.fConfig = kAlpha_8_GrPixelConfig;
577
578 // We don't want to flush the context so we claim we're in the middle of flushing so as to
579 // guarantee we do not recieve a texture with pending IO
580 GrTexture* texture = fContext->textureProvider()->refScratchTexture(
581 desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
582 if (texture) {
583 fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y ));
584 } else {
585 return false; 597 return false;
586 } 598 }
587 fAtlas->registerEvictionCallback(&GrAADistanceFieldPathRenderer::HandleE viction,
588 (void*)this);
589 } 599 }
590 600
591 AADistanceFieldPathBatch::Geometry geometry(stroke.getStrokeRec()); 601 AADistanceFieldPathBatch::Geometry geometry(stroke.getStrokeRec());
592 geometry.fPath = path; 602 geometry.fPath = path;
593 geometry.fAntiAlias = antiAlias; 603 geometry.fAntiAlias = antiAlias;
594 604
595 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix, 605 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix,
596 fAtlas, &fPathC ache, &fPathList)); 606 fAtlas, &fPathC ache, &fPathList));
597 target->drawBatch(pipelineBuilder, batch); 607 target->drawBatch(pipelineBuilder, batch);
598 608
599 return true; 609 return true;
600 } 610 }
601 611
612 //////////////////////////////////////////////////////////////////////////////// ///////////////////
613
614 #ifdef GR_TEST_UTILS
615
616 struct PathTestStruct {
617 typedef GrAADistanceFieldPathRenderer::PathCache PathCache;
618 typedef GrAADistanceFieldPathRenderer::PathData PathData;
619 typedef GrAADistanceFieldPathRenderer::PathDataList PathDataList;
620 PathTestStruct() : fContextID(SK_InvalidGenID), fAtlas(NULL) {}
621 ~PathTestStruct() { this->reset(); }
622
623 void reset() {
624 PathDataList::Iter iter;
625 iter.init(fPathList, PathDataList::Iter::kHead_IterStart);
626 PathData* pathData;
627 while ((pathData = iter.get())) {
628 iter.next();
629 fPathList.remove(pathData);
630 SkDELETE(pathData);
631 }
632 SkDELETE(fAtlas);
633 }
634
635 static void HandleEviction(GrBatchAtlas::AtlasID id, void* pr) {
636 PathTestStruct* dfpr = (PathTestStruct*)pr;
637 // remove any paths that use this plot
638 PathDataList::Iter iter;
639 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart);
640 PathData* pathData;
641 while ((pathData = iter.get())) {
642 iter.next();
643 if (id == pathData->fID) {
644 dfpr->fPathCache.remove(pathData->fKey);
645 dfpr->fPathList.remove(pathData);
646 SkDELETE(pathData);
647 }
648 }
649 }
650
651 uint32_t fContextID;
652 GrBatchAtlas* fAtlas;
653 PathCache fPathCache;
654 PathDataList fPathList;
655 };
656
657 BATCH_TEST_DEFINE(AADistanceFieldPathRenderer) {
658 static PathTestStruct gTestStruct;
659
660 if (context->uniqueID() != gTestStruct.fContextID) {
661 gTestStruct.fContextID = context->uniqueID();
662 gTestStruct.reset();
663 gTestStruct.fAtlas = create_atlas(context, &PathTestStruct::HandleEvicti on,
664 (void*)&gTestStruct);
665 }
666
667 SkMatrix viewMatrix = GrTest::TestMatrix(random);
668 GrColor color = GrRandomColor(random);
669
670 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random));
671 geometry.fPath = GrTest::TestPath(random);
672 geometry.fAntiAlias = random->nextBool();
673
674 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix,
675 gTestStruct.fAtlas,
676 &gTestStruct.fPathCache,
677 &gTestStruct.fPathList);
678 }
679
680 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrAADistanceFieldPathRenderer.h ('k') | src/gpu/GrOvalRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698