File: image_decode_accelerator_proxy.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (106 lines) | stat: -rw-r--r-- 4,585 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_IPC_CLIENT_IMAGE_DECODE_ACCELERATOR_PROXY_H_
#define GPU_IPC_CLIENT_IMAGE_DECODE_ACCELERATOR_PROXY_H_

#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "gpu/command_buffer/client/image_decode_accelerator_interface.h"
#include "gpu/ipc/client/gpu_ipc_client_export.h"

namespace gpu {
class GpuChannelHost;

// A client-side interface to schedule hardware-accelerated image decodes on the
// GPU process. This is only supported in OOP-R mode. To use this functionality,
// the renderer should first find out the supported image types (e.g., JPEG,
// WebP, etc.) and profiles (e.g., a maximum size of 8192x8192). This
// information can be obtained from GpuInfo. No decode requests should be sent
// for unsupported image types/profiles.
//
// The actual decode is done asynchronously on the service side, but the client
// can synchronize using a sync token that will be released upon the completion
// of the decode.
//
// To send a decode request, the renderer should:
//
// (1) Create a locked ClientImageTransferCacheEntry without a backing
//     SkPixmap. This entry should not be serialized over the command buffer.
//
// (2) Insert a sync token in the command buffer that is released after the
//     discardable handle's buffer corresponding to the transfer cache entry has
//     been registered.
//
// (3) Call ScheduleImageDecode(). The release count of the sync token from the
//     previous step is passed for the |discardable_handle_release_count|
//     parameter.
//
// (4) Issue a server wait on the sync token returned in step (3).
//
// When the service is done with the decode, a ServiceImageTransferCacheEntry
// will be created/locked with the decoded data and the sync token is released.
//
// Objects of this class are thread-safe.
//
// TODO(andrescj): actually put the decoder's capabilities in GpuInfo.
class GPU_IPC_CLIENT_EXPORT ImageDecodeAcceleratorProxy
    : public ImageDecodeAcceleratorInterface {
 public:
  ImageDecodeAcceleratorProxy(GpuChannelHost* host, int32_t route_id);

  ImageDecodeAcceleratorProxy(const ImageDecodeAcceleratorProxy&) = delete;
  ImageDecodeAcceleratorProxy& operator=(const ImageDecodeAcceleratorProxy&) =
      delete;

  ~ImageDecodeAcceleratorProxy() override;

  // Determines if |image_metadata| corresponds to an image that can be decoded
  // using hardware decode acceleration. The ScheduleImageDecode() method should
  // only be called for images for which IsImageSupported() returns true.
  bool IsImageSupported(
      const cc::ImageHeaderMetadata* image_metadata) const override;

  // Determines if hardware decode acceleration is supported for JPEG images.
  bool IsJpegDecodeAccelerationSupported() const override;

  // Determines if hardware decode acceleration is supported for WebP images.
  bool IsWebPDecodeAccelerationSupported() const override;

  // Schedules a hardware-accelerated image decode on the GPU process. The image
  // in |encoded_data| is decoded and scaled to |output_size|. Upon completion
  // and after the sync token corresponding to
  // |discardable_handle_release_count| has been released, a service-side
  // transfer cache entry will be created with the decoded data using
  // |transfer_cache_entry_id|, |discardable_handle_shm_id|, and
  // |discardable_handle_shm_offset|. The |raster_decoder_command_buffer_id| is
  // used to look up the appropriate command buffer and create the transfer
  // cache entry correctly. Note that it is assumed that
  // |discardable_handle_release_count| is associated to
  // |raster_decoder_command_buffer_id|. Returns a sync token that will be
  // released after the decode is done and the service-side transfer cache entry
  // is created.
  SyncToken ScheduleImageDecode(
      base::span<const uint8_t> encoded_data,
      const gfx::Size& output_size,
      CommandBufferId raster_decoder_command_buffer_id,
      uint32_t transfer_cache_entry_id,
      int32_t discardable_handle_shm_id,
      uint32_t discardable_handle_shm_offset,
      uint64_t discardable_handle_release_count,
      const gfx::ColorSpace& target_color_space,
      bool needs_mips) override;

 private:
  const raw_ptr<GpuChannelHost> host_;
  const int32_t route_id_;

  base::Lock lock_;
  uint64_t next_release_count_ GUARDED_BY(lock_) = 0;
};

}  // namespace gpu

#endif  // GPU_IPC_CLIENT_IMAGE_DECODE_ACCELERATOR_PROXY_H_