image_decode_accelerator_worker.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2018 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. #ifndef GPU_IPC_SERVICE_IMAGE_DECODE_ACCELERATOR_WORKER_H_
  5. #define GPU_IPC_SERVICE_IMAGE_DECODE_ACCELERATOR_WORKER_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <memory>
  9. #include <vector>
  10. #include "base/callback.h"
  11. #include "gpu/config/gpu_info.h"
  12. #include "third_party/skia/include/core/SkImageInfo.h"
  13. #include "ui/gfx/buffer_types.h"
  14. #include "ui/gfx/geometry/size.h"
  15. #include "ui/gfx/gpu_memory_buffer.h"
  16. namespace gpu {
  17. // An ImageDecodeAcceleratorWorker handles the actual hardware-accelerated
  18. // decode of an image of a specific type (e.g., JPEG, WebP, etc.).
  19. class ImageDecodeAcceleratorWorker {
  20. public:
  21. virtual ~ImageDecodeAcceleratorWorker() {}
  22. // Encapsulates the result of a decode request.
  23. struct DecodeResult {
  24. gfx::GpuMemoryBufferHandle handle;
  25. gfx::Size visible_size;
  26. gfx::BufferFormat buffer_format;
  27. size_t buffer_byte_size;
  28. SkYUVColorSpace yuv_color_space;
  29. };
  30. using CompletedDecodeCB =
  31. base::OnceCallback<void(std::unique_ptr<DecodeResult>)>;
  32. // Returns the profiles supported by this worker. A worker is allowed to
  33. // support multiple image types (e.g., JPEG and WebP), but only one
  34. // ImageDecodeAcceleratorSupportedProfile should be returned per supported
  35. // image type. If the supported profiles can't be computed, an empty vector is
  36. // returned.
  37. virtual std::vector<ImageDecodeAcceleratorSupportedProfile>
  38. GetSupportedProfiles() = 0;
  39. // Enqueue a decode of |encoded_data|. The |decode_cb| is called
  40. // asynchronously when the decode completes passing as parameter DecodeResult
  41. // containing a reference to the decoded image (in the form of a
  42. // gfx::GpuMemoryBufferHandle). The |buffer_byte_size| is the size of the
  43. // buffer that |handle| refers to. For a successful decode, implementations
  44. // must guarantee that |visible_size| == |output_size|.
  45. //
  46. // If the decode fails, |decode_cb| is called asynchronously with nullptr.
  47. // Callbacks should be called in the order that this method is called.
  48. virtual void Decode(std::vector<uint8_t> encoded_data,
  49. const gfx::Size& output_size,
  50. CompletedDecodeCB decode_cb) = 0;
  51. };
  52. } // namespace gpu
  53. #endif // GPU_IPC_SERVICE_IMAGE_DECODE_ACCELERATOR_WORKER_H_