From c79da1ca0520beabb827cd16a94508804bbba17b Mon Sep 17 00:00:00 2001 From: halx99 Date: Fri, 11 Sep 2020 14:45:45 +0800 Subject: [PATCH] fix ci --- cocos/base/CCData.cpp | 10 ++++++++++ cocos/base/CCData.h | 2 ++ cocos/platform/CCFileUtils.h | 8 +------- cocos/renderer/backend/Macros.h | 16 ++++++++++++++++ cocos/renderer/backend/PixelBufferDescriptor.h | 4 ++-- cocos/renderer/backend/Texture.h | 4 ++-- cocos/renderer/backend/opengl/UtilsGL.h | 1 + 7 files changed, 34 insertions(+), 11 deletions(-) diff --git a/cocos/base/CCData.cpp b/cocos/base/CCData.cpp index 2dc5712f93..20937bdc96 100644 --- a/cocos/base/CCData.cpp +++ b/cocos/base/CCData.cpp @@ -127,6 +127,16 @@ ssize_t Data::copy(const unsigned char* bytes, const ssize_t size) return _size; } +void Data::resize(ssize_t size) +{ + if (_size < size) { + auto newmb = (uint8_t*)realloc(_bytes, size); + if (!newmb) return; + _bytes = newmb; + } + _size = size; +} + void Data::fastSet(unsigned char* bytes, const ssize_t size) { CCASSERT(size >= 0, "fastSet size should be non-negative"); diff --git a/cocos/base/CCData.h b/cocos/base/CCData.h index d99ab8d11c..a6c41fe6e3 100644 --- a/cocos/base/CCData.h +++ b/cocos/base/CCData.h @@ -101,6 +101,8 @@ public: */ ssize_t copy(const unsigned char* bytes, const ssize_t size); + void resize(ssize_t size); + /** Fast set the buffer pointer and its size. Please use it carefully. * @param bytes The buffer pointer, note that it have to be allocated by 'malloc' or 'calloc', * since in the destructor of Data, the buffer will be deleted by 'free'. diff --git a/cocos/platform/CCFileUtils.h b/cocos/platform/CCFileUtils.h index 4b23ea6419..c9ed5f7797 100644 --- a/cocos/platform/CCFileUtils.h +++ b/cocos/platform/CCFileUtils.h @@ -105,13 +105,7 @@ class ResizableBufferAdapter : public ResizableBuffer { public: explicit ResizableBufferAdapter(BufferType* buffer) : _buffer(buffer) {} virtual void resize(size_t size) override { - size_t oldSize = static_cast(_buffer->getSize()); - if (oldSize != size) { - auto old = _buffer->getBytes(); - void* buffer = realloc(old, size); - if (buffer) - _buffer->fastSet((unsigned char*)buffer, size); - } + _buffer->resize(size); } virtual void* buffer() const override { return _buffer->getBytes(); diff --git a/cocos/renderer/backend/Macros.h b/cocos/renderer/backend/Macros.h index a8afec6798..729bbe10fb 100644 --- a/cocos/renderer/backend/Macros.h +++ b/cocos/renderer/backend/Macros.h @@ -30,3 +30,19 @@ #define MAX_COLOR_ATTCHMENT 1 #define MAX_INFLIGHT_BUFFER 3 + + /* + * helps the compiler's optimizer predicting branches + */ +#if __has_builtin(__builtin_expect) +# ifdef __cplusplus +# define UTILS_LIKELY( exp ) (__builtin_expect( !!(exp), true )) +# define UTILS_UNLIKELY( exp ) (__builtin_expect( !!(exp), false )) +# else +# define UTILS_LIKELY( exp ) (__builtin_expect( !!(exp), 1 )) +# define UTILS_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 )) +# endif +#else +# define UTILS_LIKELY( exp ) (!!(exp)) +# define UTILS_UNLIKELY( exp ) (!!(exp)) +#endif diff --git a/cocos/renderer/backend/PixelBufferDescriptor.h b/cocos/renderer/backend/PixelBufferDescriptor.h index d4968e3a7a..6ec70f80d2 100644 --- a/cocos/renderer/backend/PixelBufferDescriptor.h +++ b/cocos/renderer/backend/PixelBufferDescriptor.h @@ -17,8 +17,8 @@ struct PixelBufferDescriptor explicit operator bool() const { return !_data.isNull(); } Data _data; - int _width; - int _height; + int _width = 0; + int _height = 0; }; CC_BACKEND_END diff --git a/cocos/renderer/backend/Texture.h b/cocos/renderer/backend/Texture.h index 588ea5a83c..47d0909917 100644 --- a/cocos/renderer/backend/Texture.h +++ b/cocos/renderer/backend/Texture.h @@ -51,14 +51,14 @@ struct TextureDescriptor SamplerDescriptor samplerDescriptor; }; -class UtilsGL; +struct UtilsGL; /** * A base texture */ class TextureBackend : public Ref { - friend class UtilsGL; + friend struct UtilsGL; public: /** * Update sampler diff --git a/cocos/renderer/backend/opengl/UtilsGL.h b/cocos/renderer/backend/opengl/UtilsGL.h index 798f429912..dcb13ed986 100644 --- a/cocos/renderer/backend/opengl/UtilsGL.h +++ b/cocos/renderer/backend/opengl/UtilsGL.h @@ -27,6 +27,7 @@ #include "base/ccMacros.h" #include "platform/CCGL.h" #include "renderer/backend/Types.h" +#include "renderer/backend/PixelBufferDescriptor.h" CC_BACKEND_BEGIN /**