gfx/skia/trunk/src/core/SkPathHeap.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.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "SkPathHeap.h"
     9 #include "SkPath.h"
    10 #include "SkStream.h"
    11 #include "SkReadBuffer.h"
    12 #include "SkTSearch.h"
    13 #include "SkWriteBuffer.h"
    14 #include <new>
    16 #define kPathCount  64
    18 SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) {
    19 }
    21 SkPathHeap::SkPathHeap(SkReadBuffer& buffer)
    22             : fHeap(kPathCount * sizeof(SkPath)) {
    23     const int count = buffer.readInt();
    25     fPaths.setCount(count);
    26     SkPath** ptr = fPaths.begin();
    27     SkPath* p = (SkPath*)fHeap.allocThrow(count * sizeof(SkPath));
    29     for (int i = 0; i < count; i++) {
    30         new (p) SkPath;
    31         buffer.readPath(p);
    32         *ptr++ = p; // record the pointer
    33         p++;        // move to the next storage location
    34     }
    35 }
    37 SkPathHeap::~SkPathHeap() {
    38     SkPath** iter = fPaths.begin();
    39     SkPath** stop = fPaths.end();
    40     while (iter < stop) {
    41         (*iter)->~SkPath();
    42         iter++;
    43     }
    44 }
    46 int SkPathHeap::append(const SkPath& path) {
    47     SkPath* p = (SkPath*)fHeap.allocThrow(sizeof(SkPath));
    48     new (p) SkPath(path);
    49     *fPaths.append() = p;
    50     return fPaths.count();
    51 }
    53 SkPathHeap::LookupEntry::LookupEntry(const SkPath& path)
    54     : fGenerationID(path.getGenerationID()), fStorageSlot(0) {
    55 }
    57 SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) {
    58     LookupEntry searchKey(path);
    59     int index = SkTSearch<const LookupEntry, LookupEntry::Less>(
    60                                     fLookupTable.begin(),
    61                                     fLookupTable.count(),
    62                                     searchKey,
    63                                     sizeof(LookupEntry));
    64     if (index < 0) {
    65         index = ~index;
    66         *fLookupTable.insert(index) = LookupEntry(path);
    67     }
    69     return &fLookupTable[index];;
    70 }
    72 int SkPathHeap::insert(const SkPath& path) {
    73     SkPathHeap::LookupEntry* entry = this->addIfNotPresent(path);
    75     if (entry->storageSlot() > 0) {
    76         return entry->storageSlot();
    77     }
    79     int newSlot = this->append(path);
    80     SkASSERT(newSlot > 0);
    81     entry->setStorageSlot(newSlot);
    82     return newSlot;
    83 }
    85 void SkPathHeap::flatten(SkWriteBuffer& buffer) const {
    86     int count = fPaths.count();
    88     buffer.writeInt(count);
    89     SkPath* const* iter = fPaths.begin();
    90     SkPath* const* stop = fPaths.end();
    91     while (iter < stop) {
    92         buffer.writePath(**iter);
    93         iter++;
    94     }
    95 }

mercurial