tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RendererScreenshotGrabber.h (2744B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef mozilla_layers_RendererScreenshotGrabber_h
      6 #define mozilla_layers_RendererScreenshotGrabber_h
      7 
      8 #include "mozilla/TimeStamp.h"
      9 #include "mozilla/gfx/Point.h"
     10 #include "mozilla/layers/ProfilerScreenshots.h"
     11 #include "mozilla/webrender/webrender_ffi.h"
     12 #include "nsTArray.h"
     13 
     14 namespace mozilla {
     15 namespace wr {
     16 
     17 struct Renderer;
     18 class RendererOGL;
     19 
     20 /**
     21 * Used by |RendererOGL| to grab screenshots from WebRender and submit them to
     22 * the Gecko profiler.
     23 *
     24 * If the profiler is not running or the screenshots feature is disabled, no
     25 * work will be done.
     26 */
     27 class RendererScreenshotGrabber final {
     28 public:
     29  RendererScreenshotGrabber();
     30 
     31  /**
     32   * Grab a screenshot from WebRender if we are profiling and screenshots are
     33   * enabled.
     34   *
     35   * The captured screenshot will not be mapped until the second call to
     36   * |MaybeProcessQueue| after this call to |MaybeGrabScreenshot|.
     37   */
     38  void MaybeGrabScreenshot(RendererOGL* aRendererOGL,
     39                           const gfx::IntSize& aWindowSize);
     40 
     41  /**
     42   * Process the screenshots pending in the queue if we are profiling and
     43   * screenshots are enabled.
     44   */
     45  void MaybeProcessQueue(RendererOGL* aRenderer);
     46 
     47 private:
     48  /**
     49   * Drop all our allocated memory when we are no longer profiling.
     50   *
     51   * This will also instruct WebRender to drop all its Gecko profiler
     52   * associated memory.
     53   */
     54  void Destroy(Renderer* aRenderer);
     55 
     56  /**
     57   * Actually grab a screenshot from WebRender.
     58   */
     59  void GrabScreenshot(Renderer* aRenderer, const gfx::IntSize& aWindowSize);
     60 
     61  /**
     62   * Process the screenshots pending in the queue.
     63   */
     64  void ProcessQueue(Renderer* aRenderer);
     65 
     66  struct QueueItem {
     67    mozilla::TimeStamp mTimeStamp;
     68    AsyncScreenshotHandle mHandle;
     69    gfx::IntSize mScreenshotSize;
     70    gfx::IntSize mWindowSize;
     71  };
     72 
     73  /**
     74   * The maximum size for screenshots, as dictated by
     75   * |ProfilerScrenshots::ScreenshotSize|.
     76   */
     77  gfx::IntSize mMaxScreenshotSize;
     78 
     79  /**
     80   * The queue of screenshots waiting to be processed and submitted.
     81   */
     82  nsTArray<QueueItem> mQueue;
     83 
     84  /**
     85   * The queue item for the current frame. This will be inserted into the queue
     86   * after a call to |MaybeProcessQueue| so it will be not be processed until
     87   * the next frame.
     88   */
     89  Maybe<QueueItem> mCurrentFrameQueueItem;
     90 
     91  /**
     92   * Our handle to the profiler screenshots object.
     93   */
     94  RefPtr<mozilla::layers::ProfilerScreenshots> mProfilerScreenshots;
     95 };
     96 
     97 }  // namespace wr
     98 }  // namespace mozilla
     99 
    100 #endif  // mozilla_layers_RendererScreenshotGrabber_h