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 #ifndef SERVICES_GFX_COMPOSITOR_RENDER_RENDER_IMAGE_H_ |
| 6 #define SERVICES_GFX_COMPOSITOR_RENDER_RENDER_IMAGE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include <GLES2/gl2.h> |
| 11 #include <GLES2/gl2extmojo.h> |
| 12 |
| 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/task_runner.h" |
| 17 #include "services/gfx/compositor/render/painting.h" |
| 18 |
| 19 class SkImage; |
| 20 |
| 21 namespace compositor { |
| 22 |
| 23 // Describes an image which can be rendered by the compositor. |
| 24 // |
| 25 // Render objects are thread-safe, immutable, and reference counted via |
| 26 // std::shared_ptr. They have no direct references to the scene graph. |
| 27 // |
| 28 // TODO(jeffbrown): Generalize this beyond mailbox textures. |
| 29 class RenderImage { |
| 30 public: |
| 31 RenderImage(const uint8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM], |
| 32 uint32_t sync_point, |
| 33 uint32_t width, |
| 34 uint32_t height, |
| 35 const scoped_refptr<base::TaskRunner>& task_runner, |
| 36 const base::Closure& release_callback); |
| 37 ~RenderImage(); |
| 38 |
| 39 // Creates a new image backed by a mailbox texture. |
| 40 // When the last reference is released, the associated release task is |
| 41 // posted to the task runner. |
| 42 static std::shared_ptr<RenderImage> FromMailboxTexture( |
| 43 const uint8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM], |
| 44 uint32_t sync_point, |
| 45 uint32_t width, |
| 46 uint32_t height, |
| 47 const scoped_refptr<base::TaskRunner>& task_runner, |
| 48 const base::Closure& release_task) { |
| 49 return std::make_shared<RenderImage>(mailbox_name, sync_point, width, |
| 50 height, task_runner, release_task); |
| 51 } |
| 52 |
| 53 // Gets the dimensions of the image. |
| 54 uint32_t width() const { return width_; } |
| 55 uint32_t height() const { return height_; } |
| 56 |
| 57 // Creates a Skia image from the underlying texture. |
| 58 // Automatically inserts a sync point into the GL command stream. |
| 59 // Returns null if the image could not be created. |
| 60 skia::RefPtr<SkImage> CreateSkImage( |
| 61 const PaintingScope& painting_scope) const; |
| 62 |
| 63 private: |
| 64 GLbyte mailbox_name_[GL_MAILBOX_SIZE_CHROMIUM]; |
| 65 uint32_t const sync_point_; |
| 66 uint32_t const width_; |
| 67 uint32_t const height_; |
| 68 |
| 69 scoped_refptr<base::TaskRunner> const task_runner_; |
| 70 base::Closure const release_task_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(RenderImage); |
| 73 }; |
| 74 |
| 75 } // namespace compositor |
| 76 |
| 77 #endif // SERVICES_GFX_COMPOSITOR_RENDER_RENDER_IMAGE_H_ |
OLD | NEW |