Like most things, I think it was a combination of a lot of factors.There are two buildings in the background. The one he shot from is the one in front of the other. See how the roof rises slightly (reducing the roof's slope) partway down its length?... The shooter was lying alongside that rise on the other side of the peak of the roof. That is likely why he was difficult to see by the agents on the barn behind the bleachers.
Beyond the failure to have those buildings secured and maybe a breakdown in communication (I think we need to learn details/timings/etc.) re: a shooter being on them, I don't think the Secret Service near Trump did an entirely great job.
They were on him very quickly - as fast as humanly possible, really - so no complaints there... but I thought Trump remained on that stage (looking for his shoes or whatever) waaaay too long after the shooting started. Had this been a coordinated attack, think multiple attackers... maybe drones... I think the Secret Service would've looked even worse. I would think the #1 priority would be to get Trump into the car as fast as possible and that didn't seem to be the case.