summaryrefslogtreecommitdiff
path: root/chromium/components/viz/common/resources/resource.cc
blob: 2597163d010c3ba61c44b4c6420b8efda3bd9d71 (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/viz/common/resources/resource.h"

#include "build/build_config.h"
#include "components/viz/common/quads/shared_bitmap.h"

namespace viz {
namespace internal {

Resource::Resource(const gfx::Size& size,
                   ResourceType type,
                   ResourceFormat format,
                   const gfx::ColorSpace& color_space)
    : locked_for_external_use(false),
      marked_for_deletion(false),
      read_lock_fences_enabled(false),
      has_shared_bitmap_id(false),
      is_overlay_candidate(false),
#if defined(OS_ANDROID)
      is_backed_by_surface_texture(false),
      wants_promotion_hint(false),
#endif
      size(size),
      type(type),
      format(format),
      color_space(color_space) {
}

Resource::Resource(Resource&& other) = default;
Resource::~Resource() = default;
Resource& Resource::operator=(Resource&& other) = default;

void Resource::SetSharedBitmap(SharedBitmap* bitmap) {
  DCHECK(bitmap);
  DCHECK(bitmap->pixels());
  shared_bitmap = bitmap;
  pixels = bitmap->pixels();
  has_shared_bitmap_id = true;
  shared_bitmap_id = bitmap->id();
}

void Resource::SetLocallyUsed() {
  synchronization_state_ = LOCALLY_USED;
  sync_token_.Clear();
}

void Resource::SetSynchronized() {
  synchronization_state_ = SYNCHRONIZED;
}

void Resource::UpdateSyncToken(const gpu::SyncToken& sync_token) {
  DCHECK(is_gpu_resource_type());
  // An empty sync token may be used if commands are guaranteed to have run on
  // the gpu process or in case of context loss.
  sync_token_ = sync_token;
  synchronization_state_ = sync_token.HasData() ? NEEDS_WAIT : SYNCHRONIZED;
}

int8_t* Resource::GetSyncTokenData() {
  return sync_token_.GetData();
}

bool Resource::ShouldWaitSyncToken() const {
  return synchronization_state_ == NEEDS_WAIT;
}

}  // namespace internal
}  // namespace viz