1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_H_ 6 #define COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_H_ 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #include "base/hash/hash.h" 12 #include "base/macros.h" 13 #include "base/trace_event/memory_allocator_dump.h" 14 #include "components/viz/common/resources/resource_format.h" 15 #include "components/viz/common/viz_common_export.h" 16 #include "gpu/command_buffer/common/mailbox.h" 17 #include "ui/gfx/geometry/size.h" 18 19 namespace viz { 20 using SharedBitmapId = gpu::Mailbox; 21 22 struct SharedBitmapIdHash { operatorSharedBitmapIdHash23 size_t operator()(const SharedBitmapId& id) const { 24 return base::FastHash(base::as_bytes(base::make_span(id.name))); 25 } 26 }; 27 28 // An object returned by the SharedBitmapGenerator that exposes the 29 // pixels for a SharedBitmapId. They are exposed via a class so that 30 // this object (or its subclass) can ensure the lifetime of the pixels 31 // is not cut short. While this object is kept alive, the pixels should 32 // remain valid. 33 class VIZ_COMMON_EXPORT SharedBitmap { 34 public: 35 static SharedBitmapId GenerateId(); 36 37 explicit SharedBitmap(uint8_t* pixels); 38 virtual ~SharedBitmap(); 39 pixels()40 uint8_t* pixels() { return pixels_; } 41 42 private: 43 uint8_t* pixels_; 44 45 DISALLOW_COPY_AND_ASSIGN(SharedBitmap); 46 }; 47 48 } // namespace viz 49 50 #endif // COMPONENTS_VIZ_COMMON_RESOURCES_SHARED_BITMAP_H_ 51