OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_GPU_WEBGRAPHICSCONTEXT3D_GUEST_H_ |
6 #define CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 6 #define CONTENT_RENDERER_GPU_WEBGRAPHICSCONTEXT3D_GUEST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #if defined(ENABLE_GPU) |
| 10 |
9 #include <string> | 11 #include <string> |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
14 #include "content/common/gpu/client/content_gl_context.h" | |
15 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 18 #include "gpu/command_buffer/client/gles2_implementation.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsC
ontext3D.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
19 #include "ui/gfx/gl/gpu_preference.h" | 22 #include "ui/gfx/gl/gpu_preference.h" |
20 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
21 | 24 |
22 #if defined(USE_SKIA) | 25 #if defined(USE_SKIA) |
23 #define FLIP_FRAMEBUFFER_VERTICALLY | 26 #define FLIP_FRAMEBUFFER_VERTICALLY |
24 #endif | 27 #endif |
25 | 28 |
26 class GpuChannelHost; | 29 class GpuChannelHost; |
| 30 class GuestToHostChannel; |
27 | 31 |
28 namespace gpu { | 32 namespace gpu { |
| 33 class TransferBuffer; |
29 namespace gles2 { | 34 namespace gles2 { |
30 class GLES2Implementation; | 35 class GLES2Implementation; |
31 } | 36 } |
32 } | 37 } |
33 | 38 |
34 using WebKit::WebGLId; | 39 using WebKit::WebGLId; |
35 | 40 |
36 using WebKit::WGC3Dchar; | 41 using WebKit::WGC3Dchar; |
37 using WebKit::WGC3Denum; | 42 using WebKit::WGC3Denum; |
38 using WebKit::WGC3Dboolean; | 43 using WebKit::WGC3Dboolean; |
39 using WebKit::WGC3Dbitfield; | 44 using WebKit::WGC3Dbitfield; |
40 using WebKit::WGC3Dint; | 45 using WebKit::WGC3Dint; |
41 using WebKit::WGC3Dsizei; | 46 using WebKit::WGC3Dsizei; |
42 using WebKit::WGC3Duint; | 47 using WebKit::WGC3Duint; |
43 using WebKit::WGC3Dfloat; | 48 using WebKit::WGC3Dfloat; |
44 using WebKit::WGC3Dclampf; | 49 using WebKit::WGC3Dclampf; |
45 using WebKit::WGC3Dintptr; | 50 using WebKit::WGC3Dintptr; |
46 using WebKit::WGC3Dsizeiptr; | 51 using WebKit::WGC3Dsizeiptr; |
47 | 52 |
48 // TODO(piman): move this logic to the compositor and remove it from the | 53 class WebGraphicsContext3DGuest |
49 // context... | |
50 class WebGraphicsContext3DSwapBuffersClient { | |
51 public: | |
52 virtual ~WebGraphicsContext3DSwapBuffersClient() { } | |
53 virtual void OnViewContextSwapBuffersPosted() = 0; | |
54 virtual void OnViewContextSwapBuffersComplete() = 0; | |
55 virtual void OnViewContextSwapBuffersAborted() = 0; | |
56 }; | |
57 | |
58 class WebGraphicsContext3DCommandBufferImpl | |
59 : public WebKit::WebGraphicsContext3D { | 54 : public WebKit::WebGraphicsContext3D { |
60 public: | 55 public: |
61 WebGraphicsContext3DCommandBufferImpl( | 56 static const int32 kCommandBufferSize = 1024 * 1024; |
62 int surface_id, | 57 static const int32 kTransferBufferSize = 1024 * 1024; |
63 const GURL& active_url, | 58 WebGraphicsContext3DGuest(gpu::CommandBuffer* command_buffer, |
64 const base::WeakPtr<WebGraphicsContext3DSwapBuffersClient>& swap_client); | 59 GuestToHostChannel* channel, |
65 virtual ~WebGraphicsContext3DCommandBufferImpl(); | 60 WebKit::WebView* webview); |
66 | 61 virtual ~WebGraphicsContext3DGuest(); |
67 bool Initialize(const Attributes& attributes); | |
68 | 62 |
69 //---------------------------------------------------------------------- | 63 //---------------------------------------------------------------------- |
70 // WebGraphicsContext3D methods | 64 // WebGraphicsContext3D methods |
71 | 65 |
72 // Must be called after initialize() and before any of the following methods. | |
73 // Permanently binds to the first calling thread. Returns false if the | 66 // Permanently binds to the first calling thread. Returns false if the |
74 // graphics context fails to create. Do not call from more than one thread. | 67 // graphics context fails to create. Do not call from more than one thread. |
75 virtual bool makeContextCurrent(); | 68 virtual bool makeContextCurrent(); |
76 | 69 |
77 virtual int width(); | 70 virtual int width(); |
78 virtual int height(); | 71 virtual int height(); |
79 | 72 |
| 73 virtual void playDead(); |
| 74 |
80 virtual bool isGLES2Compliant(); | 75 virtual bool isGLES2Compliant(); |
81 | 76 |
82 virtual bool setParentContext(WebGraphicsContext3D* parent_context); | 77 virtual bool setParentContext(WebGraphicsContext3D* parent_context); |
83 | 78 |
84 virtual void reshape(int width, int height); | 79 virtual void reshape(int width, int height); |
85 | 80 |
86 virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size); | 81 virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size); |
87 virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size, | 82 virtual bool readBackFramebuffer(unsigned char* pixels, size_t buffer_size, |
88 WebGLId framebuffer, int width, int height); | 83 WebGLId framebuffer, int width, int height); |
89 | 84 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 WGC3Dint yoffset, | 427 WGC3Dint yoffset, |
433 WGC3Dsizei width, | 428 WGC3Dsizei width, |
434 WGC3Dsizei height, | 429 WGC3Dsizei height, |
435 WGC3Denum format, | 430 WGC3Denum format, |
436 WGC3Denum type, | 431 WGC3Denum type, |
437 WGC3Denum access); | 432 WGC3Denum access); |
438 virtual void unmapTexSubImage2DCHROMIUM(const void*); | 433 virtual void unmapTexSubImage2DCHROMIUM(const void*); |
439 | 434 |
440 virtual void setVisibilityCHROMIUM(bool visible); | 435 virtual void setVisibilityCHROMIUM(bool visible); |
441 | 436 |
442 virtual void setMemoryAllocationChangedCallbackCHROMIUM( | |
443 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback); | |
444 | |
445 virtual void copyTextureToParentTextureCHROMIUM( | 437 virtual void copyTextureToParentTextureCHROMIUM( |
446 WebGLId texture, WebGLId parentTexture); | 438 WebGLId texture, WebGLId parentTexture); |
447 | 439 |
448 virtual void rateLimitOffscreenContextCHROMIUM(); | 440 virtual void rateLimitOffscreenContextCHROMIUM(); |
449 | 441 |
450 virtual WebKit::WebString getRequestableExtensionsCHROMIUM(); | 442 virtual WebKit::WebString getRequestableExtensionsCHROMIUM(); |
451 virtual void requestExtensionCHROMIUM(const char*); | 443 virtual void requestExtensionCHROMIUM(const char*); |
452 | 444 |
453 virtual void blitFramebufferCHROMIUM( | 445 virtual void blitFramebufferCHROMIUM( |
454 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, | 446 WGC3Dint srcX0, WGC3Dint srcY0, WGC3Dint srcX1, WGC3Dint srcY1, |
455 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, | 447 WGC3Dint dstX0, WGC3Dint dstY0, WGC3Dint dstX1, WGC3Dint dstY1, |
456 WGC3Dbitfield mask, WGC3Denum filter); | 448 WGC3Dbitfield mask, WGC3Denum filter); |
457 virtual void renderbufferStorageMultisampleCHROMIUM( | 449 virtual void renderbufferStorageMultisampleCHROMIUM( |
458 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, | 450 WGC3Denum target, WGC3Dsizei samples, WGC3Denum internalformat, |
459 WGC3Dsizei width, WGC3Dsizei height); | 451 WGC3Dsizei width, WGC3Dsizei height); |
460 | 452 |
461 virtual WebKit::WebString getTranslatedShaderSourceANGLE(WebGLId shader); | 453 virtual WebKit::WebString getTranslatedShaderSourceANGLE(WebGLId shader); |
462 | 454 |
463 ContentGLContext* context() { return context_; } | |
464 | |
465 virtual void setContextLostCallback( | 455 virtual void setContextLostCallback( |
466 WebGraphicsContext3D::WebGraphicsContextLostCallback* callback); | 456 WebGraphicsContext3D::WebGraphicsContextLostCallback* callback); |
467 virtual WGC3Denum getGraphicsResetStatusARB(); | 457 virtual WGC3Denum getGraphicsResetStatusARB(); |
468 | 458 |
469 virtual void setErrorMessageCallback( | |
470 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* callback); | |
471 | |
472 virtual void setSwapBuffersCompleteCallbackCHROMIUM( | 459 virtual void setSwapBuffersCompleteCallbackCHROMIUM( |
473 WebGraphicsContext3D:: | 460 WebGraphicsContext3D:: |
474 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); | 461 WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); |
475 | 462 |
476 virtual void texImageIOSurface2DCHROMIUM( | 463 virtual void texImageIOSurface2DCHROMIUM( |
477 WGC3Denum target, WGC3Dint width, WGC3Dint height, | 464 WGC3Denum target, WGC3Dint width, WGC3Dint height, |
478 WGC3Duint ioSurfaceId, WGC3Duint plane); | 465 WGC3Duint ioSurfaceId, WGC3Duint plane); |
479 | 466 |
480 virtual void texStorage2DEXT( | 467 virtual void texStorage2DEXT( |
481 WGC3Denum target, WGC3Dint levels, WGC3Duint internalformat, | 468 WGC3Denum target, WGC3Dint levels, WGC3Duint internalformat, |
482 WGC3Dint width, WGC3Dint height); | 469 WGC3Dint width, WGC3Dint height); |
483 | 470 |
484 ContentGLContext* content_gl_context() const { return context_; } | |
485 | |
486 protected: | |
487 #if WEBKIT_USING_SKIA | |
488 virtual GrGLInterface* onCreateGrGLInterface(); | |
489 #endif | |
490 | |
491 private: | 471 private: |
| 472 friend class GuestToHostChannel; |
492 // Initialize the underlying GL context. May be called multiple times; second | 473 // Initialize the underlying GL context. May be called multiple times; second |
493 // and subsequent calls are ignored. Must be called from the thread that is | 474 // and subsequent calls are ignored. Must be called from the thread that is |
494 // going to use this object to issue GL commands (which might not be the main | 475 // going to use this object to issue GL commands (which might not be the main |
495 // thread). | 476 // thread). |
496 bool MaybeInitializeGL(); | 477 bool MaybeInitializeGL(); |
497 | 478 |
498 // SwapBuffers callback. | 479 // SwapBuffers callback. |
499 void OnSwapBuffersComplete(); | 480 void OnSwapBuffersComplete(); |
500 virtual void OnContextLost(ContentGLContext::ContextLostReason reason); | |
501 virtual void OnErrorMessage(const std::string& message, int id); | |
502 | 481 |
503 // Check if we should call into the swap client. We can only do that on the | 482 GuestToHostChannel* channel_; |
504 // main thread. | |
505 bool ShouldUseSwapClient(); | |
506 | |
507 // MemoryAllocationChanged callback. | |
508 void OnMemoryAllocationChanged(const GpuMemoryAllocation& allocation); | |
509 | 483 |
510 bool initialize_failed_; | 484 bool initialize_failed_; |
511 | 485 |
512 // The context we use for OpenGL rendering. | 486 // State needed by MaybeInitializeGL. |
513 ContentGLContext* context_; | 487 bool render_directly_to_web_view_; |
514 // The GLES2Implementation we use for OpenGL rendering. | |
515 gpu::gles2::GLES2Implementation* gl_; | |
516 | 488 |
517 // State needed by MaybeInitializeGL. | 489 // Context Lost |
518 GpuChannelHost* host_; | 490 void OnContextLost(); |
519 int32 surface_id_; | |
520 GURL active_url_; | |
521 base::WeakPtr<WebGraphicsContext3DSwapBuffersClient> swap_client_; | |
522 | 491 |
523 WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* | 492 // If rendering directly to WebView, weak pointer to it. |
524 memory_allocation_changed_callback_; | 493 // This is only set when the context is bound to the main thread. |
| 494 WebKit::WebView* web_view_; |
525 | 495 |
526 WebGraphicsContext3D::WebGraphicsContextLostCallback* context_lost_callback_; | 496 WebGraphicsContext3D::WebGraphicsContextLostCallback* context_lost_callback_; |
527 WGC3Denum context_lost_reason_; | 497 WGC3Denum context_lost_reason_; |
528 | 498 |
529 WebGraphicsContext3D::WebGraphicsErrorMessageCallback* | |
530 error_message_callback_; | |
531 | |
532 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* | 499 WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* |
533 swapbuffers_complete_callback_; | 500 swapbuffers_complete_callback_; |
534 | 501 |
535 WebKit::WebGraphicsContext3D::Attributes attributes_; | 502 WebKit::WebGraphicsContext3D::Attributes attributes_; |
536 gfx::GpuPreference gpu_preference_; | |
537 int cached_width_, cached_height_; | 503 int cached_width_, cached_height_; |
| 504 bool dead_; |
538 | 505 |
539 // For tracking which FBO is bound. | 506 // For tracking which FBO is bound. |
540 WebGLId bound_fbo_; | 507 WebGLId bound_fbo_; |
541 | 508 |
542 // Errors raised by synthesizeGLError(). | 509 // Errors raised by synthesizeGLError(). |
543 std::vector<WGC3Denum> synthetic_errors_; | 510 std::vector<WGC3Denum> synthetic_errors_; |
544 | 511 |
545 base::WeakPtrFactory<WebGraphicsContext3DCommandBufferImpl> weak_ptr_factory_; | 512 scoped_ptr<gpu::CommandBuffer> command_buffer_; |
| 513 |
| 514 scoped_ptr<gpu::gles2::GLES2CmdHelper> gles2_helper_; |
| 515 |
| 516 scoped_ptr<gpu::TransferBuffer> transfer_buffer_; |
| 517 |
| 518 scoped_ptr<gpu::gles2::GLES2Implementation> gl_; |
| 519 |
| 520 base::WeakPtrFactory<WebGraphicsContext3DGuest> weak_ptr_factory_; |
546 | 521 |
547 #ifdef FLIP_FRAMEBUFFER_VERTICALLY | 522 #ifdef FLIP_FRAMEBUFFER_VERTICALLY |
548 std::vector<uint8> scanline_; | 523 scoped_array<uint8> scanline_; |
549 void FlipVertically(uint8* framebuffer, | 524 void FlipVertically(uint8* framebuffer, |
550 unsigned int width, | 525 unsigned int width, |
551 unsigned int height); | 526 unsigned int height); |
552 #endif | 527 #endif |
| 528 |
553 }; | 529 }; |
554 | 530 |
555 #endif // CONTENT_COMMON_GPU_CLIENT_WEBGRAPHICSCONTEXT3D_COMMAND_BUFFER_IMPL_H_ | 531 #endif // defined(ENABLE_GPU) |
| 532 #endif // CONTENT_RENDERER_GPU_WEBGRAPHICSCONTEXT3D_GUEST_H_ |
OLD | NEW |