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.

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

mercurial