/* Ċ Ġ* ĠMIT ĠLicense Ċ Ġ* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 1 9 - 2 0 2 2 ĠJetBrains Ġs . r . o . Ċ Ġ* Ċ Ġ* ĠPermission Ġis Ġhereby Ġgranted , Ġfree Ġof Ġcharge , Ġto Ġany Ġperson Ġobtaining Ġa Ġcopy Ċ Ġ* Ġof Ġthis Ġsoftware Ġand Ġassociated Ġdocumentation Ġfiles Ġ( the Ġ" Software "), Ġto Ġdeal Ċ Ġ* Ġin Ġthe ĠSoftware Ġwithout Ġrestriction , Ġincluding Ġwithout Ġlimitation Ġthe Ġrights Ċ Ġ* Ġto Ġuse , Ġcopy , Ġmodify , Ġmerge , Ġpublish , Ġdistribute , Ġsublicense , Ġand / or Ġsell Ċ Ġ* Ġcopies Ġof Ġthe ĠSoftware , Ġand Ġto Ġpermit Ġpersons Ġto Ġwhom Ġthe ĠSoftware Ġis Ċ Ġ* Ġfurnished Ġto Ġdo Ġso , Ġsubject Ġto Ġthe Ġfollowing Ġconditions : Ċ Ġ* Ċ Ġ* ĠThe Ġabove Ġcopyright Ġnotice Ġand Ġthis Ġpermission Ġnotice Ġshall Ġbe Ġincluded Ġin Ġall Ċ Ġ* Ġcopies Ġor Ġsubstantial Ġportions Ġof Ġthe ĠSoftware . Ċ Ġ* Ċ Ġ* ĠTHE ĠSOFTWARE ĠIS ĠPROVIDED Ġ" AS ĠIS ", ĠWITHOUT ĠWARRANTY ĠOF ĠANY ĠKIND , ĠEXPRESS ĠOR Ċ Ġ* ĠIMPLIED , ĠINCLUDING ĠBUT ĠNOT ĠLIMITED ĠTO ĠTHE ĠWARRANTIES ĠOF ĠMERCHANTABILITY , Ċ Ġ* ĠFITNESS ĠFOR ĠA ĠPARTICULAR ĠPURPOSE ĠAND ĠNONINFRINGEMENT . ĠIN ĠNO ĠEVENT ĠSHALL ĠTHE Ċ Ġ* ĠAUTHORS ĠOR ĠCOPYRIGHT ĠHOLDERS ĠBE ĠLIABLE ĠFOR ĠANY ĠCLAIM , ĠDAMAGES ĠOR ĠOTHER Ċ Ġ* ĠLIABILITY , ĠWHETHER ĠIN ĠAN ĠACTION ĠOF ĠCONTRACT , ĠTORT ĠOR ĠOTHERWISE , ĠARISING ĠFROM , Ċ Ġ* ĠOUT ĠOF ĠOR ĠIN ĠCONNECTION ĠWITH ĠTHE ĠSOFTWARE ĠOR ĠTHE ĠUSE ĠOR ĠOTHER ĠDEALINGS ĠIN ĠTHE Ċ Ġ* ĠSOFTWARE . Ċ Ġ*/ Ċ package Ġorg . jetbrains . project or . client . common Ċ Ċ import Ġorg . jetbrains . project or . client . common . Single Rendering Surface Processor . Companion . shrink By Paint Events Ċ import Ġorg . jetbrains . project or . client . common . window . WindowManager Ċ import Ġorg . jetbrains . project or . common . protocol . to Client . Server Draw Commands Event Ċ import Ġorg . jetbrains . project or . util . logging . Logger Ċ Ċ class ĠRendering Queue ( private Ġval Ġwindow Manager : ĠWindow Manager <* >) Ġ{ ĊĊĠ Ġprivate Ġval Ġpending Draw Events Ġ= ĠArray Deque < Sh run k Draw Events >() ĊĠ Ġprivate Ġval Ġnew Draw Events Ġ= ĠArray Deque < Sh run k Draw Events >() ĊĊĠ Ġfun Ġadd ( draw Commands : ĠIterable < Server Draw Commands Event >) Ġ{ ĊĠĠĠ Ġnew Draw Events . addAll ( draw Commands . map Ġ{ ĠSh run k Draw Events ( it . target , Ġit . draw Events . shrink By Paint Events ()) Ġ}) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠServer Draw Commands Event . Target . get Command Processor (): ĠSingle Rendering Surface Processor ? Ġ= Ġwhen Ġ( this ) Ġ{ ĊĠĠĠ Ġis ĠServer Draw Commands Event . Target . On screen Ġ-> Ġwhen Ġ( val Ġwindow Ġ= Ġwindow Manager [ window Id ]) Ġ{ ĊĠĠĠĠĠ Ġnull Ġ-> Ġ{ ĊĠĠĠĠĠĠĠ Ġlogger . error Ġ{ Ġ" Skipping Ġnon existent Ġwindow : Ġ$ window Id " Ġ} ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġelse Ġ-> Ġwindow . command Processor ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġis ĠServer Draw Commands Event . Target . Off screen Ġ-> Ġwindow Manager . image C acher . get Off screen Processor ( this ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠforEach Rendering Surface ( op : Ġ( Single Rendering Surface Processor ) Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ Ġwindow Manager . forEach Ġ{ Ġop ( it . command Processor ) Ġ} ĊĠĠĠ Ġ// Ġtodo : Ġand Ġthe Ġsame Ġfor Ġoff screen Ġsurfaces ĊĠ Ġ} ĊĊĠ Ġfun Ġdraw New Events () Ġ{ ĊĠĠĠ Ġnew Draw Events . forEach Ġ{ Ġsh run k Ġ-> ĊĠĠĠĠĠ Ġval Ġcommand Processor Ġ= Ġsh run k . target . get Command Processor () Ġ?: Ġreturn @ forEach ĊĊĠĠĠĠĠ Ġval Ġfirst Un successful Ġ= Ġcommand Processor . process New ( sh run k . events ) ĊĊĠĠĠĠĠ Ġif Ġ( pending Draw Events . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġpending Draw Events . add ( sh run k ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġelse Ġif Ġ( first Un successful Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( pending Draw Events . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġlogger . error Ġ{ Ġ" Non Ġempty Ġpending Draw Events Ġare Ġhandled Ġby Ġanother Ġbranch , Ġaren 't Ġthey ? ĠThis Ġbranch Ġworks Ġonly Ġfor Ġempty ." Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġpending Draw Events . add ( sh run k . copy ( events Ġ= Ġsh run k . events . sub List ( first Un successful , Ġsh run k . events . size ))) ĊĊĠĠĠĠĠĠĠ ĠforEach Rendering Surface Ġ{ Ġsingle Rendering Surface Processor Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġsingle Rendering Surface Processor . state Saver . save IfNeeded () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġnew Draw Events . clear () ĊĠ Ġ} ĊĊĠ Ġfun Ġdraw Pending Events () Ġ{ ĊĠĠĠ Ġvar Ġfirst Un successful : ĠPair < Int , ĠInt >? Ġ= Ġnull ĊĊĠĠĠ ĠforEach Rendering Surface Ġ{ Ġsingle Rendering Surface Processor Ġ-> ĊĠĠĠĠĠ Ġsingle Rendering Surface Processor . state Saver . restore IfNeeded () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġpending Draw Events . forEach Indexed Ġ{ Ġi , Ġsh run k Ġ-> ĊĠĠĠĠĠ Ġval Ġcommand Processor Ġ= Ġsh run k . target . get Command Processor () Ġ?: Ġreturn @ forEach Indexed ĊĊĠĠĠĠĠ Ġval Ġfirst Un successful Item Ġ= Ġcommand Processor . process New ( sh run k . events ) ĊĊĠĠĠĠĠ Ġif Ġ( first Un successful Ġ== Ġnull Ġ&& Ġfirst Un successful Item Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġfirst Un successful Ġ= Ġi Ġto Ġfirst Un successful Item ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfirst Un successful ?. let Ġ{ Ġ( i 0 , Ġi 1 ) Ġ-> ĊĠĠĠĠĠ Ġrepeat ( i 0 ) Ġ{ ĊĠĠĠĠĠĠĠ Ġpending Draw Events . remove First () ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġval Ġfirst Ġ= Ġpending Draw Events . remove First () ĊĠĠĠĠĠ Ġpending Draw Events . add First ( first . copy ( events Ġ= Ġfirst . events . sub List ( i 1 , Ġfirst . events . size ))) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ?: Ġpending Draw Events . clear () ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĊĠĠĠ Ġprivate Ġdata Ġclass ĠSh run k Draw Events ( val Ġtarget : ĠServer Draw Commands Event . Target , Ġval Ġevents : ĠList < Draw Event >) ĊĊĠĠĠ Ġprivate Ġval Ġlogger Ġ= ĠLogger < Rendering Queue >() ĊĠ Ġ} Ċ } Ċ