/** * Warms up the electron beam in preparation for turning on or off. This method prepares a GL * context, and captures a screen shot. * * @param mode The desired mode for the upcoming animation. * @return True if the electron beam is ready, false if it is uncontrollable. */ public boolean prepare(int mode) { if (DEBUG) { Slog.d(TAG, "prepare: mode=" + mode); } mMode = mode; // Get the display size and layer stack. // This is not expected to change while the electron beam surface is showing. DisplayInfo displayInfo = mDisplayManager.getDisplayInfo(Display.DEFAULT_DISPLAY); mDisplayLayerStack = displayInfo.layerStack; if (mSwapNeeded) { mDisplayWidth = displayInfo.getNaturalHeight(); mDisplayHeight = displayInfo.getNaturalWidth(); } else { mDisplayWidth = displayInfo.getNaturalWidth(); mDisplayHeight = displayInfo.getNaturalHeight(); } // Prepare the surface for drawing. if (!tryPrepare()) { dismiss(); return false; } // Done. mPrepared = true; // Dejanking optimization. // Some GL drivers can introduce a lot of lag in the first few frames as they // initialize their state and allocate graphics buffers for rendering. // Work around this problem by rendering the first frame of the animation a few // times. The rest of the animation should run smoothly thereafter. // The frames we draw here aren't visible because we are essentially just // painting the screenshot as-is. if (mode == MODE_COOL_DOWN) { for (int i = 0; i < DEJANK_FRAMES; i++) { draw(1.0f); } } return true; }