1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_PAINTEDLAYERMLGPU_H 8 #define MOZILLA_GFX_PAINTEDLAYERMLGPU_H 9 10 #include "LayerManagerMLGPU.h" 11 #include "mozilla/layers/ContentHost.h" 12 #include "MLGDeviceTypes.h" 13 #include "nsRegionFwd.h" 14 #include <functional> 15 16 namespace mozilla { 17 namespace layers { 18 19 class TiledLayerBufferComposite; 20 21 class PaintedLayerMLGPU final : public PaintedLayer, public LayerMLGPU { 22 public: 23 explicit PaintedLayerMLGPU(LayerManagerMLGPU* aManager); 24 virtual ~PaintedLayerMLGPU(); 25 26 // Layer AsHostLayer()27 HostLayer* AsHostLayer() override { return this; } AsPaintedLayerMLGPU()28 PaintedLayerMLGPU* AsPaintedLayerMLGPU() override { return this; } GetLayer()29 Layer* GetLayer() override { return this; } 30 bool SetCompositableHost(CompositableHost*) override; 31 CompositableHost* GetCompositableHost() override; 32 void Disconnect() override; 33 bool IsContentOpaque() override; 34 35 // PaintedLayer InvalidateRegion(const nsIntRegion & aRegion)36 void InvalidateRegion(const nsIntRegion& aRegion) override { 37 MOZ_CRASH("PaintedLayerMLGPU can't fill invalidated regions"); 38 } 39 HasComponentAlpha()40 bool HasComponentAlpha() const { return !!mTextureOnWhite; } GetTexture()41 TextureSource* GetTexture() const { return mTexture; } GetTextureOnWhite()42 TextureSource* GetTextureOnWhite() const { 43 MOZ_ASSERT(HasComponentAlpha()); 44 return mTextureOnWhite; 45 } 46 gfx::Point GetDestOrigin() const; 47 GetSamplerMode()48 SamplerMode GetSamplerMode() { 49 // Note that when resamping, we must break the texture coordinates into 50 // no-repeat rects. When we have simple integer translations we can 51 // simply wrap around the edge of the buffer texture. 52 return MayResample() ? SamplerMode::LinearClamp : SamplerMode::LinearRepeat; 53 } 54 55 void SetRenderRegion(LayerIntRegion&& aRegion) override; 56 57 // To avoid sampling issues with complex regions and transforms, we 58 // squash the visible region for PaintedLayers into a single draw 59 // rect. RenderPasses should use this method instead of GetRenderRegion. 60 const LayerIntRegion& GetDrawRects(); 61 62 MOZ_LAYER_DECL_NAME("PaintedLayerMLGPU", TYPE_PAINTED) 63 64 void CleanupCachedResources(); 65 66 protected: 67 void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; 68 bool OnPrepareToRender(FrameBuilder* aBuilder) override; 69 70 // We override this to support tiling. 71 void AssignToView(FrameBuilder* aBuilder, RenderViewMLGPU* aView, 72 Maybe<gfx::Polygon>&& aGeometry) override; 73 74 void AssignHighResTilesToView(FrameBuilder* aBuilder, RenderViewMLGPU* aView, 75 TiledContentHost* aTileHost, 76 const Maybe<gfx::Polygon>& aGeometry); 77 78 // Helper for Assign*TilesToView. 79 void AssignTileBufferToView(FrameBuilder* aBuilder, RenderViewMLGPU* aView, 80 TiledLayerBufferComposite& aTiles, 81 const LayerIntRegion& aCompositeRegion, 82 const Maybe<gfx::Polygon>& aGeometry); 83 84 void CleanupResources(); 85 86 private: 87 RefPtr<ContentHost> mHost; 88 RefPtr<TextureSource> mTexture; 89 RefPtr<TextureSource> mTextureOnWhite; 90 #ifndef MOZ_IGNORE_PAINT_WILL_RESAMPLE 91 LayerIntRegion mDrawRects; 92 #endif 93 gfx::IntPoint mDestOrigin; 94 }; 95 96 } // namespace layers 97 } // namespace mozilla 98 99 #endif 100