Brooks' new deal, worth $37 million if he remains on the roster under this deal through 2017, will count $2.85 million against the cap in 2012, according to Matt Maiocco.
Consider this yet more evidence showing how teams usually control the salary cap, not the other way around. While it's natural to wonder whether a team can afford a certain player, the salary cap generally isn't a primary barrier. Teams find cap room to sign the players they really want to sign.
As Maiocco notes, Brooks' deal carries higher cap figures in future years. In quite a few cases, teams are happy if they get three good seasons from a player signed to a relatively lucrative deal (and in this case, as PFT notes, the 49ers can easily bail after one season). At that point, they can usually move on from the player with minimal financial considerations if performance is a concern.
The 49ers have sought to reward their own players. They know what they're likely to get from Brooks. They know how he fits in their locker room. They know how he fits in their defensive scheme. They can feel better about giving him a $7.5 million signing bonus than they might feel paying a similar talent from another team.