1 /* 2 * Copyright (c) 2010, 2013, 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 23 * questions. 24 */ 25 package com.sun.glass.ui.gtk; 26 27 import com.sun.glass.ui.Pixels; 28 import java.nio.Buffer; 29 import java.nio.ByteBuffer; 30 import java.nio.IntBuffer; 31 32 final class GtkPixels extends Pixels { 33 34 public GtkPixels(int width, int height, ByteBuffer data) { 35 super(width, height, data); 36 } 37 38 public GtkPixels(int width, int height, IntBuffer data) { 39 super(width, height, data); 40 } 41 42 public GtkPixels(int width, int height, IntBuffer data, float scale) { 43 super(width, height, data, scale); 44 } 45 46 @Override 47 protected void _fillDirectByteBuffer(ByteBuffer bb) { 48 // Taken from MacPixels 49 if (this.bytes != null) { 50 this.bytes.rewind(); 51 if (this.bytes.isDirect()) { 52 _copyPixels(bb, this.bytes, getWidth()*getHeight()); 53 } else { 54 bb.put(this.bytes); 55 } 56 this.bytes.rewind(); 57 } else { 58 this.ints.rewind(); 59 if (this.ints.isDirect()) { 60 _copyPixels(bb, this.ints, getWidth()*getHeight()); 61 } else { 62 for (int i=0; i<this.ints.capacity(); i++) { 63 int data = this.ints.get(); 64 bb.put((byte)((data)&0xff)); 65 bb.put((byte)((data>>8)&0xff)); 66 bb.put((byte)((data>>16)&0xff)); 67 bb.put((byte)((data>>24)&0xff)); 68 } 69 } 70 this.ints.rewind(); 71 } 72 } 73 74 protected native void _copyPixels(Buffer dst, Buffer src, int size); 75 76 @Override 77 protected native void _attachInt(long ptr, int w, int h, IntBuffer ints, int[] array, int offset); 78 79 @Override 80 protected native void _attachByte(long ptr, int w, int h, ByteBuffer bytes, byte[] array, int offset); 81 82 }