Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: mojo/gpu/texture_cache.cc

Issue 1533753002: Remove TextureCache and TextureUploader. (Closed) Base URL: git@github.com:domokit/mojo.git@cl-2a
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/gpu/texture_cache.h ('k') | mojo/gpu/texture_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 GL_GLEXT_PROTOTYPES
6 #define GL_GLEXT_PROTOTYPES
7 #endif
8 #include <GLES2/gl2extmojo.h>
9
10 #include "mojo/gpu/gl_context.h"
11 #include "mojo/gpu/gl_texture.h"
12 #include "mojo/gpu/texture_cache.h"
13 #include "mojo/services/geometry/interfaces/geometry.mojom.h"
14
15 namespace mojo {
16
17 TextureCache::TextureInfo::TextureInfo() : texture_(), resource_id_(0u) {}
18 TextureCache::TextureInfo::TextureInfo(scoped_ptr<mojo::GLTexture> texture,
19 uint32_t resource_id)
20 : texture_(texture.Pass()), resource_id_(resource_id) {}
21 TextureCache::TextureInfo::~TextureInfo() {}
22
23 TextureCache::TextureCache(base::WeakPtr<mojo::GLContext> gl_context,
24 mojo::ResourceReturnerPtr* out_resource_returner)
25 : gl_context_(gl_context), returner_binding_(this), next_resource_id_(0u) {
26 if (out_resource_returner) {
27 returner_binding_.Bind(GetProxy(out_resource_returner));
28 }
29 }
30
31 TextureCache::~TextureCache() {}
32
33 scoped_ptr<TextureCache::TextureInfo> TextureCache::GetTexture(
34 const mojo::Size& requested_size) {
35 // Sift through our available textures to find one the correct size. If one
36 // exists use it. As we find textures of the wrong size, clean them up.
37 while (!available_textures_.empty()) {
38 // Get the next available texture's resource id.
39 uint32_t available_resource_id = available_textures_.front();
40 available_textures_.pop_front();
41
42 // Get the texture information from the texture map.
43 auto texture_iterator =
44 resource_to_texture_map_.find(available_resource_id);
45 mojo::Size texture_size = texture_iterator->second->size();
46 scoped_ptr<TextureInfo> texture_info(new TextureInfo(
47 texture_iterator->second.Pass(), texture_iterator->first));
48 resource_to_texture_map_.erase(texture_iterator);
49
50 // Get the sync point from the sync point map.
51 auto sync_point_iterator =
52 resource_to_sync_point_map_.find(available_resource_id);
53 int sync_point = sync_point_iterator->second;
54 resource_to_sync_point_map_.erase(sync_point_iterator);
55
56 // If the texture is the right size, use it.
57 if (texture_size.width == requested_size.width &&
58 texture_size.height == requested_size.height) {
59 gl_context_->MakeCurrent();
60 glWaitSyncPointCHROMIUM(sync_point);
61 return texture_info;
62 }
63 }
64
65 // If our context is invalid return an empty scoped ptr.
66 if (!gl_context_) {
67 return scoped_ptr<TextureInfo>();
68 }
69
70 // We couldn't find an existing texture to reuse, create a new one!
71 scoped_ptr<mojo::GLTexture> new_texture(
72 new mojo::GLTexture(gl_context_, requested_size));
73 next_resource_id_++;
74 scoped_ptr<TextureInfo> texture_info(
75 new TextureInfo(new_texture.Pass(), next_resource_id_));
76 return texture_info;
77 }
78
79 void TextureCache::NotifyPendingResourceReturn(
80 uint32_t resource_id,
81 scoped_ptr<mojo::GLTexture> texture) {
82 resource_to_texture_map_[resource_id] = texture.Pass();
83 }
84
85 // mojo::ResourceReturner
86 void TextureCache::ReturnResources(
87 mojo::Array<mojo::ReturnedResourcePtr> resources) {
88 if (!gl_context_) {
89 return;
90 }
91 gl_context_->MakeCurrent();
92 for (size_t i = 0u; i < resources.size(); ++i) {
93 mojo::ReturnedResourcePtr resource = resources[i].Pass();
94 DCHECK_EQ(1, resource->count);
95 auto it = resource_to_texture_map_.find(resource->id);
96 // Ignore the returned resource if we haven't been notified of its pending
97 // return.
98 if (it != resource_to_texture_map_.end()) {
99 available_textures_.push_back(resource->id);
100 resource_to_sync_point_map_[resource->id] = resource->sync_point;
101 }
102 }
103 }
104 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/gpu/texture_cache.h ('k') | mojo/gpu/texture_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698