add Window.sendToBack/bringToFront

This commit is contained in:
houzh 2023-06-07 06:16:12 +00:00
parent b341b9b6a1
commit f559f2fa06
8 changed files with 81 additions and 36 deletions

View File

@ -50,7 +50,7 @@ GraphDevice::GraphDevice(int fmt){
mLastComposeTime = SystemClock::uptimeMillis();
mInvalidateRgn = Region::create();
//mInvalidateRgn = Region::create();
mComposing = 0;
mQuitFlag = false;
mShowFPS = false;
@ -77,8 +77,8 @@ HANDLE GraphDevice::getPrimarySurface()const{
}
void GraphDevice::invalidate(const Rect&r){
mInvalidateRgn->do_union((const RectangleInt&)r);
LOGD("(%d,%d,%d,%d)",r.left,r.top,r.width,r.height);
//mInvalidateRgn->do_union((const RectangleInt&)r);
LOGV("(%d,%d,%d,%d)",r.left,r.top,r.width,r.height);
}
void GraphDevice::trackFPS() {
@ -208,7 +208,7 @@ void GraphDevice::composeSurfaces(){
RefPtr<Region> rgn = wins[i]->mVisibleRgn;//winVisibleRgns[i];
HANDLE hdlSurface = wSurfaces[i]->mHandle;
if(rgn->empty())continue;
mInvalidateRgn->subtract((const RectangleInt&)rcw);
//mInvalidateRgn->subtract((const RectangleInt&)rcw);
rgn->intersect(wins[i]->mPendingRgn);/*it is already empty*/
LOGV_IF(!rgn->empty(),"surface[%d] has %d rects to compose",i,rgn->get_num_rectangles());
for(int j=0;j<rgn->get_num_rectangles();j++){
@ -285,8 +285,8 @@ void GraphDevice::composeSurfaces(){
}
GFXFillRect(mPrimarySurface,(const GFXRect*)&rd,0);
LOGD("%d:(%d,%d,%d,%d)->(%d,%d,%d,%d)",i,rc.x,rc.y,rc.width,rc.height,rd.x,rd.y,rd.width,rd.height);
}*/
mInvalidateRgn->do_xor(mInvalidateRgn);
}
mInvalidateRgn->do_xor(mInvalidateRgn);*/
if(mShowFPS && mPrimaryContext && mBannerContext){
mPrimaryContext->set_operator(Cairo::Context::Operator::SOURCE);
mPrimaryContext->set_source(mBannerContext->get_target(),0,0);

View File

@ -30,7 +30,7 @@ private:
HANDLE mPrimarySurface;
class Canvas*mPrimaryContext;
Canvas *mBannerContext;
Cairo::RefPtr<Cairo::Region>mInvalidateRgn;
//Cairo::RefPtr<Cairo::Region>mInvalidateRgn;
static GraphDevice*mInst;
GraphDevice(int format=-1);
void trackFPS();

View File

@ -74,21 +74,20 @@ Display& WindowManager::getDefaultDisplay(){
void WindowManager::addWindow(Window*win){
mWindows.push_back(win);
win->mLayer = (win->window_type<<16)||0x7FFF;
std::sort(mWindows.begin(),mWindows.end(),[](Window*w1,Window*w2){
return (w2->window_type-w1->window_type)>0;
return (w1->mLayer - w2->mLayer)>0;
});
for(int idx=0,type_idx=0;idx<mWindows.size();idx++){
Window*w = mWindows.at(idx);
if(w->window_type != mWindows[type_idx]->window_type)
type_idx=idx;
w->mLayer=w->window_type*10000+(idx-type_idx)*5;
for(int idx = 0 ;idx < mWindows.size();idx++){
Window *w = mWindows.at(idx);
w->mLayer = (w->window_type<<16)|(idx+1);
LOGV("%p window %p[%s] type=%d layer=%d",win,w,w->getText().c_str(),w->window_type,w->mLayer);
}
if(mActiveWindow)mActiveWindow->post(std::bind(&Window::onDeactive,mActiveWindow));
View::AttachInfo*info = new View::AttachInfo();
info->mContentInsets.set(5,5,5,5);
info->mContentInsets.setEmpty();
info->mRootView = win;
win->dispatchAttachedToWindow(info,win->getVisibility());
#if USE_UIEVENTHANDLER
@ -151,8 +150,8 @@ void WindowManager::moveWindow(Window*w,int x,int y){
Rect rc = w->getBound();
RefPtr<Region>newrgn = Region::create((RectangleInt&)rc);
for( auto it2 = it+1 ; it2 < itw ; it2++){
Rect r = (*it)->getBound();
newrgn->subtract((const RectangleInt&)r);
Rect r = (*it)->getBound();
newrgn->subtract((const RectangleInt&)r);
}
newrgn->translate(-rcw.left,-rcw.top);
(*it)->mPendingRgn->do_union((RectangleInt&)rcw);
@ -162,6 +161,34 @@ void WindowManager::moveWindow(Window*w,int x,int y){
}
}
void WindowManager::sendToBack(Window*win){
win->mLayer = (win->window_type<<16);
std::sort(mWindows.begin(),mWindows.end(),[](Window*w1,Window*w2){
return (w1->mLayer - w2->mLayer)>0;
});
for(int idx = 0 ; idx < mWindows.size();idx++){
Window *w = mWindows.at(idx);
w->mLayer = (w->window_type<<16)|(idx+1);
}
win->mPendingRgn->do_union({0,0,win->getWidth(),win->getHeight()});
GraphDevice::getInstance().flip();
}
void WindowManager::bringToFront(Window*win){
win->mLayer = (win->window_type<<16)||0x7FFF;
std::sort(mWindows.begin(),mWindows.end(),[](Window*w1,Window*w2){
return (w1->mLayer - w2->mLayer)>0;
});
for(int idx = 0 ; idx < mWindows.size();idx++){
Window *w = mWindows.at(idx);
w->mLayer = (w->window_type<<16)|(idx+1);
}
win->mPendingRgn->do_union({0,0,win->getWidth(),win->getHeight()});
GraphDevice::getInstance().flip();
}
int WindowManager::enumWindows(WNDENUMPROC cbk){
int rc = 0;
for(auto& w:mWindows)

View File

@ -54,6 +54,8 @@ public:
void addWindow(Window*w);
void removeWindow(Window*w);
void moveWindow(Window*w,int x,int y);
void sendToBack(Window*w);
void bringToFront(Window*w);
void processEvent(InputEvent&e);
void clip(Window*win);
int enumWindows(WNDENUMPROC cbk);

View File

@ -4515,17 +4515,23 @@ void View::getWindowVisibleDisplayFrame(Rect& outRect){
// Make a best guess about the display size.
//Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
//d.getRectSize(outRect);
Point sz;
WindowManager::getInstance().getDefaultDisplay().getSize(sz);
outRect.set(0,0,sz.x,sz.y);
}
void View::getWindowDisplayFrame(Rect& outRect) {
if (mAttachInfo) {
//mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect);
return;
//return;
}
// The view is not attached to a display so we don't have a context.
// Make a best guess about the display size.
//Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY);
//d.getRectSize(outRect);
Point sz;
WindowManager::getInstance().getDefaultDisplay().getSize(sz);
outRect.set(0,0,sz.x,sz.y);
}
void View::dispatchVisibilityChanged(View& changedView,int visibility){
onVisibilityChanged(changedView, visibility);

View File

@ -2704,12 +2704,12 @@ bool ViewGroup::dispatchTouchEvent(MotionEvent&ev){
const int x = ev.getX(actionIndex);
const int y = ev.getY(actionIndex);
std::vector<View*>preorderedList= buildTouchDispatchChildList();
const bool customOrder=preorderedList.empty() && isChildrenDrawingOrderEnabled();
std::vector<View*>&children=mChildren;
for(int i=childrenCount-1;i>=0;i--){
const int childIndex=getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
View*child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
std::vector<View*>preorderedList = buildTouchDispatchChildList();
const bool customOrder = preorderedList.empty() && isChildrenDrawingOrderEnabled();
std::vector<View*>&children = mChildren;
for(int i = childrenCount-1;i >= 0;i--){
const int childIndex = getAndVerifyPreorderedIndex(childrenCount, i, customOrder);
View* child = getAndVerifyPreorderedView(preorderedList, children, childIndex);
if (!canViewReceivePointerEvents(*child) || !isTransformedTouchPointInView(x, y,*child, nullptr)) {
ev.setTargetAccessibilityFocus(false);
continue;

View File

@ -100,6 +100,14 @@ const std::string Window::getText()const{
return mText;
}
void Window::sendToBack(){
WindowManager::getInstance().sendToBack(this);
}
void Window::bringToFront(){
WindowManager::getInstance().bringToFront(this);
}
void Window::draw(){
RefPtr<Canvas>canvas = getCanvas();
mAttachInfo->mDrawingTime = SystemClock::uptimeMillis();
@ -166,7 +174,7 @@ RefPtr<Canvas>Window::getCanvas(){
canvas = make_refptr_for_instance<Canvas>(new Canvas(canvasWidth,canvasHeight));
mAttachInfo->mCanvas = canvas;
Cairo::Matrix matrix = Cairo::identity_matrix();
LOGD("rotation=%d window.size=%dx%d canvas.size=%dx%d",rotation*90,getWidth(),getHeight(),canvasWidth,canvasHeight);
LOGV("rotation=%d window.size=%dx%d canvas.size=%dx%d",rotation*90,getWidth(),getHeight(),canvasWidth,canvasHeight);
switch(rotation){
case Display::ROTATION_0:break;
case Display::ROTATION_90:
@ -267,8 +275,8 @@ bool Window::dispatchKeyEvent(KeyEvent&event){
}
if(!handled){
switch(action){
case KeyEvent::ACTION_UP :handled = onKeyUp(event.getKeyCode(),event);break;
case KeyEvent::ACTION_DOWN:handled = onKeyDown(event.getKeyCode(),event);break;
case KeyEvent::ACTION_UP ://handled = onKeyUp(event.getKeyCode(),event);break;
case KeyEvent::ACTION_DOWN://handled = onKeyDown(event.getKeyCode(),event);break;
handled = ViewGroup::dispatchKeyEvent(event);break;
default:break;
}

View File

@ -76,14 +76,14 @@ protected:
ViewGroup::LayoutParams* generateLayoutParams(const ViewGroup::LayoutParams* lp)const override;
public:
typedef enum{
TYPE_WALLPAPER =1,
TYPE_APPLICATION =2,
TYPE_SYSTEM_WINDOW=2000,
TYPE_STATUS_BAR =2001,
TYPE_SEARCH_BAR =2002,
TYPE_SYSTEM_ALERT =2003,
TYPE_KEYGUARD =2004,
TYPE_TOAST =2005,
TYPE_WALLPAPER = 1,
TYPE_APPLICATION = 2,
TYPE_SYSTEM_WINDOW= 2000,
TYPE_STATUS_BAR = 2001,
TYPE_SEARCH_BAR = 2002,
TYPE_SYSTEM_ALERT = 2003,
TYPE_KEYGUARD = 2004,
TYPE_TOAST = 2005,
}WindowType;
Window(int x,int y,int w,int h,int type=TYPE_APPLICATION);
Window(Context*,const AttributeSet&);
@ -94,6 +94,8 @@ public:
const std::string getText()const;
virtual View& setPos(int x,int y)override;
View& setAlpha(float a);
void sendToBack();
void bringToFront();
virtual bool onKeyUp(int keyCode,KeyEvent& evt) override;
virtual bool onKeyDown(int keyCode,KeyEvent& evt) override;
virtual void onBackPressed();