1 /*
2 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
525 * This implementation flags to the manager that it should no
526 * longer attempt to re-create a D3DSurface.
527 */
528 void disableAccelerationForSurface() {
529 if (offscreenImage != null) {
530 SurfaceManager sm = SurfaceManager.getManager(offscreenImage);
531 if (sm instanceof D3DVolatileSurfaceManager) {
532 setSurfaceLost(true);
533 ((D3DVolatileSurfaceManager)sm).setAccelerationEnabled(false);
534 }
535 }
536 }
537
538 public void validatePipe(SunGraphics2D sg2d) {
539 TextPipe textpipe;
540 boolean validated = false;
541
542 // REMIND: the D3D pipeline doesn't support XOR!, more
543 // fixes will be needed below. For now we disable D3D rendering
544 // for the surface which had any XOR rendering done to.
545 if (sg2d.compositeState >= sg2d.COMP_XOR) {
546 super.validatePipe(sg2d);
547 sg2d.imagepipe = d3dImagePipe;
548 disableAccelerationForSurface();
549 return;
550 }
551
552 // D3DTextRenderer handles both AA and non-AA text, but
553 // only works with the following modes:
554 // (Note: For LCD text we only enter this code path if
555 // canRenderLCDText() has already validated that the mode is
556 // CompositeType.SrcNoEa (opaque color), which will be subsumed
557 // by the CompositeType.SrcNoEa (any color) test below.)
558
559 if (/* CompositeType.SrcNoEa (any color) */
560 (sg2d.compositeState <= sg2d.COMP_ISCOPY &&
561 sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) ||
562
563 /* CompositeType.SrcOver (any color) */
564 (sg2d.compositeState == sg2d.COMP_ALPHA &&
565 sg2d.paintState <= sg2d.PAINT_ALPHACOLOR &&
566 (((AlphaComposite)sg2d.composite).getRule() ==
567 AlphaComposite.SRC_OVER)) ||
568
569 /* CompositeType.Xor (any color) */
570 (sg2d.compositeState == sg2d.COMP_XOR &&
571 sg2d.paintState <= sg2d.PAINT_ALPHACOLOR))
572 {
573 textpipe = d3dTextPipe;
574 } else {
575 // do this to initialize textpipe correctly; we will attempt
576 // to override the non-text pipes below
577 super.validatePipe(sg2d);
578 textpipe = sg2d.textpipe;
579 validated = true;
580 }
581
582 PixelToParallelogramConverter txPipe = null;
583 D3DRenderer nonTxPipe = null;
584
585 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
586 if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
587 if (sg2d.compositeState <= sg2d.COMP_XOR) {
588 txPipe = d3dTxRenderPipe;
589 nonTxPipe = d3dRenderPipe;
590 }
591 } else if (sg2d.compositeState <= sg2d.COMP_ALPHA) {
592 if (D3DPaints.isValid(sg2d)) {
593 txPipe = d3dTxRenderPipe;
594 nonTxPipe = d3dRenderPipe;
595 }
596 // custom paints handled by super.validatePipe() below
597 }
598 } else {
599 if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
600 if (graphicsDevice.isCapPresent(CAPS_AA_SHADER) &&
601 (sg2d.imageComp == CompositeType.SrcOverNoEa ||
602 sg2d.imageComp == CompositeType.SrcOver))
603 {
604 if (!validated) {
605 super.validatePipe(sg2d);
606 validated = true;
607 }
608 PixelToParallelogramConverter aaConverter =
609 new PixelToParallelogramConverter(sg2d.shapepipe,
610 d3dAAPgramPipe,
611 1.0/8.0, 0.499,
612 false);
613 sg2d.drawpipe = aaConverter;
614 sg2d.fillpipe = aaConverter;
615 sg2d.shapepipe = aaConverter;
616 } else if (sg2d.compositeState == sg2d.COMP_XOR) {
617 // install the solid pipes when AA and XOR are both enabled
618 txPipe = d3dTxRenderPipe;
619 nonTxPipe = d3dRenderPipe;
620 }
621 }
622 // other cases handled by super.validatePipe() below
623 }
624
625 if (txPipe != null) {
626 if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
627 sg2d.drawpipe = txPipe;
628 sg2d.fillpipe = txPipe;
629 } else if (sg2d.strokeState != sg2d.STROKE_THIN) {
630 sg2d.drawpipe = txPipe;
631 sg2d.fillpipe = nonTxPipe;
632 } else {
633 sg2d.drawpipe = nonTxPipe;
634 sg2d.fillpipe = nonTxPipe;
635 }
636 // Note that we use the transforming pipe here because it
637 // will examine the shape and possibly perform an optimized
638 // operation if it can be simplified. The simplifications
639 // will be valid for all STROKE and TRANSFORM types.
640 sg2d.shapepipe = txPipe;
641 } else {
642 if (!validated) {
643 super.validatePipe(sg2d);
644 }
645 }
646
647 // install the text pipe based on our earlier decision
648 sg2d.textpipe = textpipe;
649
650 // always override the image pipe with the specialized D3D pipe
651 sg2d.imagepipe = d3dImagePipe;
652 }
653
654 @Override
655 protected MaskFill getMaskFill(SunGraphics2D sg2d) {
656 if (sg2d.paintState > sg2d.PAINT_ALPHACOLOR) {
657 /*
658 * We can only accelerate non-Color MaskFill operations if
659 * all of the following conditions hold true:
660 * - there is an implementation for the given paintState
661 * - the current Paint can be accelerated for this destination
662 * - multitexturing is available (since we need to modulate
663 * the alpha mask texture with the paint texture)
664 *
665 * In all other cases, we return null, in which case the
666 * validation code will choose a more general software-based loop.
667 */
668 if (!D3DPaints.isValid(sg2d) ||
669 !graphicsDevice.isCapPresent(CAPS_MULTITEXTURE))
670 {
671 return null;
672 }
673 }
674 return super.getMaskFill(sg2d);
675 }
676
677 @Override
678 public boolean copyArea(SunGraphics2D sg2d,
679 int x, int y, int w, int h, int dx, int dy)
680 {
681 if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE &&
682 sg2d.compositeState < sg2d.COMP_XOR)
683 {
684 x += sg2d.transX;
685 y += sg2d.transY;
686
687 d3dRenderPipe.copyArea(sg2d, x, y, w, h, dx, dy);
688
689 return true;
690 }
691 return false;
692 }
693
694 @Override
695 public void flush() {
696 D3DRenderQueue rq = D3DRenderQueue.getInstance();
697 rq.lock();
698 try {
699 RenderBuffer buf = rq.getBuffer();
700 rq.ensureCapacityAndAlignment(12, 4);
701 buf.putInt(FLUSH_SURFACE);
702 buf.putLong(getNativeOps());
|
1 /*
2 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
525 * This implementation flags to the manager that it should no
526 * longer attempt to re-create a D3DSurface.
527 */
528 void disableAccelerationForSurface() {
529 if (offscreenImage != null) {
530 SurfaceManager sm = SurfaceManager.getManager(offscreenImage);
531 if (sm instanceof D3DVolatileSurfaceManager) {
532 setSurfaceLost(true);
533 ((D3DVolatileSurfaceManager)sm).setAccelerationEnabled(false);
534 }
535 }
536 }
537
538 public void validatePipe(SunGraphics2D sg2d) {
539 TextPipe textpipe;
540 boolean validated = false;
541
542 // REMIND: the D3D pipeline doesn't support XOR!, more
543 // fixes will be needed below. For now we disable D3D rendering
544 // for the surface which had any XOR rendering done to.
545 if (sg2d.compositeState >= SunGraphics2D.COMP_XOR) {
546 super.validatePipe(sg2d);
547 sg2d.imagepipe = d3dImagePipe;
548 disableAccelerationForSurface();
549 return;
550 }
551
552 // D3DTextRenderer handles both AA and non-AA text, but
553 // only works with the following modes:
554 // (Note: For LCD text we only enter this code path if
555 // canRenderLCDText() has already validated that the mode is
556 // CompositeType.SrcNoEa (opaque color), which will be subsumed
557 // by the CompositeType.SrcNoEa (any color) test below.)
558
559 if (/* CompositeType.SrcNoEa (any color) */
560 (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY &&
561 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) ||
562
563 /* CompositeType.SrcOver (any color) */
564 (sg2d.compositeState == SunGraphics2D.COMP_ALPHA &&
565 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR &&
566 (((AlphaComposite)sg2d.composite).getRule() ==
567 AlphaComposite.SRC_OVER)) ||
568
569 /* CompositeType.Xor (any color) */
570 (sg2d.compositeState == SunGraphics2D.COMP_XOR &&
571 sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR))
572 {
573 textpipe = d3dTextPipe;
574 } else {
575 // do this to initialize textpipe correctly; we will attempt
576 // to override the non-text pipes below
577 super.validatePipe(sg2d);
578 textpipe = sg2d.textpipe;
579 validated = true;
580 }
581
582 PixelToParallelogramConverter txPipe = null;
583 D3DRenderer nonTxPipe = null;
584
585 if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
586 if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
587 if (sg2d.compositeState <= SunGraphics2D.COMP_XOR) {
588 txPipe = d3dTxRenderPipe;
589 nonTxPipe = d3dRenderPipe;
590 }
591 } else if (sg2d.compositeState <= SunGraphics2D.COMP_ALPHA) {
592 if (D3DPaints.isValid(sg2d)) {
593 txPipe = d3dTxRenderPipe;
594 nonTxPipe = d3dRenderPipe;
595 }
596 // custom paints handled by super.validatePipe() below
597 }
598 } else {
599 if (sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR) {
600 if (graphicsDevice.isCapPresent(CAPS_AA_SHADER) &&
601 (sg2d.imageComp == CompositeType.SrcOverNoEa ||
602 sg2d.imageComp == CompositeType.SrcOver))
603 {
604 if (!validated) {
605 super.validatePipe(sg2d);
606 validated = true;
607 }
608 PixelToParallelogramConverter aaConverter =
609 new PixelToParallelogramConverter(sg2d.shapepipe,
610 d3dAAPgramPipe,
611 1.0/8.0, 0.499,
612 false);
613 sg2d.drawpipe = aaConverter;
614 sg2d.fillpipe = aaConverter;
615 sg2d.shapepipe = aaConverter;
616 } else if (sg2d.compositeState == SunGraphics2D.COMP_XOR) {
617 // install the solid pipes when AA and XOR are both enabled
618 txPipe = d3dTxRenderPipe;
619 nonTxPipe = d3dRenderPipe;
620 }
621 }
622 // other cases handled by super.validatePipe() below
623 }
624
625 if (txPipe != null) {
626 if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
627 sg2d.drawpipe = txPipe;
628 sg2d.fillpipe = txPipe;
629 } else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN) {
630 sg2d.drawpipe = txPipe;
631 sg2d.fillpipe = nonTxPipe;
632 } else {
633 sg2d.drawpipe = nonTxPipe;
634 sg2d.fillpipe = nonTxPipe;
635 }
636 // Note that we use the transforming pipe here because it
637 // will examine the shape and possibly perform an optimized
638 // operation if it can be simplified. The simplifications
639 // will be valid for all STROKE and TRANSFORM types.
640 sg2d.shapepipe = txPipe;
641 } else {
642 if (!validated) {
643 super.validatePipe(sg2d);
644 }
645 }
646
647 // install the text pipe based on our earlier decision
648 sg2d.textpipe = textpipe;
649
650 // always override the image pipe with the specialized D3D pipe
651 sg2d.imagepipe = d3dImagePipe;
652 }
653
654 @Override
655 protected MaskFill getMaskFill(SunGraphics2D sg2d) {
656 if (sg2d.paintState > SunGraphics2D.PAINT_ALPHACOLOR) {
657 /*
658 * We can only accelerate non-Color MaskFill operations if
659 * all of the following conditions hold true:
660 * - there is an implementation for the given paintState
661 * - the current Paint can be accelerated for this destination
662 * - multitexturing is available (since we need to modulate
663 * the alpha mask texture with the paint texture)
664 *
665 * In all other cases, we return null, in which case the
666 * validation code will choose a more general software-based loop.
667 */
668 if (!D3DPaints.isValid(sg2d) ||
669 !graphicsDevice.isCapPresent(CAPS_MULTITEXTURE))
670 {
671 return null;
672 }
673 }
674 return super.getMaskFill(sg2d);
675 }
676
677 @Override
678 public boolean copyArea(SunGraphics2D sg2d,
679 int x, int y, int w, int h, int dx, int dy)
680 {
681 if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE &&
682 sg2d.compositeState < SunGraphics2D.COMP_XOR)
683 {
684 x += sg2d.transX;
685 y += sg2d.transY;
686
687 d3dRenderPipe.copyArea(sg2d, x, y, w, h, dx, dy);
688
689 return true;
690 }
691 return false;
692 }
693
694 @Override
695 public void flush() {
696 D3DRenderQueue rq = D3DRenderQueue.getInstance();
697 rq.lock();
698 try {
699 RenderBuffer buf = rq.getBuffer();
700 rq.ensureCapacityAndAlignment(12, 4);
701 buf.putInt(FLUSH_SURFACE);
702 buf.putLong(getNativeOps());
|