Have LegacySurface track its own palette validity

Accessing the palette() will cause hasValidPalette() to be set. Any
drawing operation between two LegacySurfaces will now compare palettes:
if both are valid, it ensures equality (tripping an assertion on
failure), and if only one is valid, it copies the palette the other way.

This allows us to support the common pattern of LegacySurfaces for
compositing without discarding the "every surface knows its palette"
rule. This could be considered cheating, but hey.