From 2ba1c627cbf97d4f2690903b78ec1b6f8daf631b Mon Sep 17 00:00:00 2001 From: Takaya Kakizaki Date: Tue, 30 Apr 2019 12:25:05 +0900 Subject: [PATCH 01/11] fix FastTMXLayer with anchor point --- cocos/2d/CCFastTMXLayer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index 54b09d2227cb..0c12c1f56f0b 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -152,8 +152,9 @@ void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) if( flags != 0 || _dirty || _quadsDirty || isViewProjectionUpdated) { Size s = Director::getInstance()->getVisibleSize(); - auto rect = Rect(Camera::getVisitingCamera()->getPositionX() - s.width * 0.5f, - Camera::getVisitingCamera()->getPositionY() - s.height * 0.5f, + Vec2 anchor = getAnchorPoint(); + auto rect = Rect(Camera::getVisitingCamera()->getPositionX() - s.width * anchor.x, + Camera::getVisitingCamera()->getPositionY() - s.height * anchor.y, s.width, s.height); From 7a7506951fba6497addf98e1aaa64e7a01e913ee Mon Sep 17 00:00:00 2001 From: Takaya Kakizaki Date: Tue, 30 Apr 2019 12:25:32 +0900 Subject: [PATCH 02/11] fix FastTMXLayer does not reflect Opacity --- cocos/2d/CCFastTMXLayer.cpp | 24 +++++++++++++++++++----- cocos/2d/CCFastTMXLayer.h | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index 0c12c1f56f0b..5601fb1c509d 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -442,6 +442,11 @@ void TMXLayer::updatePrimitives() } } +void TMXLayer::setOpacity(GLubyte opacity) { + Node::setOpacity(opacity); + _quadsDirty = true; +} + void TMXLayer::updateTotalQuads() { if(_quadsDirty) @@ -453,6 +458,15 @@ void TMXLayer::updateTotalQuads() _indices.resize(6 * int(_layerSize.width * _layerSize.height)); _tileToQuadIndex.resize(int(_layerSize.width * _layerSize.height),-1); _indicesVertexZOffsets.clear(); + + auto color = Color4B::WHITE; + color.a = getDisplayedOpacity(); + + if (_texture->hasPremultipliedAlpha()) { + color.r *= color.a / 255.0f; + color.g *= color.a / 255.0f; + color.b *= color.a / 255.0f; + } int quadIndex = 0; for(int y = 0; y < _layerSize.height; ++y) @@ -551,11 +565,11 @@ void TMXLayer::updateTotalQuads() quad.tl.texCoords.v = top; quad.tr.texCoords.u = right; quad.tr.texCoords.v = top; - - quad.bl.colors = Color4B::WHITE; - quad.br.colors = Color4B::WHITE; - quad.tl.colors = Color4B::WHITE; - quad.tr.colors = Color4B::WHITE; + + quad.bl.colors = color; + quad.br.colors = color; + quad.tl.colors = color; + quad.tr.colors = color; ++quadIndex; } diff --git a/cocos/2d/CCFastTMXLayer.h b/cocos/2d/CCFastTMXLayer.h index 7c71636ec060..eb289d67e86b 100644 --- a/cocos/2d/CCFastTMXLayer.h +++ b/cocos/2d/CCFastTMXLayer.h @@ -297,6 +297,8 @@ class CC_DLL TMXLayer : public Node void updateVertexBuffer(); void updateIndexBuffer(); void updatePrimitives(); + + virtual void setOpacity(GLubyte opacity) override; protected: //! name of the layer From 82763f870a543fbace9362c3692aad09f695e155 Mon Sep 17 00:00:00 2001 From: John <3619244+JohnCoconut@users.noreply.github.com> Date: Tue, 4 Jun 2019 13:54:22 +0800 Subject: [PATCH 03/11] refactor CCScene (#19767) * refactor-CCScene prefer in-class initialization * in-class initialization of pointer to nullptr --- cocos/2d/CCScene.cpp | 18 +++--------------- cocos/2d/CCScene.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 0e8d96090881..ec30342b5f94 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -52,28 +52,16 @@ THE SOFTWARE. NS_CC_BEGIN Scene::Scene() +: _defaultCamera(Camera::create()) +, _event(Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1))) { -#if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION - _physics3DWorld = nullptr; - _physics3dDebugCamera = nullptr; -#endif -#if CC_USE_NAVMESH - _navMesh = nullptr; - _navMeshDebugCamera = nullptr; -#endif -#if CC_USE_PHYSICS - _physicsWorld = nullptr; -#endif _ignoreAnchorPointForPosition = true; setAnchorPoint(Vec2(0.5f, 0.5f)); - _cameraOrderDirty = true; - //create default camera - _defaultCamera = Camera::create(); + addChild(_defaultCamera); - _event = Director::getInstance()->getEventDispatcher()->addCustomEventListener(Director::EVENT_PROJECTION_CHANGED, std::bind(&Scene::onProjectionChanged, this, std::placeholders::_1)); _event->retain(); Camera::_visitingCamera = nullptr; diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index bf10ed524e5e..aa610740a950 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -155,9 +155,9 @@ class CC_DLL Scene : public Node friend class Renderer; std::vector _cameras; //weak ref to Camera - Camera* _defaultCamera; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called - bool _cameraOrderDirty; // order is dirty, need sort - EventListenerCustom* _event; + Camera* _defaultCamera = nullptr; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called + bool _cameraOrderDirty = true; // order is dirty, need sort + EventListenerCustom* _event = nullptr; std::vector _lights; @@ -201,12 +201,12 @@ class CC_DLL Scene : public Node void addChildToPhysicsWorld(Node* child); #if CC_USE_PHYSICS - PhysicsWorld* _physicsWorld; + PhysicsWorld* _physicsWorld = nullptr; #endif #if CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION - Physics3DWorld* _physics3DWorld; - Camera* _physics3dDebugCamera; // + Physics3DWorld* _physics3DWorld = nullptr; + Camera* _physics3dDebugCamera = nullptr; #endif #endif // (CC_USE_PHYSICS || CC_USE_3D_PHYSICS) @@ -222,8 +222,8 @@ class CC_DLL Scene : public Node void setNavMeshDebugCamera(Camera *camera); protected: - NavMesh* _navMesh; - Camera * _navMeshDebugCamera; + NavMesh* _navMesh = nullptr; + Camera * _navMeshDebugCamera = nullptr; #endif #if (CC_USE_PHYSICS || (CC_USE_3D_PHYSICS && CC_ENABLE_BULLET_INTEGRATION) || CC_USE_NAVMESH) From bb2714052af10c7901c345fe8cc3d24e5af7abca Mon Sep 17 00:00:00 2001 From: rh101 Date: Tue, 4 Jun 2019 16:14:14 +1000 Subject: [PATCH 04/11] Added support for saving images with non-premultiplied alpha (#19782) * Added RenderTexture::saveToFileAsNonPMA() to save images without PMA. Set the PMA parameter to true when calling initWithRawData() inside RenderTexture::newImage(), since textures are PMA. Renamed Image::premultipliedAlpha() to Image::premultiplyAlpha() to better reflect it's action, and made it public. Added Image::reversePremultipliedAlpha() to allow the reversing of the PMA. Updated CCImage-ios.mm to set the correct bitmapInfo for PMA and non-PMA images before saving a file. Updated RenderTextureTest::RenderTextureSave() to cater for non-PMA file saving. * [CCImage-ios.mm] Fixed indentation. --- cocos/2d/CCRenderTexture.cpp | 50 ++++++++++++-- cocos/2d/CCRenderTexture.h | 27 +++++++- cocos/platform/CCImage.cpp | 27 +++++++- cocos/platform/CCImage.h | 4 +- cocos/platform/ios/CCImage-ios.mm | 9 ++- .../RenderTextureTest/RenderTextureTest.cpp | 65 ++++++++++++++++--- .../RenderTextureTest/RenderTextureTest.h | 6 +- 7 files changed, 168 insertions(+), 20 deletions(-) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index fb63b9cac6cd..3b2b54a5d153 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -506,6 +506,28 @@ void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint3 // setOrderOfArrival(0); } +bool RenderTexture::saveToFileAsNonPMA(const std::string& filename, bool isRGBA, std::function callback) +{ + std::string basename(filename); + std::transform(basename.begin(), basename.end(), basename.begin(), ::tolower); + + if (basename.find(".png") != std::string::npos) + { + return saveToFileAsNonPMA(filename, Image::Format::PNG, isRGBA, callback); + } + else if (basename.find(".jpg") != std::string::npos) + { + if (isRGBA) CCLOG("RGBA is not supported for JPG format."); + return saveToFileAsNonPMA(filename, Image::Format::JPG, false, callback); + } + else + { + CCLOG("Only PNG and JPG format are supported now!"); + } + + return saveToFileAsNonPMA(filename, Image::Format::JPG, false, callback); +} + bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::function callback) { std::string basename(filename); @@ -528,6 +550,22 @@ bool RenderTexture::saveToFile(const std::string& filename, bool isRGBA, std::fu return saveToFile(filename, Image::Format::JPG, false, callback); } +bool RenderTexture::saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback) +{ + CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, + "the image can only be saved as JPG or PNG format"); + if (isRGBA && format == Image::Format::JPG) CCLOG("RGBA is not supported for JPG format"); + + _saveFileCallback = callback; + + std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; + _saveToFileCommand.init(_globalZOrder); + _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile, this, fullpath, isRGBA, true); + + Director::getInstance()->getRenderer()->addCommand(&_saveToFileCommand); + return true; +} + bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback) { CCASSERT(format == Image::Format::JPG || format == Image::Format::PNG, @@ -538,17 +576,21 @@ bool RenderTexture::saveToFile(const std::string& fileName, Image::Format format std::string fullpath = FileUtils::getInstance()->getWritablePath() + fileName; _saveToFileCommand.init(_globalZOrder); - _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile, this, fullpath, isRGBA); + _saveToFileCommand.func = CC_CALLBACK_0(RenderTexture::onSaveToFile, this, fullpath, isRGBA, false); Director::getInstance()->getRenderer()->addCommand(&_saveToFileCommand); return true; } -void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA) +void RenderTexture::onSaveToFile(const std::string& filename, bool isRGBA, bool forceNonPMA) { Image *image = newImage(true); if (image) { + if (forceNonPMA && image->hasPremultipliedAlpha()) + { + image->reversePremultipliedAlpha(); + } image->saveToFile(filename, !isRGBA); } if(_saveFileCallback) @@ -620,11 +662,11 @@ Image* RenderTexture::newImage(bool flipImage) savedBufferWidth * 4); } - image->initWithRawData(buffer, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8); + image->initWithRawData(buffer, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, true); } else { - image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8); + image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, true); } } while (0); diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index 03a27ab334e4..771645501375 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -151,6 +151,17 @@ class CC_DLL RenderTexture : public Node CC_DEPRECATED_ATTRIBUTE Image* newCCImage(bool flipImage = true) { return newImage(flipImage); }; + /** Saves the texture into a file using JPEG format. The file will be saved in the Documents folder. + * Returns true if the operation is successful. + * + * @param filename The file name. + * @param isRGBA The file is RGBA or not. + * @param callback When the file is save finished,it will callback this function. + * @return Returns true if the operation is successful. + */ + bool saveToFileAsNonPMA(const std::string& filename, bool isRGBA = true, std::function callback = nullptr); + + /** Saves the texture into a file using JPEG format. The file will be saved in the Documents folder. * Returns true if the operation is successful. * @@ -161,6 +172,20 @@ class CC_DLL RenderTexture : public Node */ bool saveToFile(const std::string& filename, bool isRGBA = true, std::function callback = nullptr); + /** saves the texture into a file in non-PMA. The format could be JPG or PNG. The file will be saved in the Documents folder. + Returns true if the operation is successful. + * Notes: since v3.x, saveToFile will generate a custom command, which will be called in the following render->render(). + * So if this function is called in a event handler, the actual save file will be called in the next frame. If we switch to a different scene, the game will crash. + * To solve this, add Director::getInstance()->getRenderer()->render(); after this function. + * + * @param filename The file name. + * @param format The image format. + * @param isRGBA The file is RGBA or not. + * @param callback When the file is save finished,it will callback this function. + * @return Returns true if the operation is successful. + */ + bool saveToFileAsNonPMA(const std::string& fileName, Image::Format format, bool isRGBA, std::function callback); + /** saves the texture into a file. The format could be JPG or PNG. The file will be saved in the Documents folder. Returns true if the operation is successful. * Notes: since v3.x, saveToFile will generate a custom command, which will be called in the following render->render(). @@ -363,7 +388,7 @@ class CC_DLL RenderTexture : public Node void onClear(); void onClearDepth(); - void onSaveToFile(const std::string& fileName, bool isRGBA = true); + void onSaveToFile(const std::string& fileName, bool isRGBA = true, bool forceNonPMA = false); void setupDepthAndStencil(int powW, int powH); diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 1ffb8e743462..eb01683400c0 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -1149,7 +1149,7 @@ bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) { if (PNG_PREMULTIPLIED_ALPHA_ENABLED) { - premultipliedAlpha(); + premultiplyAlpha(); } else { @@ -2454,7 +2454,7 @@ bool Image::saveImageToJPG(const std::string& filePath) #endif // CC_USE_JPEG } -void Image::premultipliedAlpha() +void Image::premultiplyAlpha() { #if CC_ENABLE_PREMULTIPLIED_ALPHA == 0 _hasPremultipliedAlpha = false; @@ -2473,6 +2473,29 @@ void Image::premultipliedAlpha() #endif } +static inline unsigned char clamp(int x) { + return (unsigned char)(x >= 0 ? (x < 255 ? x : 255) : 0); +} + +void Image::reversePremultipliedAlpha() +{ + CCASSERT(_renderFormat == Texture2D::PixelFormat::RGBA8888, "The pixel format should be RGBA8888!"); + + unsigned int* fourBytes = (unsigned int*)_data; + for (int i = 0; i < _width * _height; i++) + { + unsigned char* p = _data + i * 4; + if (p[3] > 0) + { + fourBytes[i] = clamp(int(std::ceil((p[0] * 255.0f) / p[3]))) | + clamp(int(std::ceil((p[1] * 255.0f) / p[3]))) << 8 | + clamp(int(std::ceil((p[2] * 255.0f) / p[3]))) << 16 | + p[3] << 24; + } + } + + _hasPremultipliedAlpha = false; +} void Image::setPVRImagesHavePremultipliedAlpha(bool haveAlphaPremultiplied) { diff --git a/cocos/platform/CCImage.h b/cocos/platform/CCImage.h index 6a7cebf20a53..a864944905fb 100644 --- a/cocos/platform/CCImage.h +++ b/cocos/platform/CCImage.h @@ -160,6 +160,8 @@ class CC_DLL Image : public Ref @param isToRGB whether the image is saved as RGB format. */ bool saveToFile(const std::string &filename, bool isToRGB = true); + void premultiplyAlpha(); + void reversePremultipliedAlpha(); protected: #if CC_USE_WIC @@ -182,8 +184,6 @@ class CC_DLL Image : public Ref bool saveImageToPNG(const std::string& filePath, bool isToRGB = true); bool saveImageToJPG(const std::string& filePath); - void premultipliedAlpha(); - protected: /** @brief Determine how many mipmaps can we have. diff --git a/cocos/platform/ios/CCImage-ios.mm b/cocos/platform/ios/CCImage-ios.mm index baad43f45aea..ac6b04ed3f0b 100644 --- a/cocos/platform/ios/CCImage-ios.mm +++ b/cocos/platform/ios/CCImage-ios.mm @@ -91,7 +91,14 @@ of this software and associated documentation files (the "Software"), to deal CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; if (saveToPNG && hasAlpha() && (! isToRGB)) { - bitmapInfo |= kCGImageAlphaPremultipliedLast; + if (_hasPremultipliedAlpha) + { + bitmapInfo |= kCGImageAlphaPremultipliedLast; + } + else + { + bitmapInfo |= kCGImageAlphaLast; + } } CGDataProviderRef provider = CGDataProviderCreateWithData(nullptr, pixels, myDataLength, nullptr); CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp index da772b0dfd55..d2775645c2e4 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.cpp @@ -62,12 +62,15 @@ RenderTextureSave::RenderTextureSave() // Save Image menu MenuItemFont::setFontSize(16); - auto item1 = MenuItemFont::create("Save Image", CC_CALLBACK_1(RenderTextureSave::saveImage, this)); - auto item2 = MenuItemFont::create("Clear", CC_CALLBACK_1(RenderTextureSave::clearImage, this)); - auto menu = Menu::create(item1, item2, nullptr); + auto item1 = MenuItemFont::create("Save Image PMA", CC_CALLBACK_1(RenderTextureSave::saveImageWithPremultipliedAlpha, this)); + auto item2 = MenuItemFont::create("Save Image Non-PMA", CC_CALLBACK_1(RenderTextureSave::saveImageWithNonPremultipliedAlpha, this)); + auto item3 = MenuItemFont::create("Add Image", CC_CALLBACK_1(RenderTextureSave::addImage, this)); + auto item4 = MenuItemFont::create("Clear to Random", CC_CALLBACK_1(RenderTextureSave::clearImage, this)); + auto item5 = MenuItemFont::create("Clear to Transparent", CC_CALLBACK_1(RenderTextureSave::clearImageTransparent, this)); + auto menu = Menu::create(item1, item2, item3, item4, item5, nullptr); this->addChild(menu); menu->alignItemsVertically(); - menu->setPosition(Vec2(VisibleRect::rightTop().x - 80, VisibleRect::rightTop().y - 30)); + menu->setPosition(Vec2(VisibleRect::rightTop().x - 80, VisibleRect::rightTop().y - 100)); } std::string RenderTextureSave::title() const @@ -80,17 +83,46 @@ std::string RenderTextureSave::subtitle() const return "Press 'Save Image' to create an snapshot of the render texture"; } -void RenderTextureSave::clearImage(cocos2d::Ref *sender) +void RenderTextureSave::clearImage(cocos2d::Ref* sender) { _target->clear(CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1(), CCRANDOM_0_1()); } -void RenderTextureSave::saveImage(cocos2d::Ref *sender) +void RenderTextureSave::clearImageTransparent(cocos2d::Ref* sender) +{ + _target->clear(0, 0, 0, 0); +} + +void RenderTextureSave::saveImageWithPremultipliedAlpha(cocos2d::Ref* sender) +{ + static int counter = 0; + + char png[20]; + sprintf(png, "image-pma-%d.png", counter); + + auto callback = [&](RenderTexture* rt, const std::string& path) + { + auto sprite = Sprite::create(path); + addChild(sprite); + sprite->setScale(0.3f); + sprite->setPosition(Vec2(40, 40)); + sprite->setRotation(counter * 3); + }; + + _target->saveToFile(png, Image::Format::PNG, true, callback); + //Add this function to avoid crash if we switch to a new scene. + Director::getInstance()->getRenderer()->render(); + CCLOG("Image saved %s", png); + + counter++; +} + +void RenderTextureSave::saveImageWithNonPremultipliedAlpha(cocos2d::Ref *sender) { static int counter = 0; char png[20]; - sprintf(png, "image-%d.png", counter); + sprintf(png, "image-no-pma-%d.png", counter); auto callback = [&](RenderTexture* rt, const std::string& path) { @@ -101,7 +133,7 @@ void RenderTextureSave::saveImage(cocos2d::Ref *sender) sprite->setRotation(counter * 3); }; - _target->saveToFile(png, Image::Format::PNG, true, callback); + _target->saveToFileAsNonPMA(png, Image::Format::PNG, true, callback); //Add this function to avoid crash if we switch to a new scene. Director::getInstance()->getRenderer()->render(); CCLOG("Image saved %s", png); @@ -109,6 +141,21 @@ void RenderTextureSave::saveImage(cocos2d::Ref *sender) counter++; } +void RenderTextureSave::addImage(cocos2d::Ref* sender) +{ + auto s = Director::getInstance()->getWinSize(); + + // begin drawing to the render texture + _target->begin(); + + Sprite* sprite = Sprite::create("Images/test-rgba1.png"); + sprite->setPosition(sprite->getContentSize().width + CCRANDOM_0_1() * (s.width - sprite->getContentSize().width), sprite->getContentSize().height + CCRANDOM_0_1() * (s.height - sprite->getContentSize().height)); + sprite->visit(); + + // finish drawing and return context back to the screen + _target->end(); +} + RenderTextureSave::~RenderTextureSave() { _target->release(); @@ -849,4 +896,4 @@ std::string RenderTextureWithSprite3DIssue16894::title() const std::string RenderTextureWithSprite3DIssue16894::subtitle() const { return "3 ships, 1st & 3rd are the same"; -} +} \ No newline at end of file diff --git a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h index 8d0940037b76..591e5ff8ff9c 100644 --- a/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h +++ b/tests/cpp-tests/Classes/RenderTextureTest/RenderTextureTest.h @@ -44,7 +44,11 @@ class RenderTextureSave : public RenderTextureTest virtual std::string subtitle() const override; void onTouchesMoved(const std::vector& touches, cocos2d::Event* event); void clearImage(cocos2d::Ref* pSender); - void saveImage(cocos2d::Ref* pSender); + void clearImageTransparent(cocos2d::Ref* sender); + void saveImageWithPremultipliedAlpha(cocos2d::Ref* pSender); + void saveImageWithNonPremultipliedAlpha(cocos2d::Ref* pSender); + + void addImage(cocos2d::Ref* sender); private: cocos2d::RenderTexture* _target; From cefdfd4366e36dcb09f594fd4bd93950b06149db Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Tue, 4 Jun 2019 16:26:53 +0800 Subject: [PATCH 05/11] [ci skip][AUTO]: updating luabinding & jsbinding & cocos_file.json automatically (#19796) --- .../js-bindings/auto/jsb_cocos2dx_auto.cpp | 34 +++ .../js-bindings/auto/jsb_cocos2dx_auto.hpp | 2 + .../lua-bindings/auto/lua_cocos2dx_auto.cpp | 208 ++++++++++++++++++ .../lua-bindings/auto/lua_cocos2dx_auto.hpp | 3 + 4 files changed, 247 insertions(+) diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp index b152e1fc1755..d58480334bb0 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.cpp @@ -9819,6 +9819,22 @@ bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval JS_ReportError(cx, "js_cocos2dx_Image_hasPremultipliedAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Image_reversePremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_reversePremultipliedAlpha : Invalid Native Object"); + if (argc == 0) { + cobj->reversePremultipliedAlpha(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_reversePremultipliedAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -9925,6 +9941,22 @@ bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp) JS_ReportError(cx, "js_cocos2dx_Image_getHeight : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_Image_premultiplyAlpha(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); + js_proxy_t *proxy = jsb_get_js_proxy(obj); + cocos2d::Image* cobj = (cocos2d::Image *)(proxy ? proxy->ptr : NULL); + JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_Image_premultiplyAlpha : Invalid Native Object"); + if (argc == 0) { + cobj->premultiplyAlpha(); + args.rval().setUndefined(); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_Image_premultiplyAlpha : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -10210,11 +10242,13 @@ void js_register_cocos2dx_Image(JSContext *cx, JS::HandleObject global) { static JSFunctionSpec funcs[] = { JS_FN("hasPremultipliedAlpha", js_cocos2dx_Image_hasPremultipliedAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("reversePremultipliedAlpha", js_cocos2dx_Image_reversePremultipliedAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getDataLen", js_cocos2dx_Image_getDataLen, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("saveToFile", js_cocos2dx_Image_saveToFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("hasAlpha", js_cocos2dx_Image_hasAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isCompressed", js_cocos2dx_Image_isCompressed, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getHeight", js_cocos2dx_Image_getHeight, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("premultiplyAlpha", js_cocos2dx_Image_premultiplyAlpha, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("initWithImageFile", js_cocos2dx_Image_initWithImageFile, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getWidth", js_cocos2dx_Image_getWidth, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("getBitPerPixel", js_cocos2dx_Image_getBitPerPixel, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), diff --git a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp index 699ae481122c..0f9f2d57e3fe 100644 --- a/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp +++ b/cocos/scripting/js-bindings/auto/jsb_cocos2dx_auto.hpp @@ -523,11 +523,13 @@ void js_cocos2dx_Image_finalize(JSContext *cx, JSObject *obj); void js_register_cocos2dx_Image(JSContext *cx, JS::HandleObject global); void register_all_cocos2dx(JSContext* cx, JS::HandleObject obj); bool js_cocos2dx_Image_hasPremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_reversePremultipliedAlpha(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_getDataLen(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_saveToFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_hasAlpha(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_isCompressed(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_getHeight(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_Image_premultiplyAlpha(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_initWithImageFile(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_getWidth(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_Image_getBitPerPixel(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp index ed33ed98faea..414fd292f96f 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.cpp @@ -19918,6 +19918,53 @@ int lua_cocos2dx_Image_hasPremultipliedAlpha(lua_State* tolua_S) return 0; } +int lua_cocos2dx_Image_reversePremultipliedAlpha(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Image* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Image",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Image*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Image_reversePremultipliedAlpha'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Image_reversePremultipliedAlpha'", nullptr); + return 0; + } + cobj->reversePremultipliedAlpha(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Image:reversePremultipliedAlpha",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Image_reversePremultipliedAlpha'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Image_saveToFile(lua_State* tolua_S) { int argc = 0; @@ -20126,6 +20173,53 @@ int lua_cocos2dx_Image_getHeight(lua_State* tolua_S) return 0; } +int lua_cocos2dx_Image_premultiplyAlpha(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::Image* cobj = nullptr; + bool ok = true; + +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.Image",0,&tolua_err)) goto tolua_lerror; +#endif + + cobj = (cocos2d::Image*)tolua_tousertype(tolua_S,1,0); + +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_Image_premultiplyAlpha'", nullptr); + return 0; + } +#endif + + argc = lua_gettop(tolua_S)-1; + if (argc == 0) + { + if(!ok) + { + tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_Image_premultiplyAlpha'", nullptr); + return 0; + } + cobj->premultiplyAlpha(); + lua_settop(tolua_S, 1); + return 1; + } + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Image:premultiplyAlpha",argc, 0); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_Image_premultiplyAlpha'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_Image_initWithImageFile(lua_State* tolua_S) { int argc = 0; @@ -20581,10 +20675,12 @@ int lua_register_cocos2dx_Image(lua_State* tolua_S) tolua_beginmodule(tolua_S,"Image"); tolua_function(tolua_S,"new",lua_cocos2dx_Image_constructor); tolua_function(tolua_S,"hasPremultipliedAlpha",lua_cocos2dx_Image_hasPremultipliedAlpha); + tolua_function(tolua_S,"reversePremultipliedAlpha",lua_cocos2dx_Image_reversePremultipliedAlpha); tolua_function(tolua_S,"saveToFile",lua_cocos2dx_Image_saveToFile); tolua_function(tolua_S,"hasAlpha",lua_cocos2dx_Image_hasAlpha); tolua_function(tolua_S,"isCompressed",lua_cocos2dx_Image_isCompressed); tolua_function(tolua_S,"getHeight",lua_cocos2dx_Image_getHeight); + tolua_function(tolua_S,"premultiplyAlpha",lua_cocos2dx_Image_premultiplyAlpha); tolua_function(tolua_S,"initWithImageFile",lua_cocos2dx_Image_initWithImageFile); tolua_function(tolua_S,"getWidth",lua_cocos2dx_Image_getWidth); tolua_function(tolua_S,"getBitPerPixel",lua_cocos2dx_Image_getBitPerPixel); @@ -78809,6 +78905,117 @@ int lua_cocos2dx_RenderTexture_isAutoDraw(lua_State* tolua_S) return 0; } +int lua_cocos2dx_RenderTexture_saveToFileAsNonPMA(lua_State* tolua_S) +{ + int argc = 0; + cocos2d::RenderTexture* cobj = nullptr; + bool ok = true; +#if COCOS2D_DEBUG >= 1 + tolua_Error tolua_err; +#endif + +#if COCOS2D_DEBUG >= 1 + if (!tolua_isusertype(tolua_S,1,"cc.RenderTexture",0,&tolua_err)) goto tolua_lerror; +#endif + cobj = (cocos2d::RenderTexture*)tolua_tousertype(tolua_S,1,0); +#if COCOS2D_DEBUG >= 1 + if (!cobj) + { + tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_RenderTexture_saveToFileAsNonPMA'", nullptr); + return 0; + } +#endif + argc = lua_gettop(tolua_S)-1; + do{ + if (argc == 4) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + cocos2d::Image::Format arg1; + ok &= luaval_to_int32(tolua_S, 3,(int *)&arg1, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + bool arg2; + ok &= luaval_to_boolean(tolua_S, 4,&arg2, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + std::function arg3; + do { + // Lambda binding for lua is not supported. + assert(false); + } while(0) + ; + + if (!ok) { break; } + bool ret = cobj->saveToFileAsNonPMA(arg0, arg1, arg2, arg3); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + do{ + if (argc == 1) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + bool ret = cobj->saveToFileAsNonPMA(arg0); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + do{ + if (argc == 2) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + bool arg1; + ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + bool ret = cobj->saveToFileAsNonPMA(arg0, arg1); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + do{ + if (argc == 3) { + std::string arg0; + ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + bool arg1; + ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.RenderTexture:saveToFileAsNonPMA"); + + if (!ok) { break; } + std::function arg2; + do { + // Lambda binding for lua is not supported. + assert(false); + } while(0) + ; + + if (!ok) { break; } + bool ret = cobj->saveToFileAsNonPMA(arg0, arg1, arg2); + tolua_pushboolean(tolua_S,(bool)ret); + return 1; + } + }while(0); + ok = true; + luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.RenderTexture:saveToFileAsNonPMA",argc, 1); + return 0; + +#if COCOS2D_DEBUG >= 1 + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_RenderTexture_saveToFileAsNonPMA'.",&tolua_err); +#endif + + return 0; +} int lua_cocos2dx_RenderTexture_setKeepMatrix(lua_State* tolua_S) { int argc = 0; @@ -79891,6 +80098,7 @@ int lua_register_cocos2dx_RenderTexture(lua_State* tolua_S) tolua_function(tolua_S,"setSprite",lua_cocos2dx_RenderTexture_setSprite); tolua_function(tolua_S,"getSprite",lua_cocos2dx_RenderTexture_getSprite); tolua_function(tolua_S,"isAutoDraw",lua_cocos2dx_RenderTexture_isAutoDraw); + tolua_function(tolua_S,"saveToFileAsNonPMA",lua_cocos2dx_RenderTexture_saveToFileAsNonPMA); tolua_function(tolua_S,"setKeepMatrix",lua_cocos2dx_RenderTexture_setKeepMatrix); tolua_function(tolua_S,"setClearFlags",lua_cocos2dx_RenderTexture_setClearFlags); tolua_function(tolua_S,"begin",lua_cocos2dx_RenderTexture_begin); diff --git a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp index 5a4c8cc2dceb..4f5721688239 100644 --- a/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp +++ b/cocos/scripting/lua-bindings/auto/lua_cocos2dx_auto.hpp @@ -2294,6 +2294,9 @@ int register_all_cocos2dx(lua_State* tolua_S); + + + From 6af14cd68a79bd2f158b4bc63668ac84c45e4635 Mon Sep 17 00:00:00 2001 From: Arnold <40414978+PatriceJiang@users.noreply.github.com> Date: Tue, 4 Jun 2019 18:13:14 +0800 Subject: [PATCH 06/11] skip shapes of 0 area in processTriangles (#19791) --- cocos/2d/CCDrawNode.cpp | 188 +++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 87 deletions(-) diff --git a/cocos/2d/CCDrawNode.cpp b/cocos/2d/CCDrawNode.cpp index 446b92b2b055..6dc5dbce2ef3 100644 --- a/cocos/2d/CCDrawNode.cpp +++ b/cocos/2d/CCDrawNode.cpp @@ -127,11 +127,11 @@ bool Triangulate::isInsideTriangle(float Ax, float Ay, apx= Px - Ax; apy= Py - Ay; bpx= Px - Bx; bpy= Py - By; cpx= Px - Cx; cpy= Py - Cy; - + aCROSSbp = ax*bpy - ay*bpx; cCROSSap = cx*apy - cy*apx; bCROSScp = bx*cpy - by*cpx; - + return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f)); } @@ -139,18 +139,18 @@ bool Triangulate::checkSnip(const Vec2 *verts,int u,int v,int w,int n,int *V) { int p; float Ax, Ay, Bx, By, Cx, Cy, Px, Py; - + Ax = verts[V[u]].x; Ay = verts[V[u]].y; - + Bx = verts[V[v]].x; By = verts[V[v]].y; - + Cx = verts[V[w]].x; Cy = verts[V[w]].y; - + if ( EPSILON > (((Bx-Ax)*(Cy-Ay)) - ((By-Ay)*(Cx-Ax))) ) return false; - + for (p=0;p V(n); /* we want a counter-clockwise polygon in V */ if ( 0.0f < computeArea(verts,n) ) + { for (int v=0; vsupportsShareableVAO()) { GL::bindVAO(0); @@ -267,14 +281,14 @@ DrawNode* DrawNode::create(GLfloat defaultLineWidth) { CC_SAFE_DELETE(ret); } - + return ret; } void DrawNode::ensureCapacity(int count) { CCASSERT(count>=0, "capacity must be >= 0"); - + if(_bufferCount + count > _bufferCapacity) { _bufferCapacity += MAX(_bufferCapacity, count); @@ -285,7 +299,7 @@ void DrawNode::ensureCapacity(int count) void DrawNode::ensureCapacityGLPoint(int count) { CCASSERT(count>=0, "capacity must be >= 0"); - + if(_bufferCountGLPoint + count > _bufferCapacityGLPoint) { _bufferCapacityGLPoint += MAX(_bufferCapacityGLPoint, count); @@ -296,7 +310,7 @@ void DrawNode::ensureCapacityGLPoint(int count) void DrawNode::ensureCapacityGLLine(int count) { CCASSERT(count>=0, "capacity must be >= 0"); - + if(_bufferCountGLLine + count > _bufferCapacityGLLine) { _bufferCapacityGLLine += MAX(_bufferCapacityGLLine, count); @@ -382,16 +396,16 @@ bool DrawNode::init() _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR)); - + ensureCapacity(512); ensureCapacityGLPoint(64); ensureCapacityGLLine(256); - + setupBuffer(); - + _dirty = true; _dirtyGLLine = true; - _dirtyGLPoint = true; + _dirtyGLPoint = true; return true; } @@ -403,14 +417,14 @@ void DrawNode::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) _customCommand.func = CC_CALLBACK_0(DrawNode::onDraw, this, transform, flags); renderer->addCommand(&_customCommand); } - + if(_bufferCountGLPoint) { _customCommandGLPoint.init(_globalZOrder, transform, flags); _customCommandGLPoint.func = CC_CALLBACK_0(DrawNode::onDrawGLPoint, this, transform, flags); renderer->addCommand(&_customCommandGLPoint); } - + if(_bufferCountGLLine) { _customCommandGLLine.init(_globalZOrder, transform, flags); @@ -430,7 +444,7 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t /*flags*/) { glBindBuffer(GL_ARRAY_BUFFER, _vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacity, _buffer, GL_STREAM_DRAW); - + _dirty = false; } if (Configuration::getInstance()->supportsShareableVAO()) @@ -452,12 +466,12 @@ void DrawNode::onDraw(const Mat4 &transform, uint32_t /*flags*/) glDrawArrays(GL_TRIANGLES, 0, _bufferCount); glBindBuffer(GL_ARRAY_BUFFER, 0); - + if (Configuration::getInstance()->supportsShareableVAO()) { GL::bindVAO(0); } - + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, _bufferCount); CHECK_GL_ERROR_DEBUG(); } @@ -495,12 +509,12 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t /*flags*/) glLineWidth(_lineWidth); glDrawArrays(GL_LINES, 0, _bufferCountGLLine); - + if (Configuration::getInstance()->supportsShareableVAO()) { GL::bindVAO(0); } - + glBindBuffer(GL_ARRAY_BUFFER, 0); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLLine); @@ -520,10 +534,10 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t /*flags*/) { glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint); glBufferData(GL_ARRAY_BUFFER, sizeof(V2F_C4B_T2F)*_bufferCapacityGLPoint, _bufferGLPoint, GL_STREAM_DRAW); - + _dirtyGLPoint = false; } - + if (Configuration::getInstance()->supportsShareableVAO()) { GL::bindVAO(_vaoGLPoint); @@ -536,16 +550,16 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t /*flags*/) glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, colors)); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V2F_C4B_T2F), (GLvoid *)offsetof(V2F_C4B_T2F, texCoords)); } - + glDrawArrays(GL_POINTS, 0, _bufferCountGLPoint); - + if (Configuration::getInstance()->supportsShareableVAO()) { GL::bindVAO(0); } - + glBindBuffer(GL_ARRAY_BUFFER, 0); - + CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCountGLPoint); CHECK_GL_ERROR_DEBUG(); } @@ -553,11 +567,11 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t /*flags*/) void DrawNode::drawPoint(const Vec2& position, const float pointSize, const Color4F &color) { ensureCapacityGLPoint(1); - + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); V2F_C4B_T2F a = {position, Color4B(color), Tex2F(pointSize,0)}; *point = a; - + _bufferCountGLPoint += 1; _dirtyGLPoint = true; } @@ -570,15 +584,15 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, const float pointSize, const Color4F &color) { ensureCapacityGLPoint(numberOfPoints); - + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLPoint + _bufferCountGLPoint); - + for(unsigned int i=0; i < numberOfPoints; i++,point++) { V2F_C4B_T2F a = {position[i], Color4B(color), Tex2F(pointSize,0)}; *point = a; } - + _bufferCountGLPoint += numberOfPoints; _dirtyGLPoint = true; } @@ -586,15 +600,15 @@ void DrawNode::drawPoints(const Vec2 *position, unsigned int numberOfPoints, con void DrawNode::drawLine(const Vec2 &origin, const Vec2 &destination, const Color4F &color) { ensureCapacityGLLine(2); - + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine); - + V2F_C4B_T2F a = {origin, Color4B(color), Tex2F(0.0, 0.0)}; V2F_C4B_T2F b = {destination, Color4B(color), Tex2F(0.0, 0.0)}; - + *point = a; *(point+1) = b; - + _bufferCountGLLine += 2; _dirtyGLLine = true; } @@ -620,15 +634,15 @@ void DrawNode::drawPoly(const Vec2 *poli, unsigned int numberOfPoints, bool clos vertex_count = 2 * (numberOfPoints - 1); ensureCapacityGLLine(vertex_count); } - + V2F_C4B_T2F *point = (V2F_C4B_T2F*)(_bufferGLLine + _bufferCountGLLine); - + unsigned int i = 0; for(; icount(); - + for( unsigned int i=0; i < segments+1;i++) { - + float dt = (float)i / segments; - + // border if( dt == 1 ) { p = config->count() - 1; @@ -741,20 +755,20 @@ void DrawNode::drawCardinalSpline(PointArray *config, float tension, unsigned i p = dt / deltaT; lt = (dt - deltaT * (float)p) / deltaT; } - + // Interpolate Vec2 pp0 = config->getControlPointAtIndex(p-1); Vec2 pp1 = config->getControlPointAtIndex(p+0); Vec2 pp2 = config->getControlPointAtIndex(p+1); Vec2 pp3 = config->getControlPointAtIndex(p+2); - + Vec2 newPos = ccCardinalSplineAt( pp0, pp1, pp2, pp3, tension, lt); vertices[i].x = newPos.x; vertices[i].y = newPos.y; } - + drawPoly(vertices, segments+1, false, color); - + CC_SAFE_DELETE_ARRAY(vertices); } @@ -767,20 +781,20 @@ void DrawNode::drawDot(const Vec2 &pos, float radius, const Color4F &color) { unsigned int vertex_count = 2*3; ensureCapacity(vertex_count); - + V2F_C4B_T2F a = {Vec2(pos.x - radius, pos.y - radius), Color4B(color), Tex2F(-1.0, -1.0) }; V2F_C4B_T2F b = {Vec2(pos.x - radius, pos.y + radius), Color4B(color), Tex2F(-1.0, 1.0) }; V2F_C4B_T2F c = {Vec2(pos.x + radius, pos.y + radius), Color4B(color), Tex2F( 1.0, 1.0) }; V2F_C4B_T2F d = {Vec2(pos.x + radius, pos.y - radius), Color4B(color), Tex2F( 1.0, -1.0) }; - + V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount); V2F_C4B_T2F_Triangle triangle0 = {a, b, c}; V2F_C4B_T2F_Triangle triangle1 = {a, c, d}; triangles[0] = triangle0; triangles[1] = triangle1; - + _bufferCount += vertex_count; - + _dirty = true; } @@ -796,14 +810,14 @@ void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const { unsigned int vertex_count = 6*3; ensureCapacity(vertex_count); - + Vec2 a = __v2f(from); Vec2 b = __v2f(to); - - + + Vec2 n = v2fnormalize(v2fperp(v2fsub(b, a))); Vec2 t = v2fperp(n); - + Vec2 nw = v2fmult(n, radius); Vec2 tw = v2fmult(t, radius); Vec2 v0 = v2fsub(b, v2fadd(nw, tw)); @@ -814,24 +828,24 @@ void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const Vec2 v5 = v2fadd(a, nw); Vec2 v6 = v2fsub(a, v2fsub(nw, tw)); Vec2 v7 = v2fadd(a, v2fadd(nw, tw)); - - + + V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount); - + V2F_C4B_T2F_Triangle triangles0 = { {v0, Color4B(color), __t(v2fneg(v2fadd(n, t)))}, {v1, Color4B(color), __t(v2fsub(n, t))}, {v2, Color4B(color), __t(v2fneg(n))}, }; triangles[0] = triangles0; - + V2F_C4B_T2F_Triangle triangles1 = { {v3, Color4B(color), __t(n)}, {v1, Color4B(color), __t(v2fsub(n, t))}, {v2, Color4B(color), __t(v2fneg(n))}, }; triangles[1] = triangles1; - + V2F_C4B_T2F_Triangle triangles2 = { {v3, Color4B(color), __t(n)}, {v4, Color4B(color), __t(v2fneg(n))}, @@ -859,25 +873,25 @@ void DrawNode::drawSegment(const Vec2 &from, const Vec2 &to, float radius, const {v5, Color4B(color), __t(n)}, }; triangles[5] = triangles5; - + _bufferCount += vertex_count; - + _dirty = true; } void DrawNode::drawPolygon(const Vec2 *verts, int count, const Color4F &fillColor, float borderWidth, const Color4F &borderColor) { CCASSERT(count >= 0, "invalid count value"); - + bool outline = (borderColor.a > 0.0f && borderWidth > 0.0f); - + auto triangle_count = outline ? (3*count - 2) : (count - 2); auto vertex_count = 3*triangle_count; ensureCapacity(vertex_count); - + V2F_C4B_T2F_Triangle *triangles = (V2F_C4B_T2F_Triangle *)(_buffer + _bufferCount); V2F_C4B_T2F_Triangle *cursor = triangles; - + cursor = Triangulate::processTriangles(verts,cursor,count,fillColor); if(outline) From 0cb62f669b2a03c73cda15b2461c39d2efaff2b2 Mon Sep 17 00:00:00 2001 From: WangHe Date: Wed, 5 Jun 2019 09:30:40 +0800 Subject: [PATCH 07/11] [Android]Override removeDirectory function in FileUtilsAndroid, fix "rm not found" error on OPPO ColorOS (#19790) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Override removeDirectory function in FileUtilsAndroid,use JRE method instead of "rm -r path". Because We found that on OPPO's ColorOS, the environment variable PATH may not always correct, it could be ":/sbin" sometimes, then cause an error "rm not found", afterwards the directory could not be deleted。 * omitted variable while call removeDirectoryJNI * rename RemoveDirectory->renameDirectory obey the coding rule * rename childFile to childrenFile --- .../platform/android/CCFileUtils-android.cpp | 8 +++++ cocos/platform/android/CCFileUtils-android.h | 2 ++ .../src/org/cocos2dx/lib/Cocos2dxHelper.java | 33 +++++++++++++++++++ .../Java_org_cocos2dx_lib_Cocos2dxHelper.cpp | 18 ++++++++++ .../Java_org_cocos2dx_lib_Cocos2dxHelper.h | 1 + 5 files changed, 62 insertions(+) diff --git a/cocos/platform/android/CCFileUtils-android.cpp b/cocos/platform/android/CCFileUtils-android.cpp index 5c7da21a7c91..c895288d4400 100644 --- a/cocos/platform/android/CCFileUtils-android.cpp +++ b/cocos/platform/android/CCFileUtils-android.cpp @@ -344,6 +344,14 @@ std::vector FileUtilsAndroid::listFiles(const std::string& dirPath) return fileList; } +bool FileUtilsAndroid::removeDirectory(const std::string& path) const +{ + if (path.empty()) + return false; + + return removeDirectoryJNI(path.c_str()); +} + FileUtils::Status FileUtilsAndroid::getContents(const std::string& filename, ResizableBuffer* buffer) const { static const std::string apkprefix("assets/"); diff --git a/cocos/platform/android/CCFileUtils-android.h b/cocos/platform/android/CCFileUtils-android.h index 2153199b18ef..601e799b01f4 100644 --- a/cocos/platform/android/CCFileUtils-android.h +++ b/cocos/platform/android/CCFileUtils-android.h @@ -76,6 +76,8 @@ class CC_DLL FileUtilsAndroid : public FileUtils virtual long getFileSize(const std::string& filepath) const override; virtual std::vector listFiles(const std::string& dirPath) const override; + + virtual bool removeDirectory(const std::string& dirPath) const override; private: virtual bool isFileExistInternal(const std::string& strFilePath) const override; virtual bool isDirectoryExistInternal(const std::string& dirPath) const override; diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java index a86c566a2585..f25b8c17d12f 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxHelper.java @@ -207,6 +207,39 @@ public boolean accept(File dir, String name) { return Cocos2dxHelper.sAssetsPath; } + + //remove directory + public static boolean removeDirectory(final String directory) + { + try{ + File file = new File(directory); + recursionDeleteFile(file); + return true; + }catch(Exception ex){ + ex.printStackTrace(); + return false; + } + } + + + private static void recursionDeleteFile(File file) + { + if (file.isFile()) { + file.delete(); + return; + } + if (file.isDirectory()) { + File[] childrenFile = file.listFiles(); + if (childrenFile == null || childrenFile.length == 0) { + file.delete(); + return; + } + for (File f : childrenFile) { + recursionDeleteFile(f); + } + file.delete(); + } + } public static ZipResourceFile getObbFile() { if (null == sOBBFile) { diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp index c2cc9ed5257f..7de22dc8d0a4 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.cpp @@ -154,3 +154,21 @@ void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharse methodInfo.env->DeleteLocalRef(methodInfo.classID); } } + + +bool removeDirectoryJNI(const char* path) +{ + JniMethodInfo methodInfo; + if (JniHelper::getStaticMethodInfo(methodInfo,className.c_str(),"removeDirectory","(Ljava/lang/String;)Z")) + { + jstring stringArgPath = methodInfo.env->NewStringUTF(path); + jboolean suc = methodInfo.env->CallStaticBooleanMethod(methodInfo.classID,methodInfo.methodID,stringArgPath); + + methodInfo.env->DeleteLocalRef(methodInfo.classID); + methodInfo.env->DeleteLocalRef(stringArgPath); + + return suc; + } + + return false; +} \ No newline at end of file diff --git a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h index ef146c2f6094..18c4f6b2d556 100644 --- a/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h +++ b/cocos/platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h @@ -34,6 +34,7 @@ extern const char * getApkPath(); extern std::string getPackageNameJNI(); extern int getObbAssetFileDescriptorJNI(const char* path, long* startOffset, long* size); extern void conversionEncodingJNI(const char* src, int byteSize, const char* fromCharset, char* dst, const char* newCharset); +extern bool removeDirectoryJNI(const char* path); extern int getDeviceSampleRate(); extern int getDeviceAudioBufferSizeInFrames(); From 8addb57a09bc90a5444402a71a902f78ec19d3d9 Mon Sep 17 00:00:00 2001 From: John <3619244+JohnCoconut@users.noreply.github.com> Date: Wed, 5 Jun 2019 09:31:04 +0800 Subject: [PATCH 08/11] more clang-tidy perf options (#19783) * performance-move-constructor-init * performance-unnecessary-copy-initialization Disable warnings on RefPtr refcount test case. --- .clang-tidy | 2 ++ cocos/2d/CCFontAtlasCache.cpp | 2 +- cocos/3d/CCSprite3D.cpp | 4 ++-- cocos/base/CCProperties.cpp | 2 +- .../ActionTimeline/CCActionTimelineCache.cpp | 6 +++--- .../cocostudio/ActionTimeline/CSLoader.cpp | 6 +++--- cocos/physics3d/CCPhysics3D.cpp | 2 +- .../manual/cocostudio/jsb_cocos2dx_studio_manual.cpp | 2 +- .../js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp | 2 +- .../cocostudio/lua_cocos2dx_coco_studio_manual.cpp | 4 ++-- cocos/ui/UILayoutManager.cpp | 2 +- extensions/assets-manager/Manifest.cpp | 2 +- tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp | 2 +- .../Classes/SpritePolygonTest/SpritePolygonTest.cpp | 2 +- .../UIListViewTest/UIListViewTest.cpp | 2 +- .../UIPageViewTest/UIPageViewTest.cpp | 10 +++++----- .../UIScrollViewTest/UIScrollViewTest.cpp | 2 +- tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp | 4 ++-- 18 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 7bcba1fc7020..239e21fbb15e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,7 +7,9 @@ Checks: > performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, + performance-move-constructor-init, performance-type-promotion-in-math-fn, + performance-unnecessary-copy-initialization, readability-container-size-empty, readability-delete-null-pointer, readability-redundant-control-flow, diff --git a/cocos/2d/CCFontAtlasCache.cpp b/cocos/2d/CCFontAtlasCache.cpp index 1c7128d01c76..b4e944b576f5 100644 --- a/cocos/2d/CCFontAtlasCache.cpp +++ b/cocos/2d/CCFontAtlasCache.cpp @@ -119,7 +119,7 @@ FontAtlas* FontAtlasCache::getFontAtlasFNT(const std::string& fontFileName, cons FontAtlas* FontAtlasCache::getFontAtlasCharMap(const std::string& plistFile) { - std::string atlasName = plistFile; + const std::string& atlasName = plistFile; auto it = _atlasMap.find(atlasName); if ( it == _atlasMap.end() ) diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index b9f807c40ee2..fd04cef0962e 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -776,7 +776,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) // Don't override GLProgramState if using manually set Material if (_usingAutogeneratedGLProgram && scene) { - const auto lights = scene->getLights(); + const auto& lights = scene->getLights(); bool usingLight = false; for (const auto light : lights) { usingLight = light->isEnabled() && ((static_cast(light->getLightFlag()) & _lightMask) > 0); @@ -851,7 +851,7 @@ const AABB& Sprite3D::getAABB() const _aabb.reset(); if (!_meshes.empty()) { - Mat4 transform(nodeToWorldTransform); + const Mat4& transform(nodeToWorldTransform); for (const auto& it : _meshes) { if (it->isVisible()) _aabb.merge(it->getAABB()); diff --git a/cocos/base/CCProperties.cpp b/cocos/base/CCProperties.cpp index 93ec762ab0d0..522f72ea9216 100644 --- a/cocos/base/CCProperties.cpp +++ b/cocos/base/CCProperties.cpp @@ -95,7 +95,7 @@ Properties* Properties::createNonRefCounted(const std::string& url) } // Calculate the file and full namespace path from the specified url. - std::string urlString = url; + const std::string& urlString = url; std::string fileString; std::vector namespacePath; calculateNamespacePath(urlString, fileString, namespacePath); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp index 41405eb11e49..119a0d2e1221 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CCActionTimelineCache.cpp @@ -135,7 +135,7 @@ void ActionTimelineCache::removeAction(const std::string& fileName) ActionTimeline* ActionTimelineCache::createAction(const std::string& filename) { - std::string path = filename; + const std::string& path = filename; size_t pos = path.find_last_of('.'); std::string suffix = path.substr(pos + 1, path.length()); @@ -440,7 +440,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(cons if (action) return action; - std::string path = fileName; + const std::string& path = fileName; std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); @@ -460,7 +460,7 @@ ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d:: if (action) return action; - std::string path = fileName; + const std::string& path = fileName; std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName); diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index 472eda3259ee..f26db5b14506 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -270,7 +270,7 @@ void CSLoader::init() Node* CSLoader::createNode(const std::string& filename) { - std::string path = filename; + const std::string& path = filename; size_t pos = path.find_last_of('.'); std::string suffix = path.substr(pos + 1, path.length()); @@ -290,7 +290,7 @@ Node* CSLoader::createNode(const std::string& filename) Node* CSLoader::createNode(const std::string &filename, const ccNodeLoadCallback &callback) { - std::string path = filename; + const std::string& path = filename; size_t pos = path.find_last_of('.'); std::string suffix = path.substr(pos + 1, path.length()); @@ -330,7 +330,7 @@ Node* CSLoader::createNodeWithVisibleSize(const std::string &filename, const ccN std::string CSLoader::getExtentionName(const std::string& name) { - std::string path = name; + const std::string& path = name; size_t pos = path.find_last_of('.'); std::string result = path.substr(pos + 1, path.length()); diff --git a/cocos/physics3d/CCPhysics3D.cpp b/cocos/physics3d/CCPhysics3D.cpp index 6002a8337782..c710062eaa3f 100644 --- a/cocos/physics3d/CCPhysics3D.cpp +++ b/cocos/physics3d/CCPhysics3D.cpp @@ -56,7 +56,7 @@ btVector3 convertVec3TobtVector3( const cocos2d::Vec3 &vec3 ) cocos2d::Mat4 convertbtTransformToMat4( const btTransform &btTrans ) { cocos2d::Mat4 mat; - auto rot = btTrans.getBasis(); + const auto& rot = btTrans.getBasis(); auto row = rot.getRow(0); mat.m[0] = row.getX(); mat.m[4] = row.getY(); diff --git a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp index 36dd000539ee..a71989294fbb 100644 --- a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -375,7 +375,7 @@ static bool js_cocos2dx_studio_Frame_getEasingParams(JSContext *cx, uint32_t arg JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if(argc == 0) { - const std::vector ret = cobj->getEasingParams(); + const std::vector& ret = cobj->getEasingParams(); JS::RootedObject jsobj(cx, JS_NewArrayObject(cx, ret.size())); bool ok = true; diff --git a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp index d2ee206be89d..fdfdb03f9677 100755 --- a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp @@ -149,7 +149,7 @@ class JSB_EditBoxDelegate jsval dataVal[2]; dataVal[0] = OBJECT_TO_JSVAL(p->obj); - std::string arg1 = text; + const std::string& arg1 = text; dataVal[1] = std_string_to_jsval(cx, arg1); JS::RootedValue delegateVal(cx, _JSDelegate); diff --git a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp index 925bb5b68895..cbbfd6b5c974 100644 --- a/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocostudio/lua_cocos2dx_coco_studio_manual.cpp @@ -115,7 +115,7 @@ static int lua_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(lua_State* L) if (0 != handler) { - std::string strMovementID = movementID; + const std::string& strMovementID = movementID; LuaArmatureMovementEventData movementData(armature,(int)movementType, strMovementID); LuaArmatureWrapperEventData wrapperData(LuaArmatureWrapperEventData::LuaArmatureWrapperEventType::MOVEMENT_EVENT , (void*)&movementData); @@ -185,7 +185,7 @@ static int lua_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(lua_State* L) if (0 != handler) { - std::string strFrameEventName(frameEventName); + const std::string& strFrameEventName(frameEventName); LuaArmatureFrameEventData frameData(bone,frameEventName,originFrameIndex,currentFrameIndex); diff --git a/cocos/ui/UILayoutManager.cpp b/cocos/ui/UILayoutManager.cpp index 03f7b5dbe151..6863a8fdcf54 100644 --- a/cocos/ui/UILayoutManager.cpp +++ b/cocos/ui/UILayoutManager.cpp @@ -183,7 +183,7 @@ Widget* RelativeLayoutManager::getRelativeWidget(Widget* widget) { Widget* relativeWidget = nullptr; RelativeLayoutParameter* layoutParameter = dynamic_cast(widget->getLayoutParameter()); - const std::string relativeName = layoutParameter->getRelativeToWidgetName(); + const std::string& relativeName = layoutParameter->getRelativeToWidgetName(); if (!relativeName.empty()) { diff --git a/extensions/assets-manager/Manifest.cpp b/extensions/assets-manager/Manifest.cpp index 2e2dc890afbd..b7ac284c5bd4 100644 --- a/extensions/assets-manager/Manifest.cpp +++ b/extensions/assets-manager/Manifest.cpp @@ -183,7 +183,7 @@ bool Manifest::versionEquals(const Manifest *b) const bool Manifest::versionGreater(const Manifest *b, const std::function& handle) const { std::string localVersion = getVersion(); - std::string bVersion = b->getVersion(); + const std::string& bVersion = b->getVersion(); bool greater; if (handle) { diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index cd55a0d40aa4..1bb4b9485568 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -1634,7 +1634,7 @@ void Sprite3DWithOBBPerformanceTest::calculateRayByLocationInView(Ray* ray, cons { auto dir = Director::getInstance(); auto view = dir->getWinSize(); - auto mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); + const auto& mat = dir->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Vec3 src = Vec3(location.x, location.y, -1); Vec3 nearPoint; diff --git a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp index 3bd7714dae73..0be8bbdc8e2b 100644 --- a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp +++ b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp @@ -345,7 +345,7 @@ void SpritePolygonTestSlider::changeEpsilon(cocos2d::Ref *pSender, cocos2d::ui:: void SpritePolygonTestSlider::updateLabel(const cocos2d::Sprite *sp, const PolygonInfo &pinfo) { Label *label = (Label*)(sp->getChildByName(sp->getName())); - auto filename = sp->getName(); + const auto& filename = sp->getName(); auto size = pinfo.getRect().size/Director::getInstance()->getContentScaleFactor(); label->setString(filename+"\nVerts: "+Value((int)pinfo.getVertCount()).asString()+ "\nPixels: "+Value((int)(pinfo.getArea()/(size.width*size.height)*100)).asString()+"%"); } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp index 9011512ef84c..485d30f1123c 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIListViewTest/UIListViewTest.cpp @@ -84,7 +84,7 @@ bool UIListViewTest_Vertical::init() Layout* root = static_cast(_uiLayer->getChildByTag(81)); Layout* background = dynamic_cast(root->getChildByName("background_Panel")); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); // create list view ex data diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp index ef8dc8588ecd..8ce156c49edc 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIPageViewTest/UIPageViewTest.cpp @@ -81,7 +81,7 @@ bool UIPageViewTest::init() PageView* pageView = PageView::create(); pageView->setDirection(PageView::Direction::HORIZONTAL); pageView->setContentSize(size); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f); pageView->removeAllItems(); pageView->setIndicatorEnabled(true); @@ -290,7 +290,7 @@ bool UIPageViewTouchPropagationTest::init() PageView* pageView = PageView::create(); pageView->setContentSize(Size(240.0f, 130.0f)); pageView->setAnchorPoint(Vec2(0.5,0.5)); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); pageView->setPosition(Vec2(widgetSize.width / 2.0f ,widgetSize.height / 2.0f)); pageView->setBackGroundColor(Color3B::GREEN); pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID); @@ -487,7 +487,7 @@ bool UIPageViewDynamicAddAndRemoveTest::init() pageView->setDirection(ui::PageView::Direction::VERTICAL); pageView->setContentSize(Size(240.0f, 130.0f)); pageView->setAnchorPoint(Vec2(0.5,0.5)); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); pageView->setPosition(Vec2(widgetSize.width / 2.0f ,widgetSize.height / 2.0f)); pageView->setBackGroundColor(Color3B::GREEN); pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID); @@ -784,7 +784,7 @@ bool UIPageViewVerticalTest::init() pageView->setIndicatorEnabled(true); pageView->setDirection(ui::PageView::Direction::VERTICAL); pageView->setContentSize(Size(240.0f, 130.0f)); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f); pageView->removeAllItems(); @@ -948,7 +948,7 @@ bool UIPageViewChildSizeTest::init() PageView* pageView = PageView::create(); pageView->setDirection(PageView::Direction::HORIZONTAL); pageView->setContentSize(size); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); pageView->setPosition((widgetSize - pageView->getContentSize()) / 2.0f); pageView->removeAllItems(); pageView->setIndicatorEnabled(true); diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp index 450e752c13d1..480d74b78986 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIScrollViewTest/UIScrollViewTest.cpp @@ -160,7 +160,7 @@ bool UIScrollViewTest_Horizontal::init() scrollView->setInnerContainerSize(scrollView->getContentSize()); scrollView->setScrollBarPositionFromCorner(Vec2(4, 4)); scrollView->setScrollBarColor(Color3B::YELLOW); - Size backgroundSize = background->getContentSize(); + const Size& backgroundSize = background->getContentSize(); scrollView->setPosition((widgetSize - scrollView->getContentSize()) / 2.0f); _uiLayer->addChild(scrollView); diff --git a/tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp b/tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp index 2422f986a3e3..82a1244b69d5 100644 --- a/tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp +++ b/tests/cpp-tests/Classes/UnitTest/RefPtrTest.cpp @@ -47,13 +47,13 @@ void RefPtrTest::onEnter() CC_ASSERT((__String*) nullptr == ref3.get()); // Copy constructor - RefPtr<__String> ref4(ref2); + RefPtr<__String> ref4(ref2); // NOLINT(performance-unnecessary-copy-initialization) CC_ASSERT(strcmp("Hello", ref4->getCString()) == 0); CC_ASSERT(3 == ref2->getReferenceCount()); CC_ASSERT(3 == ref4->getReferenceCount()); // Copy constructor with nullptr reference - RefPtr ref5(ref1); + RefPtr ref5(ref1); // NOLINT(performance-unnecessary-copy-initialization) CC_ASSERT((Ref*) nullptr == ref5.get()); } From 8b48536088513952695ee006b65e0fbe071d2e4b Mon Sep 17 00:00:00 2001 From: John <3619244+JohnCoconut@users.noreply.github.com> Date: Thu, 6 Jun 2019 10:04:43 +0800 Subject: [PATCH 09/11] fix return value in EditBoxImpl-linux (#19798) also remove some redundant semicolon --- cocos/ui/UIEditBox/UIEditBoxImpl-linux.h | 32 ++++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cocos/ui/UIEditBox/UIEditBoxImpl-linux.h b/cocos/ui/UIEditBox/UIEditBoxImpl-linux.h index 837182a42aa4..61da3c22166b 100644 --- a/cocos/ui/UIEditBox/UIEditBoxImpl-linux.h +++ b/cocos/ui/UIEditBox/UIEditBoxImpl-linux.h @@ -56,23 +56,23 @@ class EditBoxImplLinux: public EditBoxImplCommon virtual bool isEditing() override; - virtual void createNativeControl(const Rect& frame) override {}; - virtual void setNativeFont(const char* pFontName, int fontSize) override {}; - virtual void setNativeFontColor(const Color4B& color) override {}; - virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override {}; - virtual void setNativePlaceholderFontColor(const Color4B& color) override {}; - virtual void setNativeInputMode(EditBox::InputMode inputMode) override {}; - virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override {}; - virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType)override {}; - virtual void setNativeTextHorizontalAlignment(cocos2d::TextHAlignment alignment) {}; - virtual void setNativeText(const char* pText) override {}; - virtual void setNativePlaceHolder(const char* pText) override {}; - virtual void setNativeVisible(bool visible) override {}; - virtual void updateNativeFrame(const Rect& rect) override {}; - virtual const char* getNativeDefaultFontName() override {}; + virtual void createNativeControl(const Rect& frame) override {} + virtual void setNativeFont(const char* pFontName, int fontSize) override {} + virtual void setNativeFontColor(const Color4B& color) override {} + virtual void setNativePlaceholderFont(const char* pFontName, int fontSize) override {} + virtual void setNativePlaceholderFontColor(const Color4B& color) override {} + virtual void setNativeInputMode(EditBox::InputMode inputMode) override {} + virtual void setNativeInputFlag(EditBox::InputFlag inputFlag) override {} + virtual void setNativeReturnType(EditBox::KeyboardReturnType returnType)override {} + virtual void setNativeTextHorizontalAlignment(cocos2d::TextHAlignment alignment) {} + virtual void setNativeText(const char* pText) override {} + virtual void setNativePlaceHolder(const char* pText) override {} + virtual void setNativeVisible(bool visible) override {} + virtual void updateNativeFrame(const Rect& rect) override {} + virtual const char* getNativeDefaultFontName() override { return nullptr; } virtual void nativeOpenKeyboard() override; - virtual void nativeCloseKeyboard() override {}; - virtual void setNativeMaxLength(int maxLength) override {}; + virtual void nativeCloseKeyboard() override {} + virtual void setNativeMaxLength(int maxLength) override {} private: From da1a5039ab374635d9de9618229e7a6b2126895f Mon Sep 17 00:00:00 2001 From: Takaya Kakizaki Date: Thu, 6 Jun 2019 21:56:04 +0900 Subject: [PATCH 10/11] refactor use const reference --- cocos/2d/CCFastTMXLayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index 5601fb1c509d..6c90a3a3bba4 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -152,7 +152,7 @@ void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) if( flags != 0 || _dirty || _quadsDirty || isViewProjectionUpdated) { Size s = Director::getInstance()->getVisibleSize(); - Vec2 anchor = getAnchorPoint(); + const Vec2 &anchor = getAnchorPoint(); auto rect = Rect(Camera::getVisitingCamera()->getPositionX() - s.width * anchor.x, Camera::getVisitingCamera()->getPositionY() - s.height * anchor.y, s.width, From 30414cc642bf0c5b2779fcb41cebb282f46b87b4 Mon Sep 17 00:00:00 2001 From: CHP Date: Thu, 6 Jun 2019 17:13:07 +0200 Subject: [PATCH 11/11] android_allowBackup2 --- .../android/libcocos2dx-with-controller/AndroidManifest.xml | 4 ---- cocos/platform/android/libcocos2dx/AndroidManifest.xml | 4 ---- 2 files changed, 8 deletions(-) diff --git a/cocos/platform/android/libcocos2dx-with-controller/AndroidManifest.xml b/cocos/platform/android/libcocos2dx-with-controller/AndroidManifest.xml index cc170d62a604..8daa0c3ea636 100644 --- a/cocos/platform/android/libcocos2dx-with-controller/AndroidManifest.xml +++ b/cocos/platform/android/libcocos2dx-with-controller/AndroidManifest.xml @@ -2,8 +2,4 @@ - - - - diff --git a/cocos/platform/android/libcocos2dx/AndroidManifest.xml b/cocos/platform/android/libcocos2dx/AndroidManifest.xml index cc170d62a604..8daa0c3ea636 100644 --- a/cocos/platform/android/libcocos2dx/AndroidManifest.xml +++ b/cocos/platform/android/libcocos2dx/AndroidManifest.xml @@ -2,8 +2,4 @@ - - - -