auto import from //branches/cupcake/...@131421
diff --git a/libs/surfaceflinger/Android.mk b/libs/surfaceflinger/Android.mk
index 53ba3bc..496e271 100644
--- a/libs/surfaceflinger/Android.mk
+++ b/libs/surfaceflinger/Android.mk
@@ -16,9 +16,7 @@
LayerBitmap.cpp \
LayerDim.cpp \
LayerOrientationAnim.cpp \
- LayerScreenshot.cpp \
OrientationAnimation.cpp \
- RFBServer.cpp \
SurfaceFlinger.cpp \
Tokenizer.cpp \
Transform.cpp \
diff --git a/libs/surfaceflinger/Layer.cpp b/libs/surfaceflinger/Layer.cpp
index 31e63ef..f65d669 100644
--- a/libs/surfaceflinger/Layer.cpp
+++ b/libs/surfaceflinger/Layer.cpp
@@ -186,7 +186,9 @@
copybit_device_t* copybit = mFlinger->getBlitEngine();
copybit->set_parameter(copybit, COPYBIT_TRANSFORM, getOrientation());
copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, s.alpha);
- copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE);
+ copybit->set_parameter(copybit, COPYBIT_DITHER,
+ s.flags & ISurfaceComposer::eLayerDither ?
+ COPYBIT_ENABLE : COPYBIT_DISABLE);
region_iterator it(clip);
err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
diff --git a/libs/surfaceflinger/LayerBase.cpp b/libs/surfaceflinger/LayerBase.cpp
index 9277a64..0cf53f7 100644
--- a/libs/surfaceflinger/LayerBase.cpp
+++ b/libs/surfaceflinger/LayerBase.cpp
@@ -26,6 +26,8 @@
#include <GLES/gl.h>
#include <GLES/glext.h>
+#include <hardware/hardware.h>
+
#include "clz.h"
#include "LayerBase.h"
#include "LayerBlur.h"
@@ -229,15 +231,10 @@
return Point(front.w, front.h);
}
-Transform LayerBase::getDrawingStateTransform() const
-{
- return drawingState().transform;
-}
-
void LayerBase::validateVisibility(const Transform& planeTransform)
{
const Layer::State& s(drawingState());
- const Transform tr(planeTransform * getDrawingStateTransform());
+ const Transform tr(planeTransform * s.transform);
const bool transformed = tr.transformed();
const Point size(getPhysicalSize());
@@ -420,7 +417,7 @@
}
void LayerBase::drawWithOpenGL(const Region& clip,
- GLint textureName, const GGLSurface& t) const
+ GLint textureName, const GGLSurface& t, int transform) const
{
const DisplayHardware& hw(graphicPlane(0).displayHardware());
const uint32_t fbHeight = hw.getHeight();
@@ -492,6 +489,12 @@
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
+
+ if (transform == HAL_TRANSFORM_ROT_90) {
+ glTranslatef(0, 1, 0);
+ glRotatef(-90, 0, 0, 1);
+ }
+
if (!(mFlags & DisplayHardware::NPOT_EXTENSION)) {
// find the smallest power-of-two that will accommodate our surface
GLuint tw = 1 << (31 - clz(t.width));
diff --git a/libs/surfaceflinger/LayerBase.h b/libs/surfaceflinger/LayerBase.h
index 2377a14..a020f44 100644
--- a/libs/surfaceflinger/LayerBase.h
+++ b/libs/surfaceflinger/LayerBase.h
@@ -169,13 +169,6 @@
virtual void validateVisibility(const Transform& globalTransform);
/**
- * getDrawingStateTransform - returns the drawing state's transform.
- * This is used in validateVisibility() and can be use to override or
- * modify the transform (if so make sure to trigger a transaction).
- */
- virtual Transform getDrawingStateTransform() const;
-
- /**
* lockPageFlip - called each time the screen is redrawn and returns whether
* the visible regions need to be recomputed (this is a fairly heavy
* operation, so this should be set only if needed). Typically this is used
@@ -200,10 +193,15 @@
* needsBlending - true if this surface needs blending
*/
virtual bool needsBlending() const { return false; }
-
+
/**
- * isSecure - true if this surface is secure, that is if it prevents a
- * screenshot to be taken,
+ * transformed -- true is this surface needs a to be transformed
+ */
+ virtual bool transformed() const { return mTransformed; }
+
+ /**
+ * isSecure - true if this surface is secure, that is if it prevents
+ * screenshots or vns servers.
*/
virtual bool isSecure() const { return false; }
@@ -222,7 +220,6 @@
}
int32_t getOrientation() const { return mOrientation; }
- bool transformed() const { return mTransformed; }
int tx() const { return mLeft; }
int ty() const { return mTop; }
@@ -233,7 +230,9 @@
GLuint createTexture() const;
void drawWithOpenGL(const Region& clip,
- GLint textureName, const GGLSurface& surface) const;
+ GLint textureName,
+ const GGLSurface& surface,
+ int transform = 0) const;
void clearWithOpenGL(const Region& clip) const;
diff --git a/libs/surfaceflinger/LayerBuffer.cpp b/libs/surfaceflinger/LayerBuffer.cpp
index fc0a603..00fab70 100644
--- a/libs/surfaceflinger/LayerBuffer.cpp
+++ b/libs/surfaceflinger/LayerBuffer.cpp
@@ -103,15 +103,6 @@
source->unregisterBuffers();
}
-Transform LayerBuffer::getDrawingStateTransform() const
-{
- Transform tr(LayerBaseClient::getDrawingStateTransform());
- sp<Source> source(getSource());
- if (source != 0)
- source->updateTransform(&tr);
- return tr;
-}
-
uint32_t LayerBuffer::doTransaction(uint32_t flags)
{
sp<Source> source(getSource());
@@ -141,6 +132,14 @@
}
}
+bool LayerBuffer::transformed() const
+{
+ sp<Source> source(getSource());
+ if (LIKELY(source != 0))
+ return source->transformed();
+ return false;
+}
+
/**
* This creates a "buffer" source for this surface
*/
@@ -316,7 +315,8 @@
}
void LayerBuffer::Source::unregisterBuffers() {
}
-void LayerBuffer::Source::updateTransform(Transform* tr) const {
+bool LayerBuffer::Source::transformed() const {
+ return mLayer.mTransformed;
}
// ---------------------------------------------------------------------------
@@ -363,6 +363,7 @@
mLayer.setNeedsBlending((info.h_alpha - info.l_alpha) > 0);
mBufferSize = info.getScanlineSize(buffers.hor_stride)*buffers.ver_stride;
mLayer.forceVisibilityTransaction();
+
}
LayerBuffer::BufferSource::~BufferSource()
@@ -419,15 +420,9 @@
mBuffer = buffer;
}
-void LayerBuffer::BufferSource::updateTransform(Transform* tr) const
+bool LayerBuffer::BufferSource::transformed() const
{
- uint32_t bufTransform = mBufferHeap.transform;
- // TODO: handle all transforms
- if (bufTransform == ISurface::BufferHeap::ROT_90) {
- Transform rot90;
- rot90.set(0, -1, 1, 0);
- *tr = (*tr) * rot90;
- }
+ return mBufferHeap.transform ? true : Source::transformed();
}
void LayerBuffer::BufferSource::onDraw(const Region& clip) const
@@ -476,7 +471,7 @@
if (UNLIKELY(mTemporaryDealer == 0)) {
// allocate a memory-dealer for this the first time
mTemporaryDealer = mLayer.mFlinger->getSurfaceHeapManager()
- ->createHeap(ISurfaceComposer::eHardware);
+ ->createHeap(ISurfaceComposer::eHardware);
mTempBitmap.init(mTemporaryDealer);
}
@@ -506,10 +501,23 @@
copybit_image_t dst;
hw.getDisplaySurface(&dst);
const copybit_rect_t& drect
- = reinterpret_cast<const copybit_rect_t&>(transformedBounds);
+ = reinterpret_cast<const copybit_rect_t&>(transformedBounds);
const State& s(mLayer.drawingState());
region_iterator it(clip);
- copybit->set_parameter(copybit, COPYBIT_TRANSFORM, mLayer.getOrientation());
+
+ // pick the right orientation for this buffer
+ int orientation = mLayer.getOrientation();
+ if (UNLIKELY(mBufferHeap.transform)) {
+ Transform rot90;
+ GraphicPlane::orientationToTransfrom(
+ ISurfaceComposer::eOrientation90, 0, 0, &rot90);
+ const Transform& planeTransform(mLayer.graphicPlane(0).transform());
+ const Layer::State& s(mLayer.drawingState());
+ Transform tr(planeTransform * s.transform * rot90);
+ orientation = tr.getOrientation();
+ }
+
+ copybit->set_parameter(copybit, COPYBIT_TRANSFORM, orientation);
copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, s.alpha);
copybit->set_parameter(copybit, COPYBIT_DITHER, COPYBIT_ENABLE);
@@ -536,10 +544,11 @@
t.data = (GGLubyte*)(intptr_t(src.img.base) + src.img.offset);
const Region dirty(Rect(t.width, t.height));
mLayer.loadTexture(dirty, mTextureName, t, w, h);
- mLayer.drawWithOpenGL(clip, mTextureName, t);
+ mLayer.drawWithOpenGL(clip, mTextureName, t, mBufferHeap.transform);
}
}
+
// ---------------------------------------------------------------------------
LayerBuffer::OverlaySource::OverlaySource(LayerBuffer& layer,
diff --git a/libs/surfaceflinger/LayerBuffer.h b/libs/surfaceflinger/LayerBuffer.h
index 5532532..2dc77f1 100644
--- a/libs/surfaceflinger/LayerBuffer.h
+++ b/libs/surfaceflinger/LayerBuffer.h
@@ -46,7 +46,7 @@
virtual void onVisibilityResolved(const Transform& planeTransform);
virtual void postBuffer(ssize_t offset);
virtual void unregisterBuffers();
- virtual void updateTransform(Transform* tr) const;
+ virtual bool transformed() const;
protected:
LayerBuffer& mLayer;
};
@@ -68,7 +68,7 @@
virtual void onDraw(const Region& clip) const;
virtual uint32_t doTransaction(uint32_t flags);
virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
- virtual Transform getDrawingStateTransform() const;
+ virtual bool transformed() const;
status_t registerBuffers(const ISurface::BufferHeap& buffers);
void postBuffer(ssize_t offset);
@@ -116,10 +116,10 @@
sp<Buffer> getBuffer() const;
void setBuffer(const sp<Buffer>& buffer);
- virtual void updateTransform(Transform* tr) const;
virtual void onDraw(const Region& clip) const;
virtual void postBuffer(ssize_t offset);
virtual void unregisterBuffers();
+ virtual bool transformed() const;
private:
mutable Mutex mLock;
sp<Buffer> mBuffer;
diff --git a/libs/surfaceflinger/LayerOrientationAnim.cpp b/libs/surfaceflinger/LayerOrientationAnim.cpp
index 46b3b19..2b72d7c 100644
--- a/libs/surfaceflinger/LayerOrientationAnim.cpp
+++ b/libs/surfaceflinger/LayerOrientationAnim.cpp
@@ -84,7 +84,7 @@
void LayerOrientationAnim::validateVisibility(const Transform&)
{
const Layer::State& s(drawingState());
- const Transform tr(getDrawingStateTransform());
+ const Transform tr(s.transform);
const Point size(getPhysicalSize());
uint32_t w = size.x;
uint32_t h = size.y;
diff --git a/libs/surfaceflinger/LayerScreenshot.cpp b/libs/surfaceflinger/LayerScreenshot.cpp
deleted file mode 100644
index 40c47b0..0000000
--- a/libs/surfaceflinger/LayerScreenshot.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#define LOG_TAG "SurfaceFlinger"
-
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Errors.h>
-#include <utils/Log.h>
-
-#include <core/SkBitmap.h>
-
-#include <ui/EGLDisplaySurface.h>
-
-#include "LayerBase.h"
-#include "LayerScreenshot.h"
-#include "SurfaceFlinger.h"
-#include "DisplayHardware/DisplayHardware.h"
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-const uint32_t LayerScreenshot::typeInfo = LayerBase::typeInfo | 0x40;
-const char* const LayerScreenshot::typeID = "LayerScreenshot";
-
-// ---------------------------------------------------------------------------
-
-LayerScreenshot::LayerScreenshot(SurfaceFlinger* flinger, DisplayID display)
- : LayerBase(flinger, display), mReply(0)
-{
-}
-
-LayerScreenshot::~LayerScreenshot()
-{
-}
-
-void LayerScreenshot::onDraw(const Region& clip) const
-{
- const DisplayHardware& hw(graphicPlane(0).displayHardware());
- copybit_image_t dst;
- hw.getDisplaySurface(&dst);
- if (dst.base != 0) {
- uint8_t const* src = (uint8_t const*)(intptr_t(dst.base) + dst.offset);
- const int fbWidth = dst.w;
- const int fbHeight = dst.h;
- const int fbFormat = dst.format;
-
- int x = mTransformedBounds.left;
- int y = mTransformedBounds.top;
- int w = mTransformedBounds.width();
- int h = mTransformedBounds.height();
- Parcel* const reply = mReply;
- if (reply) {
- const size_t Bpp = bytesPerPixel(fbFormat);
- const size_t size = w * h * Bpp;
- int32_t cfg = SkBitmap::kNo_Config;
- switch (fbFormat) {
- case PIXEL_FORMAT_RGBA_4444: cfg = SkBitmap::kARGB_4444_Config;
- case PIXEL_FORMAT_RGBA_8888: cfg = SkBitmap::kARGB_8888_Config;
- case PIXEL_FORMAT_RGB_565: cfg = SkBitmap::kRGB_565_Config;
- case PIXEL_FORMAT_A_8: cfg = SkBitmap::kA8_Config;
- }
- reply->writeInt32(0);
- reply->writeInt32(cfg);
- reply->writeInt32(w);
- reply->writeInt32(h);
- reply->writeInt32(w * Bpp);
- void* data = reply->writeInplace(size);
- if (data) {
- uint8_t* d = (uint8_t*)data;
- uint8_t const* s = src + (x + y*fbWidth) * Bpp;
- if (w == fbWidth) {
- memcpy(d, s, w*h*Bpp);
- } else {
- for (int y=0 ; y<h ; y++) {
- memcpy(d, s, w*Bpp);
- d += w*Bpp;
- s += fbWidth*Bpp;
- }
- }
- }
- }
- }
- mCV.broadcast();
-}
-
-void LayerScreenshot::takeScreenshot(Mutex& lock, Parcel* reply)
-{
- mReply = reply;
- mCV.wait(lock);
-}
-
-// ---------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/libs/surfaceflinger/LayerScreenshot.h b/libs/surfaceflinger/LayerScreenshot.h
deleted file mode 100644
index 2d9a8ec..0000000
--- a/libs/surfaceflinger/LayerScreenshot.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#ifndef ANDROID_LAYER_SCREENSHOT_H
-#define ANDROID_LAYER_SCREENSHOT_H
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <utils/threads.h>
-#include <utils/Parcel.h>
-
-#include "LayerBase.h"
-
-namespace android {
-
-// ---------------------------------------------------------------------------
-
-class LayerScreenshot : public LayerBase
-{
-public:
- static const uint32_t typeInfo;
- static const char* const typeID;
- virtual char const* getTypeID() const { return typeID; }
- virtual uint32_t getTypeInfo() const { return typeInfo; }
-
- LayerScreenshot(SurfaceFlinger* flinger, DisplayID display);
- virtual ~LayerScreenshot();
-
- virtual void onDraw(const Region& clip) const;
- virtual bool needsBlending() const { return true; }
- virtual bool isSecure() const { return false; }
-
- void takeScreenshot(Mutex& lock, Parcel* reply);
-
-private:
- mutable Condition mCV;
- Parcel* mReply;
-};
-
-// ---------------------------------------------------------------------------
-
-}; // namespace android
-
-#endif // ANDROID_LAYER_SCREENSHOT_H
diff --git a/libs/surfaceflinger/RFBServer.cpp b/libs/surfaceflinger/RFBServer.cpp
deleted file mode 100644
index c2c1989..0000000
--- a/libs/surfaceflinger/RFBServer.cpp
+++ /dev/null
@@ -1,722 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#define LOG_TAG "RFBServer"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-
-#include <netinet/in.h>
-
-#include <cutils/sockets.h>
-
-#include <utils/Log.h>
-#include <ui/Rect.h>
-
-#ifdef HAVE_ANDROID_OS
-#include <linux/input.h>
-#endif
-
-#include "RFBServer.h"
-#include "SurfaceFlinger.h"
-
-/* BUG=773511: this is a temporary hack required while developing the new
- set of "clean kernel headers" for the Bionic C library. */
-#ifndef KEY_STAR
-#define KEY_STAR 227
-#endif
-#ifndef KEY_SHARP
-#define KEY_SHARP 228
-#endif
-#ifndef KEY_SOFT1
-#define KEY_SOFT1 229
-#endif
-#ifndef KEY_SOFT2
-#define KEY_SOFT2 230
-#endif
-#ifndef KEY_CENTER
-#define KEY_CENTER 232
-#endif
-
-// ----------------------------------------------------------------------------
-
-#define DEBUG_MSG 0
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-const int VNC_PORT = 5900;
-
-RFBServer::RFBServer(uint32_t w, uint32_t h, android::PixelFormat format)
- : Thread(false), mFD(-1), mStatus(NO_INIT), mIoVec(0)
-{
- mFrameBuffer.version = sizeof(mFrameBuffer);
- mFrameBuffer.width = w;
- mFrameBuffer.height = h;
- mFrameBuffer.stride = w;
- mFrameBuffer.format = format;
- mFrameBuffer.data = 0;
-}
-
-RFBServer::~RFBServer()
-{
- if (mRobinThread != 0) {
- // ask the thread to exit first
- mRobinThread->exitAndWait();
- }
-
- free(mFrameBuffer.data);
-
- delete [] mIoVec;
-}
-
-void RFBServer::onFirstRef()
-{
- run("Batman");
-}
-
-status_t RFBServer::readyToRun()
-{
- LOGI("RFB server ready to run");
- return NO_ERROR;
-}
-
-bool RFBServer::threadLoop()
-{
- struct sockaddr addr;
- socklen_t alen;
- int serverfd = -1;
- int port = VNC_PORT;
-
- do {
- retry:
- if (serverfd < 0) {
- serverfd = socket_loopback_server(port, SOCK_STREAM);
- if (serverfd < 0) {
- if ((errno == EADDRINUSE) && (port < (VNC_PORT+10))) {
- LOGW("port %d already in use, trying %d", port, port+1);
- port++;
- goto retry;
- }
- LOGE("couldn't create socket, port=%d, error %d (%s)",
- port, errno, strerror(errno));
- sleep(1);
- break;
- }
- fcntl(serverfd, F_SETFD, FD_CLOEXEC);
- }
-
- alen = sizeof(addr);
- mFD = accept(serverfd, &addr, &alen);
-
- if (mFD < 0) {
- LOGE("couldn't accept(), error %d (%s)", errno, strerror(errno));
- // we could have run out of file descriptors, wait a bit and
- // try again.
- sleep(1);
- goto retry;
- }
- fcntl(mFD, F_SETFD, FD_CLOEXEC);
-
- // send protocol version and Authentication method
- mStatus = NO_ERROR;
- handshake(3, 3, Authentication::None);
-
- if (alive()) {
- // create the thread we use to send data to the client
- mRobinThread = new ServerThread(this);
- }
-
- while( alive() ) {
- // client message must be destroyed at each iteration
- // (most of the time this is a no-op)
- ClientMessage msg;
- waitForClientMessage(msg);
- if (alive()) {
- handleClientMessage(msg);
- }
- }
-
- } while( alive() );
-
- // free-up some resources
- if (mRobinThread != 0) {
- mRobinThread->exitAndWait();
- mRobinThread.clear();
- }
-
- free(mFrameBuffer.data);
- mFrameBuffer.data = 0;
-
- close(mFD);
- close(serverfd);
- mFD = -1;
-
- // we'll try again
- return true;
-}
-
-// ----------------------------------------------------------------------------
-
-RFBServer::ServerThread::ServerThread(const sp<RFBServer>& receiver)
- : Thread(false), mReceiver(receiver)
-{
- LOGD("RFB Server Thread created");
-}
-
-RFBServer::ServerThread::~ServerThread()
-{
- LOGD("RFB Server Thread destroyed");
-}
-
-void RFBServer::ServerThread::onFirstRef()
-{
- mUpdateBarrier.close();
- run("Robin");
-}
-
-status_t RFBServer::ServerThread::readyToRun()
-{
- return NO_ERROR;
-}
-
-void RFBServer::ServerThread::wake()
-{
- mUpdateBarrier.open();
-}
-
-void RFBServer::ServerThread::exitAndWait()
-{
- requestExit();
- mUpdateBarrier.open();
- requestExitAndWait();
-}
-
-bool RFBServer::ServerThread::threadLoop()
-{
- sp<RFBServer> receiver(mReceiver.promote());
- if (receiver == 0)
- return false;
-
- // wait for something to do
- mUpdateBarrier.wait();
-
- // we're asked to quit, abort everything
- if (exitPending())
- return false;
-
- mUpdateBarrier.close();
-
- // process updates
- receiver->sendFrameBufferUpdates();
- return !exitPending();
-}
-
-// ----------------------------------------------------------------------------
-
-void RFBServer::handshake(uint8_t major, uint8_t minor, uint32_t auth)
-{
- ProtocolVersion protocolVersion(major, minor);
- if( !write(protocolVersion) )
- return;
-
- if ( !read(protocolVersion) )
- return;
-
- int maj, min;
- if ( protocolVersion.decode(maj, min) != NO_ERROR ) {
- mStatus = -1;
- return;
- }
-
-#if DEBUG_MSG
- LOGD("client protocol string: <%s>", (char*)protocolVersion.payload());
- LOGD("client wants protocol version %d.%d\n", maj, min);
-#endif
-
- Authentication authentication(auth);
- if( !write(authentication) )
- return;
-
- ClientInitialization clientInit;
- if ( !read(clientInit) )
- return;
-
-#if DEBUG_MSG
- LOGD("client initialization: sharedFlags = %d\n", clientInit.sharedFlags());
-#endif
-
- ServerInitialization serverInit("Android RFB");
- ServerInitialization::Payload& message(serverInit.message());
- message.framebufferWidth = htons(mFrameBuffer.width);
- message.framebufferHeight = htons(mFrameBuffer.height);
- message.serverPixelFormat.bitsPerPixel = 16;
- message.serverPixelFormat.depth = 16;
- message.serverPixelFormat.bigEndianFlag = 0;
- message.serverPixelFormat.trueColorFlag = 1;
- message.serverPixelFormat.redMax = htons((1<<5)-1);
- message.serverPixelFormat.greenMax = htons((1<<6)-1);
- message.serverPixelFormat.blueMax = htons((1<<5)-1);
- message.serverPixelFormat.redShift = 11;
- message.serverPixelFormat.greenShift = 5;
- message.serverPixelFormat.blueShift = 0;
-
- mIoVec = new iovec[mFrameBuffer.height];
-
- write(serverInit);
-}
-
-void RFBServer::handleClientMessage(const ClientMessage& msg)
-{
- switch(msg.type()) {
- case SET_PIXEL_FORMAT:
- handleSetPixelFormat(msg.messages().setPixelFormat);
- break;
- case SET_ENCODINGS:
- handleSetEncodings(msg.messages().setEncodings);
- break;
- case FRAME_BUFFER_UPDATE_REQ:
- handleFrameBufferUpdateReq(msg.messages().frameBufferUpdateRequest);
- break;
- case KEY_EVENT:
- handleKeyEvent(msg.messages().keyEvent);
- break;
- }
-}
-
-void RFBServer::handleSetPixelFormat(const SetPixelFormat& msg)
-{
- if (!validatePixelFormat(msg.pixelFormat)) {
- LOGE("The builtin VNC server only supports the RGB 565 pixel format");
- LOGD("requested pixel format:");
- LOGD("bitsPerPixel: %d", msg.pixelFormat.bitsPerPixel);
- LOGD("depth: %d", msg.pixelFormat.depth);
- LOGD("bigEndianFlag: %d", msg.pixelFormat.bigEndianFlag);
- LOGD("trueColorFlag: %d", msg.pixelFormat.trueColorFlag);
- LOGD("redmax: %d", ntohs(msg.pixelFormat.redMax));
- LOGD("bluemax: %d", ntohs(msg.pixelFormat.greenMax));
- LOGD("greenmax: %d", ntohs(msg.pixelFormat.blueMax));
- LOGD("redshift: %d", msg.pixelFormat.redShift);
- LOGD("greenshift: %d", msg.pixelFormat.greenShift);
- LOGD("blueshift: %d", msg.pixelFormat.blueShift);
- mStatus = -1;
- }
-}
-
-bool RFBServer::validatePixelFormat(const PixelFormat& pf)
-{
- if ((pf.bitsPerPixel != 16) || (pf.depth != 16))
- return false;
-
- if (pf.bigEndianFlag || !pf.trueColorFlag)
- return false;
-
- if (ntohs(pf.redMax)!=0x1F ||
- ntohs(pf.greenMax)!=0x3F ||
- ntohs(pf.blueMax)!=0x1F) {
- return false;
- }
-
- if (pf.redShift!=11 || pf.greenShift!=5 || pf.blueShift!=0)
- return false;
-
- return true;
-}
-
-void RFBServer::handleSetEncodings(const SetEncodings& msg)
-{
- /* From the RFB specification:
- Sets the encoding types in which pixel data can be sent by the server.
- The order of the encoding types given in this message is a hint by the
- client as to its preference (the first encoding specified being most
- preferred). The server may or may not choose to make use of this hint.
- Pixel data may always be sent in raw encoding even if not specified
- explicitly here.
- */
-
- LOGW("SetEncodings received. Only RAW is supported.");
-}
-
-void RFBServer::handleFrameBufferUpdateReq(const FrameBufferUpdateRequest& msg)
-{
-#if DEBUG_MSG
- LOGD("handle FrameBufferUpdateRequest");
-#endif
-
- Rect r;
- r.left = ntohs(msg.x);
- r.top = ntohs(msg.y);
- r.right = r.left + ntohs(msg.width);
- r.bottom = r.top + ntohs(msg.height);
-
- Mutex::Autolock _l(mRegionLock);
- mClientRegionRequest.set(r);
- if (!msg.incremental)
- mDirtyRegion.orSelf(r);
-
- mRobinThread->wake();
-}
-
-void RFBServer::handleKeyEvent(const KeyEvent& msg)
-{
-#ifdef HAVE_ANDROID_OS
-
- int scancode = 0;
- int code = ntohl(msg.key);
-
- if (code>='0' && code<='9') {
- scancode = (code & 0xF) - 1;
- if (scancode<0) scancode += 10;
- scancode += KEY_1;
- } else if (code>=0xFF50 && code<=0xFF58) {
- static const uint16_t map[] =
- { KEY_HOME, KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN,
- KEY_SOFT1, KEY_SOFT2, KEY_END, 0 };
- scancode = map[code & 0xF];
- } else if (code>=0xFFE1 && code<=0xFFEE) {
- static const uint16_t map[] =
- { KEY_LEFTSHIFT, KEY_LEFTSHIFT,
- KEY_COMPOSE, KEY_COMPOSE,
- KEY_LEFTSHIFT, KEY_LEFTSHIFT,
- 0,0,
- KEY_LEFTALT, KEY_RIGHTALT,
- 0, 0, 0, 0 };
- scancode = map[code & 0xF];
- } else if ((code>='A' && code<='Z') || (code>='a' && code<='z')) {
- static const uint16_t map[] = {
- KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
- KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
- KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
- KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
- KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z };
- scancode = map[(code & 0x5F) - 'A'];
- } else {
- switch (code) {
- case 0x0003: scancode = KEY_CENTER; break;
- case 0x0020: scancode = KEY_SPACE; break;
- case 0x0023: scancode = KEY_SHARP; break;
- case 0x0033: scancode = KEY_SHARP; break;
- case 0x002C: scancode = KEY_COMMA; break;
- case 0x003C: scancode = KEY_COMMA; break;
- case 0x002E: scancode = KEY_DOT; break;
- case 0x003E: scancode = KEY_DOT; break;
- case 0x002F: scancode = KEY_SLASH; break;
- case 0x003F: scancode = KEY_SLASH; break;
- case 0x0032: scancode = KEY_EMAIL; break;
- case 0x0040: scancode = KEY_EMAIL; break;
- case 0xFF08: scancode = KEY_BACKSPACE; break;
- case 0xFF1B: scancode = KEY_BACK; break;
- case 0xFF09: scancode = KEY_TAB; break;
- case 0xFF0D: scancode = KEY_ENTER; break;
- case 0x002A: scancode = KEY_STAR; break;
- case 0xFFBE: scancode = KEY_SEND; break; // F1
- case 0xFFBF: scancode = KEY_END; break; // F2
- case 0xFFC0: scancode = KEY_HOME; break; // F3
- case 0xFFC5: scancode = KEY_POWER; break; // F8
- }
- }
-
-#if DEBUG_MSG
- LOGD("handle KeyEvent 0x%08x, %d, scancode=%d\n", code, msg.downFlag, scancode);
-#endif
-
- if (scancode) {
- mEventInjector.injectKey(uint16_t(scancode),
- msg.downFlag ? EventInjector::DOWN : EventInjector::UP);
- }
-#endif
-}
-
-void RFBServer::waitForClientMessage(ClientMessage& msg)
-{
- if ( !read(msg.payload(), 1) )
- return;
-
- switch(msg.type()) {
-
- case SET_PIXEL_FORMAT:
- read(msg.payload(1), sizeof(SetPixelFormat)-1);
- break;
-
- case FIX_COLOUR_MAP_ENTRIES:
- mStatus = UNKNOWN_ERROR;
- return;
-
- case SET_ENCODINGS:
- {
- if ( !read(msg.payload(1), sizeof(SetEncodings)-1) )
- return;
-
- size_t size = ntohs( msg.messages().setEncodings.numberOfEncodings ) * 4;
- if (msg.resize(sizeof(SetEncodings) + size) != NO_ERROR) {
- mStatus = NO_MEMORY;
- return;
- }
-
- if ( !read(msg.payload(sizeof(SetEncodings)), size) )
- return;
-
- break;
- }
-
- case FRAME_BUFFER_UPDATE_REQ:
- read(msg.payload(1), sizeof(FrameBufferUpdateRequest)-1);
- break;
-
- case KEY_EVENT:
- read(msg.payload(1), sizeof(KeyEvent)-1);
- break;
-
- case POINTER_EVENT:
- read(msg.payload(1), sizeof(PointerEvent)-1);
- break;
-
- case CLIENT_CUT_TEXT:
- {
- if ( !read(msg.payload(1), sizeof(ClientCutText)-1) )
- return;
-
- size_t size = ntohl( msg.messages().clientCutText.length );
- if (msg.resize(sizeof(ClientCutText) + size) != NO_ERROR) {
- mStatus = NO_MEMORY;
- return;
- }
-
- if ( !read(msg.payload(sizeof(SetEncodings)), size) )
- return;
-
- break;
- }
-
- default:
- LOGE("Unknown Message %d", msg.type());
- mStatus = UNKNOWN_ERROR;
- return;
- }
-}
-
-// ----------------------------------------------------------------------------
-
-bool RFBServer::write(const Message& msg)
-{
- write(msg.payload(), msg.size());
- return alive();
-}
-
-bool RFBServer::read(Message& msg)
-{
- read(msg.payload(), msg.size());
- return alive();
-}
-
-bool RFBServer::write(const void* buffer, int size)
-{
- int wr = ::write(mFD, buffer, size);
- if (wr != size) {
- //LOGE("write(%d) error %d (%s)", size, wr, strerror(errno));
- mStatus = (wr == -1) ? errno : -1;
- }
- return alive();
-}
-
-bool RFBServer::read(void* buffer, int size)
-{
- int rd = ::read(mFD, buffer, size);
- if (rd != size) {
- //LOGE("read(%d) error %d (%s)", size, rd, strerror(errno));
- mStatus = (rd == -1) ? errno : -1;
- }
- return alive();
-}
-
-bool RFBServer::alive() const
-{
- return mStatus == 0;
-}
-
-bool RFBServer::isConnected() const
-{
- return alive();
-}
-
-// ----------------------------------------------------------------------------
-
-void RFBServer::frameBufferUpdated(const GGLSurface& front, const Region& reg)
-{
- Mutex::Autolock _l(mRegionLock);
-
- // update dirty region
- mDirtyRegion.orSelf(reg);
-
- // remember the front-buffer
- mFrontBuffer = front;
-
- // The client has not requested anything, don't do anything more
- if (mClientRegionRequest.isEmpty())
- return;
-
- // wake the sending thread up
- mRobinThread->wake();
-}
-
-void RFBServer::sendFrameBufferUpdates()
-{
- Vector<Rect> rects;
- size_t countRects;
- GGLSurface fb;
-
- { // Scope for the lock
- Mutex::Autolock _l(mRegionLock);
- if (mFrontBuffer.data == 0)
- return;
-
- const Region reg( mDirtyRegion.intersect(mClientRegionRequest) );
- if (reg.isEmpty())
- return;
-
- mDirtyRegion.subtractSelf(reg);
- countRects = reg.rects(rects);
-
- // copy the frame-buffer so we can stay responsive
- size_t bytesPerPix = bytesPerPixel(mFrameBuffer.format);
- size_t bpr = mFrameBuffer.stride * bytesPerPix;
- if (mFrameBuffer.data == 0) {
- mFrameBuffer.data = (GGLubyte*)malloc(bpr * mFrameBuffer.height);
- if (mFrameBuffer.data == 0)
- return;
- }
-
- memcpy(mFrameBuffer.data, mFrontBuffer.data, bpr*mFrameBuffer.height);
- fb = mFrameBuffer;
- }
-
- FrameBufferUpdate msgHeader;
- msgHeader.type = 0;
- msgHeader.numberOfRectangles = htons(countRects);
- write(&msgHeader, sizeof(msgHeader));
-
- Rectangle rectangle;
- for (size_t i=0 ; i<countRects ; i++) {
- const Rect& r = rects[i];
- rectangle.x = htons( r.left );
- rectangle.y = htons( r.top );
- rectangle.w = htons( r.width() );
- rectangle.h = htons( r.height() );
- rectangle.encoding = htons( SetEncodings::Raw );
- write(&rectangle, sizeof(rectangle));
- size_t h = r.height();
- size_t w = r.width();
- size_t bytesPerPix = bytesPerPixel(fb.format);
- size_t bpr = fb.stride * bytesPerPix;
- size_t bytes = w * bytesPerPix;
- size_t offset = (r.top * bpr) + (r.left * bytesPerPix);
- uint8_t* src = static_cast<uint8_t*>(fb.data) + offset;
- iovec* iov = mIoVec;
- while (h--) {
- iov->iov_base = src;
- iov->iov_len = bytes;
- src += bpr;
- iov++;
- }
- size_t iovcnt = iov - mIoVec;
- int wr = ::writev(mFD, mIoVec, iovcnt);
- if (wr < 0) {
- //LOGE("write(%d) error %d (%s)", size, wr, strerror(errno));
- mStatus = errno;
- }
- }
-}
-
-// ----------------------------------------------------------------------------
-
-RFBServer::Message::Message(size_t size)
- : mSize(size), mAllocatedSize(size)
-{
- mPayload = malloc(size);
-}
-
-RFBServer::Message::Message(void* payload, size_t size)
- : mPayload(payload), mSize(size), mAllocatedSize(0)
-{
-}
-
-RFBServer::Message::~Message()
-{
- if (mAllocatedSize)
- free(mPayload);
-}
-
-status_t RFBServer::Message::resize(size_t size)
-{
- if (size > mAllocatedSize) {
- void* newp;
- if (mAllocatedSize) {
- newp = realloc(mPayload, size);
- if (!newp) return NO_MEMORY;
- } else {
- newp = malloc(size);
- if (!newp) return NO_MEMORY;
- memcpy(newp, mPayload, mSize);
- mAllocatedSize = size;
- }
- mPayload = newp;
- }
- mSize = size;
- return NO_ERROR;
-}
-
-// ----------------------------------------------------------------------------
-
-RFBServer::EventInjector::EventInjector()
- : mFD(-1)
-{
-}
-
-RFBServer::EventInjector::~EventInjector()
-{
-}
-
-void RFBServer::EventInjector::injectKey(uint16_t code, uint16_t value)
-{
-#ifdef HAVE_ANDROID_OS
- // XXX: we need to open the right event device
- int version;
- mFD = open("/dev/input/event0", O_RDWR);
- ioctl(mFD, EVIOCGVERSION, &version);
-
- input_event ev;
- memset(&ev, 0, sizeof(ev));
- ev.type = EV_KEY;
- ev.code = code;
- ev.value = value;
- ::write(mFD, &ev, sizeof(ev));
-
- close(mFD);
- mFD = -1;
-#endif
-}
-
-
-}; // namespace android
-
diff --git a/libs/surfaceflinger/RFBServer.h b/libs/surfaceflinger/RFBServer.h
deleted file mode 100644
index 420912e..0000000
--- a/libs/surfaceflinger/RFBServer.h
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#ifndef ANDROID_RFB_SERVER_H
-#define ANDROID_RFB_SERVER_H
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-
-#include <utils/Errors.h>
-#include <utils/threads.h>
-#include <ui/Region.h>
-#include <ui/PixelFormat.h>
-
-#include <pixelflinger/pixelflinger.h>
-
-#include "Barrier.h"
-
-namespace android {
-
-class SurfaceFlinger;
-
-class RFBServer : public Thread
-{
-public:
- RFBServer(uint32_t w, uint32_t h, android::PixelFormat format);
- virtual ~RFBServer();
-
- void frameBufferUpdated(const GGLSurface& front, const Region& reg);
- bool isConnected() const;
-
-private:
- typedef uint8_t card8;
- typedef uint16_t card16;
- typedef uint32_t card32;
-
- struct Message {
- Message(size_t size);
- virtual ~Message();
- void* payload(int offset=0) {
- return static_cast<char*>(mPayload)+offset;
- }
- void const * payload(int offset=0) const {
- return static_cast<char const *>(mPayload)+offset;
- }
- size_t size() const { return mSize; }
- protected:
- Message(void* payload, size_t size);
- status_t resize(size_t size);
- private:
- void* mPayload;
- size_t mSize;
- size_t mAllocatedSize;
- };
-
- struct ProtocolVersion : public Message {
- ProtocolVersion(uint8_t major, uint8_t minor)
- : Message(&messageData, 12) {
- char* p = static_cast<char*>(payload());
- snprintf(p, 13, "RFB %03u.%03u%c", major, minor, 0xA);
- }
- status_t decode(int& maj, int& min) {
- char* p = static_cast<char*>(payload());
- int n = sscanf(p, "RFB %03u.%03u", &maj, &min);
- return (n == 2) ? NO_ERROR : NOT_ENOUGH_DATA;
- }
- private:
- char messageData[12+1];
- };
-
- struct Authentication : public Message {
- enum { Failed=0, None=1, Vnc=2 };
- Authentication(int auth) : Message(&messageData, 4) {
- *static_cast<card32*>(payload()) = htonl(auth);
- }
- private:
- card32 messageData;
- };
-
- struct ClientInitialization : public Message {
- ClientInitialization() : Message(&messageData, 1) { }
- int sharedFlags() {
- return messageData;
- }
- private:
- card8 messageData;
- };
-
- struct PixelFormat {
- card8 bitsPerPixel;
- card8 depth;
- card8 bigEndianFlag;
- card8 trueColorFlag;
- card16 redMax;
- card16 greenMax;
- card16 blueMax;
- card8 redShift;
- card8 greenShift;
- card8 blueShift;
- uint8_t padding[3];
- } __attribute__((packed));
-
- struct ServerInitialization : public Message {
- ServerInitialization(char const * name)
- : Message(sizeof(Payload) + strlen(name))
- {
- const size_t nameLength = size() - sizeof(Payload);
- message().nameLength = htonl(nameLength);
- memcpy((char*)message().nameString, name,nameLength);
- }
- struct Payload {
- card16 framebufferWidth;
- card16 framebufferHeight;
- PixelFormat serverPixelFormat;
- card32 nameLength;
- card8 nameString[0];
- } __attribute__((packed));
- Payload& message() {
- return *static_cast<Payload*>(payload());
- }
- };
-
- // client messages...
-
- struct SetPixelFormat {
- card8 type;
- uint8_t padding[3];
- PixelFormat pixelFormat;
- } __attribute__((packed));
-
- struct SetEncodings {
- enum { Raw=0, CoR=1, RRE=2, CoRRE=4, Hextile=5 };
- card8 type;
- uint8_t padding;
- card16 numberOfEncodings;
- card32 encodings[0];
- } __attribute__((packed));
-
- struct FrameBufferUpdateRequest {
- card8 type;
- card8 incremental;
- card16 x;
- card16 y;
- card16 width;
- card16 height;
- } __attribute__((packed));
-
- struct KeyEvent {
- card8 type;
- card8 downFlag;
- uint8_t padding[2];
- card32 key;
- } __attribute__((packed));
-
- struct PointerEvent {
- card8 type;
- card8 buttonMask;
- card16 x;
- card16 y;
- } __attribute__((packed));
-
- struct ClientCutText {
- card8 type;
- uint8_t padding[3];
- card32 length;
- card8 text[0];
- } __attribute__((packed));
-
- union ClientMessages {
- card8 type;
- SetPixelFormat setPixelFormat;
- SetEncodings setEncodings;
- FrameBufferUpdateRequest frameBufferUpdateRequest;
- KeyEvent keyEvent;
- PointerEvent pointerEvent;
- ClientCutText clientCutText;
- };
-
- struct Rectangle {
- card16 x;
- card16 y;
- card16 w;
- card16 h;
- card32 encoding;
- } __attribute__((packed));
-
- struct FrameBufferUpdate {
- card8 type;
- uint8_t padding;
- card16 numberOfRectangles;
- Rectangle rectangles[0];
- } __attribute__((packed));
-
- enum {
- SET_PIXEL_FORMAT = 0,
- FIX_COLOUR_MAP_ENTRIES = 1,
- SET_ENCODINGS = 2,
- FRAME_BUFFER_UPDATE_REQ = 3,
- KEY_EVENT = 4,
- POINTER_EVENT = 5,
- CLIENT_CUT_TEXT = 6,
- };
-
- struct ClientMessage : public Message {
- ClientMessage()
- : Message(&messageData, sizeof(messageData)) {
- }
- const ClientMessages& messages() const {
- return *static_cast<ClientMessages const *>(payload());
- }
- const int type() const {
- return messages().type;
- }
- status_t resize(size_t size) {
- return Message::resize(size);
- }
-
- ClientMessages messageData;
- };
-
-
- class ServerThread : public Thread
- {
- friend class RFBServer;
- public:
- ServerThread(const sp<RFBServer>& receiver);
- virtual ~ServerThread();
- void wake();
- void exitAndWait();
- private:
- virtual bool threadLoop();
- virtual status_t readyToRun();
- virtual void onFirstRef();
- wp<RFBServer> mReceiver;
- bool (RFBServer::*mAction)();
- Barrier mUpdateBarrier;
- };
-
- class EventInjector {
- public:
- enum { UP=0, DOWN=1 };
- EventInjector();
- ~EventInjector();
- void injectKey(uint16_t code, uint16_t value);
- private:
- struct input_event {
- struct timeval time;
- uint16_t type;
- uint16_t code;
- uint32_t value;
- };
- int mFD;
- };
-
- void handshake(uint8_t major, uint8_t minor, uint32_t auth);
- void waitForClientMessage(ClientMessage& msg);
- void handleClientMessage(const ClientMessage& msg);
- void handleSetPixelFormat(const SetPixelFormat& msg);
- void handleSetEncodings(const SetEncodings& msg);
- void handleFrameBufferUpdateReq(const FrameBufferUpdateRequest& msg);
- void handleKeyEvent(const KeyEvent& msg);
- void sendFrameBufferUpdates();
-
- bool validatePixelFormat(const PixelFormat& pf);
- bool alive() const;
- bool write(const Message& msg);
- bool read(Message& msg);
-
- bool write(const void* buffer, int size);
- bool read(void* buffer, int size);
-
- virtual bool threadLoop();
- virtual status_t readyToRun();
- virtual void onFirstRef();
-
- sp<ServerThread> mRobinThread;
-
- int mFD;
- int mStatus;
- iovec* mIoVec;
-
- EventInjector mEventInjector;
-
- Mutex mRegionLock;
- // This is the region requested by the client since the last
- // time we updated it
- Region mClientRegionRequest;
- // This is the region of the screen that needs to be sent to the
- // client since the last time we updated it.
- // Typically this is the dirty region, but not necessarily, for
- // instance if the client asked for a non incremental update.
- Region mDirtyRegion;
-
- GGLSurface mFrameBuffer;
- GGLSurface mFrontBuffer;
-};
-
-}; // namespace android
-
-#endif // ANDROID_RFB_SERVER_H
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index 4e457c9..900282a 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -53,21 +53,14 @@
#include "LayerDim.h"
#include "LayerBitmap.h"
#include "LayerOrientationAnim.h"
-#include "LayerScreenshot.h"
#include "OrientationAnimation.h"
#include "SurfaceFlinger.h"
-#include "RFBServer.h"
#include "VRamHeap.h"
#include "DisplayHardware/DisplayHardware.h"
#include "GPUHardware/GPUHardware.h"
-// the VNC server even on local ports presents a significant
-// thread as it can allow an application to control and "see" other
-// applications, de-facto bypassing security permissions.
-#define ENABLE_VNC_SERVER 0
-
#define DISPLAY_COUNT 1
namespace android {
@@ -460,9 +453,6 @@
if (mDebugNoBootAnimation == false)
mBootAnimation = new BootAnimation(this);
- if (ENABLE_VNC_SERVER)
- mRFBServer = new RFBServer(w, h, f);
-
return NO_ERROR;
}
@@ -572,18 +562,6 @@
debugShowFPS();
}
- if (UNLIKELY(ENABLE_VNC_SERVER &&
- mRFBServer!=0 && mRFBServer->isConnected())) {
- if (!mSecureFrameBuffer) {
- GGLSurface fb;
- // backbufer, is going to become the front buffer really soon
- hw.getDisplaySurface(&fb);
- if (LIKELY(fb.data != 0)) {
- mRFBServer->frameBufferUpdated(fb, mInvalidRegion);
- }
- }
- }
-
hw.flip(mInvalidRegion);
mInvalidRegion.clear();
@@ -1571,55 +1549,17 @@
status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags);
if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
- if (code == 1012) {
- // take screen-shot of the front buffer
- if (UNLIKELY(checkCallingPermission(
- String16("android.permission.READ_FRAME_BUFFER")) == false))
- { // not allowed
- LOGE("Permission Denial: "
- "can't take screenshots from pid=%d, uid=%d\n",
- IPCThreadState::self()->getCallingPid(),
- IPCThreadState::self()->getCallingUid());
- return PERMISSION_DENIED;
- }
-
- if (UNLIKELY(mSecureFrameBuffer)) {
- LOGE("A secure window is on screen: "
- "can't take screenshots from pid=%d, uid=%d\n",
- IPCThreadState::self()->getCallingPid(),
- IPCThreadState::self()->getCallingUid());
- return PERMISSION_DENIED;
- }
-
- LOGI("Taking a screenshot...");
-
- LayerScreenshot* l = new LayerScreenshot(this, 0);
-
- Mutex::Autolock _l(mStateLock);
- const DisplayHardware& hw(graphicPlane(0).displayHardware());
- l->initStates(hw.getWidth(), hw.getHeight(), 0);
- l->setLayer(INT_MAX);
-
- addLayer_l(l);
- setTransactionFlags(eTransactionNeeded|eTraversalNeeded);
-
- l->takeScreenshot(mStateLock, reply);
-
- removeLayer_l(l);
- setTransactionFlags(eTransactionNeeded);
- return NO_ERROR;
- } else {
- // HARDWARE_TEST stuff...
- if (UNLIKELY(checkCallingPermission(
- String16("android.permission.HARDWARE_TEST")) == false))
- { // not allowed
- LOGE("Permission Denial: pid=%d, uid=%d\n",
- IPCThreadState::self()->getCallingPid(),
- IPCThreadState::self()->getCallingUid());
- return PERMISSION_DENIED;
- }
- int n;
- switch (code) {
+ // HARDWARE_TEST stuff...
+ if (UNLIKELY(checkCallingPermission(
+ String16("android.permission.HARDWARE_TEST")) == false))
+ { // not allowed
+ LOGE("Permission Denial: pid=%d, uid=%d\n",
+ IPCThreadState::self()->getCallingPid(),
+ IPCThreadState::self()->getCallingUid());
+ return PERMISSION_DENIED;
+ }
+ int n;
+ switch (code) {
case 1000: // SHOW_CPU
n = data.readInt32();
mDebugCpu = n ? 1 : 0;
@@ -1652,8 +1592,8 @@
const DisplayHardware& hw(graphicPlane(0).displayHardware());
mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe
signalEvent();
- }
- return NO_ERROR;
+ }
+ return NO_ERROR;
case 1005: // ask GPU revoke
mGPU->friendlyRevoke();
return NO_ERROR;
@@ -1669,13 +1609,12 @@
reply->writeInt32(mDebugRegion);
reply->writeInt32(mDebugBackground);
return NO_ERROR;
- case 1013: { // screenshot
+ case 1013: {
Mutex::Autolock _l(mStateLock);
const DisplayHardware& hw(graphicPlane(0).displayHardware());
reply->writeInt32(hw.getPageFlipCount());
}
return NO_ERROR;
- }
}
}
return err;
@@ -1829,10 +1768,33 @@
mGlobalTransform = mOrientationTransform * mTransform;
}
+status_t GraphicPlane::orientationToTransfrom(
+ int orientation, int w, int h, Transform* tr)
+{
+ float a, b, c, d, x, y;
+ switch (orientation) {
+ case ISurfaceComposer::eOrientationDefault:
+ a=1; b=0; c=0; d=1; x=0; y=0;
+ break;
+ case ISurfaceComposer::eOrientation90:
+ a=0; b=-1; c=1; d=0; x=w; y=0;
+ break;
+ case ISurfaceComposer::eOrientation180:
+ a=-1; b=0; c=0; d=-1; x=w; y=h;
+ break;
+ case ISurfaceComposer::eOrientation270:
+ a=0; b=1; c=-1; d=0; x=0; y=h;
+ break;
+ default:
+ return BAD_VALUE;
+ }
+ tr->set(a, b, c, d);
+ tr->set(x, y);
+ return NO_ERROR;
+}
+
status_t GraphicPlane::setOrientation(int orientation)
{
- float a, b, c, d, x, y;
-
const DisplayHardware& hw(displayHardware());
const float w = hw.getWidth();
const float h = hw.getHeight();
@@ -1846,30 +1808,21 @@
// If the rotation can be handled in hardware, this is where
// the magic should happen.
-
- switch (orientation) {
- case ISurfaceComposer::eOrientation90:
- a=0; b=-1; c=1; d=0; x=w; y=0;
- break;
- case ISurfaceComposer::eOrientation180:
- a=-1; b=0; c=0; d=-1; x=w; y=h;
- break;
- case ISurfaceComposer::eOrientation270:
- a=0; b=1; c=-1; d=0; x=0; y=h;
- break;
- case 42: {
+ if (UNLIKELY(orientation == 42)) {
+ float a, b, c, d, x, y;
const float r = (3.14159265f / 180.0f) * 42.0f;
const float si = sinf(r);
const float co = cosf(r);
a=co; b=-si; c=si; d=co;
x = si*(h*0.5f) + (1-co)*(w*0.5f);
y =-si*(w*0.5f) + (1-co)*(h*0.5f);
- } break;
- default:
- return BAD_VALUE;
+ mOrientationTransform.set(a, b, c, d);
+ mOrientationTransform.set(x, y);
+ } else {
+ GraphicPlane::orientationToTransfrom(orientation, w, h,
+ &mOrientationTransform);
}
- mOrientationTransform.set(a, b, c, d);
- mOrientationTransform.set(x, y);
+
mGlobalTransform = mOrientationTransform * mTransform;
return NO_ERROR;
}
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index 8e5fd88..f7d7764 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -58,7 +58,6 @@
class LayerBuffer;
class LayerOrientationAnim;
class OrientationAnimation;
-class RFBServer;
class SurfaceHeapManager;
typedef int32_t ClientID;
@@ -112,6 +111,8 @@
class GraphicPlane
{
public:
+ static status_t orientationToTransfrom(int orientation, int w, int h,
+ Transform* tr);
GraphicPlane();
~GraphicPlane();
@@ -344,7 +345,6 @@
sp<GPUHardwareInterface> mGPU;
GLuint mWormholeTexName;
sp<BootAnimation> mBootAnimation;
- sp<RFBServer> mRFBServer;
nsecs_t mBootTime;
// Can only accessed from the main thread, these members