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

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: 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
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 "GrBufferAllocPool.h" 14 #include "GrBufferAllocPool.h"
14 #include "GrContext.h" 15 #include "GrContext.h"
15 #include "GrPipelineBuilder.h" 16 #include "GrPipelineBuilder.h"
16 #include "GrResourceProvider.h" 17 #include "GrResourceProvider.h"
17 #include "GrSurfacePriv.h" 18 #include "GrSurfacePriv.h"
18 #include "GrSWMaskHelper.h" 19 #include "GrSWMaskHelper.h"
19 #include "GrTexturePriv.h" 20 #include "GrTexturePriv.h"
20 #include "GrVertexBuffer.h" 21 #include "GrVertexBuffer.h"
21 #include "effects/GrDistanceFieldGeoProc.h" 22 #include "effects/GrDistanceFieldGeoProc.h"
22 23
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 bool fCoverageIgnored; 551 bool fCoverageIgnored;
551 }; 552 };
552 553
553 BatchTracker fBatch; 554 BatchTracker fBatch;
554 SkSTArray<1, Geometry, true> fGeoData; 555 SkSTArray<1, Geometry, true> fGeoData;
555 GrBatchAtlas* fAtlas; 556 GrBatchAtlas* fAtlas;
556 PathCache* fPathCache; 557 PathCache* fPathCache;
557 PathDataList* fPathList; 558 PathDataList* fPathList;
558 }; 559 };
559 560
561 static GrBatchAtlas* create_atlas(GrContext* context, GrBatchAtlas::EvictionFunc func, void* data) {
562 GrBatchAtlas* atlas;
563 // Create a new atlas
564 GrSurfaceDesc desc;
565 desc.fFlags = kNone_GrSurfaceFlags;
566 desc.fWidth = ATLAS_TEXTURE_WIDTH;
567 desc.fHeight = ATLAS_TEXTURE_HEIGHT;
568 desc.fConfig = kAlpha_8_GrPixelConfig;
569
570 // We don't want to flush the context so we claim we're in the middle of flu shing so as to
571 // guarantee we do not recieve a texture with pending IO
572 GrTexture* texture = context->textureProvider()->refScratchTexture(
573 desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
574 if (texture) {
575 atlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y));
576 } else {
577 return NULL;
578 }
579 atlas->registerEvictionCallback(func, data);
580 return atlas;
581 }
582
560 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target, 583 bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target,
561 GrPipelineBuilder* pipelineBuilde r, 584 GrPipelineBuilder* pipelineBuilde r,
562 GrColor color, 585 GrColor color,
563 const SkMatrix& viewMatrix, 586 const SkMatrix& viewMatrix,
564 const SkPath& path, 587 const SkPath& path,
565 const GrStrokeInfo& stroke, 588 const GrStrokeInfo& stroke,
566 bool antiAlias) { 589 bool antiAlias) {
567 // we've already bailed on inverse filled paths, so this is safe 590 // we've already bailed on inverse filled paths, so this is safe
568 if (path.isEmpty()) { 591 if (path.isEmpty()) {
569 return true; 592 return true;
570 } 593 }
571 594
572 SkASSERT(fContext); 595 SkASSERT(fContext);
573 596
574 if (!fAtlas) { 597 if (!fAtlas) {
575 // Create a new atlas 598 fAtlas = create_atlas(fContext, &GrAADistanceFieldPathRenderer::HandleEv iction,
576 GrSurfaceDesc desc; 599 (void*)this);
577 desc.fFlags = kNone_GrSurfaceFlags; 600 if (!fAtlas) {
578 desc.fWidth = ATLAS_TEXTURE_WIDTH;
579 desc.fHeight = ATLAS_TEXTURE_HEIGHT;
580 desc.fConfig = kAlpha_8_GrPixelConfig;
581
582 // We don't want to flush the context so we claim we're in the middle of flushing so as to
583 // guarantee we do not recieve a texture with pending IO
584 GrTexture* texture = fContext->textureProvider()->refScratchTexture(
585 desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
586 if (texture) {
587 fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y ));
588 } else {
589 return false; 601 return false;
590 } 602 }
591 fAtlas->registerEvictionCallback(&GrAADistanceFieldPathRenderer::HandleE viction,
592 (void*)this);
593 } 603 }
594 604
595 AADistanceFieldPathBatch::Geometry geometry(stroke.getStrokeRec()); 605 AADistanceFieldPathBatch::Geometry geometry(stroke.getStrokeRec());
596 geometry.fPath = path; 606 geometry.fPath = path;
597 geometry.fAntiAlias = antiAlias; 607 geometry.fAntiAlias = antiAlias;
598 608
599 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix, 609 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color , viewMatrix,
600 fAtlas, &fPathC ache, &fPathList)); 610 fAtlas, &fPathC ache, &fPathList));
601 target->drawBatch(pipelineBuilder, batch); 611 target->drawBatch(pipelineBuilder, batch);
602 612
603 return true; 613 return true;
604 } 614 }
605 615
616 //////////////////////////////////////////////////////////////////////////////// ///////////////////
617
618 #ifdef GR_TEST_UTILS
619
620 struct PathTestStruct {
621 typedef GrAADistanceFieldPathRenderer::PathCache PathCache;
622 typedef GrAADistanceFieldPathRenderer::PathData PathData;
623 typedef GrAADistanceFieldPathRenderer::PathDataList PathDataList;
robertphillips 2015/05/07 19:30:24 PathTestStruct() : fContextID(0), fAtlas(NULL) {}
joshualitt 2015/05/07 21:22:38 Acknowledged.
624 ~PathTestStruct() {
625 this->reset();
626 }
627
628 void reset() {
629 PathDataList::Iter iter;
630 iter.init(fPathList, PathDataList::Iter::kHead_IterStart);
631 PathData* pathData;
632 while ((pathData = iter.get())) {
633 iter.next();
634 fPathList.remove(pathData);
635 SkDELETE(pathData);
636 }
637 SkDELETE(fAtlas);
638 }
639
640 static void HandleEviction(GrBatchAtlas::AtlasID id, void* pr) {
641 PathTestStruct* dfpr = (PathTestStruct*)pr;
642 // remove any paths that use this plot
643 PathDataList::Iter iter;
644 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart);
645 PathData* pathData;
646 while ((pathData = iter.get())) {
647 iter.next();
648 if (id == pathData->fID) {
649 dfpr->fPathCache.remove(pathData->fKey);
650 dfpr->fPathList.remove(pathData);
651 SkDELETE(pathData);
652 }
653 }
654 }
655
656 uint32_t fContextID;
657 GrBatchAtlas* fAtlas;
robertphillips 2015/05/07 19:30:24 Just PathCache as the type ?
joshualitt 2015/05/07 21:22:38 Acknowledged.
658 GrAADistanceFieldPathRenderer::PathCache fPathCache;
659 PathDataList fPathList;
660 };
661
662 BATCH_TEST_DEFINE(AADistanceFieldPathRenderer) {
663 static bool gInit;
664 static PathTestStruct gTestStruct;
665
robertphillips 2015/05/07 19:30:24 Would initializing fContextID to zero allow us to
joshualitt 2015/05/07 21:22:38 Acknowledged.
666 if(!gInit || context->uniqueID() != gTestStruct.fContextID) {
667 gInit = true;
668 gTestStruct.fContextID = context->uniqueID();
669 gTestStruct.reset();
670 gTestStruct.fAtlas = create_atlas(context, &PathTestStruct::HandleEvicti on,
671 (void*)&gTestStruct);
672 }
673
674 SkMatrix viewMatrix = GrTest::TestMatrix(random);
675 GrColor color = GrRandomColor(random);
676
677 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random));
678 geometry.fPath = GrTest::TestPath(random);
679 geometry.fAntiAlias = random->nextBool();
680
681 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix,
682 gTestStruct.fAtlas,
683 &gTestStruct.fPathCache,
684 &gTestStruct.fPathList);
685 }
686
687 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698