Merge "SurfaceFlinger: screenshots w/ protected buffers"

This commit is contained in:
James Dong 2011-10-09 09:16:37 -07:00 committed by Android (Google) Code Review
commit 17076cea6a
3 changed files with 38 additions and 30 deletions

View File

@ -280,20 +280,29 @@ void Layer::onDraw(const Region& clip) const
return;
}
const GLenum target = GL_TEXTURE_EXTERNAL_OES;
glBindTexture(target, mTextureName);
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
// TODO: we could be more subtle with isFixedSize()
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GLenum target = GL_TEXTURE_EXTERNAL_OES;
if (!isProtected()) {
glBindTexture(target, mTextureName);
if (getFiltering() || needsFiltering() || isFixedSize() || isCropped()) {
// TODO: we could be more subtle with isFixedSize()
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
} else {
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
glEnable(target);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(mTextureMatrix);
glMatrixMode(GL_MODELVIEW);
} else {
glTexParameterx(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterx(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
target = GL_TEXTURE_2D;
glBindTexture(target, mFlinger->getProtectedTexName());
glEnable(target);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
}
glEnable(target);
glMatrixMode(GL_TEXTURE);
glLoadMatrixf(mTextureMatrix);
glMatrixMode(GL_MODELVIEW);
drawWithOpenGL(clip);

View File

@ -275,7 +275,7 @@ status_t SurfaceFlinger::readyToRun()
const uint16_t g0 = pack565(0x0F,0x1F,0x0F);
const uint16_t g1 = pack565(0x17,0x2f,0x17);
const uint16_t textureData[4] = { g0, g1, g1, g0 };
const uint16_t wormholeTexData[4] = { g0, g1, g1, g0 };
glGenTextures(1, &mWormholeTexName);
glBindTexture(GL_TEXTURE_2D, mWormholeTexName);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -283,7 +283,17 @@ status_t SurfaceFlinger::readyToRun()
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData);
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, wormholeTexData);
const uint16_t protTexData[] = { pack565(0x03, 0x03, 0x03) };
glGenTextures(1, &mProtectedTexName);
glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0,
GL_RGB, GL_UNSIGNED_SHORT_5_6_5, protTexData);
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
@ -2255,22 +2265,6 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT))
return BAD_VALUE;
// make sure none of the layers are protected
const LayerVector& layers(mDrawingState.layersSortedByZ);
const size_t count = layers.size();
for (size_t i=0 ; i<count ; ++i) {
const sp<LayerBase>& layer(layers[i]);
const uint32_t flags = layer->drawingState().flags;
if (!(flags & ISurfaceComposer::eLayerHidden)) {
const uint32_t z = layer->drawingState().z;
if (z >= minLayerZ && z <= maxLayerZ) {
if (layer->isProtected()) {
return INVALID_OPERATION;
}
}
}
}
if (!GLExtensions::getInstance().haveFramebufferObject())
return INVALID_OPERATION;
@ -2320,6 +2314,8 @@ status_t SurfaceFlinger::captureScreenImplLocked(DisplayID dpy,
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
const LayerVector& layers(mDrawingState.layersSortedByZ);
const size_t count = layers.size();
for (size_t i=0 ; i<count ; ++i) {
const sp<LayerBase>& layer(layers[i]);
const uint32_t flags = layer->drawingState().flags;

View File

@ -192,6 +192,8 @@ public:
sp<Layer> getLayer(const sp<ISurface>& sur) const;
GLuint getProtectedTexName() const { return mProtectedTexName; }
private:
// DeathRecipient interface
virtual void binderDied(const wp<IBinder>& who);
@ -349,6 +351,7 @@ private:
sp<IMemoryHeap> mServerHeap;
surface_flinger_cblk_t* mServerCblk;
GLuint mWormholeTexName;
GLuint mProtectedTexName;
nsecs_t mBootTime;
// Can only accessed from the main thread, these members