summaryrefslogtreecommitdiff
path: root/chromium/content/browser/media/android/browser_surface_view_manager.h
blob: fbfeab45b6809784dbe6377d313d509c7a33f589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_SURFACE_VIEW_MANAGER_H_
#define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_SURFACE_VIEW_MANAGER_H_

#include <stdint.h>

#include <memory>

#include "base/macros.h"
#include "content/browser/android/content_video_view.h"
#include "content/common/content_export.h"
#include "ui/gfx/geometry/size.h"

namespace content {

class RenderFrameHost;

// BrowserSurfaceViewManager creates and owns a ContentVideoView on behalf of
// a fullscreen media player. Its SurfaceView is registered so that a decoder
// in the GPU process can look it up and render to it.
class CONTENT_EXPORT BrowserSurfaceViewManager
    : public ContentVideoView::Client {
 public:
  explicit BrowserSurfaceViewManager(RenderFrameHost* render_frame_host);
  ~BrowserSurfaceViewManager();

  // ContentVideoView::Client overrides.
  void SetVideoSurface(gfx::ScopedJavaSurface surface) override;
  void DidExitFullscreen(bool release_media_player) override;

  void OnCreateFullscreenSurface(const gfx::Size& video_natural_size);
  void OnNaturalSizeChanged(const gfx::Size& size);

 private:
  // Send a message to return the surface id to the caller.
  bool SendSurfaceID(int surface_id);

  // Synchronously notify the decoder that the surface is being destroyed so it
  // can stop rendering to it. This sends a message to the GPU process. Without
  // this, the MediaCodec decoder will start throwing IllegalStateException, and
  // crash on some devices (http://crbug.com/598408). There is no way for us to
  // make sure the surface outlives the decoder because Android initiates the
  // destruction in some cases.
  void SendDestroyingVideoSurfaceIfRequired(int surface_id);

  RenderFrameHost* const render_frame_host_;

  // The surface id of the ContentVideoView surface.
  int surface_id_;

  // The fullscreen view that contains a SurfaceView.
  std::unique_ptr<ContentVideoView> content_video_view_;

  DISALLOW_COPY_AND_ASSIGN(BrowserSurfaceViewManager);
};

}  // namespace content

#endif  // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_SURFACE_VIEW_MANAGER_H_