Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  GlyphVector.cpp

  Sprache: C
 

/*
 * Copyright 2022 Google LLC
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "src/text/gpu/GlyphVector.h"

#include "include/private/base/SkAssert.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkStrike.h"
#include "src/core/SkStrikeCache.h"
#include "src/core/SkWriteBuffer.h"
#include "src/text/StrikeForGPU.h"
#include "src/text/gpu/SubRunAllocator.h"

#include <climits>
#include <optional>
#include <utility>

class SkStrikeClient;

namespace sktext::gpu {

GlyphVector::GlyphVector(SkStrikePromise&& strikePromise, SkSpan<GlyphBytes> glyphs)
        : fStrikePromise{std::move(strikePromise)}, fGlyphs{glyphs} {
    SkASSERT(!fGlyphs.empty());
}

GlyphVector::GlyphVector(GlyphVector&& that)
        : fStrikePromise{std::move(that.fStrikePromise)}, fGlyphs{that.fGlyphs} {
    // We move this when creating AtlasSubRuns, before initializing backend data.
    // To support backend data we'd have to record a move proc in initBackendData to
    // do type-specific move.
    SkASSERT(!that.hasBackendData());
}

GlyphVector::~GlyphVector() {
    if (!this->hasBackendData()) {
        return;
    }
    fBackendDataReleaser(fBackendDataBytes.data());
}

GlyphVector GlyphVector::Make(SkStrikePromise&& promise,
                              SkSpan<const SkPackedGlyphID> packedIDs,
                              SubRunAllocator* alloc) {
    SkASSERT(!packedIDs.empty());
    int count = SkToInt(packedIDs.size());
    GlyphBytes* glyphs =
        alloc->makePODArray<GlyphBytes, GlyphVector_Concepts::kMaxGlyphTypeSize>(count);
    for (int i = 0; i < count; i++) {
        *reinterpret_cast<SkPackedGlyphID*>(glyphs[i].data()) = packedIDs[i];
    }
    return GlyphVector{std::move(promise), SkSpan{glyphs, count}};
}

std::optional<GlyphVector> GlyphVector::MakeFromBuffer(SkReadBuffer& buffer,
                                                       const SkStrikeClient* client,
                                                       SubRunAllocator* alloc) {
    std::optional<SkStrikePromise> promise =
            SkStrikePromise::MakeFromBuffer(buffer, client, SkStrikeCache::GlobalStrikeCache());
    if (!buffer.validate(promise.has_value())) {
        return std::nullopt;
    }

    int32_t glyphCount = buffer.read32();
    // Since the glyph count can never be zero. There was a buffer reading problem.
    if (!buffer.validate(glyphCount > 0)) {
        return std::nullopt;
    }

    // Make sure we won't overflow the glyphCount math or allocation below.
    if (!buffer.validate(BagOfBytes::WillCountFit<GlyphBytes>(glyphCount))) {
        return std::nullopt;
    }

    // Check for enough bytes to populate the packedGlyphID array. If not enough something has
    // gone wrong.
    static_assert(sizeof(GlyphBytes) >= sizeof(uint32_t));
    if (!buffer.validate(glyphCount * sizeof(uint32_t) <= buffer.available())) {
        return std::nullopt;
    }

    GlyphBytes* glyphs = alloc->makePODArray<GlyphBytes>(glyphCount);
    for (int i = 0; i < glyphCount; i++) {
        *reinterpret_cast<SkPackedGlyphID*>(glyphs[i].data()) = SkPackedGlyphID(buffer.readUInt());
    }
    return GlyphVector{std::move(promise.value()), SkSpan{glyphs, glyphCount}};
}

void GlyphVector::flatten(SkWriteBuffer& buffer) const {
    // There should never be a glyph vector with zero glyphs.
    SkASSERT(!fGlyphs.empty());
    fStrikePromise.flatten(buffer);

    // Write out the span of packedGlyphIDs.
    buffer.write32(SkTo<int32_t>(fGlyphs.size()));
    for (const auto& g : fGlyphs) {
        SkPackedGlyphID id;
        if (this->hasBackendData()) {
            id = fGetGlyphID(g.data());
        } else {
            id = *reinterpret_cast<const SkPackedGlyphID*>(g.data());
        }
        buffer.writeUInt(id.value());
    }
}

}  // namespace sktext::gpu

Messung V0.5 in Prozent
C=91 H=90 G=90

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002