OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "PictureRenderer.h" | 8 #include "PictureRenderer.h" |
9 #include "picture_utils.h" | 9 #include "picture_utils.h" |
10 #include "SamplePipeControllers.h" | 10 #include "SamplePipeControllers.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 void TiledPictureRenderer::init(SkPicture* pict, const SkString* outputDir, | 488 void TiledPictureRenderer::init(SkPicture* pict, const SkString* outputDir, |
489 const SkString* inputFilename, bool useChecksumB
asedFilenames) { | 489 const SkString* inputFilename, bool useChecksumB
asedFilenames) { |
490 SkASSERT(pict != NULL); | 490 SkASSERT(pict != NULL); |
491 SkASSERT(0 == fTileRects.count()); | 491 SkASSERT(0 == fTileRects.count()); |
492 if (NULL == pict || fTileRects.count() != 0) { | 492 if (NULL == pict || fTileRects.count() != 0) { |
493 return; | 493 return; |
494 } | 494 } |
495 | 495 |
496 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not | 496 // Do not call INHERITED::init(), which would create a (potentially large) c
anvas which is not |
497 // used by bench_pictures. | 497 // used by bench_pictures. |
498 fPicture = pict; | 498 fPicture = SkRef(pict); |
499 this->CopyString(&fOutputDir, outputDir); | 499 this->CopyString(&fOutputDir, outputDir); |
500 this->CopyString(&fInputFilename, inputFilename); | 500 this->CopyString(&fInputFilename, inputFilename); |
501 fUseChecksumBasedFilenames = useChecksumBasedFilenames; | 501 fUseChecksumBasedFilenames = useChecksumBasedFilenames; |
502 fPicture->ref(); | |
503 this->buildBBoxHierarchy(); | 502 this->buildBBoxHierarchy(); |
504 | 503 |
505 if (fTileWidthPercentage > 0) { | 504 if (fTileWidthPercentage > 0) { |
506 fTileWidth = sk_float_ceil2int(float(fTileWidthPercentage * fPicture->wi
dth() / 100)); | 505 fTileWidth = sk_float_ceil2int(float(fTileWidthPercentage * fPicture->wi
dth() / 100)); |
507 } | 506 } |
508 if (fTileHeightPercentage > 0) { | 507 if (fTileHeightPercentage > 0) { |
509 fTileHeight = sk_float_ceil2int(float(fTileHeightPercentage * fPicture->
height() / 100)); | 508 fTileHeight = sk_float_ceil2int(float(fTileHeightPercentage * fPicture->
height() / 100)); |
510 } | 509 } |
511 | 510 |
512 if (fTileMinPowerOf2Width > 0) { | 511 if (fTileMinPowerOf2Width > 0) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 } else { | 686 } else { |
688 success = false; | 687 success = false; |
689 } | 688 } |
690 } | 689 } |
691 } | 690 } |
692 return success; | 691 return success; |
693 } | 692 } |
694 | 693 |
695 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { | 694 SkCanvas* TiledPictureRenderer::setupCanvas(int width, int height) { |
696 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); | 695 SkCanvas* canvas = this->INHERITED::setupCanvas(width, height); |
697 SkASSERT(fPicture != NULL); | 696 SkASSERT(NULL != fPicture); |
698 // Clip the tile to an area that is completely inside both the SkPicture and
the viewport. This | 697 // Clip the tile to an area that is completely inside both the SkPicture and
the viewport. This |
699 // is mostly important for tiles on the right and bottom edges as they may g
o over this area and | 698 // is mostly important for tiles on the right and bottom edges as they may g
o over this area and |
700 // the picture may have some commands that draw outside of this area and so
should not actually | 699 // the picture may have some commands that draw outside of this area and so
should not actually |
701 // be written. | 700 // be written. |
702 // Uses a clipRegion so that it will be unaffected by the scale factor, whic
h may have been set | 701 // Uses a clipRegion so that it will be unaffected by the scale factor, whic
h may have been set |
703 // by INHERITED::setupCanvas. | 702 // by INHERITED::setupCanvas. |
704 SkRegion clipRegion; | 703 SkRegion clipRegion; |
705 clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight()); | 704 clipRegion.setRect(0, 0, this->getViewWidth(), this->getViewHeight()); |
706 canvas->clipRegion(clipRegion); | 705 canvas->clipRegion(clipRegion); |
707 return canvas; | 706 return canvas; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 return name; | 902 return name; |
904 } | 903 } |
905 | 904 |
906 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 905 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
907 | 906 |
908 void PlaybackCreationRenderer::setup() { | 907 void PlaybackCreationRenderer::setup() { |
909 fReplayer.reset(this->createPicture()); | 908 fReplayer.reset(this->createPicture()); |
910 SkCanvas* recorder = fReplayer->beginRecording(this->getViewWidth(), this->g
etViewHeight(), | 909 SkCanvas* recorder = fReplayer->beginRecording(this->getViewWidth(), this->g
etViewHeight(), |
911 this->recordFlags()); | 910 this->recordFlags()); |
912 this->scaleToScaleFactor(recorder); | 911 this->scaleToScaleFactor(recorder); |
913 fPicture->draw(recorder); | 912 recorder->drawPicture(*fPicture); |
914 } | 913 } |
915 | 914 |
916 bool PlaybackCreationRenderer::render(SkBitmap** out) { | 915 bool PlaybackCreationRenderer::render(SkBitmap** out) { |
917 fReplayer->endRecording(); | 916 fReplayer->endRecording(); |
918 // Since this class does not actually render, return false. | 917 // Since this class does not actually render, return false. |
919 return false; | 918 return false; |
920 } | 919 } |
921 | 920 |
922 SkString PlaybackCreationRenderer::getConfigNameInternal() { | 921 SkString PlaybackCreationRenderer::getConfigNameInternal() { |
923 return SkString("playback_creation"); | 922 return SkString("playback_creation"); |
(...skipping 14 matching lines...) Expand all Loading... |
938 aspectRatio, sortDraws); | 937 aspectRatio, sortDraws); |
939 } | 938 } |
940 }; | 939 }; |
941 | 940 |
942 SkPicture* PictureRenderer::createPicture() { | 941 SkPicture* PictureRenderer::createPicture() { |
943 switch (fBBoxHierarchyType) { | 942 switch (fBBoxHierarchyType) { |
944 case kNone_BBoxHierarchyType: | 943 case kNone_BBoxHierarchyType: |
945 return SkNEW(SkPicture); | 944 return SkNEW(SkPicture); |
946 case kQuadTree_BBoxHierarchyType: | 945 case kQuadTree_BBoxHierarchyType: |
947 return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(fPicture->widt
h(), | 946 return SkNEW_ARGS(SkQuadTreePicture, (SkIRect::MakeWH(fPicture->widt
h(), |
948 fPicture->height()))); | 947 fPicture->heig
ht()))); |
949 case kRTree_BBoxHierarchyType: | 948 case kRTree_BBoxHierarchyType: |
950 return SkNEW(RTreePicture); | 949 return SkNEW(RTreePicture); |
951 case kTileGrid_BBoxHierarchyType: | 950 case kTileGrid_BBoxHierarchyType: |
952 return SkNEW_ARGS(SkTileGridPicture, (fPicture->width(), | 951 return SkNEW_ARGS(SkTileGridPicture, (fPicture->width(), |
953 fPicture->height(), fGridInfo)); | 952 fPicture->height(), fGridInfo)
); |
954 } | 953 } |
955 SkASSERT(0); // invalid bbhType | 954 SkASSERT(0); // invalid bbhType |
956 return NULL; | 955 return NULL; |
957 } | 956 } |
958 | 957 |
959 /////////////////////////////////////////////////////////////////////////////// | 958 /////////////////////////////////////////////////////////////////////////////// |
960 | 959 |
961 class GatherRenderer : public PictureRenderer { | 960 class GatherRenderer : public PictureRenderer { |
962 public: | 961 public: |
963 virtual bool render(SkBitmap** out = NULL) | 962 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { |
964 SK_OVERRIDE { | |
965 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()), | 963 SkRect bounds = SkRect::MakeWH(SkIntToScalar(fPicture->width()), |
966 SkIntToScalar(fPicture->height())); | 964 SkIntToScalar(fPicture->height())); |
967 SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds); | 965 SkData* data = SkPictureUtils::GatherPixelRefs(fPicture, bounds); |
968 SkSafeUnref(data); | 966 SkSafeUnref(data); |
969 | 967 |
970 return (fOutputDir.isEmpty()); // we don't have anything to write | 968 return (fOutputDir.isEmpty()); // we don't have anything to write |
971 } | 969 } |
972 | 970 |
973 private: | 971 private: |
974 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 972 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
975 return SkString("gather_pixelrefs"); | 973 return SkString("gather_pixelrefs"); |
976 } | 974 } |
977 }; | 975 }; |
978 | 976 |
979 PictureRenderer* CreateGatherPixelRefsRenderer() { | 977 PictureRenderer* CreateGatherPixelRefsRenderer() { |
980 return SkNEW(GatherRenderer); | 978 return SkNEW(GatherRenderer); |
981 } | 979 } |
982 | 980 |
983 /////////////////////////////////////////////////////////////////////////////// | 981 /////////////////////////////////////////////////////////////////////////////// |
984 | 982 |
985 class PictureCloneRenderer : public PictureRenderer { | 983 class PictureCloneRenderer : public PictureRenderer { |
986 public: | 984 public: |
987 virtual bool render(SkBitmap** out = NULL) | 985 virtual bool render(SkBitmap** out = NULL) SK_OVERRIDE { |
988 SK_OVERRIDE { | |
989 for (int i = 0; i < 100; ++i) { | 986 for (int i = 0; i < 100; ++i) { |
990 SkPicture* clone = fPicture->clone(); | 987 SkPicture* clone = fPicture->clone(); |
991 SkSafeUnref(clone); | 988 SkSafeUnref(clone); |
992 } | 989 } |
993 | 990 |
994 return (fOutputDir.isEmpty()); // we don't have anything to write | 991 return (fOutputDir.isEmpty()); // we don't have anything to write |
995 } | 992 } |
996 | 993 |
997 private: | 994 private: |
998 virtual SkString getConfigNameInternal() SK_OVERRIDE { | 995 virtual SkString getConfigNameInternal() SK_OVERRIDE { |
999 return SkString("picture_clone"); | 996 return SkString("picture_clone"); |
1000 } | 997 } |
1001 }; | 998 }; |
1002 | 999 |
1003 PictureRenderer* CreatePictureCloneRenderer() { | 1000 PictureRenderer* CreatePictureCloneRenderer() { |
1004 return SkNEW(PictureCloneRenderer); | 1001 return SkNEW(PictureCloneRenderer); |
1005 } | 1002 } |
1006 | 1003 |
1007 } // namespace sk_tools | 1004 } // namespace sk_tools |
OLD | NEW |