Updated

When did Matt Cain know he had his best stuff?

"It took a couple innings," the Giants right-hander said.

And several more for anyone on the Pirates to figure him out.

Cain carried a perfect game into the sixth inning Friday and struck out 11 batters in a one-hit shutout, leading San Francisco to a 5-0 victory over Pittsburgh in an emotional home opener.

The only hit allowed by Cain was a two-out single slapped through the left side of the infield by Pirates starter James McDonald with two outs in the sixth.

Cain (1-0) threw 73 of his 106 pitches for strikes and faced one batter over the minimum, picking up his first win since signing a six-year, $127.5 million contract extension earlier this month.

McDonald (0-1) took the loss in the opener of the three-game series, giving up three runs on six hits and three walks in 5 2/3 innings.

Giants catcher Buster Posey, in his first home game since suffering a broken leg and torn ligaments in a collision at home plate last May, knocked in the first run with a double to the center field wall in the first inning.

But the game had an earlier emotional kickstart when Bryan Stowe, the Giants fan beaten nearly to death outside Dodger Stadium last year, appeared on the big screen in center field while his 13-year-old son, Tyler, threw out the first pitch.

Cain picked up his fifth shutout -- first since 2010 -- and 14th complete game while leading the Giants to their third win in four games since an 0-3 start.

The 27-year-old righty fell behind in the count, 2-1, to McDonald and threw him a fastball over the plate that was knocked in between short stop and third base.

San Francisco manager Bruce Bochy said Posey came to him during the game and told him he could tell Cain "was on, was locked in."

"And he's one of the best when he's locked in," said Bochy.

The Giants, opening a six-game homestand, took a 2-0 lead in the first inning when Aubrey Huff followed Posey's double with an RBI single. Nate Schierholtz added an RBI base hit in the sixth and Huff roped a two-run homer into the right field seats in the eighth.

Game Notes

The Pirates have lost four in a row and are 0-4 on a nine-game road trip. They were just swept by the Dodgers in Los Angeles...The Giants were 3-for-6 with runners in scoring position.