Layer.cpp revision 161534a3c5ee77bc91e7a73ffb6274f35324f8b5
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define ATRACE_TAG ATRACE_TAG_GRAPHICS 18 19#include <stdlib.h> 20#include <stdint.h> 21#include <sys/types.h> 22#include <math.h> 23 24#include <cutils/compiler.h> 25#include <cutils/native_handle.h> 26#include <cutils/properties.h> 27 28#include <utils/Errors.h> 29#include <utils/Log.h> 30#include <utils/StopWatch.h> 31#include <utils/Trace.h> 32 33#include <ui/GraphicBuffer.h> 34#include <ui/PixelFormat.h> 35 36#include <gui/Surface.h> 37 38#include "clz.h" 39#include "DisplayHardware/DisplayHardware.h" 40#include "DisplayHardware/HWComposer.h" 41#include "GLExtensions.h" 42#include "Layer.h" 43#include "SurfaceFlinger.h" 44#include "SurfaceTextureLayer.h" 45 46#define DEBUG_RESIZE 0 47 48namespace android { 49 50// --------------------------------------------------------------------------- 51 52Layer::Layer(SurfaceFlinger* flinger, 53 DisplayID display, const sp<Client>& client) 54 : LayerBaseClient(flinger, display, client), 55 mTextureName(-1U), 56 mQueuedFrames(0), 57 mCurrentTransform(0), 58 mCurrentScalingMode(NATIVE_WINDOW_SCALING_MODE_FREEZE), 59 mCurrentOpacity(true), 60 mRefreshPending(false), 61 mFrameLatencyNeeded(false), 62 mFrameLatencyOffset(0), 63 mFormat(PIXEL_FORMAT_NONE), 64 mGLExtensions(GLExtensions::getInstance()), 65 mOpaqueLayer(true), 66 mNeedsDithering(false), 67 mSecure(false), 68 mProtectedByApp(false) 69{ 70 mCurrentCrop.makeInvalid(); 71 glGenTextures(1, &mTextureName); 72} 73 74void Layer::onLayerDisplayed() { 75 if (mFrameLatencyNeeded) { 76 const DisplayHardware& hw(graphicPlane(0).displayHardware()); 77 mFrameStats[mFrameLatencyOffset].timestamp = mSurfaceTexture->getTimestamp(); 78 mFrameStats[mFrameLatencyOffset].set = systemTime(); 79 mFrameStats[mFrameLatencyOffset].vsync = hw.getRefreshTimestamp(); 80 mFrameLatencyOffset = (mFrameLatencyOffset + 1) % 128; 81 mFrameLatencyNeeded = false; 82 } 83} 84 85void Layer::onFirstRef() 86{ 87 LayerBaseClient::onFirstRef(); 88 89 struct FrameQueuedListener : public SurfaceTexture::FrameAvailableListener { 90 FrameQueuedListener(Layer* layer) : mLayer(layer) { } 91 private: 92 wp<Layer> mLayer; 93 virtual void onFrameAvailable() { 94 sp<Layer> that(mLayer.promote()); 95 if (that != 0) { 96 that->onFrameQueued(); 97 } 98 } 99 }; 100 101 // Creates a custom BufferQueue for SurfaceTexture to use 102 sp<BufferQueue> bq = new SurfaceTextureLayer(); 103 mSurfaceTexture = new SurfaceTexture(mTextureName, true, 104 GL_TEXTURE_EXTERNAL_OES, false, bq); 105 106 mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0)); 107 mSurfaceTexture->setFrameAvailableListener(new FrameQueuedListener(this)); 108 mSurfaceTexture->setSynchronousMode(true); 109 110#ifdef TARGET_DISABLE_TRIPLE_BUFFERING 111#warning "disabling triple buffering" 112 mSurfaceTexture->setBufferCountServer(2); 113#else 114 mSurfaceTexture->setBufferCountServer(3); 115#endif 116} 117 118Layer::~Layer() 119{ 120 mFlinger->postMessageAsync( 121 new SurfaceFlinger::MessageDestroyGLTexture(mTextureName) ); 122} 123 124void Layer::onFrameQueued() { 125 android_atomic_inc(&mQueuedFrames); 126 mFlinger->signalLayerUpdate(); 127} 128 129// called with SurfaceFlinger::mStateLock as soon as the layer is entered 130// in the purgatory list 131void Layer::onRemoved() 132{ 133 mSurfaceTexture->abandon(); 134} 135 136void Layer::setName(const String8& name) { 137 LayerBase::setName(name); 138 mSurfaceTexture->setName(name); 139} 140 141void Layer::validateVisibility(const Transform& globalTransform) { 142 LayerBase::validateVisibility(globalTransform); 143 144 if (mCurrentScalingMode == NATIVE_WINDOW_SCALING_MODE_FREEZE && 145 !mCurrentCrop.isEmpty()) { 146 // We need to shrink the window size to match the buffer crop 147 // rectangle. 148 const Layer::State& s(drawingState()); 149 const Transform tr(globalTransform * s.transform); 150 float windowWidth = s.w; 151 float windowHeight = s.h; 152 float bufferWidth = mActiveBuffer->getWidth(); 153 float bufferHeight = mActiveBuffer->getHeight(); 154 if (mCurrentTransform & NATIVE_WINDOW_TRANSFORM_ROT_90) { 155 float tmp = bufferWidth; 156 bufferWidth = bufferHeight; 157 bufferHeight = tmp; 158 } 159 float xScale = float(windowWidth) / float(bufferWidth); 160 float yScale = float(windowHeight) / float(bufferHeight); 161 162 // Compute the crop in post-transform coordinates. 163 Rect crop(mCurrentCrop.transform(mCurrentTransform, 164 mActiveBuffer->getWidth(), mActiveBuffer->getHeight())); 165 166 float left = ceil(xScale * float(crop.left)); 167 float right = floor(xScale * float(crop.right)); 168 float top = ceil(yScale * float(crop.top)); 169 float bottom = floor(yScale * float(crop.bottom)); 170 171 tr.transform(mVertices[0], left, top); 172 tr.transform(mVertices[1], left, bottom); 173 tr.transform(mVertices[2], right, bottom); 174 tr.transform(mVertices[3], right, top); 175 176 const DisplayHardware& hw(graphicPlane(0).displayHardware()); 177 const uint32_t hw_h = hw.getHeight(); 178 for (size_t i=0 ; i<4 ; i++) 179 mVertices[i][1] = hw_h - mVertices[i][1]; 180 181 mTransformedBounds = tr.transform( 182 Rect(int(left), int(top), int(right), int(bottom))); 183 } 184 185 // This optimization allows the SurfaceTexture to bake in 186 // the rotation so hardware overlays can be used 187 mSurfaceTexture->setTransformHint(getTransformHint()); 188} 189 190sp<ISurface> Layer::createSurface() 191{ 192 class BSurface : public BnSurface, public LayerCleaner { 193 wp<const Layer> mOwner; 194 virtual sp<ISurfaceTexture> getSurfaceTexture() const { 195 sp<ISurfaceTexture> res; 196 sp<const Layer> that( mOwner.promote() ); 197 if (that != NULL) { 198 res = that->mSurfaceTexture->getBufferQueue(); 199 } 200 return res; 201 } 202 public: 203 BSurface(const sp<SurfaceFlinger>& flinger, 204 const sp<Layer>& layer) 205 : LayerCleaner(flinger, layer), mOwner(layer) { } 206 }; 207 sp<ISurface> sur(new BSurface(mFlinger, this)); 208 return sur; 209} 210 211wp<IBinder> Layer::getSurfaceTextureBinder() const 212{ 213 return mSurfaceTexture->getBufferQueue()->asBinder(); 214} 215 216status_t Layer::setBuffers( uint32_t w, uint32_t h, 217 PixelFormat format, uint32_t flags) 218{ 219 // this surfaces pixel format 220 PixelFormatInfo info; 221 status_t err = getPixelFormatInfo(format, &info); 222 if (err) { 223 ALOGE("unsupported pixelformat %d", format); 224 return err; 225 } 226 227 // the display's pixel format 228 const DisplayHardware& hw(graphicPlane(0).displayHardware()); 229 uint32_t const maxSurfaceDims = min( 230 hw.getMaxTextureSize(), hw.getMaxViewportDims()); 231 232 // never allow a surface larger than what our underlying GL implementation 233 // can handle. 234 if ((uint32_t(w)>maxSurfaceDims) || (uint32_t(h)>maxSurfaceDims)) { 235 ALOGE("dimensions too large %u x %u", uint32_t(w), uint32_t(h)); 236 return BAD_VALUE; 237 } 238 239 PixelFormatInfo displayInfo; 240 getPixelFormatInfo(hw.getFormat(), &displayInfo); 241 const uint32_t hwFlags = hw.getFlags(); 242 243 mFormat = format; 244 245 mSecure = (flags & ISurfaceComposer::eSecure) ? true : false; 246 mProtectedByApp = (flags & ISurfaceComposer::eProtectedByApp) ? true : false; 247 mOpaqueLayer = (flags & ISurfaceComposer::eOpaque); 248 mCurrentOpacity = getOpacityForFormat(format); 249 250 mSurfaceTexture->setDefaultBufferSize(w, h); 251 mSurfaceTexture->setDefaultBufferFormat(format); 252 mSurfaceTexture->setConsumerUsageBits(getEffectiveUsage(0)); 253 254 // we use the red index 255 int displayRedSize = displayInfo.getSize(PixelFormatInfo::INDEX_RED); 256 int layerRedsize = info.getSize(PixelFormatInfo::INDEX_RED); 257 mNeedsDithering = layerRedsize > displayRedSize; 258 259 return NO_ERROR; 260} 261 262void Layer::setGeometry(hwc_layer_t* hwcl) 263{ 264 LayerBaseClient::setGeometry(hwcl); 265 266 hwcl->flags &= ~HWC_SKIP_LAYER; 267 268 // we can't do alpha-fade with the hwc HAL 269 const State& s(drawingState()); 270 if (s.alpha < 0xFF) { 271 hwcl->flags = HWC_SKIP_LAYER; 272 } 273 274 /* 275 * Transformations are applied in this order: 276 * 1) buffer orientation/flip/mirror 277 * 2) state transformation (window manager) 278 * 3) layer orientation (screen orientation) 279 * mTransform is already the composition of (2) and (3) 280 * (NOTE: the matrices are multiplied in reverse order) 281 */ 282 283 const Transform bufferOrientation(mCurrentTransform); 284 const Transform tr(mTransform * bufferOrientation); 285 286 // this gives us only the "orientation" component of the transform 287 const uint32_t finalTransform = tr.getOrientation(); 288 289 // we can only handle simple transformation 290 if (finalTransform & Transform::ROT_INVALID) { 291 hwcl->flags = HWC_SKIP_LAYER; 292 } else { 293 hwcl->transform = finalTransform; 294 } 295 296 if (isCropped()) { 297 hwcl->sourceCrop.left = mCurrentCrop.left; 298 hwcl->sourceCrop.top = mCurrentCrop.top; 299 hwcl->sourceCrop.right = mCurrentCrop.right; 300 hwcl->sourceCrop.bottom = mCurrentCrop.bottom; 301 } else { 302 const sp<GraphicBuffer>& buffer(mActiveBuffer); 303 hwcl->sourceCrop.left = 0; 304 hwcl->sourceCrop.top = 0; 305 if (buffer != NULL) { 306 hwcl->sourceCrop.right = buffer->width; 307 hwcl->sourceCrop.bottom = buffer->height; 308 } else { 309 hwcl->sourceCrop.right = mTransformedBounds.width(); 310 hwcl->sourceCrop.bottom = mTransformedBounds.height(); 311 } 312 } 313} 314 315void Layer::setPerFrameData(hwc_layer_t* hwcl) { 316 const sp<GraphicBuffer>& buffer(mActiveBuffer); 317 if (buffer == NULL) { 318 // this can happen if the client never drew into this layer yet, 319 // or if we ran out of memory. In that case, don't let 320 // HWC handle it. 321 hwcl->flags |= HWC_SKIP_LAYER; 322 hwcl->handle = NULL; 323 } else { 324 hwcl->handle = buffer->handle; 325 } 326} 327 328void Layer::onDraw(const Region& clip) const 329{ 330 ATRACE_CALL(); 331 332 if (CC_UNLIKELY(mActiveBuffer == 0)) { 333 // the texture has not been created yet, this Layer has 334 // in fact never been drawn into. This happens frequently with 335 // SurfaceView because the WindowManager can't know when the client 336 // has drawn the first time. 337 338 // If there is nothing under us, we paint the screen in black, otherwise 339 // we just skip this update. 340 341 // figure out if there is something below us 342 Region under; 343 const SurfaceFlinger::LayerVector& drawingLayers( 344 mFlinger->mDrawingState.layersSortedByZ); 345 const size_t count = drawingLayers.size(); 346 for (size_t i=0 ; i<count ; ++i) { 347 const sp<LayerBase>& layer(drawingLayers[i]); 348 if (layer.get() == static_cast<LayerBase const*>(this)) 349 break; 350 under.orSelf(layer->visibleRegionScreen); 351 } 352 // if not everything below us is covered, we plug the holes! 353 Region holes(clip.subtract(under)); 354 if (!holes.isEmpty()) { 355 clearWithOpenGL(holes, 0, 0, 0, 1); 356 } 357 return; 358 } 359 360 if (!isProtected()) { 361 // TODO: we could be more subtle with isFixedSize() 362 const bool useFiltering = getFiltering() || needsFiltering() || isFixedSize(); 363 364 // Query the texture matrix given our current filtering mode. 365 float textureMatrix[16]; 366 mSurfaceTexture->setFilteringEnabled(useFiltering); 367 mSurfaceTexture->getTransformMatrix(textureMatrix); 368 369 // Set things up for texturing. 370 glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureName); 371 GLenum filter = GL_NEAREST; 372 if (useFiltering) { 373 filter = GL_LINEAR; 374 } 375 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, filter); 376 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, filter); 377 glMatrixMode(GL_TEXTURE); 378 glLoadMatrixf(textureMatrix); 379 glMatrixMode(GL_MODELVIEW); 380 glDisable(GL_TEXTURE_2D); 381 glEnable(GL_TEXTURE_EXTERNAL_OES); 382 } else { 383 glBindTexture(GL_TEXTURE_2D, mFlinger->getProtectedTexName()); 384 glMatrixMode(GL_TEXTURE); 385 glLoadIdentity(); 386 glMatrixMode(GL_MODELVIEW); 387 glDisable(GL_TEXTURE_EXTERNAL_OES); 388 glEnable(GL_TEXTURE_2D); 389 } 390 391 drawWithOpenGL(clip); 392 393 glDisable(GL_TEXTURE_EXTERNAL_OES); 394 glDisable(GL_TEXTURE_2D); 395} 396 397// As documented in libhardware header, formats in the range 398// 0x100 - 0x1FF are specific to the HAL implementation, and 399// are known to have no alpha channel 400// TODO: move definition for device-specific range into 401// hardware.h, instead of using hard-coded values here. 402#define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) 403 404bool Layer::getOpacityForFormat(uint32_t format) 405{ 406 if (HARDWARE_IS_DEVICE_FORMAT(format)) { 407 return true; 408 } 409 PixelFormatInfo info; 410 status_t err = getPixelFormatInfo(PixelFormat(format), &info); 411 // in case of error (unknown format), we assume no blending 412 return (err || info.h_alpha <= info.l_alpha); 413} 414 415 416bool Layer::isOpaque() const 417{ 418 // if we don't have a buffer yet, we're translucent regardless of the 419 // layer's opaque flag. 420 if (mActiveBuffer == 0) { 421 return false; 422 } 423 424 // if the layer has the opaque flag, then we're always opaque, 425 // otherwise we use the current buffer's format. 426 return mOpaqueLayer || mCurrentOpacity; 427} 428 429bool Layer::isProtected() const 430{ 431 const sp<GraphicBuffer>& activeBuffer(mActiveBuffer); 432 return (activeBuffer != 0) && 433 (activeBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); 434} 435 436uint32_t Layer::doTransaction(uint32_t flags) 437{ 438 ATRACE_CALL(); 439 440 const Layer::State& front(drawingState()); 441 const Layer::State& temp(currentState()); 442 443 const bool sizeChanged = (front.requested_w != temp.requested_w) || 444 (front.requested_h != temp.requested_h); 445 446 if (sizeChanged) { 447 // the size changed, we need to ask our client to request a new buffer 448 ALOGD_IF(DEBUG_RESIZE, 449 "doTransaction: " 450 "resize (layer=%p), requested (%dx%d), drawing (%d,%d), " 451 "scalingMode=%d", 452 this, 453 int(temp.requested_w), int(temp.requested_h), 454 int(front.requested_w), int(front.requested_h), 455 mCurrentScalingMode); 456 457 if (!isFixedSize()) { 458 // this will make sure LayerBase::doTransaction doesn't update 459 // the drawing state's size 460 Layer::State& editDraw(mDrawingState); 461 editDraw.requested_w = temp.requested_w; 462 editDraw.requested_h = temp.requested_h; 463 } 464 465 // record the new size, form this point on, when the client request 466 // a buffer, it'll get the new size. 467 mSurfaceTexture->setDefaultBufferSize(temp.requested_w, 468 temp.requested_h); 469 } 470 471 return LayerBase::doTransaction(flags); 472} 473 474bool Layer::isFixedSize() const { 475 return mCurrentScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE; 476} 477 478bool Layer::isCropped() const { 479 return !mCurrentCrop.isEmpty(); 480} 481 482// ---------------------------------------------------------------------------- 483// pageflip handling... 484// ---------------------------------------------------------------------------- 485 486bool Layer::onPreComposition() { 487 mRefreshPending = false; 488 return mQueuedFrames > 0; 489} 490 491void Layer::lockPageFlip(bool& recomputeVisibleRegions) 492{ 493 ATRACE_CALL(); 494 495 if (mQueuedFrames > 0) { 496 497 // if we've already called updateTexImage() without going through 498 // a composition step, we have to skip this layer at this point 499 // because we cannot call updateTeximage() without a corresponding 500 // compositionComplete() call. 501 // we'll trigger an update in onPreComposition(). 502 if (mRefreshPending) { 503 mPostedDirtyRegion.clear(); 504 return; 505 } 506 mRefreshPending = true; 507 508 // Capture the old state of the layer for comparisons later 509 const bool oldOpacity = isOpaque(); 510 sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer; 511 512 // signal another event if we have more frames pending 513 if (android_atomic_dec(&mQueuedFrames) > 1) { 514 mFlinger->signalLayerUpdate(); 515 } 516 517 if (mSurfaceTexture->updateTexImage() < NO_ERROR) { 518 // something happened! 519 recomputeVisibleRegions = true; 520 return; 521 } 522 523 // update the active buffer 524 mActiveBuffer = mSurfaceTexture->getCurrentBuffer(); 525 mFrameLatencyNeeded = true; 526 527 if (oldActiveBuffer == NULL && mActiveBuffer != NULL) { 528 // the first time we receive a buffer, we need to trigger a 529 // geometry invalidation. 530 mFlinger->invalidateHwcGeometry(); 531 } 532 533 Rect crop(mSurfaceTexture->getCurrentCrop()); 534 const uint32_t transform(mSurfaceTexture->getCurrentTransform()); 535 const uint32_t scalingMode(mSurfaceTexture->getCurrentScalingMode()); 536 if ((crop != mCurrentCrop) || 537 (transform != mCurrentTransform) || 538 (scalingMode != mCurrentScalingMode)) 539 { 540 mCurrentCrop = crop; 541 mCurrentTransform = transform; 542 mCurrentScalingMode = scalingMode; 543 mFlinger->invalidateHwcGeometry(); 544 } 545 546 uint32_t bufWidth = mActiveBuffer->getWidth(); 547 uint32_t bufHeight = mActiveBuffer->getHeight(); 548 if (oldActiveBuffer != NULL) { 549 if (bufWidth != uint32_t(oldActiveBuffer->width) || 550 bufHeight != uint32_t(oldActiveBuffer->height)) { 551 mFlinger->invalidateHwcGeometry(); 552 } 553 } 554 555 mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format); 556 if (oldOpacity != isOpaque()) { 557 recomputeVisibleRegions = true; 558 } 559 560 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 561 glTexParameterx(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 562 563 // update the layer size if needed 564 const Layer::State& front(drawingState()); 565 566 // FIXME: mPostedDirtyRegion = dirty & bounds 567 mPostedDirtyRegion.set(front.w, front.h); 568 569 if ((front.w != front.requested_w) || 570 (front.h != front.requested_h)) 571 { 572 // check that we received a buffer of the right size 573 // (Take the buffer's orientation into account) 574 if (mCurrentTransform & Transform::ROT_90) { 575 swap(bufWidth, bufHeight); 576 } 577 578 if (isFixedSize() || 579 (bufWidth == front.requested_w && 580 bufHeight == front.requested_h)) 581 { 582 // Here we pretend the transaction happened by updating the 583 // current and drawing states. Drawing state is only accessed 584 // in this thread, no need to have it locked 585 Layer::State& editDraw(mDrawingState); 586 editDraw.w = editDraw.requested_w; 587 editDraw.h = editDraw.requested_h; 588 589 // We also need to update the current state so that we don't 590 // end-up doing too much work during the next transaction. 591 // NOTE: We actually don't need hold the transaction lock here 592 // because State::w and State::h are only accessed from 593 // this thread 594 Layer::State& editTemp(currentState()); 595 editTemp.w = editDraw.w; 596 editTemp.h = editDraw.h; 597 598 // recompute visible region 599 recomputeVisibleRegions = true; 600 } 601 602 ALOGD_IF(DEBUG_RESIZE, 603 "lockPageFlip : " 604 " (layer=%p), buffer (%ux%u, tr=%02x), " 605 "requested (%dx%d)", 606 this, 607 bufWidth, bufHeight, mCurrentTransform, 608 front.requested_w, front.requested_h); 609 } 610 } 611} 612 613void Layer::unlockPageFlip( 614 const Transform& planeTransform, Region& outDirtyRegion) 615{ 616 ATRACE_CALL(); 617 618 Region postedRegion(mPostedDirtyRegion); 619 if (!postedRegion.isEmpty()) { 620 mPostedDirtyRegion.clear(); 621 if (!visibleRegionScreen.isEmpty()) { 622 // The dirty region is given in the layer's coordinate space 623 // transform the dirty region by the surface's transformation 624 // and the global transformation. 625 const Layer::State& s(drawingState()); 626 const Transform tr(planeTransform * s.transform); 627 postedRegion = tr.transform(postedRegion); 628 629 // At this point, the dirty region is in screen space. 630 // Make sure it's constrained by the visible region (which 631 // is in screen space as well). 632 postedRegion.andSelf(visibleRegionScreen); 633 outDirtyRegion.orSelf(postedRegion); 634 } 635 } 636} 637 638void Layer::dump(String8& result, char* buffer, size_t SIZE) const 639{ 640 LayerBaseClient::dump(result, buffer, SIZE); 641 642 sp<const GraphicBuffer> buf0(mActiveBuffer); 643 uint32_t w0=0, h0=0, s0=0, f0=0; 644 if (buf0 != 0) { 645 w0 = buf0->getWidth(); 646 h0 = buf0->getHeight(); 647 s0 = buf0->getStride(); 648 f0 = buf0->format; 649 } 650 snprintf(buffer, SIZE, 651 " " 652 "format=%2d, activeBuffer=[%4ux%4u:%4u,%3X]," 653 " transform-hint=0x%02x, queued-frames=%d, mRefreshPending=%d\n", 654 mFormat, w0, h0, s0,f0, 655 getTransformHint(), mQueuedFrames, mRefreshPending); 656 657 result.append(buffer); 658 659 if (mSurfaceTexture != 0) { 660 mSurfaceTexture->dump(result, " ", buffer, SIZE); 661 } 662} 663 664void Layer::dumpStats(String8& result, char* buffer, size_t SIZE) const 665{ 666 LayerBaseClient::dumpStats(result, buffer, SIZE); 667 const size_t o = mFrameLatencyOffset; 668 const DisplayHardware& hw(graphicPlane(0).displayHardware()); 669 const nsecs_t period = hw.getRefreshPeriod(); 670 result.appendFormat("%lld\n", period); 671 for (size_t i=0 ; i<128 ; i++) { 672 const size_t index = (o+i) % 128; 673 const nsecs_t time_app = mFrameStats[index].timestamp; 674 const nsecs_t time_set = mFrameStats[index].set; 675 const nsecs_t time_vsync = mFrameStats[index].vsync; 676 result.appendFormat("%lld\t%lld\t%lld\n", 677 time_app, 678 time_vsync, 679 time_set); 680 } 681 result.append("\n"); 682} 683 684void Layer::clearStats() 685{ 686 LayerBaseClient::clearStats(); 687 memset(mFrameStats, 0, sizeof(mFrameStats)); 688} 689 690uint32_t Layer::getEffectiveUsage(uint32_t usage) const 691{ 692 // TODO: should we do something special if mSecure is set? 693 if (mProtectedByApp) { 694 // need a hardware-protected path to external video sink 695 usage |= GraphicBuffer::USAGE_PROTECTED; 696 } 697 usage |= GraphicBuffer::USAGE_HW_COMPOSER; 698 return usage; 699} 700 701uint32_t Layer::getTransformHint() const { 702 uint32_t orientation = 0; 703 if (!mFlinger->mDebugDisableTransformHint) { 704 orientation = getPlaneOrientation(); 705 if (orientation & Transform::ROT_INVALID) { 706 orientation = 0; 707 } 708 } 709 return orientation; 710} 711 712// --------------------------------------------------------------------------- 713 714 715}; // namespace android 716