123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- // Copyright 2015 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
- #define GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
- #include <vector>
- #import "base/mac/scoped_nsobject.h"
- #include "base/memory/weak_ptr.h"
- #include "gpu/ipc/service/command_buffer_stub.h"
- #include "gpu/ipc/service/image_transport_surface.h"
- #include "ui/gfx/ca_layer_result.h"
- #include "ui/gfx/presentation_feedback.h"
- #include "ui/gl/gl_bindings.h"
- #include "ui/gl/gl_surface.h"
- #include "ui/gl/gpu_switching_observer.h"
- #if defined(USE_EGL)
- #include "ui/gl/gl_surface_egl.h"
- #endif
- @class CAContext;
- @class CALayer;
- namespace ui {
- class CALayerTreeCoordinator;
- struct CARendererLayerParams;
- }
- namespace gl {
- class GLFence;
- }
- namespace gpu {
- // ImageTransportSurfaceOverlayMac is used by the validating command decoder
- // and ImageTransportSurfaceOverlayMacEGL is used by the passthrough command
- // decoder.
- // Once the validating command decoder is removed,
- // ImageTransportSurfaceOverlayMac can be removed.
- class ImageTransportSurfaceOverlayMac : public gl::GLSurface,
- public ui::GpuSwitchingObserver {
- public:
- explicit ImageTransportSurfaceOverlayMac(
- base::WeakPtr<ImageTransportSurfaceDelegate> delegate);
- // GLSurface implementation
- bool Initialize(gl::GLSurfaceFormat format) override;
- void Destroy() override;
- void PrepareToDestroy(bool have_context) override;
- bool Resize(const gfx::Size& size,
- float scale_factor,
- const gfx::ColorSpace& color_space,
- bool has_alpha) override;
- bool IsOffscreen() override;
- gfx::SwapResult SwapBuffers(
- gl::GLSurface::PresentationCallback callback) override;
- void SwapBuffersAsync(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- gfx::SwapResult PostSubBuffer(
- int x,
- int y,
- int width,
- int height,
- gl::GLSurface::PresentationCallback callback) override;
- void PostSubBufferAsync(
- int x,
- int y,
- int width,
- int height,
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- gfx::SwapResult CommitOverlayPlanes(
- gl::GLSurface::PresentationCallback callback) override;
- void CommitOverlayPlanesAsync(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- bool SupportsPostSubBuffer() override;
- bool SupportsCommitOverlayPlanes() override;
- bool SupportsAsyncSwap() override;
- gfx::Size GetSize() override;
- void* GetHandle() override;
- gl::GLSurfaceFormat GetFormat() override;
- bool OnMakeCurrent(gl::GLContext* context) override;
- bool ScheduleOverlayPlane(
- gl::GLImage* image,
- std::unique_ptr<gfx::GpuFence> gpu_fence,
- const gfx::OverlayPlaneData& overlay_plane_data) override;
- bool ScheduleCALayer(const ui::CARendererLayerParams& params) override;
- bool IsSurfaceless() const override;
- gfx::SurfaceOrigin GetOrigin() const override;
- // ui::GpuSwitchingObserver implementation.
- void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
- void SetCALayerErrorCode(gfx::CALayerResult ca_layer_error_code) override;
- private:
- ~ImageTransportSurfaceOverlayMac() override;
- gfx::SwapResult SwapBuffersInternal(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback);
- void ApplyBackpressure();
- void BufferPresented(gl::GLSurface::PresentationCallback callback,
- const gfx::PresentationFeedback& feedback);
- base::WeakPtr<ImageTransportSurfaceDelegate> delegate_;
- bool use_remote_layer_api_;
- base::scoped_nsobject<CAContext> ca_context_;
- std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
- gfx::Size pixel_size_;
- float scale_factor_;
- gfx::CALayerResult ca_layer_error_code_ = gfx::kCALayerSuccess;
- // A GLFence marking the end of the previous frame, used for applying
- // backpressure.
- uint64_t previous_frame_fence_ = 0;
- // The renderer ID that all contexts made current to this surface should be
- // targeting.
- GLint gl_renderer_id_;
- base::WeakPtrFactory<ImageTransportSurfaceOverlayMac> weak_ptr_factory_;
- };
- #if defined(USE_EGL)
- class ImageTransportSurfaceOverlayMacEGL : public gl::GLSurfaceEGL,
- public ui::GpuSwitchingObserver {
- public:
- ImageTransportSurfaceOverlayMacEGL(
- gl::GLDisplayEGL* display,
- base::WeakPtr<ImageTransportSurfaceDelegate> delegate);
- // GLSurface implementation
- bool Initialize(gl::GLSurfaceFormat format) override;
- void Destroy() override;
- void PrepareToDestroy(bool have_context) override;
- bool Resize(const gfx::Size& size,
- float scale_factor,
- const gfx::ColorSpace& color_space,
- bool has_alpha) override;
- bool IsOffscreen() override;
- gfx::SwapResult SwapBuffers(
- gl::GLSurface::PresentationCallback callback) override;
- void SwapBuffersAsync(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- gfx::SwapResult PostSubBuffer(
- int x,
- int y,
- int width,
- int height,
- gl::GLSurface::PresentationCallback callback) override;
- void PostSubBufferAsync(
- int x,
- int y,
- int width,
- int height,
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- gfx::SwapResult CommitOverlayPlanes(
- gl::GLSurface::PresentationCallback callback) override;
- void CommitOverlayPlanesAsync(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback) override;
- bool SupportsPostSubBuffer() override;
- bool SupportsCommitOverlayPlanes() override;
- bool SupportsAsyncSwap() override;
- gfx::Size GetSize() override;
- void* GetHandle() override;
- gl::GLSurfaceFormat GetFormat() override;
- bool OnMakeCurrent(gl::GLContext* context) override;
- bool ScheduleOverlayPlane(
- gl::GLImage* image,
- std::unique_ptr<gfx::GpuFence> gpu_fence,
- const gfx::OverlayPlaneData& overlay_plane_data) override;
- bool ScheduleCALayer(const ui::CARendererLayerParams& params) override;
- bool IsSurfaceless() const override;
- gfx::SurfaceOrigin GetOrigin() const override;
- // ui::GpuSwitchingObserver implementation.
- void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
- void SetCALayerErrorCode(gfx::CALayerResult ca_layer_error_code) override;
- private:
- ~ImageTransportSurfaceOverlayMacEGL() override;
- gfx::SwapResult SwapBuffersInternal(
- gl::GLSurface::SwapCompletionCallback completion_callback,
- gl::GLSurface::PresentationCallback presentation_callback);
- void ApplyBackpressure();
- void BufferPresented(gl::GLSurface::PresentationCallback callback,
- const gfx::PresentationFeedback& feedback);
- base::WeakPtr<ImageTransportSurfaceDelegate> delegate_;
- bool use_remote_layer_api_;
- base::scoped_nsobject<CAContext> ca_context_;
- std::unique_ptr<ui::CALayerTreeCoordinator> ca_layer_tree_coordinator_;
- gfx::Size pixel_size_;
- float scale_factor_;
- gfx::CALayerResult ca_layer_error_code_ = gfx::kCALayerSuccess;
- // A GLFence marking the end of the previous frame, used for applying
- // backpressure.
- uint64_t previous_frame_fence_ = 0;
- // The renderer ID that all contexts made current to this surface should be
- // targeting.
- GLint gl_renderer_id_;
- base::WeakPtrFactory<ImageTransportSurfaceOverlayMacEGL> weak_ptr_factory_;
- };
- #endif // USE_EGL
- } // namespace gpu
- #endif // GPU_IPC_SERVICE_IMAGE_TRANSPORT_SURFACE_OVERLAY_MAC_H_
|