From 20c1e3abfc681771f73eb19fde7284196e028940 Mon Sep 17 00:00:00 2001 From: mtklein Date: Thu, 10 Mar 2016 10:10:03 -0800 Subject: Use std::unique_ptr. TBR=reed@google.com Review URL: https://codereview.chromium.org/1780933003 --- gyp/core.gypi | 1 - include/core/SkRefCnt.h | 7 +- include/gpu/gl/SkGLContext.h | 2 +- include/private/SkOncePtr.h | 6 +- include/private/SkTemplates.h | 18 +- include/private/SkUniquePtr.h | 408 -------------------------- src/core/SkGlyphCache.h | 4 +- src/core/SkSharedMutex.h | 8 +- src/gpu/GrLayerAtlas.cpp | 6 +- src/gpu/text/GrStencilAndCoverTextContext.cpp | 2 +- src/pdf/SkPDFDevice.cpp | 4 +- src/pdf/SkPDFDevice.h | 2 +- src/ports/SkFontHost_FreeType.cpp | 6 +- tests/CPlusPlusEleven.cpp | 69 ----- tests/ClearTest.cpp | 2 +- tests/PictureTest.cpp | 2 +- tests/ResourceCacheTest.cpp | 16 +- 17 files changed, 43 insertions(+), 520 deletions(-) delete mode 100644 include/private/SkUniquePtr.h diff --git a/gyp/core.gypi b/gyp/core.gypi index 548eeea928..50e7aadd09 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -419,7 +419,6 @@ '<(skia_include_path)/private/SkTDict.h', '<(skia_include_path)/private/SkTSearch.h', '<(skia_include_path)/private/SkTLogic.h', - '<(skia_include_path)/private/SkUniquePtr.h', '<(skia_include_path)/private/SkWeakRefCnt.h', # Path ops diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index f159e3b1b7..5e334395a9 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -9,9 +9,10 @@ #define SkRefCnt_DEFINED #include "../private/SkAtomics.h" -#include "../private/SkUniquePtr.h" +#include "../private/SkTLogic.h" #include "SkTypes.h" #include +#include #include #define SK_SUPPORT_TRANSITION_TO_SP_INTERFACES @@ -189,9 +190,9 @@ template struct SkTUnref { /** * Utility class that simply unref's its argument in the destructor. */ -template class SkAutoTUnref : public skstd::unique_ptr> { +template class SkAutoTUnref : public std::unique_ptr> { public: - explicit SkAutoTUnref(T* obj = nullptr) : skstd::unique_ptr>(obj) {} + explicit SkAutoTUnref(T* obj = nullptr) : std::unique_ptr>(obj) {} T* detach() { return this->release(); } operator T*() const { return this->get(); } diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContext.h index ddf5dc080a..fe41a606ef 100644 --- a/include/gpu/gl/SkGLContext.h +++ b/include/gpu/gl/SkGLContext.h @@ -25,7 +25,7 @@ public: const GrGLInterface* gl() const { return fGL.get(); } - bool fenceSyncSupport() const { return SkToBool(fFenceSync); } + bool fenceSyncSupport() const { return fFenceSync != nullptr; } bool getMaxGpuFrameLag(int* maxFrameLag) const { if (!fFenceSync) { diff --git a/include/private/SkOncePtr.h b/include/private/SkOncePtr.h index 261f9a7ef4..3c1ab634ee 100644 --- a/include/private/SkOncePtr.h +++ b/include/private/SkOncePtr.h @@ -9,7 +9,7 @@ #define SkOncePtr_DEFINED #include "../private/SkAtomics.h" -#include "SkUniquePtr.h" +#include template class SkBaseOncePtr; @@ -17,7 +17,7 @@ template class SkBaseOncePtr; #define SK_DECLARE_STATIC_ONCE_PTR(type, name) namespace {} static SkBaseOncePtr name; // Use this for a local or member pointer that's initialized exactly once when you call get(). -template > +template > class SkOncePtr : SkNoncopyable { public: SkOncePtr() { sk_bzero(this, sizeof(*this)); } @@ -42,7 +42,7 @@ private: // If you ask for SkOncePtr, we'll clean up with delete[] by default. template -class SkOncePtr : public SkOncePtr> {}; +class SkOncePtr : public SkOncePtr> {}; /* TODO(mtklein): in next CL typedef SkBaseOncePtr SkOnceFlag; diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h index e36910e814..e74f512623 100644 --- a/include/private/SkTemplates.h +++ b/include/private/SkTemplates.h @@ -13,8 +13,8 @@ #include "SkMath.h" #include "SkTLogic.h" #include "SkTypes.h" -#include "SkUniquePtr.h" #include +#include #include /** \file SkTemplates.h @@ -58,9 +58,9 @@ template struct SkFunctionWrapper { function. */ template class SkAutoTCallVProc - : public skstd::unique_ptr> { + : public std::unique_ptr> { public: - SkAutoTCallVProc(T* obj): skstd::unique_ptr>(obj) {} + SkAutoTCallVProc(T* obj): std::unique_ptr>(obj) {} operator T*() const { return this->get(); } T* detach() { return this->release(); } @@ -75,9 +75,9 @@ reference is null when the destructor is called, we do not call the function. */ template class SkAutoTCallIProc - : public skstd::unique_ptr> { + : public std::unique_ptr> { public: - SkAutoTCallIProc(T* obj): skstd::unique_ptr>(obj) {} + SkAutoTCallIProc(T* obj): std::unique_ptr>(obj) {} operator T*() const { return this->get(); } T* detach() { return this->release(); } @@ -93,18 +93,18 @@ public: The size of a SkAutoTDelete is small: sizeof(SkAutoTDelete) == sizeof(T*) */ -template class SkAutoTDelete : public skstd::unique_ptr { +template class SkAutoTDelete : public std::unique_ptr { public: - SkAutoTDelete(T* obj = NULL) : skstd::unique_ptr(obj) {} + SkAutoTDelete(T* obj = NULL) : std::unique_ptr(obj) {} operator T*() const { return this->get(); } void free() { this->reset(nullptr); } T* detach() { return this->release(); } }; -template class SkAutoTDeleteArray : public skstd::unique_ptr { +template class SkAutoTDeleteArray : public std::unique_ptr { public: - SkAutoTDeleteArray(T array[]) : skstd::unique_ptr(array) {} + SkAutoTDeleteArray(T array[]) : std::unique_ptr(array) {} void free() { this->reset(nullptr); } T* detach() { return this->release(); } diff --git a/include/private/SkUniquePtr.h b/include/private/SkUniquePtr.h deleted file mode 100644 index b1097d51eb..0000000000 --- a/include/private/SkUniquePtr.h +++ /dev/null @@ -1,408 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkUniquePtr_DEFINED -#define SkUniquePtr_DEFINED - -#include "SkTLogic.h" -#include -#include - -namespace skstd { - -template struct default_delete { - /*constexpr*/ default_delete() /*noexcept*/ = default; - - template ::value>> - default_delete(const default_delete&) /*noexcept*/ {} - - void operator()(T* obj) const { - static_assert(sizeof(T) > 0, "Deleting pointer to incomplete type!"); - delete obj; - } -}; -template struct default_delete { - /*constexpr*/ default_delete() /*noexcept*/ = default; - - void operator()(T* obj) const { - static_assert(sizeof(T) > 0, "Deleting pointer to incomplete type!"); - delete [] obj; - } -}; - -template > class unique_ptr { - // remove_reference_t::pointer if that type exists, otherwise T*. - struct pointer_type_detector { - template static typename U::pointer detector(typename U::pointer*); - template static T* detector(...); - using type = decltype(detector>(0)); - }; - -public: - using pointer = typename pointer_type_detector::type; - using element_type = T; - using deleter_type = D; - -private: - template - struct compressed_base : private B { - /*constexpr*/ compressed_base() : B() {} - /*constexpr*/ compressed_base(const B& b) : B(b) {} - /*constexpr*/ compressed_base(B&& b) : B(std::move(b)) {} - /*constexpr*/ B& get() /*noexcept*/ { return *this; } - /*constexpr*/ B const& get() const /*noexcept*/ { return *this; } - void swap(compressed_base&) /*noexcept*/ { } - }; - - template struct compressed_base { - B fb; - /*constexpr*/ compressed_base() : B() {} - /*constexpr*/ compressed_base(const B& b) : fb(b) {} - /*constexpr*/ compressed_base(B&& b) : fb(std::move(b)) {} - /*constexpr*/ B& get() /*noexcept*/ { return fb; } - /*constexpr*/ B const& get() const /*noexcept*/ { return fb; } - void swap(compressed_base& that) /*noexcept*/ { SkTSwap(fb, that.fB); } - }; - - // C++14 adds '&& !std::is_final::value' to the bool condition. - // compressed_base_t exists and has this form to work around a bug in vs2013sp2-3 - using compressed_base_t = compressed_base::value>; - - struct compressed_data : private compressed_base_t { - pointer fPtr; - /*constexpr*/ compressed_data() : compressed_base_t(), fPtr() {} - /*constexpr*/ compressed_data(const pointer& ptr, const deleter_type& d) - : compressed_base_t(d), fPtr(ptr) {} - template ::value && is_convertible::value - >> /*constexpr*/ compressed_data(U1&& ptr, U2&& d) - : compressed_base_t(std::forward(d)), fPtr(std::forward(ptr)) {} - /*constexpr*/ pointer& getPointer() /*noexcept*/ { return fPtr; } - /*constexpr*/ pointer const& getPointer() const /*noexcept*/ { return fPtr; } - /*constexpr*/ deleter_type& getDeleter() /*noexcept*/ { - return compressed_base_t::get(); - } - /*constexpr*/ deleter_type const& getDeleter() const /*noexcept*/ { - return compressed_base_t::get(); - } - void swap(compressed_data& that) /*noexcept*/ { - compressed_base_t::swap(static_cast(that)); - SkTSwap(fPtr, that.fPtr); - } - }; - compressed_data data; - -public: - /*constexpr*/ unique_ptr() /*noexcept*/ : data() { - static_assert(!std::is_pointer::value, "Deleter nullptr function pointer!"); - } - - /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } - - explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { - static_assert(!std::is_pointer::value, "Deleter nullptr function pointer!"); - } - - unique_ptr(pointer ptr, - conditional_t::value, - deleter_type, const deleter_type&> d) - /*noexcept*/ : data(ptr, d) - {} - - unique_ptr(pointer ptr, remove_reference_t&& d) /*noexcept*/ - : data(std::move(ptr), std::move(d)) - { - static_assert(!std::is_reference::value, - "Binding an rvalue reference deleter as an lvalue reference deleter is not allowed."); - } - - - unique_ptr(unique_ptr&& that) /*noexcept*/ - : data(that.release(), std::forward(that.get_deleter())) - {} - - template ::pointer, pointer>::value && - !std::is_array::value && - conditional_t::value, - std::is_same, - is_convertible>::value>> - unique_ptr(unique_ptr&& that) /*noexcept*/ - : data(that.release(), std::forward(that.get_deleter())) - {} - - ~unique_ptr() /*noexcept*/ { - pointer& ptr = data.getPointer(); - if (ptr != nullptr) { - get_deleter()(ptr); - } - ptr = pointer(); - } - - unique_ptr& operator=(unique_ptr&& that) /*noexcept*/ { - reset(that.release()); - get_deleter() = std::forward(that.get_deleter()); - return *this; - } - - template enable_if_t< - is_convertible::pointer, pointer>::value && - !std::is_array::value, - unique_ptr&> operator=(unique_ptr&& that) /*noexcept*/ { - reset(that.release()); - get_deleter() = std::forward(that.get_deleter()); - return *this; - } - - unique_ptr& operator=(std::nullptr_t) /*noexcept*/ { - reset(); - return *this; - } - - add_lvalue_reference_t operator*() const { - SkASSERT(get() != pointer()); - return *get(); - } - - pointer operator->() const /*noexcept*/ { - SkASSERT(get() != pointer()); - return get(); - } - - pointer get() const /*noexcept*/ { - return data.getPointer(); - } - - deleter_type& get_deleter() /*noexcept*/ { - return data.getDeleter(); - } - - const deleter_type& get_deleter() const /*noexcept*/ { - return data.getDeleter(); - } - - //explicit operator bool() const noexcept { - bool is_attached() const /*noexcept*/ { - return get() == pointer() ? false : true; - } - - pointer release() /*noexcept*/ { - pointer ptr = get(); - data.getPointer() = pointer(); - return ptr; - } - - void reset(pointer ptr = pointer()) /*noexcept*/ { - SkTSwap(data.getPointer(), ptr); - if (ptr != pointer()) { - get_deleter()(ptr); - } - } - - void swap(unique_ptr& that) /*noexcept*/ { - SkTSwap(data, that.data); - } - - unique_ptr(const unique_ptr&) = delete; - unique_ptr& operator=(const unique_ptr&) = delete; -}; - -template class unique_ptr { - // remove_reference_t::pointer if that type exists, otherwise T*. - struct pointer_type_detector { - template static typename U::pointer detector(typename U::pointer*); - template static T* detector(...); - using type = decltype(detector>(0)); - }; - -public: - using pointer = typename pointer_type_detector::type; - using element_type = T; - using deleter_type = D; - -private: - template struct compressed_base : private B { - /*constexpr*/ compressed_base() : B() {} - /*constexpr*/ compressed_base(const B& b) : B(b) {} - /*constexpr*/ compressed_base(B&& b) : B(std::move(b)) {} - /*constexpr*/ B& get() /*noexcept*/ { return *this; } - /*constexpr*/ B const& get() const /*noexcept*/ { return *this; } - void swap(compressed_base&) /*noexcept*/ { } - }; - - template struct compressed_base { - B fb; - /*constexpr*/ compressed_base() : B() {} - /*constexpr*/ compressed_base(const B& b) : fb(b) {} - /*constexpr*/ compressed_base(B&& b) : fb(std::move(b)) {} - /*constexpr*/ B& get() /*noexcept*/ { return fb; } - /*constexpr*/ B const& get() const /*noexcept*/ { return fb; } - void swap(compressed_base& that) /*noexcept*/ { SkTSwap(fb, that.fB); } - }; - - // C++14 adds '&& !std::is_final::value' to the bool condition. - // compressed_base_t exists and has this form to work around a bug in vs2013sp2-3 - using compressed_base_t = compressed_base::value>; - - struct compressed_data : private compressed_base_t { - pointer fPtr; - /*constexpr*/ compressed_data() : compressed_base_t(), fPtr() {} - /*constexpr*/ compressed_data(const pointer& ptr, const deleter_type& d) - : compressed_base_t(d), fPtr(ptr) {} - template ::value && is_convertible::value - >> /*constexpr*/ compressed_data(U1&& ptr, U2&& d) - : compressed_base_t(std::forward(d)), fPtr(std::forward(ptr)) {} - /*constexpr*/ pointer& getPointer() /*noexcept*/ { return fPtr; } - /*constexpr*/ pointer const& getPointer() const /*noexcept*/ { return fPtr; } - /*constexpr*/ deleter_type& getDeleter() /*noexcept*/ { - return compressed_base_t::get(); - } - /*constexpr*/ deleter_type const& getDeleter() const /*noexcept*/ { - return compressed_base_t::get(); - } - void swap(compressed_data& that) /*noexcept*/ { - compressed_base_t::swap(static_cast(that)); - SkTSwap(fPtr, that.fPtr); - } - }; - compressed_data data; - -public: - /*constexpr*/ unique_ptr() /*noexcept*/ : data() { - static_assert(!std::is_pointer::value, "Deleter nullptr function pointer!"); - } - - /*constexpr*/ unique_ptr(std::nullptr_t) /*noexcept*/ : unique_ptr() { } - - explicit unique_ptr(pointer ptr) /*noexcept*/ : data(ptr, deleter_type()) { - static_assert(!std::is_pointer::value, "Deleter nullptr function pointer!"); - } - - unique_ptr(pointer ptr, - conditional_t::value, - deleter_type, const deleter_type&> d) - /*noexcept*/ : data(ptr, d) - {} - - unique_ptr(pointer ptr, remove_reference_t&& d) /*noexcept*/ - : data(std::move(ptr), std::move(d)) - { - static_assert(!std::is_reference::value, - "Binding an rvalue reference deleter as an lvalue reference deleter is not allowed."); - } - - unique_ptr(unique_ptr&& that) /*noexcept*/ - : data(that.release(), std::forward(that.get_deleter())) - {} - - ~unique_ptr() { - pointer& ptr = data.getPointer(); - if (ptr != nullptr) { - get_deleter()(ptr); - } - ptr = pointer(); - } - - unique_ptr& operator=(unique_ptr&& that) /*noexcept*/ { - reset(that.release()); - get_deleter() = std::forward(that.get_deleter()); - return *this; - } - - unique_ptr& operator=(std::nullptr_t) /*noexcept*/ { - reset(); - return *this; - } - - add_lvalue_reference_t operator[](size_t i) const { - SkASSERT(get() != pointer()); - return get()[i]; - } - - pointer get() const /*noexcept*/ { - return data.getPointer(); - } - - deleter_type& get_deleter() /*noexcept*/ { - return data.getDeleter(); - } - - const deleter_type& get_deleter() const /*noexcept*/ { - return data.getDeleter(); - } - - //explicit operator bool() const noexcept { - bool is_attached() const /*noexcept*/ { - return get() == pointer() ? false : true; - } - - pointer release() /*noexcept*/ { - pointer ptr = get(); - data.getPointer() = pointer(); - return ptr; - } - - void reset(pointer ptr = pointer()) /*noexcept*/ { - SkTSwap(data.getPointer(), ptr); - if (ptr != pointer()) { - get_deleter()(ptr); - } - } - - template void reset(U*) = delete; - - void swap(unique_ptr& that) /*noexcept*/ { - data.swap(that.data); - } - - unique_ptr(const unique_ptr&) = delete; - unique_ptr& operator=(const unique_ptr&) = delete; -}; - -template -inline void swap(unique_ptr& a, unique_ptr& b) /*noexcept*/ { - a.swap(b); -} - -template -inline bool operator==(const unique_ptr& a, const unique_ptr& b) { - return a.get() == b.get(); -} - -template -inline bool operator==(const unique_ptr& a, std::nullptr_t) /*noexcept*/ { - //return !a; - return !a.is_attached(); -} - -template -inline bool operator==(std::nullptr_t, const unique_ptr& b) /*noexcept*/ { - //return !b; - return !b.is_attached(); -} - -template -inline bool operator!=(const unique_ptr& a, const unique_ptr& b) { - return a.get() != b.get(); -} - -template -inline bool operator!=(const unique_ptr& a, std::nullptr_t) /*noexcept*/ { - //return (bool)a; - return a.is_attached(); -} - -template -inline bool operator!=(std::nullptr_t, const unique_ptr& b) /*noexcept*/ { - //return (bool)b; - return b.is_attached(); -} - -} // namespace skstd - -#endif diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index 2c49530e7c..8d6bae6992 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -272,7 +272,7 @@ private: AuxProcRec* fAuxProcList; }; -class SkAutoGlyphCache : public skstd::unique_ptr { +class SkAutoGlyphCache : public std::unique_ptr { public: /** deprecated: use get() */ SkGlyphCache* getCache() const { return this->get(); } @@ -294,7 +294,7 @@ public: : INHERITED(paint.detachCache(surfaceProps, fakeGamma, matrix)) {} private: - using INHERITED = skstd::unique_ptr; + using INHERITED = std::unique_ptr; }; class SkAutoGlyphCacheNoGamma : public SkAutoGlyphCache { diff --git a/src/core/SkSharedMutex.h b/src/core/SkSharedMutex.h index 840c2d36ad..21c9f46d64 100644 --- a/src/core/SkSharedMutex.h +++ b/src/core/SkSharedMutex.h @@ -14,7 +14,7 @@ #ifdef SK_DEBUG #include "SkMutex.h" - #include "SkUniquePtr.h" + #include #endif // SK_DEBUG // There are two shared lock implementations one debug the other is high performance. They implement @@ -50,9 +50,9 @@ public: private: #ifdef SK_DEBUG class ThreadIDSet; - skstd::unique_ptr fCurrentShared; - skstd::unique_ptr fWaitingExclusive; - skstd::unique_ptr fWaitingShared; + std::unique_ptr fCurrentShared; + std::unique_ptr fWaitingExclusive; + std::unique_ptr fWaitingShared; int fSharedQueueSelect{0}; mutable SkMutex fMu; SkSemaphore fSharedQueue[2]; diff --git a/src/gpu/GrLayerAtlas.cpp b/src/gpu/GrLayerAtlas.cpp index df8215a607..c1f8732b35 100644 --- a/src/gpu/GrLayerAtlas.cpp +++ b/src/gpu/GrLayerAtlas.cpp @@ -12,7 +12,7 @@ #include "GrTextureProvider.h" /////////////////////////////////////////////////////////////////////////////// -GrLayerAtlas::Plot::Plot() +GrLayerAtlas::Plot::Plot() : fID(-1) , fRects(nullptr) { fOffset.set(0, 0); @@ -54,7 +54,7 @@ bool GrLayerAtlas::reattachBackingTexture() { SkASSERT(!fTexture); fTexture.reset(fTexProvider->findAndRefTextureByUniqueKey(get_layer_atlas_key())); - return SkToBool(fTexture); + return fTexture != nullptr; } void GrLayerAtlas::createBackingTexture() { @@ -71,7 +71,7 @@ void GrLayerAtlas::createBackingTexture() { fTexture->resourcePriv().setUniqueKey(get_layer_atlas_key()); } -GrLayerAtlas::GrLayerAtlas(GrTextureProvider* texProvider, GrPixelConfig config, +GrLayerAtlas::GrLayerAtlas(GrTextureProvider* texProvider, GrPixelConfig config, GrSurfaceFlags flags, const SkISize& backingTextureSize, int numPlotsX, int numPlotsY) { diff --git a/src/gpu/text/GrStencilAndCoverTextContext.cpp b/src/gpu/text/GrStencilAndCoverTextContext.cpp index ab9025d316..661f22512d 100644 --- a/src/gpu/text/GrStencilAndCoverTextContext.cpp +++ b/src/gpu/text/GrStencilAndCoverTextContext.cpp @@ -329,7 +329,7 @@ class GrStencilAndCoverTextContext::FallbackBlobBuilder { public: FallbackBlobBuilder() : fBuffIdx(0), fCount(0) {} - bool isInitialized() const { return SkToBool(fBuilder); } + bool isInitialized() const { return fBuilder != nullptr; } void init(const SkPaint& font, SkScalar textRatio); diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp index 744d42d25e..57b5269423 100644 --- a/src/pdf/SkPDFDevice.cpp +++ b/src/pdf/SkPDFDevice.cpp @@ -1533,10 +1533,10 @@ sk_sp SkPDFDevice::copyMediaBox() const { return mediaBox; } -skstd::unique_ptr SkPDFDevice::content() const { +std::unique_ptr SkPDFDevice::content() const { SkDynamicMemoryWStream buffer; this->writeContent(&buffer); - return skstd::unique_ptr( + return std::unique_ptr( buffer.bytesWritten() > 0 ? buffer.detachAsStream() : new SkMemoryStream); diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h index b1345a8e3f..b214839f5a 100644 --- a/src/pdf/SkPDFDevice.h +++ b/src/pdf/SkPDFDevice.h @@ -168,7 +168,7 @@ public: /** Returns a SkStream with the page contents. */ - skstd::unique_ptr content() const; + std::unique_ptr content() const; /** Writes the page contents to the stream. */ void writeContent(SkWStream*) const; diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 9230507662..f01c7d7cc5 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -25,7 +25,7 @@ #include "SkString.h" #include "SkTemplates.h" #include "SkTypes.h" -#include "SkUniquePtr.h" +#include #if defined(SK_CAN_USE_DLOPEN) #include @@ -802,7 +802,7 @@ SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface, const S // load the font file using UnrefFTFace = SkFunctionWrapper, unref_ft_face>; - skstd::unique_ptr, UnrefFTFace> ftFace(ref_ft_face(typeface)); + std::unique_ptr, UnrefFTFace> ftFace(ref_ft_face(typeface)); if (nullptr == ftFace) { SkDEBUGF(("Could not create FT_Face.\n")); return; @@ -891,7 +891,7 @@ SkScalerContext_FreeType::SkScalerContext_FreeType(SkTypeface* typeface, const S } using DoneFTSize = SkFunctionWrapper, FT_Done_Size>; - skstd::unique_ptr, DoneFTSize> ftSize([&ftFace]() -> FT_Size { + std::unique_ptr, DoneFTSize> ftSize([&ftFace]() -> FT_Size { FT_Size size; FT_Error err = FT_New_Size(ftFace.get(), &size); if (err != 0) { diff --git a/tests/CPlusPlusEleven.cpp b/tests/CPlusPlusEleven.cpp index 0cd2e937b2..5fbd46429d 100644 --- a/tests/CPlusPlusEleven.cpp +++ b/tests/CPlusPlusEleven.cpp @@ -28,72 +28,3 @@ DEF_TEST(CPlusPlusEleven_RvalueAndMove, r) { Moveable src1; Moveable dst1(std::move(src1)); Moveable src2, dst2; dst2 = std::move(src2); } - -#define TOO_BIG "The unique_ptr was bigger than expected." -#define WEIRD_SIZE "The unique_ptr was a different size than expected." - -DEF_TEST(CPlusPlusEleven_UniquePtr, r) { - struct SmallUniquePtr { - Moveable* p; - }; - struct BigUniquePtr { - void(*d)(Moveable*); - Moveable* p; - }; - - static_assert(sizeof(skstd::unique_ptr) == sizeof(SmallUniquePtr), TOO_BIG); - static_assert(sizeof(skstd::unique_ptr) == sizeof(SmallUniquePtr), TOO_BIG); - - using proc = void(*)(Moveable*); - static_assert(sizeof(skstd::unique_ptr) == sizeof(BigUniquePtr), WEIRD_SIZE); - static_assert(sizeof(skstd::unique_ptr) == sizeof(BigUniquePtr), WEIRD_SIZE); - - { - skstd::unique_ptr u(nullptr, deleter); - static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); - } - - { - skstd::unique_ptr u(nullptr, [](Moveable* m){ deleter(m); }); - static_assert(sizeof(u) == sizeof(BigUniquePtr), WEIRD_SIZE); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(BigUniquePtr), WEIRD_SIZE); - } - - { - auto d = [](Moveable* m){ deleter(m); }; - skstd::unique_ptr u(nullptr, d); - static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); - } - - { - skstd::unique_ptr> u(nullptr, Deleter()); - static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); - } - - { - skstd::unique_ptr> u(new Moveable(), Deleter()); - static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); - } - - { - skstd::unique_ptr> u(new Moveable(), Deleter()); - static_assert(sizeof(u) == sizeof(SmallUniquePtr), TOO_BIG); - - auto u2 = std::move(u); - static_assert(sizeof(u2) == sizeof(SmallUniquePtr), TOO_BIG); - } -} diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp index df152089fb..25fcf85849 100644 --- a/tests/ClearTest.cpp +++ b/tests/ClearTest.cpp @@ -62,7 +62,7 @@ static bool reset_dc(SkAutoTUnref* dc, SkAutoTUnref* r GrRenderTarget* rt = (*rtKeepAlive)->asRenderTarget(); SkASSERT(rt->getUniqueID() != oldID); dc->reset(context->drawContext(rt)); - return SkToBool(*dc); + return *dc != nullptr; } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, context) { diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp index 448e079958..a33deeb218 100644 --- a/tests/PictureTest.cpp +++ b/tests/PictureTest.cpp @@ -1409,7 +1409,7 @@ DEF_TEST(Picture_preserveCullRect, r) { SkAutoTDelete rstream(wstream.detachAsStream()); SkAutoTUnref deserializedPicture(SkPicture::CreateFromStream(rstream)); - REPORTER_ASSERT(r, SkToBool(deserializedPicture)); + REPORTER_ASSERT(r, deserializedPicture != nullptr); REPORTER_ASSERT(r, deserializedPicture->cullRect().left() == 1); REPORTER_ASSERT(r, deserializedPicture->cullRect().top() == 2); REPORTER_ASSERT(r, deserializedPicture->cullRect().right() == 3); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index c715b2efcc..784ae7e94d 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -136,7 +136,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, contex resourceProvider->attachStencilAttachment(bigRT->asRenderTarget())); if (context->caps()->maxSampleCount() >= 4) { - // An RT with a different sample count should not share. + // An RT with a different sample count should not share. GrSurfaceDesc smallMSAADesc = smallDesc; smallMSAADesc.fSampleCnt = 4; SkAutoTUnref smallMSAART0(cache->createTexture(smallMSAADesc, SkBudgeted::kNo)); @@ -216,8 +216,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, cont SkAutoTUnref adopted(context->textureProvider()->wrapBackendTexture( desc, kAdopt_GrWrapOwnership)); - REPORTER_ASSERT(reporter, SkToBool(borrowed) && SkToBool(adopted)); - if (!SkToBool(borrowed) || !SkToBool(adopted)) { + REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); + if (!borrowed || !adopted) { return; } @@ -242,7 +242,7 @@ class TestResource : public GrGpuResource { enum ScratchConstructor { kScratchConstructor }; public: static const size_t kDefaultSize = 100; - + /** Property that distinctly categorizes the resource. * For example, textures have width, height, ... */ enum SimulatedProperty { kA_SimulatedProperty, kB_SimulatedProperty }; @@ -590,7 +590,7 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted()); if (0 == i) { - // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try + // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try // the above tests again. resource->resourcePriv().makeUnbudgeted(); } else { @@ -784,11 +784,11 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) { GrUniqueKey key; make_unique_key<0>(&key, 0); - + // Create two resources that we will attempt to register with the same unique key. TestResource* a = new TestResource(context->getGpu()); a->setSize(11); - + // Set key on resource a. a->resourcePriv().setUniqueKey(key); REPORTER_ASSERT(reporter, a == cache->findAndRefUniqueResource(key)); @@ -882,7 +882,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) { make_unique_key<0>(&key1, 1); make_unique_key<0>(&key2, 2); make_unique_key<0>(&key3, 3); - + // Add three resources to the cache. Only c is usable as scratch. TestResource* a = new TestResource(context->getGpu()); TestResource* b = new TestResource(context->getGpu()); -- cgit v1.2.3