summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCindy Zhou <zhouci@google.com>2020-01-27 15:10:24 -0800
committerandroid-build-merger <android-build-merger@google.com>2020-01-27 15:10:24 -0800
commit6016fa60619233fa30a8b0c0241eca8929a18583 (patch)
treeb49b13a099f2d593d78a267a8bccd4a52617d488
parent3b75ec772b0b48bbb4123a792e0a67abd285f5b0 (diff)
parentaea7cab66ab8ccf9ed4b94787e884adca59bc609 (diff)
downloadteeui-6016fa60619233fa30a8b0c0241eca8929a18583.tar.gz
Device Resizing & Pass device parameters and magnified mode down to the renderer
am: aea7cab66a Change-Id: Ie4de2ef2c6716a06ac3e6b1586f3f5de3686d54e
-rw-r--r--libteeui/example/layout.h4
-rw-r--r--libteeui/example/teeui.cpp39
-rw-r--r--libteeui/include/teeui/example/teeui.h14
-rw-r--r--libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h8
-rw-r--r--libteeui_jni/libteeui_jni.cpp24
-rw-r--r--tools/framebufferizer/src/com/android/framebufferizer/Main.java16
-rw-r--r--tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java4
-rw-r--r--tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfo.java72
-rw-r--r--tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfoDB.java38
-rw-r--r--tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java160
10 files changed, 294 insertions, 85 deletions
diff --git a/libteeui/example/layout.h b/libteeui/example/layout.h
index 8a93ed0..0c4a183 100644
--- a/libteeui/example/layout.h
+++ b/libteeui/example/layout.h
@@ -135,8 +135,8 @@ LineHeight(DefaultFontSize() * 1.5_px);
NumberOfLines(4);
Dimension(LabelWidth, HeightFromLines);
Position(BorderWidth, BottomOfScreen() - BorderWidth - dim_h);
-DefaultText("This confirmation provides an extra layer of security for the action that you're "
- "about to take");
+DefaultText("This confirmation provides an extra layer of security for the action you're "
+ "about to take.");
VerticallyCentered;
TextColor(DefaultTextColor);
Font(DefaultFont);
diff --git a/libteeui/example/teeui.cpp b/libteeui/example/teeui.cpp
index a72ae07..58b6aad 100644
--- a/libteeui/example/teeui.cpp
+++ b/libteeui/example/teeui.cpp
@@ -20,10 +20,8 @@
using namespace teeui;
-static uint32_t device_width_px;
-static uint32_t device_height_px;
-static double dp2px_;
-static double mm2px_;
+static DeviceInfo sDeviceInfo;
+static bool sMagnified;
uint32_t alfaCombineChannel(uint32_t shift, double alfa, uint32_t a, uint32_t b) {
a >>= shift;
@@ -86,13 +84,9 @@ Error drawElements(std::tuple<Elements...>& layout, const PixelDrawer& drawPixel
return (std::get<Elements>(layout).draw(drawPixel) || ...);
}
-uint32_t setDeviceInfo(uint32_t width, uint32_t height, uint32_t colormodel, double dp2px,
- double mm2px) {
- dp2px_ = dp2px;
- mm2px_ = mm2px;
- (void)colormodel; // ignored for now;
- device_width_px = width;
- device_height_px = height;
+uint32_t setDeviceInfo(DeviceInfo deviceInfo, bool magnified) {
+ sDeviceInfo = deviceInfo;
+ sMagnified = magnified;
return 0;
}
@@ -107,15 +101,20 @@ uint32_t renderUIIntoBuffer(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint
afterLastPixelIndex > buffer_size_in_elements_not_bytes) {
return uint32_t(Error::OutOfBoundsDrawing);
}
- context<ConUIParameters> conv(mm2px_, dp2px_);
- conv.setParam<RightEdgeOfScreen>(pxs(device_width_px));
- conv.setParam<BottomOfScreen>(pxs(device_height_px));
- conv.setParam<PowerButtonTop>(100_dp);
- conv.setParam<PowerButtonBottom>(150_dp);
- conv.setParam<VolUpButtonTop>(200_dp);
- conv.setParam<VolUpButtonBottom>(250_dp);
- conv.setParam<DefaultFontSize>(14_dp);
- conv.setParam<BodyFontSize>(16_dp);
+ context<ConUIParameters> conv(sDeviceInfo.mm2px_, sDeviceInfo.dp2px_);
+ conv.setParam<RightEdgeOfScreen>(pxs(sDeviceInfo.width_));
+ conv.setParam<BottomOfScreen>(pxs(sDeviceInfo.height_));
+ conv.setParam<PowerButtonTop>(mms(sDeviceInfo.powerButtonTopMm_));
+ conv.setParam<PowerButtonBottom>(mms(sDeviceInfo.powerButtonBottomMm_));
+ conv.setParam<VolUpButtonTop>(mms(sDeviceInfo.volUpButtonTopMm_));
+ conv.setParam<VolUpButtonBottom>(mms(sDeviceInfo.volUpButtonBottomMm_));
+ if (sMagnified) {
+ conv.setParam<DefaultFontSize>(18_dp);
+ conv.setParam<BodyFontSize>(20_dp);
+ } else {
+ conv.setParam<DefaultFontSize>(14_dp);
+ conv.setParam<BodyFontSize>(16_dp);
+ }
auto layoutInstance = instantiateLayout(ConfUILayout(), conv);
diff --git a/libteeui/include/teeui/example/teeui.h b/libteeui/include/teeui/example/teeui.h
index 7fdc032..058ad01 100644
--- a/libteeui/include/teeui/example/teeui.h
+++ b/libteeui/include/teeui/example/teeui.h
@@ -21,8 +21,18 @@
#include <stddef.h>
#include <stdint.h>
-uint32_t setDeviceInfo(uint32_t width, uint32_t height, uint32_t colormodel, double dp2px,
- double mm2px);
+struct DeviceInfo {
+ uint32_t width_;
+ uint32_t height_;
+ double dp2px_;
+ double mm2px_;
+ double powerButtonTopMm_;
+ double powerButtonBottomMm_;
+ double volUpButtonTopMm_;
+ double volUpButtonBottomMm_;
+};
+
+uint32_t setDeviceInfo(DeviceInfo device_info, bool magnified);
uint32_t renderUIIntoBuffer(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t lineStride,
uint32_t* buffer, size_t buffer_size_in_elements_not_bytes);
diff --git a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
index 3ec4b09..0eb1625 100644
--- a/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
+++ b/libteeui_jni/include/com_android_framebufferizer_NativeRenderer.h
@@ -10,10 +10,12 @@ extern "C" {
/*
* Class: com_android_framebufferizer_NativeRenderer
* Method: setDeviceInfo
- * Signature: (IIIDD)I
+ * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;Z)I
*/
-JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_setDeviceInfo(
- JNIEnv*, jclass, jint, jint, jint, jdouble, jdouble);
+JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_setDeviceInfo(JNIEnv*,
+ jclass,
+ jobject,
+ jboolean);
/*
* Class: com_android_framebufferizer_NativeRenderer
diff --git a/libteeui_jni/libteeui_jni.cpp b/libteeui_jni/libteeui_jni.cpp
index b71dc4a..bf51080 100644
--- a/libteeui_jni/libteeui_jni.cpp
+++ b/libteeui_jni/libteeui_jni.cpp
@@ -125,11 +125,29 @@ using JString = JArray<jstring>;
/*
* Class: com_android_framebufferizer_NativeRenderer
* Method: setDeviceInfo
- * Signature: (IIIDD)I
+ * Signature: (Lcom/android/framebufferizer/utils/DeviceInfo;Z)I
*/
extern "C" JNIEXPORT jint JNICALL Java_com_android_framebufferizer_NativeRenderer_setDeviceInfo(
- JNIEnv*, jclass, jint width, jint height, jint colormodel, jdouble dp2px, jdouble mm2px) {
- return setDeviceInfo(width, height, colormodel, dp2px, mm2px);
+ JNIEnv* env, jclass, jobject jDeviceInfo, jboolean magnified) {
+ jclass cDeviceInfo = env->FindClass("Lcom/android/framebufferizer/utils/DeviceInfo;");
+ jmethodID method = env->GetMethodID(cDeviceInfo, "getWidthPx", "()I");
+ DeviceInfo device_info;
+ device_info.width_ = env->CallIntMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getHeightPx", "()I");
+ device_info.height_ = env->CallIntMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getDp2px", "()D");
+ device_info.dp2px_ = env->CallDoubleMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getMm2px", "()D");
+ device_info.mm2px_ = env->CallDoubleMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getPowerButtonTopMm", "()D");
+ device_info.powerButtonTopMm_ = env->CallDoubleMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getPowerButtonBottomMm", "()D");
+ device_info.powerButtonBottomMm_ = env->CallDoubleMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getVolUpButtonTopMm", "()D");
+ device_info.volUpButtonTopMm_ = env->CallDoubleMethod(jDeviceInfo, method);
+ method = env->GetMethodID(cDeviceInfo, "getVolUpButtonBottomMm", "()D");
+ device_info.volUpButtonBottomMm_ = env->CallDoubleMethod(jDeviceInfo, method);
+ return setDeviceInfo(device_info, magnified);
}
/*
diff --git a/tools/framebufferizer/src/com/android/framebufferizer/Main.java b/tools/framebufferizer/src/com/android/framebufferizer/Main.java
index c1d204e..7d81fd3 100644
--- a/tools/framebufferizer/src/com/android/framebufferizer/Main.java
+++ b/tools/framebufferizer/src/com/android/framebufferizer/Main.java
@@ -32,16 +32,22 @@ public class Main {
static private Random random;
private static void createAndShowUI() {
- theFrame = new JFrame("Framebufferizer");
+ theFrame = new JFrame("TeeuiFramebufferizer");
theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- theFramebuffer = FrameBufferBuffer.createFrameBufferBuffer(256, 400, 256);
+ theFramebuffer = new FrameBufferBuffer();
+ theFramebuffer.setFrame(theFrame);
FrameBufferBuffer.MagnifiedView magnifiedView = theFramebuffer.getMagnifiedView();
+ FrameBufferBuffer.DeviceSelector deviceSelector = theFramebuffer.getDeviceSelector();
magnifiedView.setPreferredSize(new Dimension(100, 100));
- theFrame.getContentPane().add(theFramebuffer, BorderLayout.CENTER);
+ magnifiedView.setMinimumSize(new Dimension(100, 100));
+ magnifiedView.setMaximumSize(new Dimension(100, 100));
theFrame.getContentPane().add(magnifiedView, BorderLayout.EAST);
- theFrame.setSize(400, 500);
+ theFrame.getContentPane().add(theFramebuffer, BorderLayout.CENTER);
+ theFrame.getContentPane().add(deviceSelector, BorderLayout.NORTH);
+ theFrame.pack();
theFrame.setVisible(true);
+ deviceSelector.refreshSelections();
+
}
public static void main(String[] args) {
diff --git a/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java b/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java
index 3f38e13..e670123 100644
--- a/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java
+++ b/tools/framebufferizer/src/com/android/framebufferizer/NativeRenderer.java
@@ -16,11 +16,13 @@
package com.android.framebufferizer;
+import com.android.framebufferizer.utils.DeviceInfo;
+
public class NativeRenderer {
static {
System.loadLibrary("teeui_jni");
}
- public static native int setDeviceInfo(int width, int height, int colormodel, double dp2px, double mm2px);
+ public static native int setDeviceInfo(DeviceInfo deviceInfo, boolean magnified);
public static native int renderBuffer(int x, int y, int width, int height, int lineStride, int[] buffer);
}
diff --git a/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfo.java b/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfo.java
new file mode 100644
index 0000000..d38e550
--- /dev/null
+++ b/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfo.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.framebufferizer.utils;
+
+public class DeviceInfo {
+ final private int widthPx;
+ final private int heightPx;
+ final private double dp2px;
+ final private double mm2px;
+ final private double powerButtonTopMm;
+ final private double powerButtonBottomMm;
+ final private double volUpButtonTopMm;
+ final private double volUpButtonBottomMm;
+
+ DeviceInfo(int widthPx, int heightPx, double dp2px, double mm2px, double powerButtonTopMm,
+ double powerButtonBottomMm, double volUpButtonTopMm, double volUpButtonBottomMm) {
+ this.widthPx = widthPx;
+ this.heightPx = heightPx;
+ this.dp2px = dp2px;
+ this.mm2px = mm2px;
+ this.powerButtonTopMm = powerButtonTopMm;
+ this.powerButtonBottomMm = powerButtonBottomMm;
+ this.volUpButtonTopMm = volUpButtonTopMm;
+ this.volUpButtonBottomMm = volUpButtonBottomMm;
+ }
+
+ public int getWidthPx() {
+ return widthPx;
+ }
+
+ public int getHeightPx() {
+ return heightPx;
+ }
+
+ public double getDp2px() {
+ return dp2px;
+ }
+
+ public double getMm2px() {
+ return mm2px;
+ }
+
+ public double getPowerButtonTopMm() {
+ return powerButtonTopMm;
+ }
+
+ public double getPowerButtonBottomMm() {
+ return powerButtonBottomMm;
+ }
+
+ public double getVolUpButtonTopMm() {
+ return volUpButtonTopMm;
+ }
+
+ public double getVolUpButtonBottomMm() {
+ return volUpButtonBottomMm;
+ }
+}
diff --git a/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfoDB.java b/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfoDB.java
new file mode 100644
index 0000000..2e8d6ba
--- /dev/null
+++ b/tools/framebufferizer/src/com/android/framebufferizer/utils/DeviceInfoDB.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.framebufferizer.utils;
+
+
+public class DeviceInfoDB {
+ public static enum Device { BLUELINE, BONITO, CROSSHATCH, CORAL, SARGO};
+ public static final double DEFAULT_DENSITY_INDEPENDENT_WIDTH = 412.0;
+
+ static DeviceInfo getDeviceInfo(Device device) {
+ switch (device) {
+ case BLUELINE:
+ return new DeviceInfo(1080, 2160, 1080/DEFAULT_DENSITY_INDEPENDENT_WIDTH, 17.42075974, 20.26, 30.26, 40.26, 50.26);
+ case CROSSHATCH:
+ return new DeviceInfo(1440, 2950, 1440/DEFAULT_DENSITY_INDEPENDENT_WIDTH, 20.42958729, 34.146, 44.146, 54.146, 64.146);
+ case BONITO:
+ case CORAL:
+ case SARGO:
+ // return Blueline for now. TODO needs correnct values for other devices
+ return new DeviceInfo(1080, 2160, 1080/DEFAULT_DENSITY_INDEPENDENT_WIDTH, 17.42075974, 20.26, 30.26, 40.26, 50.26);
+ }
+ return new DeviceInfo(1080, 2160, 1080/DEFAULT_DENSITY_INDEPENDENT_WIDTH, 17.42075974, 20.26, 30.26, 40.26, 50.26);
+ }
+}
diff --git a/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java b/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java
index fc14186..aefa8dc 100644
--- a/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java
+++ b/tools/framebufferizer/src/com/android/framebufferizer/utils/FrameBufferBuffer.java
@@ -23,6 +23,10 @@ import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
+import java.awt.event.ItemListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
@@ -83,9 +87,44 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous
}
+ public static enum Devices { CORAL, BONITO, SARGO, CROSSHATCH, BLUELINE;}
+
+ public class DeviceSelector extends JPanel implements ActionListener {
+ private JComboBox<String> dropDownMenu = new JComboBox(DeviceInfoDB.Device.values());
+ private JCheckBox magnifiedCheckbox = new JCheckBox("Magnified");
+
+ protected DeviceSelector() {
+ dropDownMenu.addActionListener(this);
+ magnifiedCheckbox.addActionListener(this);
+ this.add(dropDownMenu);
+ this.add(magnifiedCheckbox);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ synchronized (this) {
+ FrameBufferBuffer.this.calibrateNativeBuffer();
+ }
+ }
+
+ public void refreshSelections(){
+ dropDownMenu.setSelectedItem(Devices.CORAL);
+ }
+
+ public DeviceInfoDB.Device currentDevice() {
+ return (DeviceInfoDB.Device) dropDownMenu.getSelectedItem();
+ }
+
+ public boolean magnified() {
+ return magnifiedCheckbox.isSelected();
+ }
+ }
+
+
private BufferedImage mImage;
private DataBufferInt mBuffer;
private MagnifiedView mMagnifiedView;
+ private DeviceSelector mDeviceSelector;
+ private JFrame mFrame;
public MagnifiedView getMagnifiedView() {
if (mMagnifiedView == null) {
@@ -94,6 +133,13 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous
return mMagnifiedView;
}
+ public DeviceSelector getDeviceSelector(){
+ if (mDeviceSelector == null){
+ mDeviceSelector = new DeviceSelector();
+ }
+ return mDeviceSelector;
+ }
+
@Override
public void mouseDragged(MouseEvent e) {
@@ -128,63 +174,42 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous
}
- protected FrameBufferBuffer(BufferedImage image, DataBufferInt buffer) {
- mImage = image;
- mBuffer = buffer;
+ public FrameBufferBuffer() {
+ setSize(412, 900);
+ setPreferredSize(new Dimension(412, 900));
+ calibrateNativeBuffer();
addComponentListener(this);
addMouseMotionListener(this);
}
- public static FrameBufferBuffer createFrameBufferBuffer(int w, int h, int linestride) {
- final int rMask = 0xff;
- final int gMask = 0xff00;
- final int bMask = 0xff0000;
- final int bpp = 24;
- DataBufferInt dataBuffer = new DataBufferInt(h * linestride);
- WritableRaster raster = Raster.createPackedRaster(dataBuffer, w, h, linestride,
- new int[]{rMask, gMask, bMask}, null);
- ColorModel colorModel = new DirectColorModel(bpp, rMask, gMask, bMask);
- BufferedImage image = new BufferedImage(colorModel, raster, true, null);
- NativeRenderer.setDeviceInfo(w, h, -1, 3.5, 5.5);
- int error = NativeRenderer.renderBuffer(0, 0, w, h, linestride, dataBuffer.getData());
- if (error != 0) {
- System.out.println("Error rendering native buffer " + error);
- }
- return new FrameBufferBuffer(image, dataBuffer);
- }
-
- public BufferedImage getImage() {
- return mImage;
- }
-
- public DataBufferInt getBuffer() {
- return mBuffer;
- }
-
@Override
public void componentResized(ComponentEvent e) {
- int w = getWidth();
- int h = getHeight();
- final int linestride = w;
- final int rMask = 0xff;
- final int gMask = 0xff00;
- final int bMask = 0xff0000;
- final int bpp = 24;
- synchronized (this) {
- mBuffer = new DataBufferInt(h * linestride);
- WritableRaster raster = Raster.createPackedRaster(mBuffer, w, h, linestride,
- new int[]{rMask, gMask, bMask}, null);
- ColorModel colorModel = new DirectColorModel(bpp, rMask, gMask, bMask);
- mImage = new BufferedImage(colorModel, raster, true, null);
- NativeRenderer.setDeviceInfo(w, h, -1, w/412.0, 5.5);
- int error = NativeRenderer.renderBuffer(0, 0, w, h, linestride, mBuffer.getData());
- if (error != 0) {
- System.out.println("Error rendering native buffer " + error);
- }
- }
+ calibrateNativeBuffer();
repaint();
+ /* get set values and then let it resize based off of the values passed through this */
+ // int w = getWidth();
+ // int h = getHeight();
+ // System.out.println( "width=" + getWidth() + " height=" + getHeight());
+ // final int linestride = w;
+ // final int rMask = 0xff;
+ // final int gMask = 0xff00;
+ // final int bMask = 0xff0000;
+ // final int bpp = 24;
+ // synchronized (this) {
+ // mBuffer = new DataBufferInt(h * linestride);
+ // WritableRaster raster = Raster.createPackedRaster(mBuffer, w, h, linestride,
+ // new int[]{rMask, gMask, bMask}, null);
+ // ColorModel colorModel = new DirectColorModel(bpp, rMask, gMask, bMask);
+ // mDeviceSelector.mImage = new BufferedImage(colorModel, raster, true, null);
+ // NativeRenderer.setDeviceInfo(w, h, -1, w/412.0, 5.5);
+ // int error = NativeRenderer.renderBuffer(0, 0, w, h, linestride, mBuffer.getData());
+ // if (error != 0) {
+ // System.out.println("Error rendering native buffer " + error);
+ // }
+ // }
+ // repaint();
+ // how to resize within ratio of everything
}
-
@Override
public void componentMoved(ComponentEvent e) {
@@ -206,4 +231,41 @@ public class FrameBufferBuffer extends JPanel implements ComponentListener, Mous
g.drawImage(mImage, 0, 0, null);
}
}
+
+ public void setFrame(JFrame frame){
+ mFrame = frame;
+ }
+
+ public void calibrateNativeBuffer(){
+ DeviceInfo deviceInfo = DeviceInfoDB.getDeviceInfo(getDeviceSelector().currentDevice());
+ boolean magnified = getDeviceSelector().magnified();
+ int w = deviceInfo.getWidthPx();
+ int h = deviceInfo.getHeightPx();
+ final int linestride = w;
+ final int rMask = 0xff;
+ final int gMask = 0xff00;
+ final int bMask = 0xff0000;
+ final int bpp = 24;
+ synchronized (this) {
+ mBuffer = new DataBufferInt(h * linestride);
+ WritableRaster raster = Raster.createPackedRaster(mBuffer, w, h, linestride,
+ new int[]{rMask, gMask, bMask}, null);
+ ColorModel colorModel = new DirectColorModel(bpp, rMask, gMask, bMask);
+ BufferedImage image = new BufferedImage(colorModel, raster, true, null);
+ NativeRenderer.setDeviceInfo(deviceInfo, magnified);
+ int error = NativeRenderer.renderBuffer(0, 0, w, h, linestride, mBuffer.getData());
+ if (error != 0) {
+ System.out.println("Error rendering native buffer " + error);
+ }
+
+ mImage = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
+ Graphics2D gc = mImage.createGraphics();
+ double scale = (double)getWidth()/(double)w;
+ gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+ gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ gc.drawRenderedImage(image, AffineTransform.getScaleInstance(scale, scale));
+ }
+ repaint();
+ }
}