change readTypeface to return sk_sp
authorreed <reed@google.com>
Mon, 29 Aug 2016 13:57:28 +0000 (06:57 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 29 Aug 2016 13:57:28 +0000 (06:57 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2290653002

TBR=mtklein

Review-Url: https://codereview.chromium.org/2290653002

src/core/SkPaint.cpp
src/core/SkReadBuffer.cpp
src/core/SkReadBuffer.h
src/core/SkValidatingReadBuffer.cpp
src/core/SkValidatingReadBuffer.h

index 44b2928..58d6a0f 100644 (file)
@@ -1958,7 +1958,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
     this->setTextEncoding(static_cast<TextEncoding>((tmp >> 0) & 0xFF));
 
     if (flatFlags & kHasTypeface_FlatFlag) {
-        this->setTypeface(sk_ref_sp(buffer.readTypeface()));
+        this->setTypeface(buffer.readTypeface());
     } else {
         this->setTypeface(nullptr);
     }
index 5356d4a..43eaf20 100644 (file)
@@ -297,14 +297,13 @@ sk_sp<SkImage> SkReadBuffer::readImage() {
     return image ? image : MakeEmptyImage(width, height);
 }
 
-SkTypeface* SkReadBuffer::readTypeface() {
-
+sk_sp<SkTypeface> SkReadBuffer::readTypeface() {
     uint32_t index = fReader.readU32();
     if (0 == index || index > (unsigned)fTFCount) {
         return nullptr;
     } else {
         SkASSERT(fTFArray);
-        return fTFArray[index - 1];
+        return sk_ref_sp(fTFArray[index - 1]);
     }
 }
 
index a8bed7b..7c4ecc6 100644 (file)
@@ -166,14 +166,9 @@ public:
     // helpers to get info about arrays and binary data
     virtual uint32_t getArrayCount();
 
-    /**
-     *  Returns false if the image could not be completely read. In that case, it will be set
-     *  to have width/height, but no pixels.
-     */
     sk_sp<SkImage> readBitmapAsImage();
     sk_sp<SkImage> readImage();
-
-    virtual SkTypeface* readTypeface();
+    virtual sk_sp<SkTypeface> readTypeface();
 
     void setTypefaceArray(SkTypeface* array[], int count) {
         fTFArray = array;
index 2dd7070..326d0cf 100644 (file)
@@ -210,12 +210,6 @@ uint32_t SkValidatingReadBuffer::getArrayCount() {
     return fError ? 0 : *(uint32_t*)fReader.peek();
 }
 
-SkTypeface* SkValidatingReadBuffer::readTypeface() {
-    SkASSERT(false);
-    // TODO: Implement this (securely) when needed
-    return nullptr;
-}
-
 bool SkValidatingReadBuffer::validateAvailable(size_t size) {
     return this->validate((size <= SK_MaxU32) && fReader.isAvailable(static_cast<uint32_t>(size)));
 }
index d8575bd..bad5f2f 100644 (file)
@@ -62,9 +62,6 @@ public:
     // helpers to get info about arrays and binary data
     uint32_t getArrayCount() override;
 
-    // TODO: Implement this (securely) when needed
-    SkTypeface* readTypeface() override;
-
     bool validate(bool isValid) override;
     bool isValid() const override;