All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.prism.sw.SWRTTexture Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

package com.sun.prism.sw;

import com.sun.glass.ui.Screen;
import com.sun.javafx.geom.Rectangle;
import com.sun.pisces.JavaSurface;
import com.sun.pisces.PiscesRenderer;
import com.sun.pisces.RendererBase;
import com.sun.prism.Graphics;
import com.sun.prism.RTTexture;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;

class SWRTTexture extends SWArgbPreTexture implements RTTexture {

    private PiscesRenderer pr;
    private JavaSurface surface;
    private final Rectangle dimensions = new Rectangle();
    private boolean isOpaque;

    SWRTTexture(SWResourceFactory factory, int w, int h) {
        super(factory, WrapMode.CLAMP_TO_ZERO, w, h);
        this.allocate();
        this.surface = new JavaSurface(getDataNoClone(), RendererBase.TYPE_INT_ARGB_PRE, w, h);
        this.dimensions.setBounds(0, 0, w, h);
    }

    JavaSurface getSurface() {
        return this.surface;
    }

    @Override
    public int[] getPixels() {
        return getDataNoClone();
    }

    @Override
    public boolean readPixels(Buffer pixels, int x, int y, int width, int height) {
        if (x != getContentX() || y != getContentY() 
                || width != getContentWidth() || height != getContentHeight())
        {
            throw new IllegalArgumentException("reading subtexture not yet supported!");
        }
        return readPixels(pixels);
    }
    
    @Override
    public boolean readPixels(Buffer pixels) {
        final int pixbuf[] = getPixels();

        pixels.clear();
        // REMIND: This assumes that the caller wants BGRA PRE data...?
        if (pixels instanceof IntBuffer) {
            ((IntBuffer)pixels).put(pixbuf);
        } else if (pixels instanceof ByteBuffer) {
            final ByteBuffer bPixels = (ByteBuffer)pixels;
            final int length = getContentWidth() * getContentHeight();
            for (int i = 0; i < length; i++) {
                final int argb = pixbuf[i];
                final byte a = (byte) (argb >> 24);
                final byte r = (byte) (argb >> 16);
                final byte g = (byte) (argb >>  8);
                final byte b = (byte) (argb      );
                bPixels.put(b).put(g).put(r).put(a);
            }
        } else {
            return false;
        }
        return true;
    }

    @Override public boolean isSurfaceLost() {
        return false;
    }

    public Screen getAssociatedScreen() {
        return getResourceFactory().getScreen();
    }

    public Graphics createGraphics() {
        if (pr == null) {
            pr = new PiscesRenderer(this.surface);
        }
        return new SWGraphics(this, getResourceFactory().getContext(), pr);
    }

    public boolean isOpaque() {
        return isOpaque;
    }

    public void setOpaque(boolean opaque) {
        this.isOpaque = opaque;
    }

    public int getPhysicalWidth() {
        // If the surface has not yet been created (typically that means
        // createGraphics() has not yet been called), we will plan to
        // create it at the content size initially.
        return (getSurface() == null) ? getContentWidth() : getSurface().getWidth();
    }

    public int getPhysicalHeight() {
        // If the surface has not yet been created (typically that means
        // createGraphics() has not yet been called), we will plan to
        // create it at the content size initially.
        return (getSurface() == null) ? getContentHeight() : getSurface().getHeight();
    }

    Rectangle getDimensions() { return dimensions; }

    public boolean isVolatile() {
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy