Пример #1
0
  @Override
  protected void drawGlyphList(SunGraphics2D sg2d, GlyphList gl) {
    /*
     * The native drawGlyphList() only works with two composite types:
     *    - CompositeType.SrcOver (with any extra alpha), or
     *    - CompositeType.Xor
     */
    Composite comp = sg2d.composite;
    if (comp == AlphaComposite.Src) {
      /*
       * In addition to the composite types listed above, the logic
       * in OGL/D3DSurfaceData.validatePipe() allows for
       * CompositeType.SrcNoEa, but only in the presence of an opaque
       * color.  If we reach this case, we know the color is opaque,
       * and therefore SrcNoEa is the same as SrcOverNoEa, so we
       * override the composite here.
       */
      comp = AlphaComposite.SrcOver;
    }

    rq.lock();
    try {
      validateContext(sg2d, comp);
      enqueueGlyphList(sg2d, gl);
    } finally {
      rq.unlock();
    }
  }
Пример #2
0
  private void enqueueGlyphList(final SunGraphics2D sg2d, final GlyphList gl) {
    // assert rq.lock.isHeldByCurrentThread();
    RenderBuffer buf = rq.getBuffer();
    final int totalGlyphs = gl.getNumGlyphs();
    int glyphBytesRequired = totalGlyphs * BYTES_PER_GLYPH_IMAGE;
    int posBytesRequired = gl.usePositions() ? totalGlyphs * BYTES_PER_GLYPH_POSITION : 0;
    int totalBytesRequired = 24 + glyphBytesRequired + posBytesRequired;

    final long[] images = gl.getImages();
    final float glyphListOrigX = gl.getX() + 0.5f;
    final float glyphListOrigY = gl.getY() + 0.5f;

    // make sure the RenderQueue keeps a hard reference to the FontStrike
    // so that the associated glyph images are not disposed while enqueued
    rq.addReference(gl.getStrike());

    if (totalBytesRequired <= buf.capacity()) {
      if (totalBytesRequired > buf.remaining()) {
        // process the queue first and then enqueue the glyphs
        rq.flushNow();
      }
      rq.ensureAlignment(20);
      buf.putInt(DRAW_GLYPH_LIST);
      // enqueue parameters
      buf.putInt(totalGlyphs);
      buf.putInt(createPackedParams(sg2d, gl));
      buf.putFloat(glyphListOrigX);
      buf.putFloat(glyphListOrigY);
      // now enqueue glyph information
      buf.put(images, 0, totalGlyphs);
      if (gl.usePositions()) {
        float[] positions = gl.getPositions();
        buf.put(positions, 0, 2 * totalGlyphs);
      }
    } else {
      // queue is too small to accomodate glyphs; perform
      // the operation directly on the queue flushing thread
      rq.flushAndInvokeNow(
          new Runnable() {
            public void run() {
              drawGlyphList(
                  totalGlyphs,
                  gl.usePositions(),
                  gl.isSubPixPos(),
                  gl.isRGBOrder(),
                  sg2d.lcdTextContrast,
                  glyphListOrigX,
                  glyphListOrigY,
                  images,
                  gl.getPositions());
            }
          });
    }
  }
Пример #3
0
 private void setSurfaces(AccelSurface srcData, AccelSurface dstData) {
   // assert rq.lock.isHeldByCurrentThread();
   rq.ensureCapacityAndAlignment(20, 4);
   buf.putInt(SET_SURFACES);
   buf.putLong(srcData.getNativeOps());
   buf.putLong(dstData.getNativeOps());
 }
Пример #4
0
 private void setComposite(Composite comp, int flags) {
   // assert rq.lock.isHeldByCurrentThread();
   if (comp instanceof AlphaComposite) {
     AlphaComposite ac = (AlphaComposite) comp;
     rq.ensureCapacity(16);
     buf.putInt(SET_ALPHA_COMPOSITE);
     buf.putInt(ac.getRule());
     buf.putFloat(ac.getAlpha());
     buf.putInt(flags);
   } else if (comp instanceof XORComposite) {
     int xorPixel = ((XORComposite) comp).getXorPixel();
     rq.ensureCapacity(8);
     buf.putInt(SET_XOR_COMPOSITE);
     buf.putInt(xorPixel);
   } else {
     throw new InternalError("not yet implemented");
   }
 }
Пример #5
0
 private void setTransform(AffineTransform xform) {
   // assert rq.lock.isHeldByCurrentThread();
   rq.ensureCapacityAndAlignment(52, 4);
   buf.putInt(SET_TRANSFORM);
   buf.putDouble(xform.getScaleX());
   buf.putDouble(xform.getShearY());
   buf.putDouble(xform.getShearX());
   buf.putDouble(xform.getScaleY());
   buf.putDouble(xform.getTranslateX());
   buf.putDouble(xform.getTranslateY());
 }
Пример #6
0
 private void setClip(Region clip) {
   // assert rq.lock.isHeldByCurrentThread();
   if (clip.isRectangular()) {
     rq.ensureCapacity(20);
     buf.putInt(SET_RECT_CLIP);
     buf.putInt(clip.getLoX()).putInt(clip.getLoY());
     buf.putInt(clip.getHiX()).putInt(clip.getHiY());
   } else {
     rq.ensureCapacity(28); // so that we have room for at least a span
     buf.putInt(BEGIN_SHAPE_CLIP);
     buf.putInt(SET_SHAPE_CLIP_SPANS);
     // include a placeholder for the span count
     int countIndex = buf.position();
     buf.putInt(0);
     int spanCount = 0;
     int remainingSpans = buf.remaining() / BYTES_PER_SPAN;
     int span[] = new int[4];
     SpanIterator si = clip.getSpanIterator();
     while (si.nextSpan(span)) {
       if (remainingSpans == 0) {
         buf.putInt(countIndex, spanCount);
         rq.flushNow();
         buf.putInt(SET_SHAPE_CLIP_SPANS);
         countIndex = buf.position();
         buf.putInt(0);
         spanCount = 0;
         remainingSpans = buf.remaining() / BYTES_PER_SPAN;
       }
       buf.putInt(span[0]); // x1
       buf.putInt(span[1]); // y1
       buf.putInt(span[2]); // x2
       buf.putInt(span[3]); // y2
       spanCount++;
       remainingSpans--;
     }
     buf.putInt(countIndex, spanCount);
     rq.ensureCapacity(4);
     buf.putInt(END_SHAPE_CLIP);
   }
 }
Пример #7
0
 protected BufferedContext(RenderQueue rq) {
   this.rq = rq;
   this.buf = rq.getBuffer();
 }
Пример #8
0
 private void resetTransform() {
   // assert rq.lock.isHeldByCurrentThread();
   rq.ensureCapacity(4);
   buf.putInt(RESET_TRANSFORM);
 }
Пример #9
0
 private void resetComposite() {
   // assert rq.lock.isHeldByCurrentThread();
   rq.ensureCapacity(4);
   buf.putInt(RESET_COMPOSITE);
 }
Пример #10
0
 private void resetClip() {
   // assert rq.lock.isHeldByCurrentThread();
   rq.ensureCapacity(4);
   buf.putInt(RESET_CLIP);
 }