diff options
author | robertphillips <robertphillips@google.com> | 2014-08-29 08:03:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-29 08:03:56 -0700 |
commit | a8d7f0b13cd4c6d773fcf055fe17db75d260fa05 (patch) | |
tree | 37e85b212ccd5761b9a736282e75ebf838840798 /gm | |
parent | 77d724c07878b21602e96e095f6a446c429a079a (diff) | |
download | skia-a8d7f0b13cd4c6d773fcf055fe17db75d260fa05.tar.gz |
Try out scalar picture sizes
This paves the way for removing the 'fTile' parameter from SkPictureShader (although that should be a different CL). If we like this we could also move to providing an entire cull SkRect.
R=reed@google.com, mtklein@google.com, fmalita@google.com, fmalita@chromium.org
Author: robertphillips@google.com
Review URL: https://codereview.chromium.org/513983002
Diffstat (limited to 'gm')
-rw-r--r-- | gm/distantclip.cpp | 24 | ||||
-rw-r--r-- | gm/gmmain.cpp | 4 | ||||
-rw-r--r-- | gm/multipicturedraw.cpp | 16 | ||||
-rw-r--r-- | gm/optimizations.cpp | 20 | ||||
-rw-r--r-- | gm/pictureshader.cpp | 6 | ||||
-rw-r--r-- | gm/pictureshadertile.cpp | 4 |
6 files changed, 35 insertions, 39 deletions
diff --git a/gm/distantclip.cpp b/gm/distantclip.cpp index 9c44140d8..0f8955948 100644 --- a/gm/distantclip.cpp +++ b/gm/distantclip.cpp @@ -27,37 +27,33 @@ protected: SkISize onISize() { return SkISize::Make(100, 100); } virtual void onDraw(SkCanvas* canvas) { - int offset = 35000; - int extents = 1000; + static const SkScalar kOffset = 35000.0f; + static const SkScalar kExtents = 1000.0f; SkPictureRecorder recorder; // We record a picture of huge vertical extents in which we clear the canvas to red, create // a 'extents' by 'extents' round rect clip at a vertical offset of 'offset', then draw // green into that. - SkCanvas* rec = recorder.beginRecording(100, offset + extents, NULL, 0); - rec->drawColor(0xffff0000); + SkCanvas* rec = recorder.beginRecording(kExtents, kOffset + kExtents, NULL, 0); + rec->drawColor(SK_ColorRED); rec->save(); - SkRect r = { - SkIntToScalar(-extents), - SkIntToScalar(offset - extents), - SkIntToScalar(extents), - SkIntToScalar(offset + extents) - }; + SkRect r = SkRect::MakeXYWH(-kExtents, kOffset - kExtents, 2 * kExtents, 2 * kExtents); SkPath p; p.addRoundRect(r, 5, 5); rec->clipPath(p, SkRegion::kIntersect_Op, true); - rec->drawColor(0xff00ff00); + rec->drawColor(SK_ColorGREEN); rec->restore(); SkAutoTUnref<SkPicture> pict(recorder.endRecording()); // Next we play that picture into another picture of the same size. - pict->draw(recorder.beginRecording(100, offset + extents, NULL, 0)); + pict->draw(recorder.beginRecording(pict->cullRect().width(), + pict->cullRect().height(), + NULL, 0)); SkAutoTUnref<SkPicture> pict2(recorder.endRecording()); // Finally we play the part of that second picture that should be green into the canvas. canvas->save(); - canvas->translate(SkIntToScalar(extents / 2), - SkIntToScalar(-(offset - extents / 2))); + canvas->translate(kExtents / 2, -(kOffset - kExtents / 2)); pict2->draw(canvas); canvas->restore(); diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index cf9e25b48..5d6481c34 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -1011,8 +1011,8 @@ public: static SkPicture* generate_new_picture(GM* gm, BbhType bbhType, uint32_t recordFlags, SkScalar scale = SK_Scalar1) { - int width = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().width()), scale)); - int height = SkScalarCeilToInt(SkScalarMul(SkIntToScalar(gm->getISize().height()), scale)); + SkScalar width = SkScalarMul(SkIntToScalar(gm->getISize().width()), scale); + SkScalar height = SkScalarMul(SkIntToScalar(gm->getISize().height()), scale); SkAutoTDelete<SkBBHFactory> factory; if (kTileGrid_BbhType == bbhType) { diff --git a/gm/multipicturedraw.cpp b/gm/multipicturedraw.cpp index 2da1ab6c5..11756a79a 100644 --- a/gm/multipicturedraw.cpp +++ b/gm/multipicturedraw.cpp @@ -52,7 +52,8 @@ static const SkPicture* make_picture(SkColor fillColor) { SkPictureRecorder recorder; - SkCanvas* canvas = recorder.beginRecording(kPicWidth, kPicHeight); + SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), + SkIntToScalar(kPicHeight)); SkScalar xPos, yPos = 0; @@ -111,7 +112,7 @@ static void no_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { canvas->drawPicture(pictures[0]); - SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHeight)); + SkRect rect = pictures[0]->cullRect(); rect.inset(kInset, kInset); canvas->clipRect(rect); @@ -123,7 +124,7 @@ static void rect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { static void rrect_clip(SkCanvas* canvas, const SkPicture* pictures[2]) { canvas->drawPicture(pictures[0]); - SkRect rect = SkRect::MakeWH(SkIntToScalar(kPicWidth), SkIntToScalar(kPicHeight)); + SkRect rect = pictures[0]->cullRect(); rect.inset(kInset, kInset); SkRRect rrect; @@ -175,7 +176,8 @@ static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, { SkPictureRecorder recorder; - SkCanvas* pictureCanvas = recorder.beginRecording(kPicWidth, kPicHeight); + SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidth), + SkIntToScalar(kPicHeight)); (*pfGen)(pictureCanvas, pictures); @@ -299,7 +301,7 @@ namespace skiagm { fPictures[1] = make_picture(SK_ColorGRAY); } - virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE{ + virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { SkMultiPictureDraw mpd; SkTArray<ComposeStep> composeSteps; @@ -320,9 +322,9 @@ namespace skiagm { } } - virtual SkISize onISize() SK_OVERRIDE{ return SkISize::Make(kPicWidth, kPicHeight); } + virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(kPicWidth, kPicHeight); } - virtual SkString onShortName() SK_OVERRIDE{ + virtual SkString onShortName() SK_OVERRIDE { static const char* gContentNames[] = { "noclip", "rectclip", "rrectclip", "pathclip", "invpathclip" }; diff --git a/gm/optimizations.cpp b/gm/optimizations.cpp index a33f45711..00be04cee 100644 --- a/gm/optimizations.cpp +++ b/gm/optimizations.cpp @@ -17,8 +17,8 @@ // heavy-weight operation since we are drawing the picture into a debug canvas // to extract the commands. static bool check_pattern(SkPicture& input, const SkTDArray<DrawType> &pattern) { - SkDebugCanvas debugCanvas(input.width(), input.height()); - debugCanvas.setBounds(input.width(), input.height()); + SkDebugCanvas debugCanvas(SkScalarCeilToInt(input.cullRect().width()), + SkScalarCeilToInt(input.cullRect().height())); input.draw(&debugCanvas); if (pattern.count() != debugCanvas.getSize()) { @@ -340,7 +340,7 @@ protected: }; SkTDArray<DrawType> prePattern, postPattern; - int xPos = 0, yPos = 0; + SkScalar xPos = 0, yPos = 0; for (size_t i = 0; i < SK_ARRAY_COUNT(gOpts); ++i) { SkAutoTUnref<SkPicture> pre((*gOpts[i])(&prePattern, &postPattern, fCheckerboard)); @@ -351,16 +351,18 @@ protected: } canvas->save(); - canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos)); + canvas->translate(xPos, yPos); pre->draw(canvas); - xPos += pre->width(); + xPos += pre->cullRect().width(); canvas->restore(); // re-render the 'pre' picture and thus 'apply' the optimization SkPictureRecorder recorder; SkCanvas* recordCanvas = - recorder.DEPRECATED_beginRecording(pre->width(), pre->height(), NULL, 0); + recorder.DEPRECATED_beginRecording(pre->cullRect().width(), + pre->cullRect().height(), + NULL, 0); pre->draw(recordCanvas); @@ -372,15 +374,15 @@ protected: } canvas->save(); - canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos)); + canvas->translate(xPos, yPos); post->draw(canvas); - xPos += post->width(); + xPos += post->cullRect().width(); canvas->restore(); if (xPos >= kWidth) { // start a new line xPos = 0; - yPos += post->height(); + yPos += post->cullRect().height(); } // TODO: we could also render the pre and post pictures to bitmaps diff --git a/gm/pictureshader.cpp b/gm/pictureshader.cpp index 0b0a99e02..152cdf37a 100644 --- a/gm/pictureshader.cpp +++ b/gm/pictureshader.cpp @@ -30,14 +30,12 @@ public: // Build the picture. SkPictureRecorder recorder; - SkCanvas* pictureCanvas = recorder.beginRecording(SkScalarRoundToInt(tileSize), - SkScalarRoundToInt(tileSize), - NULL, 0); + SkCanvas* pictureCanvas = recorder.beginRecording(tileSize, tileSize, NULL, 0); this->drawTile(pictureCanvas); fPicture.reset(recorder.endRecording()); // Build a reference bitmap. - fBitmap.allocN32Pixels(SkScalarRoundToInt(tileSize), SkScalarRoundToInt(tileSize)); + fBitmap.allocN32Pixels(SkScalarCeilToInt(tileSize), SkScalarCeilToInt(tileSize)); fBitmap.eraseColor(SK_ColorTRANSPARENT); SkCanvas bitmapCanvas(fBitmap); this->drawTile(&bitmapCanvas); diff --git a/gm/pictureshadertile.cpp b/gm/pictureshadertile.cpp index 9343da364..ecea55334 100644 --- a/gm/pictureshadertile.cpp +++ b/gm/pictureshadertile.cpp @@ -61,9 +61,7 @@ class PictureShaderTileGM : public skiagm::GM { public: PictureShaderTileGM() { SkPictureRecorder recorder; - SkCanvas* pictureCanvas = recorder.beginRecording(SkScalarCeilToInt(kPictureSize), - SkScalarCeilToInt(kPictureSize), - NULL, 0); + SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize, NULL, 0); drawScene(pictureCanvas, kPictureSize); SkAutoTUnref<SkPicture> picture(recorder.endRecording()); |