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

Side by Side Diff: sky/compositor/resource_manager.cc

Issue 740923002: Add a simple compositor for Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address reviewer comments Created 6 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "sky/compositor/resource_manager.h"
6
7 #ifndef GL_GLEXT_PROTOTYPES
8 #define GL_GLEXT_PROTOTYPES
9 #endif
10
11 #include "base/logging.h"
12 #include "gpu/GLES2/gl2chromium.h"
13 #include "gpu/GLES2/gl2extchromium.h"
14 #include "mojo/converters/geometry/geometry_type_converters.h"
15 #include "mojo/gpu/gl_context.h"
16 #include "mojo/gpu/gl_texture.h"
17 #include "mojo/public/c/gles2/gles2.h"
18 #include "sky/compositor/layer.h"
19
20 namespace sky {
21
22 ResourceManager::ResourceManager(base::WeakPtr<mojo::GLContext> gl_context)
23 : gl_context_(gl_context), next_resource_id_(0) {
24 }
25
26 ResourceManager::~ResourceManager() {
27 }
28
29 scoped_ptr<mojo::GLTexture> ResourceManager::CreateTexture(
30 const gfx::Size& size) {
31 gl_context_->MakeCurrent();
32 return make_scoped_ptr(new mojo::GLTexture(
33 gl_context_, mojo::TypeConverter<mojo::Size, gfx::Size>::Convert(size)));
34 }
35
36 mojo::TransferableResourcePtr ResourceManager::CreateTransferableResource(
37 Layer* layer) {
38 scoped_ptr<mojo::GLTexture> texture = layer->GetTexture();
39 mojo::Size size = texture->size();
40
41 gl_context_->MakeCurrent();
42 glBindTexture(GL_TEXTURE_2D, texture->texture_id());
43 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM];
44 glGenMailboxCHROMIUM(mailbox);
45 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox);
46 GLuint sync_point = glInsertSyncPointCHROMIUM();
47
48 mojo::TransferableResourcePtr resource = mojo::TransferableResource::New();
49 resource->id = next_resource_id_++;
50 resource_to_texture_map_[resource->id] = texture.release();
51 resource->format = mojo::RESOURCE_FORMAT_RGBA_8888;
52 resource->filter = GL_LINEAR;
53 resource->size = size.Clone();
54 resource->is_repeated = false;
55 resource->is_software = false;
56
57 mojo::MailboxHolderPtr mailbox_holder = mojo::MailboxHolder::New();
58 mailbox_holder->mailbox = mojo::Mailbox::New();
59 for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i)
60 mailbox_holder->mailbox->name.push_back(mailbox[i]);
61 mailbox_holder->texture_target = GL_TEXTURE_2D;
62 mailbox_holder->sync_point = sync_point;
63 resource->mailbox_holder = mailbox_holder.Pass();
64
65 return resource.Pass();
66 }
67
68 void ResourceManager::ReturnResources(
69 mojo::Array<mojo::ReturnedResourcePtr> resources) {
70 DCHECK(resources.size());
71
72 gl_context_->MakeCurrent();
73 for (size_t i = 0u; i < resources.size(); ++i) {
74 mojo::ReturnedResourcePtr resource = resources[i].Pass();
75 DCHECK_EQ(1, resource->count);
76 glWaitSyncPointCHROMIUM(resource->sync_point);
77 mojo::GLTexture* texture = resource_to_texture_map_[resource->id];
78 DCHECK_NE(0u, texture->texture_id());
79 resource_to_texture_map_.erase(resource->id);
80 // TODO(abarth): Consider recycling the texture.
81 delete texture;
82 }
83 }
84
85 } // namespace examples
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698