17eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com/* 27eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com * Copyright 2012 Google Inc. 37eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com * 47eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com * Use of this source code is governed by a BSD-style license that can be 57eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com * found in the LICENSE file. 67eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com */ 77eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 87eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com#include "gm.h" 97eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com#include "SkCanvas.h" 10af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com#include "SkGradientShader.h" 117eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com#include "SkPath.h" 127eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 13af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.comstatic void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { 14eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com bm->allocN32Pixels(width, height); 15af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkCanvas canvas(*bm); 16af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; 17af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkScalar radius = 40; 18af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2, 19af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkShader::kMirror_TileMode); 20af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkPaint paint; 21af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com paint.setShader(shader)->unref(); 22af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com paint.setXfermodeMode(SkXfermode::kSrc_Mode); 23af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com canvas.drawPaint(paint); 247eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com bm->setImmutable(); 257eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com} 267eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 27af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.comstatic void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) { 287eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com SkBitmap bm; 29af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com make_bm(&bm, width, height, colors); 307eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 317eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com SkPaint paint; 327eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com SkRect r; 337eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com SkIRect ir; 347eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 357eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com paint.setStyle(SkPaint::kStroke_Style); 367eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 377eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com ir.set(0, 0, 128, 128); 387eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com r.set(ir); 397eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 407eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->save(); 417eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->clipRect(r); 427eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawBitmap(bm, 0, 0, NULL); 437eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->restore(); 447eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawRect(r, paint); 457eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 467eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com r.offset(SkIntToScalar(150), 0); 477eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com // exercises extract bitmap, but not shader 487eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawBitmapRect(bm, &ir, r, NULL); 497eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawRect(r, paint); 507eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 517eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com r.offset(SkIntToScalar(150), 0); 527eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com // exercises bitmapshader 537eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawBitmapRect(bm, NULL, r, NULL); 547eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->drawRect(r, paint); 557eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com} 567eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 577eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.comclass VeryLargeBitmapGM : public skiagm::GM { 587eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.compublic: 597eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com VeryLargeBitmapGM() {} 607eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 617eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.comprotected: 627eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com virtual SkString onShortName() SK_OVERRIDE { 637eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com return SkString("verylargebitmap"); 647eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com } 657eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 667eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com virtual SkISize onISize() SK_OVERRIDE { 67af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com return SkISize::Make(500, 600); 687eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com } 697eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 707eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 71edf00c7a59b6f18f4bd90932734b42ec941b4491bsalomon@google.com int veryBig = 65*1024; // 64K < size 72edf00c7a59b6f18f4bd90932734b42ec941b4491bsalomon@google.com int big = 33*1024; // 32K < size < 64K 73af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons. 74edf00c7a59b6f18f4bd90932734b42ec941b4491bsalomon@google.com int medium = 5*1024; 75c3dc12da2e3716105f580f5b4aa759a8d7214d94robertphillips@google.com int small = 150; 767eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 77af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com SkColor colors[2]; 78af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com 797eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); 80af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[0] = SK_ColorRED; 81af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[1] = SK_ColorGREEN; 82af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com show_bm(canvas, small, small, colors); 83af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com canvas->translate(0, SkIntToScalar(150)); 84af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com 85af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[0] = SK_ColorBLUE; 86af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[1] = SK_ColorMAGENTA; 87af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com show_bm(canvas, big, small, colors); 887eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->translate(0, SkIntToScalar(150)); 897eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 90af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[0] = SK_ColorMAGENTA; 91af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[1] = SK_ColorYELLOW; 92af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com show_bm(canvas, medium, medium, colors); 937eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com canvas->translate(0, SkIntToScalar(150)); 94ae933ce0ea5fd9d21cb6ef2cee7e729d32690aacrmistry@google.com 95af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[0] = SK_ColorGREEN; 96af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com colors[1] = SK_ColorYELLOW; 977eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com // as of this writing, the raster code will fail to draw the scaled version 987eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com // since it has a 64K limit on x,y coordinates... (but gpu should succeed) 99af562b437e43a99f5371585ba50643b1d88f09e0bsalomon@google.com show_bm(canvas, veryBig, small, colors); 1007eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com } 1017eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 102537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org virtual uint32_t onGetFlags() const { 103537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org#ifdef SK_BUILD_FOR_WIN32 104537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org // The Windows bot runs out of memory in replay modes on this test in 32bit builds: 105537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org // http://skbug.com/1756 106537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org return kSkipPicture_Flag | 107537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org kSkipPipe_Flag | 108537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org kSkipPipeCrossProcess_Flag | 109537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org kSkipTiled_Flag | 110537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org kSkipScaledReplay_Flag; 111537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org#else 112a90c6803865766d28e92091f56f718f5e41fe80fcommit-bot@chromium.org return kSkipTiled_Flag; 113537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org#endif 114537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org } 115537e26ae3ce715d34c75cb815c781a1e535b7d92commit-bot@chromium.org 1167eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.comprivate: 1177eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com typedef skiagm::GM INHERITED; 1187eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com}; 1197eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 1207eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com////////////////////////////////////////////////////////////////////////////// 1217eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.com 1227eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.comstatic skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } 1237eb3a2653bf18e7c3cadaa5663d4d0060c728b5areed@google.comstatic skiagm::GMRegistry reg(MyFactory); 124