public void validateCompositeState(
      Composite comp, AffineTransform xform, Paint paint, SunGraphics2D sg2d) {
    boolean updatePaint = (paint != validatedPaint) || paint == null;

    // validate composite
    if ((comp != validatedComp)) {
      if (comp != null) {
        setComposite(comp);
      } else {
        comp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
        setComposite(comp);
      }
      // the paint state is dependent on the composite state, so make
      // sure we update the color below
      updatePaint = true;
      validatedComp = comp;
    }

    if (sg2d != null && validatedPixel != sg2d.pixel) {
      validatedPixel = sg2d.pixel;
      setForeground(validatedPixel);
    }

    // validate paint
    if (updatePaint) {
      if (paint != null && sg2d != null && sg2d.paintState >= SunGraphics2D.PAINT_GRADIENT) {
        XRPaints.setPaint(sg2d, paint);
      } else {
        XRResetPaint();
      }
      validatedPaint = paint;
    }

    if (src != solidSrcPict) {
      AffineTransform at = (AffineTransform) xform.clone();
      try {
        at.invert();
      } catch (NoninvertibleTransformException e) {
        at.setToIdentity();
      }
      src.validateAsSource(at, -1, -1);
    }
  }