[Ozone-Gbm] Explicitly crash if trying software rendering on GBM
[chromium-blink-merge.git] / content / renderer / pepper / plugin_instance_throttler_impl.h
blobb223cd26b613c65c5de327ad5676ec3b2e98e553
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h"
11 #include "content/common/content_export.h"
12 #include "content/public/renderer/plugin_instance_throttler.h"
13 #include "ppapi/shared_impl/ppb_view_shared.h"
15 namespace blink {
16 class WebInputEvent;
17 struct WebRect;
20 namespace content {
22 class RenderFrameImpl;
24 class CONTENT_EXPORT PluginInstanceThrottlerImpl
25 : public PluginInstanceThrottler {
26 public:
27 PluginInstanceThrottlerImpl(bool power_saver_enabled);
29 ~PluginInstanceThrottlerImpl() override;
31 // PluginInstanceThrottler implementation:
32 void AddObserver(Observer* observer) override;
33 void RemoveObserver(Observer* observer) override;
34 bool IsThrottled() const override;
35 bool IsHiddenForPlaceholder() const override;
36 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override;
37 void SetHiddenForPlaceholder(bool hidden) override;
38 blink::WebPlugin* GetWebPlugin() const override;
40 void SetWebPlugin(blink::WebPlugin* web_plugin);
42 bool needs_representative_keyframe() const {
43 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME;
46 bool power_saver_enabled() const {
47 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME ||
48 state_ == THROTTLER_STATE_PLUGIN_THROTTLED;
51 // Throttler needs to be initialized with the real plugin's view bounds.
52 void Initialize(RenderFrameImpl* frame,
53 const GURL& content_origin,
54 const std::string& plugin_module_name,
55 const blink::WebRect& bounds);
57 // Called when the plugin flushes it's graphics context. Supplies the
58 // throttler with a candidate to use as the representative keyframe.
59 void OnImageFlush(const SkBitmap* bitmap);
61 // Returns true if |event| was handled and shouldn't be further processed.
62 bool ConsumeInputEvent(const blink::WebInputEvent& event);
64 private:
65 friend class PluginInstanceThrottlerImplTest;
67 enum ThrottlerState {
68 // Power saver is disabled, but the plugin instance is still peripheral.
69 THROTTLER_STATE_POWER_SAVER_DISABLED,
70 // Plugin has been found to be peripheral, Plugin Power Saver is enabled,
71 // and throttler is awaiting a representative keyframe.
72 THROTTLER_STATE_AWAITING_KEYFRAME,
73 // A representative keyframe has been chosen and the plugin is throttled.
74 THROTTLER_STATE_PLUGIN_THROTTLED,
75 // Plugin instance has been marked essential.
76 THROTTLER_STATE_MARKED_ESSENTIAL,
79 // Maximum number of frames to examine for a suitable keyframe. After that, we
80 // simply suspend the plugin where it's at. Chosen arbitrarily.
81 static const int kMaximumFramesToExamine;
83 void EngageThrottle();
85 ThrottlerState state_;
87 bool is_hidden_for_placeholder_;
89 blink::WebPlugin* web_plugin_;
91 // Number of consecutive interesting frames we've encountered.
92 int consecutive_interesting_frames_;
94 // Number of frames we've examined to find a keyframe.
95 int frames_examined_;
97 ObserverList<Observer> observer_list_;
99 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_;
101 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl);
105 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_