1c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org/* 2c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org * Copyright 2013 Google Inc. 3c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org * 4c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 5c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org * found in the LICENSE file. 6c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org */ 7c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org#include "gm.h" 8c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org#include "SkBitmapDevice.h" 9c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org#include "SkTypeface.h" 10c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 11c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgnamespace skiagm { 12c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 13c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgclass DevicePropertiesGM : public GM { 14c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgpublic: 15c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org DevicePropertiesGM() { 16c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org this->setBGColor(0xFFFFFFFF); 17c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 18c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 19c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org virtual ~DevicePropertiesGM() { 20c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 21c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 22c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgprotected: 23c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org virtual SkString onShortName() { 24c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org return SkString("deviceproperties"); 25c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 26c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 27c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org virtual SkISize onISize() { 28f539318f0d3dba743ec1886d5d9df0fb1be628a1tfarina return SkISize::Make(1450, 750); 29c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 30c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 31c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org static void rotate_about(SkCanvas* canvas, 32c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkScalar degrees, 33c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkScalar px, SkScalar py) { 34c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas->translate(px, py); 35c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas->rotate(degrees); 36c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas->translate(-px, -py); 37c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 38c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 39c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org virtual void onDraw(SkCanvas* originalCanvas) { 40c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkISize size = this->getISize(); 41c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkBitmap bitmap; 42eb9a46cbbb475e862a084aa2224ec18d4ac5e95breed@google.com bitmap.allocN32Pixels(size.width(), size.height()); 43c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkDeviceProperties properties = SkDeviceProperties::Make( 44c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkDeviceProperties::Geometry::Make(SkDeviceProperties::Geometry::kVertical_Orientation, 45c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkDeviceProperties::Geometry::kBGR_Layout), 46c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SK_Scalar1); 471f2f338e23789f3eef168dcbd8171a28820ba6c1robertphillips@google.com SkBitmapDevice device(bitmap, properties); 48c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkCanvas canvas(&device); 49c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas.drawColor(SK_ColorWHITE); 50c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 51c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkPaint paint; 52c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 53c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org paint.setAntiAlias(true); 54c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org paint.setLCDRenderText(true); 55c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org //With freetype the default (normal hinting) can be really ugly. 56c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org //Most distros now set slight (vertical hinting only) in any event. 57c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org paint.setHinting(SkPaint::kSlight_Hinting); 58c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkSafeUnref(paint.setTypeface(SkTypeface::CreateFromName("Times Roman", SkTypeface::kNormal))); 59c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 60c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org const char* text = "Hamburgefons ooo mmm"; 61c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org const size_t textLen = strlen(text); 62c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 63c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org for (int j = 0; j < 2; ++j) { 64c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org for (int i = 0; i < 6; ++i) { 65c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkScalar x = SkIntToScalar(10); 66c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkScalar y = SkIntToScalar(20); 67c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 68c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkAutoCanvasRestore acr(&canvas, true); 69c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas.translate(SkIntToScalar(50 + i * 230), 70c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkIntToScalar(20)); 71c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org rotate_about(&canvas, SkIntToScalar(i * 5), x, y * 10); 72c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 73c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org { 74c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkPaint p; 75c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org p.setAntiAlias(true); 76c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org SkRect r; 77c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org r.set(x - SkIntToScalar(3), SkIntToScalar(15), 78c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org x - SkIntToScalar(1), SkIntToScalar(280)); 79c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas.drawRect(r, p); 80c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 81c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 82c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org int index = 0; 83c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org for (int ps = 6; ps <= 22; ps++) { 84c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org paint.setTextSize(SkIntToScalar(ps)); 85c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas.drawText(text, textLen, x, y, paint); 86c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org y += paint.getFontMetrics(NULL); 87c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org index += 1; 88c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 89c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 90c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org canvas.translate(0, SkIntToScalar(360)); 91c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org paint.setSubpixelText(true); 92c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 93c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org originalCanvas->drawBitmap(bitmap, 0, 0); 94c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 95c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 96c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org#ifdef SK_BUILD_FOR_ANDROID 97c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org virtual uint32_t onGetFlags() const SK_OVERRIDE { 98c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org // On android, we fail due to bad gpu drivers (it seems) by adding too 99c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org // much to our text atlas (texture). 100c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org return kSkipGPU_Flag; 101c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org } 102c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org#endif 103c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 104c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgprivate: 105c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org typedef GM INHERITED; 106c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org}; 107c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 108c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org////////////////////////////////////////////////////////////////////////////// 109c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 110c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgstatic GM* MyFactory(void*) { return new DevicePropertiesGM; } 111c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.orgstatic GMRegistry reg(MyFactory); 112c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org 113c5fd46171841711973b9433c726ff8608335940ccommit-bot@chromium.org} 114