Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.h

Issue 1507863005: [2D Canvas] Send GPU resources into hibernation when page is not visible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 22 matching lines...) Expand all
33 #include "public/platform/WebExternalTextureLayerClient.h" 33 #include "public/platform/WebExternalTextureLayerClient.h"
34 #include "public/platform/WebExternalTextureMailbox.h" 34 #include "public/platform/WebExternalTextureMailbox.h"
35 #include "public/platform/WebThread.h" 35 #include "public/platform/WebThread.h"
36 #include "third_party/khronos/GLES2/gl2.h" 36 #include "third_party/khronos/GLES2/gl2.h"
37 #include "third_party/skia/include/core/SkImage.h" 37 #include "third_party/skia/include/core/SkImage.h"
38 #include "wtf/Allocator.h" 38 #include "wtf/Allocator.h"
39 #include "wtf/Deque.h" 39 #include "wtf/Deque.h"
40 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassOwnPtr.h"
41 #include "wtf/RefCounted.h" 41 #include "wtf/RefCounted.h"
42 #include "wtf/RefPtr.h" 42 #include "wtf/RefPtr.h"
43 #include "wtf/WeakPtr.h"
43 44
44 class SkPictureRecorder; 45 class SkPictureRecorder;
45 46
46 namespace blink { 47 namespace blink {
47 48
49 class Canvas2DLayerBridgeHistogramLogger;
48 class Canvas2DLayerBridgeTest; 50 class Canvas2DLayerBridgeTest;
49 class ImageBuffer; 51 class ImageBuffer;
50 class WebGraphicsContext3D; 52 class WebGraphicsContext3D;
51 class WebGraphicsContext3DProvider; 53 class WebGraphicsContext3DProvider;
52 class SharedContextRateLimiter; 54 class SharedContextRateLimiter;
53 55
54 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient , public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBridge> { 56 class PLATFORM_EXPORT Canvas2DLayerBridge : public WebExternalTextureLayerClient , public WebThread::TaskObserver, public RefCounted<Canvas2DLayerBridge> {
55 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge); 57 WTF_MAKE_NONCOPYABLE(Canvas2DLayerBridge);
56 public: 58 public:
57 enum AccelerationMode { 59 enum AccelerationMode {
(...skipping 25 matching lines...) Expand all
83 void setIsHidden(bool); 85 void setIsHidden(bool);
84 void setImageBuffer(ImageBuffer*); 86 void setImageBuffer(ImageBuffer*);
85 void didDraw(const FloatRect&); 87 void didDraw(const FloatRect&);
86 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y); 88 bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, in t x, int y);
87 void flush(); 89 void flush();
88 void flushGpu(); 90 void flushGpu();
89 void prepareSurfaceForPaintingIfNeeded(); 91 void prepareSurfaceForPaintingIfNeeded();
90 bool isHidden() { return m_isHidden; } 92 bool isHidden() { return m_isHidden; }
91 93
92 void beginDestruction(); 94 void beginDestruction();
95 void hibernate();
96 bool isHibernating() const { return m_hibernationImage; }
93 97
94 PassRefPtr<SkImage> newImageSnapshot(AccelerationHint); 98 PassRefPtr<SkImage> newImageSnapshot(AccelerationHint);
95 99
100 // The values of the enum entries must not change because they are used for
101 // usage metrics histograms. New values can be added to the end.
102 enum HibernationEvent {
103 HibernationScheduled = 0,
104 HibernationAbortedDueToDestructionWhileHibernatePending = 1,
105 HibernationAbortedDueToPendingDestruction = 2,
106 HibernationAbortedDueToVisibilityChange = 3,
107 HibernationAbortedDueGpuContextLoss = 4,
108 HibernationAbortedDueToSwitchToUnacceleratedRendering = 5,
109 HibernationAbortedDueToAllocationFailure = 6,
110 HibernationEndedNormally = 7,
111 HibernationEndedWithSwitchToBackgroundRendering = 8,
112 HibernationEndedWithFallbackToSW = 9,
113 HibernationEndedWithTeardown = 10,
114
115 HibernationEventCount = 11,
116 };
117
118 class PLATFORM_EXPORT Logger {
119 public:
120 virtual void reportHibernationEvent(HibernationEvent);
121 virtual void didStartHibernating() { }
122 virtual ~Logger() { }
123 };
124
125 void setLoggerForTesting(PassOwnPtr<Logger>);
126
96 private: 127 private:
97 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize& , int msaaSampleCount, OpacityMode, AccelerationMode); 128 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize& , int msaaSampleCount, OpacityMode, AccelerationMode);
98 WebGraphicsContext3D* context(); 129 WebGraphicsContext3D* context();
99 void startRecording(); 130 void startRecording();
100 void skipQueuedDrawCommands(); 131 void skipQueuedDrawCommands();
101 void flushRecordingOnly(); 132 void flushRecordingOnly();
102 void unregisterTaskObserver(); 133 void unregisterTaskObserver();
103 134
104 // WebThread::TaskOberver implementation 135 // WebThread::TaskOberver implementation
105 void willProcessTask() override; 136 void willProcessTask() override;
106 void didProcessTask() override; 137 void didProcessTask() override;
107 138
108 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); 139 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration);
109 bool shouldAccelerate(AccelerationHint) const; 140 bool shouldAccelerate(AccelerationHint) const;
110 141
111 OwnPtr<SkPictureRecorder> m_recorder; 142 OwnPtr<SkPictureRecorder> m_recorder;
112 RefPtr<SkSurface> m_surface; 143 RefPtr<SkSurface> m_surface;
144 RefPtr<SkImage> m_hibernationImage;
113 int m_initialSurfaceSaveCount; 145 int m_initialSurfaceSaveCount;
114 OwnPtr<WebExternalTextureLayer> m_layer; 146 OwnPtr<WebExternalTextureLayer> m_layer;
115 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; 147 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
116 OwnPtr<SharedContextRateLimiter> m_rateLimiter; 148 OwnPtr<SharedContextRateLimiter> m_rateLimiter;
149 OwnPtr<Logger> m_logger;
150 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory;
117 ImageBuffer* m_imageBuffer; 151 ImageBuffer* m_imageBuffer;
118 int m_msaaSampleCount; 152 int m_msaaSampleCount;
119 size_t m_bytesAllocated; 153 size_t m_bytesAllocated;
120 bool m_haveRecordedDrawCommands; 154 bool m_haveRecordedDrawCommands;
121 bool m_destructionInProgress; 155 bool m_destructionInProgress;
122 SkFilterQuality m_filterQuality; 156 SkFilterQuality m_filterQuality;
123 bool m_isHidden; 157 bool m_isHidden;
124 bool m_isDeferralEnabled; 158 bool m_isDeferralEnabled;
125 bool m_isRegisteredTaskObserver; 159 bool m_isRegisteredTaskObserver;
126 bool m_renderingTaskCompletedForCurrentFrame; 160 bool m_renderingTaskCompletedForCurrentFrame;
161 bool m_softwareRenderingWhileHidden;
127 162
128 friend class Canvas2DLayerBridgeTest; 163 friend class Canvas2DLayerBridgeTest;
129 164
130 struct MailboxInfo { 165 struct MailboxInfo {
131 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 166 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
132 WebExternalTextureMailbox m_mailbox; 167 WebExternalTextureMailbox m_mailbox;
133 RefPtr<SkImage> m_image; 168 RefPtr<SkImage> m_image;
134 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; 169 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge;
135 170
136 MailboxInfo(const MailboxInfo&); 171 MailboxInfo(const MailboxInfo&);
(...skipping 12 matching lines...) Expand all
149 GLenum m_lastFilter; 184 GLenum m_lastFilter;
150 AccelerationMode m_accelerationMode; 185 AccelerationMode m_accelerationMode;
151 OpacityMode m_opacityMode; 186 OpacityMode m_opacityMode;
152 IntSize m_size; 187 IntSize m_size;
153 int m_recordingPixelCount; 188 int m_recordingPixelCount;
154 }; 189 };
155 190
156 } // namespace blink 191 } // namespace blink
157 192
158 #endif 193 #endif
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridge.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698