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

cc / paint / image_provider.cc [blame]

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/paint/image_provider.h"

#include <optional>
#include <utility>

#include "cc/paint/paint_record.h"

namespace cc {

ImageProvider::ScopedResult::ScopedResult() = default;

ImageProvider::ScopedResult::ScopedResult(DecodedDrawImage image)
    : image_(std::move(image)) {}

ImageProvider::ScopedResult::ScopedResult(std::optional<PaintRecord> record)
    : record_(std::move(record)) {}

ImageProvider::ScopedResult::ScopedResult(DecodedDrawImage image,
                                          DestructionCallback callback)
    : image_(std::move(image)), destruction_callback_(std::move(callback)) {}

ImageProvider::ScopedResult::ScopedResult(ScopedResult&& other)
    : image_(std::move(other.image_)),
      record_(std::move(other.record_)),
      destruction_callback_(std::move(other.destruction_callback_)) {}

ImageProvider::ScopedResult& ImageProvider::ScopedResult::operator=(
    ScopedResult&& other) {
  DestroyDecode();

  image_ = std::move(other.image_);
  record_ = std::move(other.record_);
  destruction_callback_ = std::move(other.destruction_callback_);
  return *this;
}

ImageProvider::ScopedResult::~ScopedResult() {
  DestroyDecode();
}

void ImageProvider::ScopedResult::DestroyDecode() {
  if (!destruction_callback_.is_null())
    std::move(destruction_callback_).Run();
}

}  // namespace cc