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

Side by Side Diff: athena/content/content_proxy.h

Issue 591693002: Creating PNG images from web content to be used by OverviewMode navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed comment Created 6 years, 2 months 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 | « athena/content/app_activity_registry.h ('k') | athena/content/content_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ATHENA_CONTENT_CONTENT_PROXY_H_ 5 #ifndef ATHENA_CONTENT_CONTENT_PROXY_H_
6 #define ATHENA_CONTENT_CONTENT_PROXY_H_ 6 #define ATHENA_CONTENT_CONTENT_PROXY_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/ref_counted_memory.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
10 #include "ui/gfx/image/image_skia.h" 12 #include "ui/gfx/image/image_skia.h"
11 13
12 namespace aura {
13 class Window;
14 }
15
16 namespace views { 14 namespace views {
17 class View;
18 class WebView; 15 class WebView;
19 } 16 }
20 17
21 typedef unsigned int SkColor;
22
23 namespace athena { 18 namespace athena {
24 19
25 class Activity; 20 class Activity;
26 class AppActivity; 21 class ProxyImageData;
27 class AppActivityProxy;
28 class WebActivity;
29 22
30 // This object creates and holds proxy content which gets shown instead of the 23 // This object creates and holds proxy content which gets shown instead of the
31 // actual web content, generated from the passed |web_view|. 24 // actual web content, generated from the passed |web_view|.
32 // The created |proxy_content_| will be destroyed with the destruction of this 25 // The created |proxy_content_| will be destroyed with the destruction of this
33 // object. 26 // object.
34 // Calling EvictContent() will release the rendered content and replaces it with 27 // Calling EvictContent() will release the rendered content.
35 // a solid color to save memory. 28 // When ContentGetsDestroyed() gets called, the old view will be made visible
36 // Calling Reparent() will transfer the |proxy_content_| to an ActivityProxy, 29 // and then the link to the |web_view_| will get severed.
37 // allowing the destruction of the original activity / content.
38 class ContentProxy { 30 class ContentProxy {
39 public: 31 public:
40 // Creates the object by creating a sized down |web_view| layer and making it 32 // Creates the object by creating a sized down |web_view| layer and making it
41 // visible inside |activity|'s window. 33 // visible inside |activity|'s window.
42 ContentProxy(views::WebView* web_view, Activity* activity); 34 ContentProxy(views::WebView* web_view, Activity* activity);
43 // TODO(skuhne): Add a function to create this object from a passed PNG, so 35 // TODO(skuhne): Add a function to create this object from a passed PNG, so
44 // that we can create it from a session restore. 36 // that we can create it from a session restore.
45 37
46 // With the destruction of the object, the layer should get destroyed and the 38 // With the destruction of the object, the layer should get destroyed and the
47 // content should become visible again. 39 // content should become visible again.
48 virtual ~ContentProxy(); 40 virtual ~ContentProxy();
49 41
50 // Called when the content will get unloaded. 42 // Called when the content will get unloaded.
51 void ContentWillUnload(); 43 void ContentWillUnload();
52 44
53 // Can be called to save resources by creating a layer with a solid color 45 // Can be called to save resources by creating a layer with a solid color
54 // instead of creating a content image layer. 46 // instead of creating a content image layer.
55 // Note: Currently the GPU does create a full size texture and fills it with 47 // Note: Currently the GPU does create a full size texture and fills it with
56 // the given color - so there isn't really memory savings yet. 48 // the given color - so there isn't really memory savings yet.
57 void EvictContent(); 49 void EvictContent();
58 50
59 // Get the image of the content. If there is no image known, an empty image 51 // Get the image of the content. If there is no image known, an empty image
60 // will be returned. 52 // will be returned.
61 gfx::ImageSkia GetContentImage(); 53 gfx::ImageSkia GetContentImage();
62 54
63 // Transfer the owned |proxy_content_| to the |new_parent_window|. 55 // The content is about to get destroyed by its creator.
64 // Once called, the |web_view_| will be made visible again and the connection
65 // to it will be removed since the old activity might go away.
66 // Note: This function should only be used by AppActivity. 56 // Note: This function should only be used by AppActivity.
67 void Reparent(aura::Window* new_parent_window); 57 void OnPreContentDestroyed();
68 58
69 private: 59 private:
70 // Make the original (web)content visible. This call should only be paired 60 // Make the original (web)content visible. This call should only be paired
71 // with HideOriginalContent. 61 // with HideOriginalContent.
72 void ShowOriginalContent(); 62 void ShowOriginalContent();
73 63
74 // Make the content invisible. This call should only be paired with 64 // Make the content invisible. This call should only be paired with
75 // MakeVisible. 65 // MakeVisible.
76 void HideOriginalContent(); 66 void HideOriginalContent();
77 67
78 // Creates proxy content from |web_view_|. If there is no |web_view_|, 68 // Creates proxy content from |web_view_|.
79 // a solid |proxy_content_| with |background_color_| will be created.
80 void CreateProxyContent(); 69 void CreateProxyContent();
81 70
82 // Creates a solid |proxy_content_| with |background_color_|. 71 // Creates an image from the current content.
83 void CreateSolidProxyContent(); 72 bool CreateContentImage();
84 73
85 // Show the |proxy_content_| in the current |window_|. 74 // Called once the content was read back.
86 void ShowProxyContent(); 75 void OnContentImageRead(bool success, const SkBitmap& bitmap);
87 76
88 // Removes the |proxy_content_| from the window again. 77 // Called once the image content has been converted to PNG.
89 void HideProxyContent(); 78 void OnContentImageEncodeComplete(scoped_refptr<ProxyImageData> image);
90 79
91 // The web view which is associated with this object. It will be NULL after 80 // The web view which was passed on creation and is associated with this
92 // the object got called with Reparent(), since the Activity which owns it 81 // object. It will be shown when OnPreContentDestroyed() gets called and then
93 // will be destroyed shortly after. 82 // set to NULL. The ownership remains with the creator.
94 views::WebView* web_view_; 83 views::WebView* web_view_;
95 84
96 // The window which shows our |proxy_content_|, 85 // While we are doing our PNG encode, we keep the read back image to have
97 aura::Window* window_; 86 // something which we can pass back to the overview mode. (It would make no
87 // sense to the user to see that more recent windows get painted later than
88 // older ones).
89 gfx::ImageSkia raw_image_;
98 90
99 // The background color to use when evicted. 91 // True if the content is visible.
100 SkColor background_color_; 92 bool content_visible_;
101 93
102 // If we have an image (e.g. from session restore) it is stored here. 94 // True if the content is loaded and needs a re-layout when it gets shown
103 gfx::ImageSkia image_; 95 // again.
104
105 // True if the content is loaded.
106 bool content_loaded_; 96 bool content_loaded_;
107 97
108 // The content representation which which will be presented to the user. It 98 // True if a content creation was kicked off once. This ensures that the
109 // will either contain a shrunken down image of the |web_view| content or a 99 // function is never called twice.
110 // solid |background_color_|. 100 bool content_creation_called_;
111 scoped_ptr<views::View> proxy_content_; 101
102 // The PNG image data.
103 scoped_refptr<base::RefCountedBytes> png_data_;
104
105 // Creating an encoded image from the content will be asynchronous. Use a
106 // weakptr for the callback to make sure that the read back / encoding image
107 // completion callback does not trigger on a destroyed ContentProxy.
108 base::WeakPtrFactory<ContentProxy> proxy_content_to_image_factory_;
112 109
113 DISALLOW_COPY_AND_ASSIGN(ContentProxy); 110 DISALLOW_COPY_AND_ASSIGN(ContentProxy);
114 }; 111 };
115 112
116 } // namespace athena 113 } // namespace athena
117 114
118 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_ 115 #endif // ATHENA_CONTENT_CONTENT_PROXY_H_
OLDNEW
« no previous file with comments | « athena/content/app_activity_registry.h ('k') | athena/content/content_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698