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

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

Issue 2125023002: Reland "webgl: use immutable texture for the default FBO." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: m_webGLVersion > WebGL1 (for future versions) Created 4 years, 5 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) 2010, Google Inc. All rights reserved. 2 * Copyright (c) 2010, 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering 66 // Manages a rendering target (framebuffer + attachment) for a canvas. Can publ ish its rendering
67 // results to a WebLayer for compositing. 67 // results to a WebLayer for compositing.
68 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W ebExternalTextureLayerClient { 68 class PLATFORM_EXPORT DrawingBuffer : public RefCounted<DrawingBuffer>, public W ebExternalTextureLayerClient {
69 WTF_MAKE_NONCOPYABLE(DrawingBuffer); 69 WTF_MAKE_NONCOPYABLE(DrawingBuffer);
70 public: 70 public:
71 enum PreserveDrawingBuffer { 71 enum PreserveDrawingBuffer {
72 Preserve, 72 Preserve,
73 Discard 73 Discard
74 }; 74 };
75 enum WebGLVersion {
76 WebGL1,
77 WebGL2,
78 };
75 79
76 static PassRefPtr<DrawingBuffer> create( 80 static PassRefPtr<DrawingBuffer> create(
77 std::unique_ptr<WebGraphicsContext3DProvider>, 81 std::unique_ptr<WebGraphicsContext3DProvider>,
78 const IntSize&, 82 const IntSize&,
79 bool premultipliedAlpha, 83 bool premultipliedAlpha,
80 bool wantAlphaChannel, 84 bool wantAlphaChannel,
81 bool wantDepthBuffer, 85 bool wantDepthBuffer,
82 bool wantStencilBuffer, 86 bool wantStencilBuffer,
83 bool wantAntialiasing, 87 bool wantAntialiasing,
84 PreserveDrawingBuffer); 88 PreserveDrawingBuffer,
89 WebGLVersion);
85 static void forceNextDrawingBufferCreationToFail(); 90 static void forceNextDrawingBufferCreationToFail();
86 91
87 ~DrawingBuffer() override; 92 ~DrawingBuffer() override;
88 93
89 // Destruction will be completed after all mailboxes are released. 94 // Destruction will be completed after all mailboxes are released.
90 void beginDestruction(); 95 void beginDestruction();
91 96
92 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for 97 // Issues a glClear() on all framebuffers associated with this DrawingBuffer . The caller is responsible for
93 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding. 98 // making the context current and setting the clear values and masks. Modifi es the framebuffer binding.
94 void clearFramebuffers(GLbitfield clearMask); 99 void clearFramebuffers(GLbitfield clearMask);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 void addNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) { m_newMai lboxCallback = std::move(closure); } 225 void addNewMailboxCallback(std::unique_ptr<WTF::Closure> closure) { m_newMai lboxCallback = std::move(closure); }
221 226
222 protected: // For unittests 227 protected: // For unittests
223 DrawingBuffer( 228 DrawingBuffer(
224 std::unique_ptr<WebGraphicsContext3DProvider>, 229 std::unique_ptr<WebGraphicsContext3DProvider>,
225 std::unique_ptr<Extensions3DUtil>, 230 std::unique_ptr<Extensions3DUtil>,
226 bool discardFramebufferSupported, 231 bool discardFramebufferSupported,
227 bool wantAlphaChannel, 232 bool wantAlphaChannel,
228 bool premultipliedAlpha, 233 bool premultipliedAlpha,
229 PreserveDrawingBuffer, 234 PreserveDrawingBuffer,
235 WebGLVersion,
230 bool wantsDepth, 236 bool wantsDepth,
231 bool wantsStencil); 237 bool wantsStencil);
232 238
233 bool initialize(const IntSize&, bool useMultisampling); 239 bool initialize(const IntSize&, bool useMultisampling);
234 240
235 private: 241 private:
236 // All parameters necessary to generate the texture that will be passed to 242 // All parameters necessary to generate the texture that will be passed to
237 // prepareMailbox. 243 // prepareMailbox.
238 struct TextureParameters { 244 struct TextureParameters {
239 DISALLOW_NEW(); 245 DISALLOW_NEW();
240 GLenum target = 0; 246 GLenum target = 0;
241 GLenum internalColorFormat = 0; 247 GLenum internalColorFormat = 0;
242 248
243 // The internal color format used when allocating storage for the 249 // The internal color format used when allocating storage for the
244 // texture. This may be different from internalColorFormat if RGB 250 // texture. This may be different from internalColorFormat if RGB
245 // emulation is required. 251 // emulation is required.
246 GLenum creationInternalColorFormat = 0; 252 GLenum creationInternalColorFormat = 0;
247 GLenum colorFormat = 0; 253 GLenum colorFormat = 0;
248 }; 254 };
249 255
250 // If we used CHROMIUM_image as the backing storage for our buffers, 256 // If we used CHROMIUM_image as the backing storage for our buffers,
251 // we need to know the mapping from texture id to image. 257 // we need to know the mapping from texture id to image.
252 struct TextureInfo { 258 struct TextureInfo {
253 DISALLOW_NEW(); 259 DISALLOW_NEW();
254 GLuint textureId = 0; 260 GLuint textureId = 0;
255 GLuint imageId = 0; 261 GLuint imageId = 0;
262 bool immutable = false;
256 263
257 // A GpuMemoryBuffer is a concept that the compositor understands. and 264 // A GpuMemoryBuffer is a concept that the compositor understands. and
258 // is able to operate on. The id is scoped to renderer process. 265 // is able to operate on. The id is scoped to renderer process.
259 GLint gpuMemoryBufferId = -1; 266 GLint gpuMemoryBufferId = -1;
260 267
261 TextureParameters parameters; 268 TextureParameters parameters;
262 }; 269 };
263 270
264 struct MailboxInfo : public RefCounted<MailboxInfo> { 271 struct MailboxInfo : public RefCounted<MailboxInfo> {
265 WTF_MAKE_NONCOPYABLE(MailboxInfo); 272 WTF_MAKE_NONCOPYABLE(MailboxInfo);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ReadbackSkia 321 ReadbackSkia
315 }; 322 };
316 323
317 // Helper function which does a readback from the currently-bound 324 // Helper function which does a readback from the currently-bound
318 // framebuffer into a buffer of a certain size with 4-byte pixels. 325 // framebuffer into a buffer of a certain size with 4-byte pixels.
319 void readBackFramebuffer(unsigned char* pixels, int width, int height, Readb ackOrder, WebGLImageConversion::AlphaOp); 326 void readBackFramebuffer(unsigned char* pixels, int width, int height, Readb ackOrder, WebGLImageConversion::AlphaOp);
320 327
321 // Helper function to flip a bitmap vertically. 328 // Helper function to flip a bitmap vertically.
322 void flipVertically(uint8_t* data, int width, int height); 329 void flipVertically(uint8_t* data, int width, int height);
323 330
324 // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. 331 // Allocate a storage texture if possible. Otherwise, allocate a regular tex ture.
325 // By default, alignment is 4, the OpenGL default setting. 332 void allocateConditionallyImmutableTexture(GLenum target, GLenum internalfor mat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type);
326 void texImage2DResourceSafe(GLenum target, GLint level, GLenum internalforma t, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, GLin t alignment = 4);
327 // Allocate buffer storage to be sent to compositor using either texImage2D or CHROMIUM_image based on available support. 333 // Allocate buffer storage to be sent to compositor using either texImage2D or CHROMIUM_image based on available support.
328 void deleteChromiumImageForTexture(TextureInfo*); 334 void deleteChromiumImageForTexture(TextureInfo*);
329 335
330 // If RGB emulation is required, then the CHROMIUM image's alpha channel 336 // If RGB emulation is required, then the CHROMIUM image's alpha channel
331 // must be immediately cleared after it is bound to a texture. Nothing 337 // must be immediately cleared after it is bound to a texture. Nothing
332 // should be allowed to change the alpha channel after this. 338 // should be allowed to change the alpha channel after this.
333 void clearChromiumImageAlpha(const TextureInfo&); 339 void clearChromiumImageAlpha(const TextureInfo&);
334 340
335 // Tries to create a CHROMIUM_image backed texture if 341 // Tries to create a CHROMIUM_image backed texture if
336 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure, 342 // RuntimeEnabledFeatures::webGLImageChromiumEnabled() is true. On failure,
(...skipping 14 matching lines...) Expand all
351 // renderbuffer, which is resolved before any read operations or swaps. 357 // renderbuffer, which is resolved before any read operations or swaps.
352 bool wantExplicitResolve(); 358 bool wantExplicitResolve();
353 359
354 // Whether the WebGL client wants a depth or stencil buffer. 360 // Whether the WebGL client wants a depth or stencil buffer.
355 bool wantDepthOrStencil(); 361 bool wantDepthOrStencil();
356 362
357 // The format to use when creating a multisampled renderbuffer. 363 // The format to use when creating a multisampled renderbuffer.
358 GLenum getMultisampledRenderbufferFormat(); 364 GLenum getMultisampledRenderbufferFormat();
359 365
360 const PreserveDrawingBuffer m_preserveDrawingBuffer; 366 const PreserveDrawingBuffer m_preserveDrawingBuffer;
367 const WebGLVersion m_webGLVersion;
361 bool m_scissorEnabled = false; 368 bool m_scissorEnabled = false;
362 GLuint m_texture2DBinding = 0; 369 GLuint m_texture2DBinding = 0;
363 GLuint m_drawFramebufferBinding = 0; 370 GLuint m_drawFramebufferBinding = 0;
364 GLuint m_readFramebufferBinding = 0; 371 GLuint m_readFramebufferBinding = 0;
365 GLuint m_renderbufferBinding = 0; 372 GLuint m_renderbufferBinding = 0;
366 GLenum m_activeTextureUnit = GL_TEXTURE0; 373 GLenum m_activeTextureUnit = GL_TEXTURE0;
367 GLfloat m_clearColor[4]; 374 GLfloat m_clearColor[4];
368 GLboolean m_colorMask[4]; 375 GLboolean m_colorMask[4];
369 376
370 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; 377 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider;
371 // Lifetime is tied to the m_contextProvider. 378 // Lifetime is tied to the m_contextProvider.
372 gpu::gles2::GLES2Interface* m_gl; 379 gpu::gles2::GLES2Interface* m_gl;
373 std::unique_ptr<Extensions3DUtil> m_extensionsUtil; 380 std::unique_ptr<Extensions3DUtil> m_extensionsUtil;
374 IntSize m_size = { -1, -1 }; 381 IntSize m_size = { -1, -1 };
375 const bool m_discardFramebufferSupported; 382 const bool m_discardFramebufferSupported;
376 const bool m_wantAlphaChannel; 383 const bool m_wantAlphaChannel;
377 const bool m_premultipliedAlpha; 384 const bool m_premultipliedAlpha;
378 bool m_hasImplicitStencilBuffer = false; 385 bool m_hasImplicitStencilBuffer = false;
386 bool m_storageTextureSupported = false;
379 struct FrontBufferInfo { 387 struct FrontBufferInfo {
380 TextureInfo texInfo; 388 TextureInfo texInfo;
381 WebExternalTextureMailbox mailbox; 389 WebExternalTextureMailbox mailbox;
382 }; 390 };
383 FrontBufferInfo m_frontColorBuffer; 391 FrontBufferInfo m_frontColorBuffer;
384 392
385 std::unique_ptr<WTF::Closure> m_newMailboxCallback; 393 std::unique_ptr<WTF::Closure> m_newMailboxCallback;
386 394
387 // This is used when the user requests either a depth or stencil buffer. 395 // This is used when the user requests either a depth or stencil buffer.
388 GLuint m_depthStencilBuffer = 0; 396 GLuint m_depthStencilBuffer = 0;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 // used to resize the Canvas. 452 // used to resize the Canvas.
445 SkBitmap m_resizingBitmap; 453 SkBitmap m_resizingBitmap;
446 454
447 // Used to flip a bitmap vertically. 455 // Used to flip a bitmap vertically.
448 Vector<uint8_t> m_scanline; 456 Vector<uint8_t> m_scanline;
449 }; 457 };
450 458
451 } // namespace blink 459 } // namespace blink
452 460
453 #endif // DrawingBuffer_h 461 #endif // DrawingBuffer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698