//return the loaded region, or nullptr on failure Region* RegionPagerLua::LoadRegion(int x, int y) { //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); //check if this function is available if (lua_isnil(lua, -1)) { lua_pop(lua, 1); //signal that there is no load function return nullptr; } //something to work on Region tmpRegion(x, y); lua_pushlightuserdata(lua, &tmpRegion); //call the funtion, 1 arg, 1 return if (lua_pcall(lua, 1, 1, 0) != LUA_OK) { throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); } //check the return value, success or failure if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) { lua_pop(lua, 1); //push and return the loaded region regionList.push_front(tmpRegion); return ®ionList.front(); } else { lua_pop(lua, 1); //signal a failure return nullptr; } }
//DOCS: since this method is the last ditch call from GetRegion, it must return a valid region object, even if the create function hasn't been set. //return a new region, throwing an error on failure Region* RegionPagerLua::CreateRegion(int x, int y) { if (FindRegion(x, y)) { throw(std::logic_error("Cannot overwrite an existing region")); } //get the pager's function from the registry lua_rawgeti(lua, LUA_REGISTRYINDEX, createRef); //check if this function is available if (lua_isnil(lua, -1)) { lua_pop(lua, 1); //return an empty region object regionList.emplace_front(x, y); return ®ionList.front(); } //something to work on Region tmpRegion(x, y); //TODO: add x & y as parameters lua_pushlightuserdata(lua, &tmpRegion); //call the function, 1 arg, 0 return if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); } //return the new region regionList.push_front(tmpRegion); return ®ionList.front(); }
int CBUtils::getuiClearRegion(hwc_display_contents_1_t* list, hwc_rect_t &clearWormholeRect, LayerProp *layerProp) { size_t last = list->numHwLayers - 1; hwc_rect_t fbFrame = list->hwLayers[last].displayFrame; Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom); Region wormholeRegion(fbFrameRect); if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){ wormholeRegion.set(0,0); for(size_t i = 0 ; i < last; i++) { if(((list->hwLayers[i].blending == HWC_BLENDING_NONE) && (list->hwLayers[i].planeAlpha == 0xFF)) || !(layerProp[i].mFlags & HWC_COPYBIT) || (list->hwLayers[i].flags & HWC_SKIP_HWC_COMPOSITION)) continue ; hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; Rect tmpRect(displayFrame.left,displayFrame.top, displayFrame.right,displayFrame.bottom); wormholeRegion.set(tmpRect); } }else{ for (size_t i = 0 ; i < last; i++) { // need to take care only in per pixel blending. // Restrict calculation only for copybit layers. if((list->hwLayers[i].blending != HWC_BLENDING_NONE) || (list->hwLayers[i].planeAlpha != 0xFF) || !(layerProp[i].mFlags & HWC_COPYBIT)) continue ; hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right, displayFrame.bottom); Region tmpRegion(tmpRect); wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion)); } } if(wormholeRegion.isEmpty()){ return 0; } //TO DO :- 1. remove union and call clear for each rect. Region::const_iterator it = wormholeRegion.begin(); Region::const_iterator const end = wormholeRegion.end(); while (it != end) { const Rect& r = *it++; hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom}; int dst_w = clearWormholeRect.right - clearWormholeRect.left; int dst_h = clearWormholeRect.bottom - clearWormholeRect.top; if (!(dst_w || dst_h)) clearWormholeRect = tmpWormRect; else getUnion(clearWormholeRect, tmpWormRect, clearWormholeRect); } return 1; }
bool Renderable::load(const tinyxml2::XMLElement *pElement) { pElement->QueryIntAttribute("order", &m_drawOrder); const tinyxml2::XMLElement* childElement = pElement->FirstChildElement("Texture"); if(!childElement) { CORE_WARNING("No Texture element declared in Renderable component."); return false; } // Get file name std::string textureFile = make_string(childElement->GetText()); if(textureFile.empty()) { CORE_WARNING("No texture file defined in Renderable Component"); return false; } // Trim whitespace trim(textureFile); sf::TexturePtr pTexture = TextureLocator::getObject()->get(textureFile); if(!pTexture) { CORE_ERROR("Failed to get texture: " + textureFile); return false; } TextureRegion tmpRegion(pTexture); childElement = pElement->FirstChildElement("Dimensions"); if(childElement) { pElement->QueryFloatAttribute("width", &m_width); pElement->QueryFloatAttribute("height", &m_height); setWidth(m_width != 0 ? m_width / PhysicsLocator::PixelsPerMeter.x : 0); setHeight(m_height != 0 ? m_height / PhysicsLocator::PixelsPerMeter.y : 0); } m_textureRegion = tmpRegion; return true; }