From f7ea4f5d5d2283096a45a9131b41d9f44bdd8889 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Wed, 6 Feb 2019 14:06:46 -0500 Subject: [PATCH] Remove the distinction between key and device descriptors Change-Id: I12ac0f77124caae0be7b3a178683e5a3213f9beb Reviewed-on: https://skia-review.googlesource.com/c/189869 Commit-Queue: Herb Derby Reviewed-by: Mike Klein Reviewed-by: Khushal Sagar --- src/core/SkRemoteGlyphCache.cpp | 53 +++++++++++-------------------- src/core/SkRemoteGlyphCacheImpl.h | 18 +++-------- 2 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp index 15a402e9fc..6ece2c4355 100644 --- a/src/core/SkRemoteGlyphCache.cpp +++ b/src/core/SkRemoteGlyphCache.cpp @@ -60,9 +60,9 @@ static const SkDescriptor* create_descriptor( const SkPaint& paint, const SkFont& font, const SkMatrix& m, const SkSurfaceProps& props, SkScalerContextFlags flags, SkAutoDescriptor* ad, SkScalerContextEffects* effects) { - SkScalerContextRec deviceRec; - SkScalerContext::MakeRecAndEffects(font, paint, props, flags, m, &deviceRec, effects); - return SkScalerContext::AutoDescriptorGivenRecAndEffects(deviceRec, *effects, ad); + SkScalerContextRec rec; + SkScalerContext::MakeRecAndEffects(font, paint, props, flags, m, &rec, effects); + return SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, *effects, ad); } // -- Serializer ---------------------------------------------------------------------------------- @@ -306,15 +306,15 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache( const SkMatrix& matrix, SkScalerContextFlags flags, SkScalerContextEffects* effects) { - SkAutoDescriptor keyAutoDesc; - auto keyDesc = create_descriptor(paint, font, matrix, props, flags, &keyAutoDesc, effects); + SkAutoDescriptor descStorage; + auto desc = create_descriptor(paint, font, matrix, props, flags, &descStorage, effects); // In cases where tracing is turned off, make sure not to get an unused function warning. // Lambdaize the function. TRACE_EVENT1("skia", "RecForDesc", "rec", TRACE_STR_COPY( - [keyDesc](){ - auto ptr = keyDesc->findEntry(kRec_SkDescriptorTag, nullptr); + [desc](){ + auto ptr = desc->findEntry(kRec_SkDescriptorTag, nullptr); SkScalerContextRec rec; std::memcpy(&rec, ptr, sizeof(rec)); return rec.dump(); @@ -323,8 +323,8 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache( ); // Already locked. - if (fLockedDescs.find(keyDesc) != fLockedDescs.end()) { - auto it = fRemoteGlyphStateMap.find(keyDesc); + if (fLockedDescs.find(desc) != fLockedDescs.end()) { + auto it = fRemoteGlyphStateMap.find(desc); SkASSERT(it != fRemoteGlyphStateMap.end()); SkGlyphCacheState* cache = it->second.get(); cache->setFontAndEffects(font, SkScalerContextEffects{paint}); @@ -332,16 +332,9 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache( } // Try to lock. - auto it = fRemoteGlyphStateMap.find(keyDesc); + auto it = fRemoteGlyphStateMap.find(desc); if (it != fRemoteGlyphStateMap.end()) { SkGlyphCacheState* cache = it->second.get(); -#ifdef SK_DEBUG - SkScalerContextEffects deviceEffects; - SkAutoDescriptor deviceAutoDesc; - auto deviceDesc = create_descriptor( - paint, font, matrix, props, flags, &deviceAutoDesc, &deviceEffects); - SkASSERT(cache->getDeviceDescriptor() == *deviceDesc); -#endif bool locked = fDiscardableHandleManager->lockHandle(it->second->discardableHandleId()); if (locked) { fLockedDescs.insert(it->first); @@ -362,22 +355,17 @@ SkStrikeServer::SkGlyphCacheState* SkStrikeServer::getOrCreateCache( tf->isFixedPitch()); } - SkScalerContextEffects deviceEffects; - SkAutoDescriptor deviceAutoDesc; - auto deviceDesc = create_descriptor( - paint, font, matrix, props, flags, &deviceAutoDesc, &deviceEffects); - - auto context = tf->createScalerContext(deviceEffects, deviceDesc); + auto context = tf->createScalerContext(*effects, desc); // Create a new cache state and insert it into the map. auto newHandle = fDiscardableHandleManager->createHandle(); auto cacheState = skstd::make_unique( - *keyDesc, *deviceDesc, std::move(context), newHandle); + *desc, std::move(context), newHandle); auto* cacheStatePtr = cacheState.get(); - fLockedDescs.insert(&cacheStatePtr->getKeyDescriptor()); - fRemoteGlyphStateMap[&cacheStatePtr->getKeyDescriptor()] = std::move(cacheState); + fLockedDescs.insert(&cacheStatePtr->getDescriptor()); + fRemoteGlyphStateMap[&cacheStatePtr->getDescriptor()] = std::move(cacheState); checkForDeletedEntries(); @@ -399,19 +387,16 @@ void SkStrikeServer::checkForDeletedEntries() { // -- SkGlyphCacheState ---------------------------------------------------------------------------- SkStrikeServer::SkGlyphCacheState::SkGlyphCacheState( - const SkDescriptor& keyDescriptor, - const SkDescriptor& deviceDescriptor, + const SkDescriptor& descriptor, std::unique_ptr context, uint32_t discardableHandleId) - : fKeyDescriptor{keyDescriptor} - , fDeviceDescriptor{deviceDescriptor} + : fDescriptor{descriptor} , fDiscardableHandleId(discardableHandleId) , fIsSubpixel{context->isSubpixel()} , fAxisAlignmentForHText{context->computeAxisAlignmentForHText()} // N.B. context must come last because it is used above. , fContext{std::move(context)} { - SkASSERT(fKeyDescriptor.getDesc() != nullptr); - SkASSERT(fDeviceDescriptor.getDesc() != nullptr); + SkASSERT(fDescriptor.getDesc() != nullptr); SkASSERT(fContext != nullptr); } @@ -457,7 +442,7 @@ void SkStrikeServer::SkGlyphCacheState::writePendingGlyphs(Serializer* serialize // Write the desc. serializer->emplace(fContext->getTypeface()->uniqueID(), fDiscardableHandleId); - serializer->writeDescriptor(*fKeyDescriptor.getDesc()); + serializer->writeDescriptor(*fDescriptor.getDesc()); // Write FontMetrics. // TODO(khushalsagar): Do we need to re-send each time? @@ -509,7 +494,7 @@ const SkGlyph& SkStrikeServer::SkGlyphCacheState::findGlyph(SkPackedGlyphID glyp void SkStrikeServer::SkGlyphCacheState::ensureScalerContext() { if (fContext == nullptr) { auto tf = fFont->getTypefaceOrDefault(); - fContext = tf->createScalerContext(fEffects, fDeviceDescriptor.getDesc()); + fContext = tf->createScalerContext(fEffects, fDescriptor.getDesc()); } } diff --git a/src/core/SkRemoteGlyphCacheImpl.h b/src/core/SkRemoteGlyphCacheImpl.h index af9d201e1e..6b0fe70b3f 100644 --- a/src/core/SkRemoteGlyphCacheImpl.h +++ b/src/core/SkRemoteGlyphCacheImpl.h @@ -17,8 +17,7 @@ class SkStrikeServer::SkGlyphCacheState : public SkStrikeInterface { public: // N.B. SkGlyphCacheState is not valid until ensureScalerContext is called. - SkGlyphCacheState(const SkDescriptor& keyDescriptor, - const SkDescriptor& deviceDescriptor, + SkGlyphCacheState(const SkDescriptor& descriptor, std::unique_ptr context, SkDiscardableHandleId discardableHandleId); ~SkGlyphCacheState() override; @@ -26,15 +25,12 @@ public: void addGlyph(SkPackedGlyphID, bool pathOnly); void writePendingGlyphs(Serializer* serializer); SkDiscardableHandleId discardableHandleId() const { return fDiscardableHandleId; } - const SkDescriptor& getDeviceDescriptor() { - return *fDeviceDescriptor.getDesc(); - } bool isSubpixel() const { return fIsSubpixel; } SkAxisAlignment axisAlignmentForHText() const { return fAxisAlignmentForHText; } - const SkDescriptor& getKeyDescriptor() { - return *fKeyDescriptor.getDesc(); + const SkDescriptor& getDescriptor() { + return *fDescriptor.getDesc(); } const SkGlyph& findGlyph(SkPackedGlyphID); @@ -67,11 +63,7 @@ private: std::vector fPendingGlyphImages; std::vector fPendingGlyphPaths; - // The device descriptor is used to create the scaler context. The glyphs to have the - // correct device rendering. The key descriptor is used for communication. The GPU side will - // create descriptors with out the device filtering, thus matching the key descriptor. - const SkAutoDescriptor fKeyDescriptor; - const SkAutoDescriptor fDeviceDescriptor; + const SkAutoDescriptor fDescriptor; const SkDiscardableHandleId fDiscardableHandleId; @@ -79,7 +71,7 @@ private: const bool fIsSubpixel; const SkAxisAlignment fAxisAlignmentForHText; - // The context built using fDeviceDescriptor + // The context built using fDescriptor std::unique_ptr fContext; // These fields are set everytime getOrCreateCache. This allows the code to maintain the