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

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

Issue 1752083003: mac: Use IOSurfaces in Canvas2DLayerBridge. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp36_canvas2d_refactor
Patch Set: Set pixel test expectations. Created 4 years, 9 months 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
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/Vector.h"
43 #include "wtf/WeakPtr.h" 44 #include "wtf/WeakPtr.h"
44 45
46 // IOSurfaces are a primitive only present on OS X.
47 #if OS(MACOSX)
Justin Novosad 2016/03/09 23:13:11 I just landed this minutes ago: https://codereview
erikchen 2016/03/09 23:42:24 Done.
48 #define USE_IOSURFACE_FOR_2D_CANVAS 1
49 #else
50 #define USE_IOSURFACE_FOR_2D_CANVAS 0
51 #endif
52
45 class SkPictureRecorder; 53 class SkPictureRecorder;
46 54
47 namespace blink { 55 namespace blink {
48 56
49 class Canvas2DLayerBridgeHistogramLogger; 57 class Canvas2DLayerBridgeHistogramLogger;
50 class Canvas2DLayerBridgeTest; 58 class Canvas2DLayerBridgeTest;
51 class ImageBuffer; 59 class ImageBuffer;
52 class WebGraphicsContext3D; 60 class WebGraphicsContext3D;
53 class WebGraphicsContext3DProvider; 61 class WebGraphicsContext3DProvider;
54 class SharedContextRateLimiter; 62 class SharedContextRateLimiter;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 class PLATFORM_EXPORT Logger { 127 class PLATFORM_EXPORT Logger {
120 public: 128 public:
121 virtual void reportHibernationEvent(HibernationEvent); 129 virtual void reportHibernationEvent(HibernationEvent);
122 virtual void didStartHibernating() { } 130 virtual void didStartHibernating() { }
123 virtual ~Logger() { } 131 virtual ~Logger() { }
124 }; 132 };
125 133
126 void setLoggerForTesting(PassOwnPtr<Logger>); 134 void setLoggerForTesting(PassOwnPtr<Logger>);
127 135
128 private: 136 private:
137 #if USE_IOSURFACE_FOR_2D_CANVAS
138 // All information associated with a CHROMIUM image.
139 struct ImageInfo {
140 ImageInfo() {}
141 ImageInfo(GLuint imageId, GLuint textureId);
142
143 // Whether this structure holds references to a CHROMIUM image.
144 bool empty();
145
146 // The id of the CHROMIUM image.
147 GLuint m_imageId = 0;
148
149 // The id of the texture bound to the CHROMIUM image.
150 GLuint m_textureId = 0;
151 };
152 #endif // USE_IOSURFACE_FOR_2D_CANVAS
153
129 struct MailboxInfo { 154 struct MailboxInfo {
130 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 155 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
131 WebExternalTextureMailbox m_mailbox; 156 WebExternalTextureMailbox m_mailbox;
132 RefPtr<SkImage> m_image; 157 RefPtr<SkImage> m_image;
133 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge; 158 RefPtr<Canvas2DLayerBridge> m_parentLayerBridge;
134 159
160 #if USE_IOSURFACE_FOR_2D_CANVAS
161 // If this mailbox wraps an IOSurface-backed texture, the ids of the
162 // CHROMIUM image and the texture.
163 ImageInfo m_imageInfo;
164 #endif // USE_IOSURFACE_FOR_2D_CANVAS
165
135 MailboxInfo(const MailboxInfo&); 166 MailboxInfo(const MailboxInfo&);
136 MailboxInfo() {} 167 MailboxInfo() {}
137 }; 168 };
138 169
139 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize& , int msaaSampleCount, OpacityMode, AccelerationMode); 170 Canvas2DLayerBridge(PassOwnPtr<WebGraphicsContext3DProvider>, const IntSize& , int msaaSampleCount, OpacityMode, AccelerationMode);
140 WebGraphicsContext3D* context(); 171 WebGraphicsContext3D* context();
141 void startRecording(); 172 void startRecording();
142 void skipQueuedDrawCommands(); 173 void skipQueuedDrawCommands();
143 void flushRecordingOnly(); 174 void flushRecordingOnly();
144 void unregisterTaskObserver(); 175 void unregisterTaskObserver();
145 void reportSurfaceCreationFailure(); 176 void reportSurfaceCreationFailure();
146 177
147 // WebThread::TaskOberver implementation 178 // WebThread::TaskOberver implementation
148 void willProcessTask() override; 179 void willProcessTask() override;
149 void didProcessTask() override; 180 void didProcessTask() override;
150 181
151 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration); 182 SkSurface* getOrCreateSurface(AccelerationHint = PreferAcceleration);
152 bool shouldAccelerate(AccelerationHint) const; 183 bool shouldAccelerate(AccelerationHint) const;
153 184
154 // Returns the GL filter associated with |m_filterQuality|. 185 // Returns the GL filter associated with |m_filterQuality|.
155 GLenum getGLFilter(); 186 GLenum getGLFilter();
156 187
157 // Prepends a new MailboxInfo object to |m_mailboxes|, and returns a 188 #if USE_IOSURFACE_FOR_2D_CANVAS
158 // reference. The reference is no longer valid after |m_mailboxes| is 189 // Creates an IOSurface-backed texture. Copies |image| into the texture.
159 // mutated. 190 // Prepares a mailbox from the texture. The caller must have created a new
160 MailboxInfo& createMailboxInfo(); 191 // MailboxInfo, and prepended it to |m_mailboxs|. Returns whether the
192 // mailbox was successfully prepared. |mailbox| is an out parameter only
193 // populated on success.
194 bool prepareIOSurfaceMailboxFromImage(SkImage*, WebExternalTextureMailbox*);
195
196 // Creates an IOSurface-backed texture. Returns an ImageInfo, which is empty
197 // on failure. The caller takes ownership of both the texture and the image.
198 ImageInfo createIOSurfaceBackedTexture();
199
200 // Releases all resources associated with a CHROMIUM image.
201 void deleteCHROMIUMImage(ImageInfo);
202
203 // Releases all resources in the CHROMIUM image cache.
204 void clearCHROMIUMImageCache();
205 #endif // USE_IOSURFACE_FOR_2D_CANVAS
206
207 // Prepends a new MailboxInfo object to |m_mailboxes|.
208 void createMailboxInfo();
161 209
162 // Returns whether the mailbox was successfully prepared from the SkImage. 210 // Returns whether the mailbox was successfully prepared from the SkImage.
163 // The mailbox is an out parameter only populated on success. 211 // The mailbox is an out parameter only populated on success.
164 bool prepareMailboxFromImage(PassRefPtr<SkImage>, WebExternalTextureMailbox* ); 212 bool prepareMailboxFromImage(PassRefPtr<SkImage>, WebExternalTextureMailbox* );
165 213
214 // Resets Skia's texture bindings. This method should be called after
215 // changing texture bindings.
216 void resetSkiaTextureBinding();
217
166 OwnPtr<SkPictureRecorder> m_recorder; 218 OwnPtr<SkPictureRecorder> m_recorder;
167 RefPtr<SkSurface> m_surface; 219 RefPtr<SkSurface> m_surface;
168 RefPtr<SkImage> m_hibernationImage; 220 RefPtr<SkImage> m_hibernationImage;
169 int m_initialSurfaceSaveCount; 221 int m_initialSurfaceSaveCount;
170 OwnPtr<WebExternalTextureLayer> m_layer; 222 OwnPtr<WebExternalTextureLayer> m_layer;
171 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; 223 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider;
172 OwnPtr<SharedContextRateLimiter> m_rateLimiter; 224 OwnPtr<SharedContextRateLimiter> m_rateLimiter;
173 OwnPtr<Logger> m_logger; 225 OwnPtr<Logger> m_logger;
174 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory; 226 WeakPtrFactory<Canvas2DLayerBridge> m_weakPtrFactory;
175 ImageBuffer* m_imageBuffer; 227 ImageBuffer* m_imageBuffer;
(...skipping 17 matching lines...) Expand all
193 enum { 245 enum {
194 // We should normally not have more that two active mailboxes at a time, 246 // We should normally not have more that two active mailboxes at a time,
195 // but sometime we may have three due to the async nature of mailbox han dling. 247 // but sometime we may have three due to the async nature of mailbox han dling.
196 MaxActiveMailboxes = 3, 248 MaxActiveMailboxes = 3,
197 }; 249 };
198 250
199 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes; 251 Deque<MailboxInfo, MaxActiveMailboxes> m_mailboxes;
200 GLenum m_lastFilter; 252 GLenum m_lastFilter;
201 AccelerationMode m_accelerationMode; 253 AccelerationMode m_accelerationMode;
202 OpacityMode m_opacityMode; 254 OpacityMode m_opacityMode;
203 IntSize m_size; 255 const IntSize m_size;
204 int m_recordingPixelCount; 256 int m_recordingPixelCount;
257
258 #if USE_IOSURFACE_FOR_2D_CANVAS
259 // Each element in this vector represents an IOSurface backed texture that
260 // is ready to be reused.
261 // Elements in this vector can safely be purged in low memory conditions.
262 Vector<ImageInfo> m_imageInfoCache;
263 #endif // USE_IOSURFACE_FOR_2D_CANVAS
205 }; 264 };
206 265
207 } // namespace blink 266 } // namespace blink
208 267
209 #endif 268 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698