OLD | NEW |
| (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 #include "mojo/gpu/texture_uploader.h" | |
6 | |
7 #ifndef GL_GLEXT_PROTOTYPES | |
8 #define GL_GLEXT_PROTOTYPES | |
9 #endif | |
10 | |
11 #include <GLES2/gl2.h> | |
12 #include <GLES2/gl2extmojo.h> | |
13 | |
14 #include "mojo/services/geometry/cpp/geometry_util.h" | |
15 #include "mojo/services/surfaces/cpp/surfaces_utils.h" | |
16 | |
17 namespace mojo { | |
18 | |
19 mojo::FramePtr TextureUploader::GetUploadFrame( | |
20 base::WeakPtr<mojo::GLContext> context, | |
21 uint32_t resource_id, | |
22 const scoped_ptr<mojo::GLTexture>& texture) { | |
23 if (!context) { | |
24 return mojo::FramePtr(); | |
25 } | |
26 | |
27 mojo::Size size = texture->size(); | |
28 | |
29 mojo::FramePtr frame = mojo::Frame::New(); | |
30 frame->resources.resize(0u); | |
31 | |
32 mojo::Rect bounds; | |
33 bounds.width = size.width; | |
34 bounds.height = size.height; | |
35 mojo::PassPtr pass = mojo::CreateDefaultPass(1, bounds); | |
36 pass->quads.resize(0u); | |
37 pass->shared_quad_states.push_back(mojo::CreateDefaultSQS(size)); | |
38 | |
39 context->MakeCurrent(); | |
40 glBindTexture(GL_TEXTURE_2D, texture->texture_id()); | |
41 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM]; | |
42 glGenMailboxCHROMIUM(mailbox); | |
43 glProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox); | |
44 GLuint sync_point = glInsertSyncPointCHROMIUM(); | |
45 | |
46 mojo::TransferableResourcePtr resource = mojo::TransferableResource::New(); | |
47 resource->id = resource_id; | |
48 resource->format = mojo::ResourceFormat::RGBA_8888; | |
49 resource->filter = GL_LINEAR; | |
50 resource->size = size.Clone(); | |
51 mojo::MailboxHolderPtr mailbox_holder = mojo::MailboxHolder::New(); | |
52 mailbox_holder->mailbox = mojo::Mailbox::New(); | |
53 for (int i = 0; i < GL_MAILBOX_SIZE_CHROMIUM; ++i) | |
54 mailbox_holder->mailbox->name.push_back(mailbox[i]); | |
55 mailbox_holder->texture_target = GL_TEXTURE_2D; | |
56 mailbox_holder->sync_point = sync_point; | |
57 resource->mailbox_holder = mailbox_holder.Pass(); | |
58 resource->is_repeated = false; | |
59 resource->is_software = false; | |
60 | |
61 mojo::QuadPtr quad = mojo::Quad::New(); | |
62 quad->material = mojo::Material::TEXTURE_CONTENT; | |
63 | |
64 mojo::RectPtr rect = mojo::Rect::New(); | |
65 rect->width = size.width; | |
66 rect->height = size.height; | |
67 quad->rect = rect.Clone(); | |
68 quad->opaque_rect = rect.Clone(); | |
69 quad->visible_rect = rect.Clone(); | |
70 quad->needs_blending = true; | |
71 quad->shared_quad_state_index = 0u; | |
72 | |
73 mojo::TextureQuadStatePtr texture_state = mojo::TextureQuadState::New(); | |
74 texture_state->resource_id = resource->id; | |
75 texture_state->premultiplied_alpha = true; | |
76 texture_state->uv_top_left = mojo::PointF::New(); | |
77 texture_state->uv_bottom_right = mojo::PointF::New(); | |
78 texture_state->uv_bottom_right->x = 1.f; | |
79 texture_state->uv_bottom_right->y = 1.f; | |
80 texture_state->background_color = mojo::Color::New(); | |
81 texture_state->background_color->rgba = 0; | |
82 for (int i = 0; i < 4; ++i) | |
83 texture_state->vertex_opacity.push_back(1.f); | |
84 texture_state->flipped = false; | |
85 | |
86 frame->resources.push_back(resource.Pass()); | |
87 quad->texture_quad_state = texture_state.Pass(); | |
88 pass->quads.push_back(quad.Pass()); | |
89 | |
90 frame->passes.push_back(pass.Pass()); | |
91 return frame; | |
92 } | |
93 | |
94 } // namespace mojo | |
OLD | NEW |