gfx/tests/gtest/gfxTextRunPerfTest.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "gtest/gtest.h"
michael@0 7
michael@0 8 #include "mozilla/ArrayUtils.h"
michael@0 9
michael@0 10 #include "nsCOMPtr.h"
michael@0 11 #include "nsTArray.h"
michael@0 12 #include "nsString.h"
michael@0 13 #include "nsDependentString.h"
michael@0 14
michael@0 15 #include "prinrval.h"
michael@0 16
michael@0 17 #include "gfxContext.h"
michael@0 18 #include "gfxFont.h"
michael@0 19 #include "gfxPlatform.h"
michael@0 20
michael@0 21 #include "gfxFontTest.h"
michael@0 22
michael@0 23 using namespace mozilla;
michael@0 24
michael@0 25 struct TestEntry {
michael@0 26 const char* mFamilies;
michael@0 27 const char* mString;
michael@0 28 };
michael@0 29
michael@0 30 TestEntry testList[] = {
michael@0 31 #include "per-word-runs.h"
michael@0 32 { nullptr, nullptr } // terminator
michael@0 33 };
michael@0 34
michael@0 35 static already_AddRefed<gfxContext>
michael@0 36 MakeContext ()
michael@0 37 {
michael@0 38 const int size = 200;
michael@0 39
michael@0 40 nsRefPtr<gfxASurface> surface;
michael@0 41
michael@0 42 surface = gfxPlatform::GetPlatform()->
michael@0 43 CreateOffscreenSurface(IntSize(size, size),
michael@0 44 gfxASurface::ContentFromFormat(gfxImageFormat::RGB24));
michael@0 45 nsRefPtr<gfxContext> ctx = new gfxContext(surface);
michael@0 46 return ctx.forget();
michael@0 47 }
michael@0 48
michael@0 49 const char* lastFamilies = nullptr;
michael@0 50
michael@0 51 static void
michael@0 52 RunTest (TestEntry *test, gfxContext *ctx) {
michael@0 53 nsRefPtr<gfxFontGroup> fontGroup;
michael@0 54 if (!lastFamilies || strcmp(lastFamilies, test->mFamilies)) {
michael@0 55 gfxFontStyle style_western_normal_16 (mozilla::gfx::FontStyle::NORMAL,
michael@0 56 400,
michael@0 57 0,
michael@0 58 16.0,
michael@0 59 NS_NewPermanentAtom(NS_LITERAL_STRING("en")),
michael@0 60 0.0,
michael@0 61 false, false,
michael@0 62 NS_LITERAL_STRING(""));
michael@0 63
michael@0 64 fontGroup = gfxPlatform::GetPlatform()->CreateFontGroup(NS_ConvertUTF8toUTF16(test->mFamilies), &style_western_normal_16, nullptr);
michael@0 65 }
michael@0 66
michael@0 67 nsAutoPtr<gfxTextRun> textRun;
michael@0 68 uint32_t i;
michael@0 69 bool isASCII = true;
michael@0 70 for (i = 0; test->mString[i]; ++i) {
michael@0 71 if (test->mString[i] & 0x80) {
michael@0 72 isASCII = false;
michael@0 73 }
michael@0 74 }
michael@0 75 gfxTextRunFactory::Parameters params = {
michael@0 76 ctx, nullptr, nullptr, nullptr, 0, 60
michael@0 77 };
michael@0 78 uint32_t flags = gfxTextRunFactory::TEXT_IS_PERSISTENT;
michael@0 79 uint32_t length;
michael@0 80 gfxFontTestStore::NewStore();
michael@0 81 if (isASCII) {
michael@0 82 flags |= gfxTextRunFactory::TEXT_IS_ASCII |
michael@0 83 gfxTextRunFactory::TEXT_IS_8BIT;
michael@0 84 length = strlen(test->mString);
michael@0 85 textRun = fontGroup->MakeTextRun(reinterpret_cast<const uint8_t*>(test->mString), length, &params, flags);
michael@0 86 } else {
michael@0 87 NS_ConvertUTF8toUTF16 str(nsDependentCString(test->mString));
michael@0 88 length = str.Length();
michael@0 89 textRun = fontGroup->MakeTextRun(str.get(), length, &params, flags);
michael@0 90 }
michael@0 91
michael@0 92 // Should we test drawing?
michael@0 93 // textRun->Draw(ctx, gfxPoint(0,0), 0, length, nullptr, nullptr, nullptr);
michael@0 94
michael@0 95 textRun->GetAdvanceWidth(0, length, nullptr);
michael@0 96 gfxFontTestStore::DeleteStore();
michael@0 97 }
michael@0 98
michael@0 99 uint32_t iterations = 1;
michael@0 100
michael@0 101 TEST(Gfx, TextRunPref) {
michael@0 102 nsRefPtr<gfxContext> context = MakeContext();
michael@0 103
michael@0 104 // Start timing
michael@0 105 PRIntervalTime start = PR_IntervalNow();
michael@0 106
michael@0 107 for (uint32_t i = 0; i < iterations; ++i) {
michael@0 108 for (uint test = 0;
michael@0 109 test < ArrayLength(testList) - 1;
michael@0 110 test++)
michael@0 111 {
michael@0 112 RunTest(&testList[test], context);
michael@0 113 }
michael@0 114 }
michael@0 115
michael@0 116 PRIntervalTime end = PR_IntervalNow();
michael@0 117
michael@0 118 printf("Elapsed time (ms): %d\n", PR_IntervalToMilliseconds(end - start));
michael@0 119
michael@0 120 }

mercurial